1/* $Id: elsa.c,v 1.1.1.1 2007/08/03 18:52:35 Exp $
2 *
3 * low level stuff for Elsa isdn cards
4 *
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.
10 *
11 * For changes and modifications please read
12 * Documentation/isdn/HiSax.cert
13 *
14 * Thanks to    Elsa GmbH for documents and information
15 *
16 *              Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
17 *              for ELSA PCMCIA support
18 *
19 */
20
21#include <linux/init.h>
22#include "hisax.h"
23#include "arcofi.h"
24#include "isac.h"
25#include "ipac.h"
26#include "hscx.h"
27#include "isdnl1.h"
28#include <linux/pci.h>
29#include <linux/isapnp.h>
30#include <linux/serial.h>
31#include <linux/serial_reg.h>
32
33extern const char *CardType[];
34
35static const char *Elsa_revision = "$Revision: 1.1.1.1 $";
36static const char *Elsa_Types[] =
37{"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
38 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
39 "PCMCIA-IPAC" };
40
41static const char *ITACVer[] =
42{"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
43 "B1", "A1"};
44
45#define byteout(addr,val) outb(val,addr)
46#define bytein(addr) inb(addr)
47
48#define ELSA_ISAC	0
49#define ELSA_ISAC_PCM	1
50#define ELSA_ITAC	1
51#define ELSA_HSCX	2
52#define ELSA_ALE	3
53#define ELSA_ALE_PCM	4
54#define ELSA_CONTROL	4
55#define ELSA_CONFIG	5
56#define ELSA_START_TIMER 6
57#define ELSA_TRIG_IRQ	7
58
59#define ELSA_PC      1
60#define ELSA_PCC8    2
61#define ELSA_PCC16   3
62#define ELSA_PCF     4
63#define ELSA_PCFPRO  5
64#define ELSA_PCMCIA  6
65#define ELSA_QS1000  7
66#define ELSA_QS3000  8
67#define ELSA_QS1000PCI 9
68#define ELSA_QS3000PCI 10
69#define ELSA_PCMCIA_IPAC 11
70
71/* PCI stuff */
72#define ELSA_PCI_IRQ_MASK	0x04
73
74/* ITAC Registeradressen (only Microlink PC) */
75#define ITAC_SYS	0x34
76#define ITAC_ISEN	0x48
77#define ITAC_RFIE	0x4A
78#define ITAC_XFIE	0x4C
79#define ITAC_SCIE	0x4E
80#define ITAC_STIE	0x46
81
82/***                                                                    ***
83 ***   Makros als Befehle fuer die Kartenregister                       ***
84 ***   (mehrere Befehle werden durch Bit-Oderung kombiniert)            ***
85 ***                                                                    ***/
86
87/* Config-Register (Read) */
88#define ELIRQF_TIMER_RUN       0x02	/* Bit 1 des Config-Reg     */
89#define ELIRQF_TIMER_RUN_PCC8  0x01	/* Bit 0 des Config-Reg  bei PCC */
90#define ELSA_IRQ_IDX       0x38	/* Bit 3,4,5 des Config-Reg */
91#define ELSA_IRQ_IDX_PCC8  0x30	/* Bit 4,5 des Config-Reg */
92#define ELSA_IRQ_IDX_PC    0x0c	/* Bit 2,3 des Config-Reg */
93
94/* Control-Register (Write) */
95#define ELSA_LINE_LED        0x02	/* Bit 1 Gelbe LED */
96#define ELSA_STAT_LED        0x08	/* Bit 3 Gruene LED */
97#define ELSA_ISDN_RESET      0x20	/* Bit 5 Reset-Leitung */
98#define ELSA_ENA_TIMER_INT   0x80	/* Bit 7 Freigabe Timer Interrupt */
99
100/* ALE-Register (Read) */
101#define ELSA_HW_RELEASE      0x07	/* Bit 0-2 Hardwarerkennung */
102#define ELSA_S0_POWER_BAD    0x08	/* Bit 3 S0-Bus Spannung fehlt */
103
104/* Status Flags */
105#define ELIRQF_TIMER_AKTIV 1
106#define ELSA_BAD_PWR     2
107#define ELSA_ASSIGN      4
108
109#define RS_ISR_PASS_LIMIT 256
110#define FLG_MODEM_ACTIVE 1
111/* IPAC AUX */
112#define ELSA_IPAC_LINE_LED	0x40	/* Bit 6 Gelbe LED */
113#define ELSA_IPAC_STAT_LED	0x80	/* Bit 7 Gruene LED */
114
115#if ARCOFI_USE
116static struct arcofi_msg ARCOFI_XOP_F =
117	{NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
118static struct arcofi_msg ARCOFI_XOP_1 =
119	{&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
120static struct arcofi_msg ARCOFI_SOP_F =
121	{&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
122static struct arcofi_msg ARCOFI_COP_9 =
123	{&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
124static struct arcofi_msg ARCOFI_COP_8 =
125	{&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
126static struct arcofi_msg ARCOFI_COP_7 =
127	{&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
128static struct arcofi_msg ARCOFI_COP_6 =
129	{&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
130static struct arcofi_msg ARCOFI_COP_5 =
131	{&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
132static struct arcofi_msg ARCOFI_VERSION =
133	{NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
134static struct arcofi_msg ARCOFI_XOP_0 =
135	{NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
136
137static void set_arcofi(struct IsdnCardState *cs, int bc);
138
139#include "elsa_ser.c"
140#endif /* ARCOFI_USE */
141
142static inline u_char
143readreg(unsigned int ale, unsigned int adr, u_char off)
144{
145	register u_char ret;
146
147	byteout(ale, off);
148	ret = bytein(adr);
149	return (ret);
150}
151
152static inline void
153readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
154{
155	byteout(ale, off);
156	insb(adr, data, size);
157}
158
159
160static inline void
161writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
162{
163	byteout(ale, off);
164	byteout(adr, data);
165}
166
167static inline void
168writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
169{
170	byteout(ale, off);
171	outsb(adr, data, size);
172}
173
174/* Interface functions */
175
176static u_char
177ReadISAC(struct IsdnCardState *cs, u_char offset)
178{
179	return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
180}
181
182static void
183WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
184{
185	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
186}
187
188static void
189ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
190{
191	readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
192}
193
194static void
195WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
196{
197	writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
198}
199
200static u_char
201ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
202{
203	return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset+0x80));
204}
205
206static void
207WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
208{
209	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset|0x80, value);
210}
211
212static void
213ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
214{
215	readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
216}
217
218static void
219WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
220{
221	writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
222}
223
224static u_char
225ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
226{
227	return (readreg(cs->hw.elsa.ale,
228			cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
229}
230
231static void
232WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
233{
234	writereg(cs->hw.elsa.ale,
235		 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
236}
237
238static inline u_char
239readitac(struct IsdnCardState *cs, u_char off)
240{
241	register u_char ret;
242
243	byteout(cs->hw.elsa.ale, off);
244	ret = bytein(cs->hw.elsa.itac);
245	return (ret);
246}
247
248static inline void
249writeitac(struct IsdnCardState *cs, u_char off, u_char data)
250{
251	byteout(cs->hw.elsa.ale, off);
252	byteout(cs->hw.elsa.itac, data);
253}
254
255static inline int
256TimerRun(struct IsdnCardState *cs)
257{
258	register u_char v;
259
260	v = bytein(cs->hw.elsa.cfg);
261	if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
262		return (0 == (v & ELIRQF_TIMER_RUN));
263	else if (cs->subtyp == ELSA_PCC8)
264		return (v & ELIRQF_TIMER_RUN_PCC8);
265	return (v & ELIRQF_TIMER_RUN);
266}
267/*
268 * fast interrupt HSCX stuff goes here
269 */
270
271#define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
272		cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
273#define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
274		cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
275
276#define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
277		cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
278
279#define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
280		cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
281
282#include "hscx_irq.c"
283
284static irqreturn_t
285elsa_interrupt(int intno, void *dev_id)
286{
287	struct IsdnCardState *cs = dev_id;
288	u_long flags;
289	u_char val;
290	int icnt=5;
291
292	if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
293	/* The card tends to generate interrupts while being removed
294	   causing us to just crash the kernel. bad. */
295		printk(KERN_WARNING "Elsa: card not available!\n");
296		return IRQ_NONE;
297	}
298	spin_lock_irqsave(&cs->lock, flags);
299#if ARCOFI_USE
300	if (cs->hw.elsa.MFlag) {
301		val = serial_inp(cs, UART_IIR);
302		if (!(val & UART_IIR_NO_INT)) {
303			debugl1(cs,"IIR %02x", val);
304			rs_interrupt_elsa(intno, cs);
305		}
306	}
307#endif
308	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
309      Start_HSCX:
310	if (val) {
311		hscx_int_main(cs, val);
312	}
313	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
314      Start_ISAC:
315	if (val) {
316		isac_interrupt(cs, val);
317	}
318	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
319	if (val && icnt) {
320		if (cs->debug & L1_DEB_HSCX)
321			debugl1(cs, "HSCX IntStat after IntRoutine");
322		icnt--;
323		goto Start_HSCX;
324	}
325	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
326	if (val && icnt) {
327		if (cs->debug & L1_DEB_ISAC)
328			debugl1(cs, "ISAC IntStat after IntRoutine");
329		icnt--;
330		goto Start_ISAC;
331	}
332	if (!icnt)
333		printk(KERN_WARNING"ELSA IRQ LOOP\n");
334	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
335	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
336	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
337	if (cs->hw.elsa.status & ELIRQF_TIMER_AKTIV) {
338		if (!TimerRun(cs)) {
339			/* Timer Restart */
340			byteout(cs->hw.elsa.timer, 0);
341			cs->hw.elsa.counter++;
342		}
343	}
344#if ARCOFI_USE
345	if (cs->hw.elsa.MFlag) {
346		val = serial_inp(cs, UART_MCR);
347		val ^= 0x8;
348		serial_outp(cs, UART_MCR, val);
349		val = serial_inp(cs, UART_MCR);
350		val ^= 0x8;
351		serial_outp(cs, UART_MCR, val);
352	}
353#endif
354	if (cs->hw.elsa.trig)
355		byteout(cs->hw.elsa.trig, 0x00);
356	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
357	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
358	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
359	spin_unlock_irqrestore(&cs->lock, flags);
360	return IRQ_HANDLED;
361}
362
363static irqreturn_t
364elsa_interrupt_ipac(int intno, void *dev_id)
365{
366	struct IsdnCardState *cs = dev_id;
367	u_long flags;
368	u_char ista,val;
369	int icnt=5;
370
371	spin_lock_irqsave(&cs->lock, flags);
372	if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
373		val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
374		if (!(val & ELSA_PCI_IRQ_MASK)) {
375			spin_unlock_irqrestore(&cs->lock, flags);
376			return IRQ_NONE;
377		}
378	}
379#if ARCOFI_USE
380	if (cs->hw.elsa.MFlag) {
381		val = serial_inp(cs, UART_IIR);
382		if (!(val & UART_IIR_NO_INT)) {
383			debugl1(cs,"IIR %02x", val);
384			rs_interrupt_elsa(intno, cs);
385		}
386	}
387#endif
388	ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
389Start_IPAC:
390	if (cs->debug & L1_DEB_IPAC)
391		debugl1(cs, "IPAC ISTA %02X", ista);
392	if (ista & 0x0f) {
393		val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
394		if (ista & 0x01)
395			val |= 0x01;
396		if (ista & 0x04)
397			val |= 0x02;
398		if (ista & 0x08)
399			val |= 0x04;
400		if (val)
401			hscx_int_main(cs, val);
402	}
403	if (ista & 0x20) {
404		val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
405		if (val) {
406			isac_interrupt(cs, val);
407		}
408	}
409	if (ista & 0x10) {
410		val = 0x01;
411		isac_interrupt(cs, val);
412	}
413	ista  = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
414	if ((ista & 0x3f) && icnt) {
415		icnt--;
416		goto Start_IPAC;
417	}
418	if (!icnt)
419		printk(KERN_WARNING "ELSA IRQ LOOP\n");
420	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
421	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
422	spin_unlock_irqrestore(&cs->lock, flags);
423	return IRQ_HANDLED;
424}
425
426static void
427release_io_elsa(struct IsdnCardState *cs)
428{
429	int bytecnt = 8;
430
431	del_timer(&cs->hw.elsa.tl);
432#if ARCOFI_USE
433	clear_arcofi(cs);
434#endif
435	if (cs->hw.elsa.ctrl)
436		byteout(cs->hw.elsa.ctrl, 0);	/* LEDs Out */
437	if (cs->subtyp == ELSA_QS1000PCI) {
438		byteout(cs->hw.elsa.cfg + 0x4c, 0x01);  /* disable IRQ */
439		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
440		bytecnt = 2;
441		release_region(cs->hw.elsa.cfg, 0x80);
442	}
443	if (cs->subtyp == ELSA_QS3000PCI) {
444		byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
445		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
446		release_region(cs->hw.elsa.cfg, 0x80);
447	}
448 	if (cs->subtyp == ELSA_PCMCIA_IPAC) {
449		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
450 	}
451	if ((cs->subtyp == ELSA_PCFPRO) ||
452		(cs->subtyp == ELSA_QS3000) ||
453		(cs->subtyp == ELSA_PCF) ||
454		(cs->subtyp == ELSA_QS3000PCI)) {
455		bytecnt = 16;
456#if ARCOFI_USE
457		release_modem(cs);
458#endif
459	}
460	if (cs->hw.elsa.base)
461		release_region(cs->hw.elsa.base, bytecnt);
462}
463
464static void
465reset_elsa(struct IsdnCardState *cs)
466{
467	if (cs->hw.elsa.timer) {
468		/* Wait 1 Timer */
469		byteout(cs->hw.elsa.timer, 0);
470		while (TimerRun(cs));
471		cs->hw.elsa.ctrl_reg |= 0x50;
472		cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET;	/* Reset On */
473		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
474		/* Wait 1 Timer */
475		byteout(cs->hw.elsa.timer, 0);
476		while (TimerRun(cs));
477		cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET;	/* Reset Off */
478		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
479		/* Wait 1 Timer */
480		byteout(cs->hw.elsa.timer, 0);
481		while (TimerRun(cs));
482		if (cs->hw.elsa.trig)
483			byteout(cs->hw.elsa.trig, 0xff);
484	}
485	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
486		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
487		mdelay(10);
488		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
489		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
490		mdelay(10);
491		if (cs->subtyp != ELSA_PCMCIA_IPAC) {
492			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
493			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
494		} else {
495			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
496			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
497			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
498		}
499		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
500		if (cs->subtyp == ELSA_QS1000PCI)
501			byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
502		else if (cs->subtyp == ELSA_QS3000PCI)
503			byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
504	}
505}
506
507#if ARCOFI_USE
508
509static void
510set_arcofi(struct IsdnCardState *cs, int bc) {
511	cs->dc.isac.arcofi_bc = bc;
512	arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
513	interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
514}
515
516static int
517check_arcofi(struct IsdnCardState *cs)
518{
519	int arcofi_present = 0;
520	char tmp[40];
521	char *t;
522	u_char *p;
523
524	if (!cs->dc.isac.mon_tx)
525		if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
526			if (cs->debug & L1_DEB_WARN)
527				debugl1(cs, "ISAC MON TX out of buffers!");
528			return(0);
529		}
530	cs->dc.isac.arcofi_bc = 0;
531	arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
532	interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
533	if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
534			debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
535			p = cs->dc.isac.mon_rx;
536			t = tmp;
537			t += sprintf(tmp, "Arcofi data");
538			QuickHex(t, p, cs->dc.isac.mon_rxp);
539			debugl1(cs, tmp);
540			if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
541				switch(cs->dc.isac.mon_rx[1]) {
542					case 0x80:
543						debugl1(cs, "Arcofi 2160 detected");
544						arcofi_present = 1;
545						break;
546					case 0x82:
547						debugl1(cs, "Arcofi 2165 detected");
548						arcofi_present = 2;
549						break;
550					case 0x84:
551						debugl1(cs, "Arcofi 2163 detected");
552						arcofi_present = 3;
553						break;
554					default:
555						debugl1(cs, "unknown Arcofi response");
556						break;
557				}
558			} else
559				debugl1(cs, "undefined Monitor response");
560			cs->dc.isac.mon_rxp = 0;
561	} else if (cs->dc.isac.mon_tx) {
562		debugl1(cs, "Arcofi not detected");
563	}
564	if (arcofi_present) {
565		if (cs->subtyp==ELSA_QS1000) {
566			cs->subtyp = ELSA_QS3000;
567			printk(KERN_INFO
568				"Elsa: %s detected modem at 0x%lx\n",
569				Elsa_Types[cs->subtyp],
570				cs->hw.elsa.base+8);
571			release_region(cs->hw.elsa.base, 8);
572			if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
573				printk(KERN_WARNING
574					"HiSax: %s config port %lx-%lx already in use\n",
575					Elsa_Types[cs->subtyp],
576					cs->hw.elsa.base + 8,
577					cs->hw.elsa.base + 16);
578			}
579		} else if (cs->subtyp==ELSA_PCC16) {
580			cs->subtyp = ELSA_PCF;
581			printk(KERN_INFO
582				"Elsa: %s detected modem at 0x%lx\n",
583				Elsa_Types[cs->subtyp],
584				cs->hw.elsa.base+8);
585			release_region(cs->hw.elsa.base, 8);
586			if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
587				printk(KERN_WARNING
588					"HiSax: %s config port %lx-%lx already in use\n",
589					Elsa_Types[cs->subtyp],
590					cs->hw.elsa.base + 8,
591					cs->hw.elsa.base + 16);
592			}
593		} else
594			printk(KERN_INFO
595				"Elsa: %s detected modem at 0x%lx\n",
596				Elsa_Types[cs->subtyp],
597				cs->hw.elsa.base+8);
598		arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
599		interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
600		return(1);
601	}
602	return(0);
603}
604#endif /* ARCOFI_USE */
605
606static void
607elsa_led_handler(struct IsdnCardState *cs)
608{
609	int blink = 0;
610
611	if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
612		return;
613	del_timer(&cs->hw.elsa.tl);
614	if (cs->hw.elsa.status & ELSA_ASSIGN)
615		cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
616	else if (cs->hw.elsa.status & ELSA_BAD_PWR)
617		cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
618	else {
619		cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
620		blink = 250;
621	}
622	if (cs->hw.elsa.status & 0xf000)
623		cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
624	else if (cs->hw.elsa.status & 0x0f00) {
625		cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
626		blink = 500;
627	} else
628		cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
629
630	if ((cs->subtyp == ELSA_QS1000PCI) ||
631		(cs->subtyp == ELSA_QS3000PCI)) {
632		u_char led = 0xff;
633		if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
634			led ^= ELSA_IPAC_LINE_LED;
635		if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
636			led ^= ELSA_IPAC_STAT_LED;
637		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
638	} else
639		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
640	if (blink) {
641		init_timer(&cs->hw.elsa.tl);
642		cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
643		add_timer(&cs->hw.elsa.tl);
644	}
645}
646
647static int
648Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
649{
650	int ret = 0;
651	u_long flags;
652
653	switch (mt) {
654		case CARD_RESET:
655			spin_lock_irqsave(&cs->lock, flags);
656			reset_elsa(cs);
657			spin_unlock_irqrestore(&cs->lock, flags);
658			return(0);
659		case CARD_RELEASE:
660			release_io_elsa(cs);
661			return(0);
662		case CARD_INIT:
663			spin_lock_irqsave(&cs->lock, flags);
664			cs->debug |= L1_DEB_IPAC;
665			reset_elsa(cs);
666			inithscxisac(cs, 1);
667			if ((cs->subtyp == ELSA_QS1000) ||
668			    (cs->subtyp == ELSA_QS3000))
669			{
670				byteout(cs->hw.elsa.timer, 0);
671			}
672			if (cs->hw.elsa.trig)
673				byteout(cs->hw.elsa.trig, 0xff);
674			inithscxisac(cs, 2);
675			spin_unlock_irqrestore(&cs->lock, flags);
676			return(0);
677		case CARD_TEST:
678			if ((cs->subtyp == ELSA_PCMCIA) ||
679				(cs->subtyp == ELSA_PCMCIA_IPAC) ||
680				(cs->subtyp == ELSA_QS1000PCI)) {
681				return(0);
682			} else if (cs->subtyp == ELSA_QS3000PCI) {
683				ret = 0;
684			} else {
685				spin_lock_irqsave(&cs->lock, flags);
686				cs->hw.elsa.counter = 0;
687				cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
688				cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
689				byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
690				byteout(cs->hw.elsa.timer, 0);
691				spin_unlock_irqrestore(&cs->lock, flags);
692				msleep(110);
693				spin_lock_irqsave(&cs->lock, flags);
694				cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
695				byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
696				cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
697				spin_unlock_irqrestore(&cs->lock, flags);
698				printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
699				       cs->hw.elsa.counter);
700				if ((cs->hw.elsa.counter > 10) &&
701					(cs->hw.elsa.counter < 16)) {
702					printk(KERN_INFO "Elsa: timer and irq OK\n");
703					ret = 0;
704				} else {
705					printk(KERN_WARNING
706					       "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
707					       cs->hw.elsa.counter, cs->irq);
708					ret = 1;
709				}
710			}
711#if ARCOFI_USE
712			if (check_arcofi(cs)) {
713				init_modem(cs);
714			}
715#endif
716			elsa_led_handler(cs);
717			return(ret);
718		case (MDL_REMOVE | REQUEST):
719			cs->hw.elsa.status &= 0;
720			break;
721		case (MDL_ASSIGN | REQUEST):
722			cs->hw.elsa.status |= ELSA_ASSIGN;
723			break;
724		case MDL_INFO_SETUP:
725			if ((long) arg)
726				cs->hw.elsa.status |= 0x0200;
727			else
728				cs->hw.elsa.status |= 0x0100;
729			break;
730		case MDL_INFO_CONN:
731			if ((long) arg)
732				cs->hw.elsa.status |= 0x2000;
733			else
734				cs->hw.elsa.status |= 0x1000;
735			break;
736		case MDL_INFO_REL:
737			if ((long) arg) {
738				cs->hw.elsa.status &= ~0x2000;
739				cs->hw.elsa.status &= ~0x0200;
740			} else {
741				cs->hw.elsa.status &= ~0x1000;
742				cs->hw.elsa.status &= ~0x0100;
743			}
744			break;
745#if ARCOFI_USE
746		case CARD_AUX_IND:
747			if (cs->hw.elsa.MFlag) {
748				int len;
749				u_char *msg;
750
751				if (!arg)
752					return(0);
753				msg = arg;
754				len = *msg;
755				msg++;
756				modem_write_cmd(cs, msg, len);
757			}
758			break;
759#endif
760	}
761	if (cs->typ == ISDN_CTYPE_ELSA) {
762		int pwr = bytein(cs->hw.elsa.ale);
763		if (pwr & 0x08)
764			cs->hw.elsa.status |= ELSA_BAD_PWR;
765		else
766			cs->hw.elsa.status &= ~ELSA_BAD_PWR;
767	}
768	elsa_led_handler(cs);
769	return(ret);
770}
771
772static unsigned char
773probe_elsa_adr(unsigned int adr, int typ)
774{
775	int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
776	 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
777
778	/* In case of the elsa pcmcia card, this region is in use,
779	   reserved for us by the card manager. So we do not check it
780	   here, it would fail. */
781	if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
782		if (request_region(adr, 8, "elsa card")) {
783			release_region(adr, 8);
784		} else {
785			printk(KERN_WARNING
786			       "Elsa: Probing Port 0x%x: already in use\n", adr);
787			return (0);
788		}
789	}
790	for (i = 0; i < 16; i++) {
791		in1 = inb(adr + ELSA_CONFIG);	/* 'toggelt' bei */
792		in2 = inb(adr + ELSA_CONFIG);	/* jedem Zugriff */
793		p16_1 += 0x04 & in1;
794		p16_2 += 0x04 & in2;
795		p8_1 += 0x02 & in1;
796		p8_2 += 0x02 & in2;
797		pc_1 += 0x01 & in1;
798		pc_2 += 0x01 & in2;
799		pfp_1 += 0x40 & in1;
800		pfp_2 += 0x40 & in2;
801	}
802	printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
803	if (65 == ++p16_1 * ++p16_2) {
804		printk(" PCC-16/PCF found\n");
805		return (ELSA_PCC16);
806	} else if (1025 == ++pfp_1 * ++pfp_2) {
807		printk(" PCF-Pro found\n");
808		return (ELSA_PCFPRO);
809	} else if (33 == ++p8_1 * ++p8_2) {
810		printk(" PCC8 found\n");
811		return (ELSA_PCC8);
812	} else if (17 == ++pc_1 * ++pc_2) {
813		printk(" PC found\n");
814		return (ELSA_PC);
815	} else {
816		printk(" failed\n");
817		return (0);
818	}
819}
820
821static unsigned int
822probe_elsa(struct IsdnCardState *cs)
823{
824	int i;
825	unsigned int CARD_portlist[] =
826	{0x160, 0x170, 0x260, 0x360, 0};
827
828	for (i = 0; CARD_portlist[i]; i++) {
829		if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
830			break;
831	}
832	return (CARD_portlist[i]);
833}
834
835static 	struct pci_dev *dev_qs1000 __devinitdata = NULL;
836static 	struct pci_dev *dev_qs3000 __devinitdata = NULL;
837
838#ifdef __ISAPNP__
839static struct isapnp_device_id elsa_ids[] __devinitdata = {
840	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
841	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
842	  (unsigned long) "Elsa QS1000" },
843	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
844	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
845	  (unsigned long) "Elsa QS3000" },
846	{ 0, }
847};
848
849static struct isapnp_device_id *ipid __devinitdata = &elsa_ids[0];
850static struct pnp_card *pnp_c __devinitdata = NULL;
851#endif
852
853int __devinit
854setup_elsa(struct IsdnCard *card)
855{
856	int bytecnt;
857	u_char val;
858	struct IsdnCardState *cs = card->cs;
859	char tmp[64];
860
861	strcpy(tmp, Elsa_revision);
862	printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
863	cs->hw.elsa.ctrl_reg = 0;
864	cs->hw.elsa.status = 0;
865	cs->hw.elsa.MFlag = 0;
866	cs->subtyp = 0;
867	if (cs->typ == ISDN_CTYPE_ELSA) {
868		cs->hw.elsa.base = card->para[0];
869		printk(KERN_INFO "Elsa: Microlink IO probing\n");
870		if (cs->hw.elsa.base) {
871			if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
872							  cs->typ))) {
873				printk(KERN_WARNING
874				       "Elsa: no Elsa Microlink at %#lx\n",
875				       cs->hw.elsa.base);
876				return (0);
877			}
878		} else
879			cs->hw.elsa.base = probe_elsa(cs);
880		if (cs->hw.elsa.base) {
881			cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
882			cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
883			cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
884			cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
885			cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
886			cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
887			cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
888			cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
889			val = bytein(cs->hw.elsa.cfg);
890			if (cs->subtyp == ELSA_PC) {
891				const u_char CARD_IrqTab[8] =
892				{7, 3, 5, 9, 0, 0, 0, 0};
893				cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
894			} else if (cs->subtyp == ELSA_PCC8) {
895				const u_char CARD_IrqTab[8] =
896				{7, 3, 5, 9, 0, 0, 0, 0};
897				cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
898			} else {
899				const u_char CARD_IrqTab[8] =
900				{15, 10, 15, 3, 11, 5, 11, 9};
901				cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
902			}
903			val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
904			if (val < 3)
905				val |= 8;
906			val += 'A' - 3;
907			if (val == 'B' || val == 'C')
908				val ^= 1;
909			if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
910				val = 'C';
911			printk(KERN_INFO
912			       "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
913			       Elsa_Types[cs->subtyp],
914			       cs->hw.elsa.base,
915			       val, cs->irq);
916			val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
917			if (val) {
918				printk(KERN_WARNING
919				   "Elsa: Microlink S0 bus power bad\n");
920				cs->hw.elsa.status |= ELSA_BAD_PWR;
921			}
922		} else {
923			printk(KERN_WARNING
924			       "No Elsa Microlink found\n");
925			return (0);
926		}
927	} else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
928#ifdef __ISAPNP__
929		if (!card->para[1] && isapnp_present()) {
930			struct pnp_dev *pnp_d;
931			while(ipid->card_vendor) {
932				if ((pnp_c = pnp_find_card(ipid->card_vendor,
933					ipid->card_device, pnp_c))) {
934					pnp_d = NULL;
935					if ((pnp_d = pnp_find_dev(pnp_c,
936						ipid->vendor, ipid->function, pnp_d))) {
937						int err;
938
939						printk(KERN_INFO "HiSax: %s detected\n",
940							(char *)ipid->driver_data);
941						pnp_disable_dev(pnp_d);
942						err = pnp_activate_dev(pnp_d);
943						if (err<0) {
944							printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
945								__FUNCTION__, err);
946							return(0);
947						}
948						card->para[1] = pnp_port_start(pnp_d, 0);
949						card->para[0] = pnp_irq(pnp_d, 0);
950
951						if (!card->para[0] || !card->para[1]) {
952							printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
953								card->para[0], card->para[1]);
954							pnp_disable_dev(pnp_d);
955							return(0);
956						}
957						if (ipid->function == ISAPNP_FUNCTION(0x133))
958							cs->subtyp = ELSA_QS1000;
959						else
960							cs->subtyp = ELSA_QS3000;
961						break;
962					} else {
963						printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
964						return(0);
965					}
966				}
967				ipid++;
968				pnp_c=NULL;
969			}
970			if (!ipid->card_vendor) {
971				printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
972				return(0);
973			}
974		}
975#endif
976		if (card->para[1] && card->para[0]) {
977			cs->hw.elsa.base = card->para[1];
978			cs->irq = card->para[0];
979			if (!cs->subtyp)
980				cs->subtyp = ELSA_QS1000;
981		} else {
982			printk(KERN_ERR "Elsa PnP: no parameter\n");
983		}
984		cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
985		cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
986		cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
987		cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
988		cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
989		cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
990		cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
991		printk(KERN_INFO
992		       "Elsa: %s defined at %#lx IRQ %d\n",
993		       Elsa_Types[cs->subtyp],
994		       cs->hw.elsa.base,
995		       cs->irq);
996	} else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA) {
997		cs->hw.elsa.base = card->para[1];
998		cs->irq = card->para[0];
999		val = readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2, IPAC_ID);
1000		if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
1001			cs->subtyp = ELSA_PCMCIA_IPAC;
1002			cs->hw.elsa.ale = cs->hw.elsa.base + 0;
1003			cs->hw.elsa.isac = cs->hw.elsa.base + 2;
1004			cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
1005			test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1006		} else {
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		}
1012		cs->hw.elsa.timer = 0;
1013		cs->hw.elsa.trig = 0;
1014		cs->hw.elsa.ctrl = 0;
1015		cs->irq_flags |= IRQF_SHARED;
1016		printk(KERN_INFO
1017		       "Elsa: %s defined at %#lx IRQ %d\n",
1018		       Elsa_Types[cs->subtyp],
1019		       cs->hw.elsa.base,
1020		       cs->irq);
1021	} else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
1022#ifdef CONFIG_PCI
1023		cs->subtyp = 0;
1024		if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1025			PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1026			if (pci_enable_device(dev_qs1000))
1027				return(0);
1028			cs->subtyp = ELSA_QS1000PCI;
1029			cs->irq = dev_qs1000->irq;
1030			cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
1031			cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1032		} else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1033			PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1034			if (pci_enable_device(dev_qs3000))
1035				return(0);
1036			cs->subtyp = ELSA_QS3000PCI;
1037			cs->irq = dev_qs3000->irq;
1038			cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
1039			cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
1040		} else {
1041			printk(KERN_WARNING "Elsa: No PCI card found\n");
1042			return(0);
1043		}
1044		if (!cs->irq) {
1045			printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
1046			return(0);
1047		}
1048
1049		if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
1050			printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
1051			return(0);
1052		}
1053		if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
1054			printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
1055			printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
1056			printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
1057		}
1058		cs->hw.elsa.ale  = cs->hw.elsa.base;
1059		cs->hw.elsa.isac = cs->hw.elsa.base +1;
1060		cs->hw.elsa.hscx = cs->hw.elsa.base +1;
1061		test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1062		cs->hw.elsa.timer = 0;
1063		cs->hw.elsa.trig  = 0;
1064		cs->irq_flags |= IRQF_SHARED;
1065		printk(KERN_INFO
1066		       "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1067		       Elsa_Types[cs->subtyp],
1068		       cs->hw.elsa.base,
1069		       cs->hw.elsa.cfg,
1070		       cs->irq);
1071#else
1072		printk(KERN_WARNING "Elsa: Elsa PCI and NO_PCI_BIOS\n");
1073		printk(KERN_WARNING "Elsa: unable to config Elsa PCI\n");
1074		return (0);
1075#endif /* CONFIG_PCI */
1076	} else
1077		return (0);
1078
1079	switch (cs->subtyp) {
1080		case ELSA_PC:
1081		case ELSA_PCC8:
1082		case ELSA_PCC16:
1083		case ELSA_QS1000:
1084		case ELSA_PCMCIA:
1085		case ELSA_PCMCIA_IPAC:
1086			bytecnt = 8;
1087			break;
1088		case ELSA_PCFPRO:
1089		case ELSA_PCF:
1090		case ELSA_QS3000:
1091		case ELSA_QS3000PCI:
1092			bytecnt = 16;
1093			break;
1094		case ELSA_QS1000PCI:
1095			bytecnt = 2;
1096			break;
1097		default:
1098			printk(KERN_WARNING
1099			       "Unknown ELSA subtype %d\n", cs->subtyp);
1100			return (0);
1101	}
1102	/* In case of the elsa pcmcia card, this region is in use,
1103	   reserved for us by the card manager. So we do not check it
1104	   here, it would fail. */
1105	if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
1106		printk(KERN_WARNING
1107		       "HiSax: %s config port %#lx-%#lx already in use\n",
1108		       CardType[card->typ],
1109		       cs->hw.elsa.base,
1110		       cs->hw.elsa.base + bytecnt);
1111		return (0);
1112	}
1113	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
1114		if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
1115			printk(KERN_WARNING
1116			       "HiSax: %s pci port %x-%x already in use\n",
1117				CardType[card->typ],
1118				cs->hw.elsa.cfg,
1119				cs->hw.elsa.cfg + 0x80);
1120			release_region(cs->hw.elsa.base, bytecnt);
1121			return (0);
1122		}
1123	}
1124#if ARCOFI_USE
1125	init_arcofi(cs);
1126#endif
1127	setup_isac(cs);
1128	cs->hw.elsa.tl.function = (void *) elsa_led_handler;
1129	cs->hw.elsa.tl.data = (long) cs;
1130	init_timer(&cs->hw.elsa.tl);
1131	/* Teste Timer */
1132	if (cs->hw.elsa.timer) {
1133		byteout(cs->hw.elsa.trig, 0xff);
1134		byteout(cs->hw.elsa.timer, 0);
1135		if (!TimerRun(cs)) {
1136			byteout(cs->hw.elsa.timer, 0);	/* 2. Versuch */
1137			if (!TimerRun(cs)) {
1138				printk(KERN_WARNING
1139				       "Elsa: timer do not start\n");
1140				release_io_elsa(cs);
1141				return (0);
1142			}
1143		}
1144		HZDELAY((HZ/100) + 1);	/* wait >=10 ms */
1145		if (TimerRun(cs)) {
1146			printk(KERN_WARNING "Elsa: timer do not run down\n");
1147			release_io_elsa(cs);
1148			return (0);
1149		}
1150		printk(KERN_INFO "Elsa: timer OK; resetting card\n");
1151	}
1152	cs->BC_Read_Reg = &ReadHSCX;
1153	cs->BC_Write_Reg = &WriteHSCX;
1154	cs->BC_Send_Data = &hscx_fill_fifo;
1155	cs->cardmsg = &Elsa_card_msg;
1156	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
1157		cs->readisac = &ReadISAC_IPAC;
1158		cs->writeisac = &WriteISAC_IPAC;
1159		cs->readisacfifo = &ReadISACfifo_IPAC;
1160		cs->writeisacfifo = &WriteISACfifo_IPAC;
1161		cs->irq_func = &elsa_interrupt_ipac;
1162		val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
1163		printk(KERN_INFO "Elsa: IPAC version %x\n", val);
1164	} else {
1165		cs->readisac = &ReadISAC;
1166		cs->writeisac = &WriteISAC;
1167		cs->readisacfifo = &ReadISACfifo;
1168		cs->writeisacfifo = &WriteISACfifo;
1169		cs->irq_func = &elsa_interrupt;
1170		ISACVersion(cs, "Elsa:");
1171		if (HscxVersion(cs, "Elsa:")) {
1172			printk(KERN_WARNING
1173				"Elsa: wrong HSCX versions check IO address\n");
1174			release_io_elsa(cs);
1175			return (0);
1176		}
1177	}
1178	if (cs->subtyp == ELSA_PC) {
1179		val = readitac(cs, ITAC_SYS);
1180		printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
1181		writeitac(cs, ITAC_ISEN, 0);
1182		writeitac(cs, ITAC_RFIE, 0);
1183		writeitac(cs, ITAC_XFIE, 0);
1184		writeitac(cs, ITAC_SCIE, 0);
1185		writeitac(cs, ITAC_STIE, 0);
1186	}
1187	return (1);
1188}
1189