elsa.c 29.5 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/* $Id: elsa.c,v 2.26.6.6 2001/09/23 22:24:47 kai Exp $
Linus Torvalds's avatar
Linus Torvalds committed
2
 *
Linus Torvalds's avatar
Linus Torvalds committed
3
 * low level stuff for Elsa isdn cards
Linus Torvalds's avatar
Linus Torvalds committed
4
 *
Linus Torvalds's avatar
Linus Torvalds committed
5 6 7 8 9
 * Author       Karsten Keil
 * Copyright    by Karsten Keil      <keil@isdn4linux.de>
 * 
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
Linus Torvalds's avatar
Linus Torvalds committed
10
 *
Linus Torvalds's avatar
Linus Torvalds committed
11 12
 * For changes and modifications please read
 * ../../../Documentation/isdn/HiSax.cert
Linus Torvalds's avatar
Linus Torvalds committed
13
 *
Linus Torvalds's avatar
Linus Torvalds committed
14
 * Thanks to    Elsa GmbH for documents and information
Linus Torvalds's avatar
Linus Torvalds committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 *              Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
 *              for ELSA PCMCIA support
 *
 */

#include <linux/init.h>
#include <linux/config.h>
#include "hisax.h"
#include "arcofi.h"
#include "isac.h"
#include "ipac.h"
#include "hscx.h"
#include "isdnl1.h"
#include <linux/pci.h>
30
#include <linux/isapnp.h>
Linus Torvalds's avatar
Linus Torvalds committed
31 32 33 34
#include <linux/serial.h>
#include <linux/serial_reg.h>

extern const char *CardType[];
35
static spinlock_t elsa_lock = SPIN_LOCK_UNLOCKED;
Linus Torvalds's avatar
Linus Torvalds committed
36

Linus Torvalds's avatar
Linus Torvalds committed
37
const char *Elsa_revision = "$Revision: 2.26.6.6 $";
Linus Torvalds's avatar
Linus Torvalds committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
const char *Elsa_Types[] =
{"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI", 
 "PCMCIA-IPAC" };

const char *ITACVer[] =
{"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
 "B1", "A1"};

#define byteout(addr,val) outb(val,addr)
#define bytein(addr) inb(addr)

#define ELSA_ISAC	0
#define ELSA_ISAC_PCM	1
#define ELSA_ITAC	1
#define ELSA_HSCX	2
#define ELSA_ALE	3
#define ELSA_ALE_PCM	4
#define ELSA_CONTROL	4
#define ELSA_CONFIG	5
#define ELSA_START_TIMER 6
#define ELSA_TRIG_IRQ	7

#define ELSA_PC      1
#define ELSA_PCC8    2
#define ELSA_PCC16   3
#define ELSA_PCF     4
#define ELSA_PCFPRO  5
#define ELSA_PCMCIA  6
#define ELSA_QS1000  7
#define ELSA_QS3000  8
#define ELSA_QS1000PCI 9
#define ELSA_QS3000PCI 10
#define ELSA_PCMCIA_IPAC 11

/* PCI stuff */
#define ELSA_PCI_IRQ_MASK	0x04

/* ITAC Registeradressen (only Microlink PC) */
#define ITAC_SYS	0x34
#define ITAC_ISEN	0x48
#define ITAC_RFIE	0x4A
#define ITAC_XFIE	0x4C
#define ITAC_SCIE	0x4E
#define ITAC_STIE	0x46

/***                                                                    ***
 ***   Makros als Befehle fuer die Kartenregister                       ***
 ***   (mehrere Befehle werden durch Bit-Oderung kombiniert)            ***
 ***                                                                    ***/

/* Config-Register (Read) */
#define ELSA_TIMER_RUN       0x02	/* Bit 1 des Config-Reg     */
#define ELSA_TIMER_RUN_PCC8  0x01	/* Bit 0 des Config-Reg  bei PCC */
#define ELSA_IRQ_IDX       0x38	/* Bit 3,4,5 des Config-Reg */
#define ELSA_IRQ_IDX_PCC8  0x30	/* Bit 4,5 des Config-Reg */
#define ELSA_IRQ_IDX_PC    0x0c	/* Bit 2,3 des Config-Reg */

/* Control-Register (Write) */
#define ELSA_LINE_LED        0x02	/* Bit 1 Gelbe LED */
#define ELSA_STAT_LED        0x08	/* Bit 3 Gruene LED */
#define ELSA_ISDN_RESET      0x20	/* Bit 5 Reset-Leitung */
#define ELSA_ENA_TIMER_INT   0x80	/* Bit 7 Freigabe Timer Interrupt */

/* ALE-Register (Read) */
#define ELSA_HW_RELEASE      0x07	/* Bit 0-2 Hardwarerkennung */
#define ELSA_S0_POWER_BAD    0x08	/* Bit 3 S0-Bus Spannung fehlt */

/* Status Flags */
#define ELSA_TIMER_AKTIV 1
#define ELSA_BAD_PWR     2

#define RS_ISR_PASS_LIMIT 256
#define _INLINE_ inline
#define FLG_MODEM_ACTIVE 1
/* IPAC AUX */
#define ELSA_IPAC_LINE_LED	0x40	/* Bit 6 Gelbe LED */
#define ELSA_IPAC_STAT_LED	0x80	/* Bit 7 Gruene LED */

#if ARCOFI_USE
static struct arcofi_msg ARCOFI_XOP_F =
	{NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
static struct arcofi_msg ARCOFI_XOP_1 =
	{&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
static struct arcofi_msg ARCOFI_SOP_F = 
	{&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
static struct arcofi_msg ARCOFI_COP_9 =
	{&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
static struct arcofi_msg ARCOFI_COP_8 =
	{&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
static struct arcofi_msg ARCOFI_COP_7 =
	{&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
static struct arcofi_msg ARCOFI_COP_6 =
	{&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
static struct arcofi_msg ARCOFI_COP_5 =
	{&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
static struct arcofi_msg ARCOFI_VERSION =
	{NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
static struct arcofi_msg ARCOFI_XOP_0 =
	{NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */

static void set_arcofi(struct IsdnCardState *cs, int bc);

#include "elsa_ser.c"
#endif /* ARCOFI_USE */

144 145
static inline u8
readreg(struct IsdnCardState *cs, unsigned int adr, u8 off)
Linus Torvalds's avatar
Linus Torvalds committed
146
{
147
	u8 ret;
148
	unsigned long flags;
Linus Torvalds's avatar
Linus Torvalds committed
149

150
	spin_lock_irqsave(&elsa_lock, flags);
151
	byteout(cs->hw.elsa.ale, off);
Linus Torvalds's avatar
Linus Torvalds committed
152
	ret = bytein(adr);
153
	spin_unlock_irqrestore(&elsa_lock, flags);
154
	return ret;
Linus Torvalds's avatar
Linus Torvalds committed
155 156 157
}

static inline void
158
writereg(struct IsdnCardState *cs, unsigned int adr, u8 off, u8 data)
Linus Torvalds's avatar
Linus Torvalds committed
159
{
160
	unsigned long flags;
Linus Torvalds's avatar
Linus Torvalds committed
161

162 163 164 165
	spin_lock_irqsave(&elsa_lock, flags);
	byteout(cs->hw.elsa.ale, off);
	byteout(adr, data);
	spin_unlock_irqrestore(&elsa_lock, flags);
Linus Torvalds's avatar
Linus Torvalds committed
166 167 168
}

static inline void
169
readfifo(struct IsdnCardState *cs, unsigned int adr, u8 off, u8 * data, int size)
Linus Torvalds's avatar
Linus Torvalds committed
170
{
171 172
	byteout(cs->hw.elsa.ale, off);
	insb(adr, data, size);
Linus Torvalds's avatar
Linus Torvalds committed
173 174 175
}

static inline void
176
writefifo(struct IsdnCardState *cs, unsigned int adr, u8 off, u8 * data, int size)
Linus Torvalds's avatar
Linus Torvalds committed
177
{
178
	byteout(cs->hw.elsa.ale, off);
Linus Torvalds's avatar
Linus Torvalds committed
179 180 181
	outsb(adr, data, size);
}

182
static u8
183
isac_read(struct IsdnCardState *cs, u8 offset)
Linus Torvalds's avatar
Linus Torvalds committed
184
{
185
	return readreg(cs, cs->hw.elsa.isac, offset);
Linus Torvalds's avatar
Linus Torvalds committed
186 187 188
}

static void
189
isac_write(struct IsdnCardState *cs, u8 offset, u8 value)
Linus Torvalds's avatar
Linus Torvalds committed
190
{
191
	writereg(cs, cs->hw.elsa.isac, offset, value);
Linus Torvalds's avatar
Linus Torvalds committed
192 193 194
}

static void
195
isac_read_fifo(struct IsdnCardState *cs, u8 *data, int size)
Linus Torvalds's avatar
Linus Torvalds committed
196
{
197
	readfifo(cs, cs->hw.elsa.isac, 0, data, size);
Linus Torvalds's avatar
Linus Torvalds committed
198 199 200
}

static void
201
isac_write_fifo(struct IsdnCardState *cs, u8 *data, int size)
Linus Torvalds's avatar
Linus Torvalds committed
202
{
203
	writefifo(cs, cs->hw.elsa.isac, 0, data, size);
Linus Torvalds's avatar
Linus Torvalds committed
204 205
}

206
static struct dc_hw_ops isac_ops = {
207 208 209 210
	.read_reg   = isac_read,
	.write_reg  = isac_write,
	.read_fifo  = isac_read_fifo,
	.write_fifo = isac_write_fifo,
211 212
};

213
static u8
214
hscx_read(struct IsdnCardState *cs, int hscx, u8 offset)
Linus Torvalds's avatar
Linus Torvalds committed
215
{
216
	return readreg(cs, cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0));
Linus Torvalds's avatar
Linus Torvalds committed
217 218 219
}

static void
220
hscx_write(struct IsdnCardState *cs, int hscx, u8 offset, u8 value)
Linus Torvalds's avatar
Linus Torvalds committed
221
{
222
	writereg(cs, cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
Linus Torvalds's avatar
Linus Torvalds committed
223 224
}

225 226 227 228 229 230 231 232 233 234 235 236
static void
hscx_read_fifo(struct IsdnCardState *cs, int hscx, u8 *data, int size)
{
	writefifo(cs, cs->hw.elsa.hscx, hscx ? 0x40 : 0, data, size);
}

static void
hscx_write_fifo(struct IsdnCardState *cs, int hscx, u8 *data, int size)
{
	writefifo(cs, cs->hw.elsa.hscx, hscx ? 0x40 : 0, data, size);
}

237
static struct bc_hw_ops hscx_ops = {
238 239 240 241
	.read_reg   = hscx_read,
	.write_reg  = hscx_write,
	.read_fifo  = hscx_read_fifo,
	.write_fifo = hscx_write_fifo,
242 243
};

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
static inline u8
ipac_read(struct IsdnCardState *cs, u8 offset)
{
	return readreg(cs, cs->hw.elsa.isac, offset);
}

static inline void
ipac_write(struct IsdnCardState *cs, u8 offset, u8 value)
{
	writereg(cs, cs->hw.elsa.isac, offset, value);
}

static inline void
ipac_readfifo(struct IsdnCardState *cs, u8 offset, u8 *data, int size)
{
	readfifo(cs, cs->hw.elsa.isac, offset, data, size);
}

static inline void
ipac_writefifo(struct IsdnCardState *cs, u8 offset, u8 *data, int size)
{
	writefifo(cs, cs->hw.elsa.isac, offset, data, size);
}

/* This will generate ipac_dc_ops and ipac_bc_ops using the functions
 * above */

BUILD_IPAC_OPS(ipac);

273 274
static inline u8
readitac(struct IsdnCardState *cs, u8 off)
Linus Torvalds's avatar
Linus Torvalds committed
275
{
276
	u8 ret;
277
	unsigned long flags;
Linus Torvalds's avatar
Linus Torvalds committed
278

279
	spin_lock_irqsave(&elsa_lock, flags);
Linus Torvalds's avatar
Linus Torvalds committed
280 281
	byteout(cs->hw.elsa.ale, off);
	ret = bytein(cs->hw.elsa.itac);
282
	spin_unlock_irqrestore(&elsa_lock, flags);
283
	return ret;
Linus Torvalds's avatar
Linus Torvalds committed
284 285 286
}

static inline void
287
writeitac(struct IsdnCardState *cs, u8 off, u8 data)
Linus Torvalds's avatar
Linus Torvalds committed
288
{
289
	unsigned long flags;
Linus Torvalds's avatar
Linus Torvalds committed
290

291
	spin_lock_irqsave(&elsa_lock, flags);
Linus Torvalds's avatar
Linus Torvalds committed
292 293
	byteout(cs->hw.elsa.ale, off);
	byteout(cs->hw.elsa.itac, data);
294
	spin_unlock_irqrestore(&elsa_lock, flags);
Linus Torvalds's avatar
Linus Torvalds committed
295 296 297 298 299
}

static inline int
TimerRun(struct IsdnCardState *cs)
{
300
	register u8 v;
Linus Torvalds's avatar
Linus Torvalds committed
301 302 303 304 305 306 307 308 309 310 311 312 313

	v = bytein(cs->hw.elsa.cfg);
	if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
		return (0 == (v & ELSA_TIMER_RUN));
	else if (cs->subtyp == ELSA_PCC8)
		return (v & ELSA_TIMER_RUN_PCC8);
	return (v & ELSA_TIMER_RUN);
}

static void
elsa_interrupt(int intno, void *dev_id, struct pt_regs *regs)
{
	struct IsdnCardState *cs = dev_id;
314
	u8 val;
Linus Torvalds's avatar
Linus Torvalds committed
315 316 317 318 319

	if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
	/* The card tends to generate interrupts while being removed
	   causing us to just crash the kernel. bad. */
		printk(KERN_WARNING "Elsa: card not available!\n");
320
		return;
Linus Torvalds's avatar
Linus Torvalds committed
321 322 323 324 325 326
	}
#if ARCOFI_USE
	if (cs->hw.elsa.MFlag) {
		val = serial_inp(cs, UART_IIR);
		if (!(val & UART_IIR_NO_INT)) {
			debugl1(cs,"IIR %02x", val);
327
			spin_lock(&cs->lock);
Linus Torvalds's avatar
Linus Torvalds committed
328
			rs_interrupt_elsa(intno, cs);
329
			spin_unlock(&cs->lock);
Linus Torvalds's avatar
Linus Torvalds committed
330 331 332
		}
	}
#endif
333 334
	hscxisac_irq(intno, dev_id, regs);

Linus Torvalds's avatar
Linus Torvalds committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
	if (cs->hw.elsa.status & ELSA_TIMER_AKTIV) {
		if (!TimerRun(cs)) {
			/* Timer Restart */
			byteout(cs->hw.elsa.timer, 0);
			cs->hw.elsa.counter++;
		}
	}
#if ARCOFI_USE
	if (cs->hw.elsa.MFlag) {
		val = serial_inp(cs, UART_MCR);
		val ^= 0x8;
		serial_outp(cs, UART_MCR, val);
		val = serial_inp(cs, UART_MCR);
		val ^= 0x8;
		serial_outp(cs, UART_MCR, val);
	}
#endif
	if (cs->hw.elsa.trig)
		byteout(cs->hw.elsa.trig, 0x00);
}

static void
elsa_interrupt_ipac(int intno, void *dev_id, struct pt_regs *regs)
{
	struct IsdnCardState *cs = dev_id;
360
	u8 val;
Linus Torvalds's avatar
Linus Torvalds committed
361 362 363 364 365 366 367

	if (!cs) {
		printk(KERN_WARNING "Elsa: Spurious interrupt!\n");
		return;
	}
	if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
		val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
368 369
		if (!test_bit(FLG_BUGGY_PLX9050, &cs->HW_Flags) && 
		    !(val & ELSA_PCI_IRQ_MASK))
Linus Torvalds's avatar
Linus Torvalds committed
370 371 372 373 374 375 376
			return;
	}
#if ARCOFI_USE
	if (cs->hw.elsa.MFlag) {
		val = serial_inp(cs, UART_IIR);
		if (!(val & UART_IIR_NO_INT)) {
			debugl1(cs,"IIR %02x", val);
377
			spin_lock(&cs->lock);
Linus Torvalds's avatar
Linus Torvalds committed
378
			rs_interrupt_elsa(intno, cs);
379
			spin_unlock(&cs->lock);
Linus Torvalds's avatar
Linus Torvalds committed
380 381 382
		}
	}
#endif
383
	ipac_irq(intno, dev_id, regs);
Linus Torvalds's avatar
Linus Torvalds committed
384 385
}

386 387
static void
elsa_release(struct IsdnCardState *cs)
Linus Torvalds's avatar
Linus Torvalds committed
388 389 390 391 392 393 394 395 396
{
	del_timer(&cs->hw.elsa.tl);
#if ARCOFI_USE
	clear_arcofi(cs);
#endif
	if (cs->hw.elsa.ctrl)
		byteout(cs->hw.elsa.ctrl, 0);	/* LEDs Out */
	if (cs->subtyp == ELSA_QS1000PCI) {
		byteout(cs->hw.elsa.cfg + 0x4c, 0x01);  /* disable IRQ */
397
		writereg(cs, cs->hw.elsa.isac, IPAC_ATX, 0xff);
Linus Torvalds's avatar
Linus Torvalds committed
398 399 400
	}
	if (cs->subtyp == ELSA_QS3000PCI) {
		byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
401
		writereg(cs, cs->hw.elsa.isac, IPAC_ATX, 0xff);
Linus Torvalds's avatar
Linus Torvalds committed
402 403
	}
 	if (cs->subtyp == ELSA_PCMCIA_IPAC) {
404
		writereg(cs, cs->hw.elsa.isac, IPAC_ATX, 0xff);
Linus Torvalds's avatar
Linus Torvalds committed
405
 	}
406
#if ARCOFI_USE
Linus Torvalds's avatar
Linus Torvalds committed
407 408 409 410 411 412
	if ((cs->subtyp == ELSA_PCFPRO) ||
		(cs->subtyp == ELSA_QS3000) ||
		(cs->subtyp == ELSA_PCF) ||
		(cs->subtyp == ELSA_QS3000PCI)) {
		release_modem(cs);
	}
413 414
#endif
	hisax_release_resources(cs);
Linus Torvalds's avatar
Linus Torvalds committed
415 416
}

417 418
static int
elsa_reset(struct IsdnCardState *cs)
Linus Torvalds's avatar
Linus Torvalds committed
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
{
	if (cs->hw.elsa.timer) {
		/* Wait 1 Timer */
		byteout(cs->hw.elsa.timer, 0);
		while (TimerRun(cs));
		cs->hw.elsa.ctrl_reg |= 0x50;
		cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET;	/* Reset On */
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
		/* Wait 1 Timer */
		byteout(cs->hw.elsa.timer, 0);
		while (TimerRun(cs));
		cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET;	/* Reset Off */
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
		/* Wait 1 Timer */
		byteout(cs->hw.elsa.timer, 0);
		while (TimerRun(cs));
		if (cs->hw.elsa.trig)
			byteout(cs->hw.elsa.trig, 0xff);
	}
	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
439
		writereg(cs, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
Linus Torvalds's avatar
Linus Torvalds committed
440 441
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout((10*HZ)/1000); /* Timeout 10ms */
442
		writereg(cs, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
Linus Torvalds's avatar
Linus Torvalds committed
443
		set_current_state(TASK_UNINTERRUPTIBLE);
444
		writereg(cs, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
Linus Torvalds's avatar
Linus Torvalds committed
445 446
		schedule_timeout((10*HZ)/1000); /* Timeout 10ms */
		if (cs->subtyp != ELSA_PCMCIA_IPAC) {
447 448
			writereg(cs, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
			writereg(cs, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
Linus Torvalds's avatar
Linus Torvalds committed
449
		} else {
450 451 452
			writereg(cs, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
			writereg(cs, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
			writereg(cs, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
Linus Torvalds's avatar
Linus Torvalds committed
453
		}
454
		writereg(cs, cs->hw.elsa.isac, IPAC_ATX, 0xff);
Linus Torvalds's avatar
Linus Torvalds committed
455 456 457 458 459
		if (cs->subtyp == ELSA_QS1000PCI)
			byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
		else if (cs->subtyp == ELSA_QS3000PCI)
			byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
	}
460
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
}

#if ARCOFI_USE

static void
set_arcofi(struct IsdnCardState *cs, int bc) {
	cs->dc.isac.arcofi_bc = bc;
	arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
	interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
}

static int
check_arcofi(struct IsdnCardState *cs)
{
	int arcofi_present = 0;
	char tmp[40];
	char *t;
478
	u8 *p;
Linus Torvalds's avatar
Linus Torvalds committed
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

	if (!cs->dc.isac.mon_tx)
		if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
			if (cs->debug & L1_DEB_WARN)
				debugl1(cs, "ISAC MON TX out of buffers!");
			return(0);
		}
	cs->dc.isac.arcofi_bc = 0;
	arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
	interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
	if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
			debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
			p = cs->dc.isac.mon_rx;
			t = tmp;
			t += sprintf(tmp, "Arcofi data");
			QuickHex(t, p, cs->dc.isac.mon_rxp);
			debugl1(cs, tmp);
			if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
				switch(cs->dc.isac.mon_rx[1]) {
					case 0x80:
						debugl1(cs, "Arcofi 2160 detected");
						arcofi_present = 1;
						break;
					case 0x82:
						debugl1(cs, "Arcofi 2165 detected");
						arcofi_present = 2;
						break;
					case 0x84:
						debugl1(cs, "Arcofi 2163 detected");
						arcofi_present = 3;
						break;
					default:
						debugl1(cs, "unknown Arcofi response");
						break;
				}
			} else
				debugl1(cs, "undefined Monitor response");
			cs->dc.isac.mon_rxp = 0;
	} else if (cs->dc.isac.mon_tx) {
		debugl1(cs, "Arcofi not detected");
	}
	if (arcofi_present) {
		if (cs->subtyp==ELSA_QS1000) {
			cs->subtyp = ELSA_QS3000;
			printk(KERN_INFO
Linus Torvalds's avatar
Linus Torvalds committed
524
				"Elsa: %s detected modem at 0x%lx\n",
Linus Torvalds's avatar
Linus Torvalds committed
525 526
				Elsa_Types[cs->subtyp],
				cs->hw.elsa.base+8);
527
			request_io(&cs->rs, cs->hw.elsa.base+8, 8, "elsa isdn modem");
Linus Torvalds's avatar
Linus Torvalds committed
528 529 530
		} else if (cs->subtyp==ELSA_PCC16) {
			cs->subtyp = ELSA_PCF;
			printk(KERN_INFO
Linus Torvalds's avatar
Linus Torvalds committed
531
				"Elsa: %s detected modem at 0x%lx\n",
Linus Torvalds's avatar
Linus Torvalds committed
532 533
				Elsa_Types[cs->subtyp],
				cs->hw.elsa.base+8);
534
			request_io(&cs->rs, cs->hw.elsa.base+8, 8, "elsa isdn modem");
Linus Torvalds's avatar
Linus Torvalds committed
535 536
		} else
			printk(KERN_INFO
Linus Torvalds's avatar
Linus Torvalds committed
537
				"Elsa: %s detected modem at 0x%lx\n",
Linus Torvalds's avatar
Linus Torvalds committed
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
				Elsa_Types[cs->subtyp],
				cs->hw.elsa.base+8);
		arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
		interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
		return(1);
	}
	return(0);
}
#endif /* ARCOFI_USE */

static void
elsa_led_handler(struct IsdnCardState *cs)
{
	int blink = 0;

	if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
		return;
555 556 557 558 559 560 561 562 563

	if (cs->typ == ISDN_CTYPE_ELSA) {
		int pwr = bytein(cs->hw.elsa.ale);
		if (pwr & 0x08)
			cs->hw.elsa.status |= ELSA_BAD_PWR;
		else
			cs->hw.elsa.status &= ~ELSA_BAD_PWR;
	}
	if (cs->status & 0x0001)
Linus Torvalds's avatar
Linus Torvalds committed
564 565 566 567 568 569 570
		cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
	else if (cs->hw.elsa.status & ELSA_BAD_PWR)
		cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
	else {
		cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
		blink = 250;
	}
571
	if (cs->status & 0xf000)
Linus Torvalds's avatar
Linus Torvalds committed
572
		cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
573
	else if (cs->status & 0x0f00) {
Linus Torvalds's avatar
Linus Torvalds committed
574 575 576 577 578 579 580
		cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
		blink = 500;
	} else
		cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;

	if ((cs->subtyp == ELSA_QS1000PCI) ||
		(cs->subtyp == ELSA_QS3000PCI)) {
581
		u8 led = 0xff;
Linus Torvalds's avatar
Linus Torvalds committed
582 583 584 585
		if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
			led ^= ELSA_IPAC_LINE_LED;
		if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
			led ^= ELSA_IPAC_STAT_LED;
586
		writereg(cs, cs->hw.elsa.isac, IPAC_ATX, led);
Linus Torvalds's avatar
Linus Torvalds committed
587 588 589
	} else
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);

590 591
	if (blink)
		mod_timer(&cs->hw.elsa.tl, jiffies + (blink * HZ) / 1000);
Linus Torvalds's avatar
Linus Torvalds committed
592 593
}

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
#if ARCOFI_USE
static void
elsa_aux_ind(struct IsdnCardState *cs, void *arg)
{
	 if (cs->hw.elsa.MFlag) {
		 int len;
		 u8 *msg;
		 
		 if (!arg)
			 return;
		 msg = arg;
		 len = *msg;
		 msg++;
		 modem_write_cmd(cs, msg, len);
	 }
}
#else
#define elsa_aux_ind NULL
#endif

614 615 616 617 618 619 620 621 622 623 624 625
static void
elsa_init(struct IsdnCardState *cs)
{
	if (cs->subtyp == ELSA_QS1000 || cs->subtyp == ELSA_QS3000)
		byteout(cs->hw.elsa.timer, 0);

	if (cs->hw.elsa.trig)
		byteout(cs->hw.elsa.trig, 0xff);

	inithscxisac(cs);
}

626 627 628 629 630 631 632 633 634
static void
elsa_ipac_init(struct IsdnCardState *cs)
{
	if (cs->hw.elsa.trig)
		byteout(cs->hw.elsa.trig, 0xff);

	ipac_init(cs);
}

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
static void
elsa_test(struct IsdnCardState *cs)
{
	if ((cs->subtyp == ELSA_PCMCIA) ||
	    (cs->subtyp == ELSA_PCMCIA_IPAC) ||
	    (cs->subtyp == ELSA_QS1000PCI)) {
		return;
	} 
	if (cs->subtyp != ELSA_QS3000PCI) {
		cs->hw.elsa.counter = 0;
		cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
		cs->hw.elsa.status |= ELSA_TIMER_AKTIV;
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
		byteout(cs->hw.elsa.timer, 0);
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout((110*HZ)/1000);
		cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
		cs->hw.elsa.status &= ~ELSA_TIMER_AKTIV;
		printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
		       cs->hw.elsa.counter);
		if ((cs->hw.elsa.counter > 10) &&
		    (cs->hw.elsa.counter < 16)) {
			printk(KERN_INFO "Elsa: timer and irq OK\n");
		} else {
			printk(KERN_WARNING
			       "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
			       cs->hw.elsa.counter, cs->irq);
		}
	}
#if ARCOFI_USE
	if (check_arcofi(cs)) {
		init_modem(cs);
	}
#endif
	elsa_led_handler(cs);
}

673
static struct card_ops elsa_ops = {
674 675 676 677 678 679 680
	.init        = elsa_init,
	.test        = elsa_test,
	.reset       = elsa_reset,
	.release     = elsa_release,
	.aux_ind     = elsa_aux_ind,
	.led_handler = elsa_led_handler,
	.irq_func    = elsa_interrupt,
681 682 683
};

static struct card_ops elsa_ipac_ops = {
684 685 686 687 688 689 690
	.init        = elsa_ipac_init,
	.test        = elsa_test,
	.reset       = elsa_reset,
	.release     = elsa_release,
	.aux_ind     = elsa_aux_ind,
	.led_handler = elsa_led_handler,
	.irq_func    = elsa_interrupt_ipac,
691 692
};

693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
static void __init
elsa_arcofi_init(struct IsdnCardState *cs)
{
#if ARCOFI_USE
	init_arcofi(cs);
#endif
}

static void __init
elsa_timer_init(struct IsdnCardState *cs)
{
	cs->hw.elsa.tl.function = (void *) elsa_led_handler;
	cs->hw.elsa.tl.data = (long) cs;
	init_timer(&cs->hw.elsa.tl);
}

static int __init
elsa_timer_test(struct IsdnCardState *cs)
{
	/* test timer */
	byteout(cs->hw.elsa.trig, 0xff);
	byteout(cs->hw.elsa.timer, 0);
	if (!TimerRun(cs)) {
		byteout(cs->hw.elsa.timer, 0);	/* second attempt */
		if (!TimerRun(cs)) {
			printk(KERN_WARNING "Elsa: timer does not start\n");
			goto err;
		}
	}
	HZDELAY(10 * HZ / 1000); /* wait >=10 ms */
	if (TimerRun(cs)) {
		printk(KERN_WARNING "Elsa: timer does not run\n");
		goto err;
	}
	printk(KERN_INFO "Elsa: timer OK; resetting card\n");
	return 0;
 err:
	return -EBUSY;
}

static unsigned char __init
Linus Torvalds's avatar
Linus Torvalds committed
734 735 736 737 738 739 740 741
probe_elsa_adr(unsigned int adr, int typ)
{
	int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
	 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;

	/* In case of the elsa pcmcia card, this region is in use,
	   reserved for us by the card manager. So we do not check it
	   here, it would fail. */
742 743 744
	if (typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(adr, 8, "elsa")) {
		printk(KERN_WARNING "Elsa: probing port 0x%x: in use\n",  adr);
		return 0;
Linus Torvalds's avatar
Linus Torvalds committed
745 746
	}
	for (i = 0; i < 16; i++) {
747 748
		in1 = inb(adr + ELSA_CONFIG);	/* 'toggels' at */
		in2 = inb(adr + ELSA_CONFIG);	/* each access  */
Linus Torvalds's avatar
Linus Torvalds committed
749 750 751 752 753 754 755 756 757
		p16_1 += 0x04 & in1;
		p16_2 += 0x04 & in2;
		p8_1 += 0x02 & in1;
		p8_2 += 0x02 & in2;
		pc_1 += 0x01 & in1;
		pc_2 += 0x01 & in2;
		pfp_1 += 0x40 & in1;
		pfp_2 += 0x40 & in2;
	}
758
	release_region(adr, 8);
Linus Torvalds's avatar
Linus Torvalds committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
	printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
	if (65 == ++p16_1 * ++p16_2) {
		printk(" PCC-16/PCF found\n");
		return (ELSA_PCC16);
	} else if (1025 == ++pfp_1 * ++pfp_2) {
		printk(" PCF-Pro found\n");
		return (ELSA_PCFPRO);
	} else if (33 == ++p8_1 * ++p8_2) {
		printk(" PCC8 found\n");
		return (ELSA_PCC8);
	} else if (17 == ++pc_1 * ++pc_2) {
		printk(" PC found\n");
		return (ELSA_PC);
	} else {
		printk(" failed\n");
		return (0);
	}
}

778 779
static int __init
elsa_probe(struct IsdnCardState *cs, struct IsdnCard *card)
Linus Torvalds's avatar
Linus Torvalds committed
780
{
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
	u8 val;
	int i, bytecnt = 8;
	unsigned int CARD_portlist[] = {0x160, 0x170, 0x260, 0x360, 0};

	cs->hw.elsa.base = card->para[0];
	printk(KERN_INFO "Elsa: Microlink IO probing\n");
	if (cs->hw.elsa.base) {
		cs->subtyp = probe_elsa_adr(cs->hw.elsa.base, cs->typ);
		if (!cs->subtyp) {
			printk(KERN_WARNING "Elsa: no Microlink at %#lx\n",
			       cs->hw.elsa.base);
			goto err;
		}
	} else {
		for (i = 0; CARD_portlist[i]; i++) {
			cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ);
			if (cs->subtyp)
				cs->hw.elsa.base = CARD_portlist[i];
Linus Torvalds's avatar
Linus Torvalds committed
799
			break;
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
		}
	}
	if (!cs->hw.elsa.base)
		goto err;
		
	cs->hw.elsa.cfg   = cs->hw.elsa.base + ELSA_CONFIG;
	cs->hw.elsa.ctrl  = cs->hw.elsa.base + ELSA_CONTROL;
	cs->hw.elsa.ale   = cs->hw.elsa.base + ELSA_ALE;
	cs->hw.elsa.isac  = cs->hw.elsa.base + ELSA_ISAC;
	cs->hw.elsa.itac  = cs->hw.elsa.base + ELSA_ITAC;
	cs->hw.elsa.hscx  = cs->hw.elsa.base + ELSA_HSCX;
	cs->hw.elsa.trig  = cs->hw.elsa.base + ELSA_TRIG_IRQ;
	cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
	val = bytein(cs->hw.elsa.cfg);
	if (cs->subtyp == ELSA_PC) {
		const u8 CARD_IrqTab[8] = {7, 3, 5, 9, 0, 0, 0, 0};
		cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
	} else if (cs->subtyp == ELSA_PCC8) {
		const u8 CARD_IrqTab[8] = {7, 3, 5, 9, 0, 0, 0, 0};
		cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
	} else {
		const u8 CARD_IrqTab[8] = {15, 10, 15, 3, 11, 5, 11, 9};
		cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
	}
	val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
	if (val < 3)
		val |= 8;
	val += 'A' - 3;
	if (val == 'B' || val == 'C')
		val ^= 1;
	if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
		val = 'C';
	printk(KERN_INFO "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
	       Elsa_Types[cs->subtyp], cs->hw.elsa.base, val, cs->irq);
	val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
	if (val) {
		printk(KERN_WARNING "Elsa: Microlink S0 bus power bad\n");
		cs->hw.elsa.status |= ELSA_BAD_PWR;
Linus Torvalds's avatar
Linus Torvalds committed
838
	}
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
	switch (cs->subtyp) {
	case ELSA_PCFPRO: bytecnt = 16;	break;
	}
	if (!request_io(&cs->rs, cs->hw.elsa.base, bytecnt, "elsa isdn"))
		goto err;
	elsa_arcofi_init(cs);
	elsa_timer_init(cs);
	if (elsa_timer_test(cs))
		goto err;
	elsa_reset(cs);
	cs->card_ops = &elsa_ops;
	if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
		goto err;
	if (cs->subtyp == ELSA_PC) {
		val = readitac(cs, ITAC_SYS);
		printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
		writeitac(cs, ITAC_ISEN, 0);
		writeitac(cs, ITAC_RFIE, 0);
		writeitac(cs, ITAC_XFIE, 0);
		writeitac(cs, ITAC_SCIE, 0);
		writeitac(cs, ITAC_STIE, 0);
	}
	return 0;
 err:
	elsa_release(cs);
	return -EBUSY;
}

static int __init
elsa_qs_probe(struct IsdnCardState *cs, struct IsdnCard *card)
{
	int bytecnt = 8;

	cs->irq           = card->para[0];
	cs->hw.elsa.base  = card->para[1];
	cs->hw.elsa.cfg   = cs->hw.elsa.base + ELSA_CONFIG;
	cs->hw.elsa.ale   = cs->hw.elsa.base + ELSA_ALE;
	cs->hw.elsa.isac  = cs->hw.elsa.base + ELSA_ISAC;
	cs->hw.elsa.hscx  = cs->hw.elsa.base + ELSA_HSCX;
	cs->hw.elsa.trig  = cs->hw.elsa.base + ELSA_TRIG_IRQ;
	cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
	cs->hw.elsa.ctrl  = cs->hw.elsa.base + ELSA_CONTROL;
	printk(KERN_INFO "Elsa: %s defined at %#lx IRQ %d\n",
	       Elsa_Types[cs->subtyp], cs->hw.elsa.base, cs->irq);
	switch (cs->subtyp) {
	case ELSA_QS3000: bytecnt = 16;	break;
	}
	if (!request_io(&cs->rs, cs->hw.elsa.base, bytecnt, "elsa isdn"))
		goto err;
	elsa_arcofi_init(cs);
	elsa_timer_init(cs);
	if (elsa_timer_test(cs))
		goto err;
	elsa_reset(cs);
	cs->card_ops = &elsa_ops;
	if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
		goto err;
	return 0;
 err:
	elsa_release(cs);
	return -EBUSY;
}

static int __init
elsa_qs1000_probe(struct IsdnCardState *cs, struct IsdnCard *card)
{
	cs->subtyp = ELSA_QS1000;
	return elsa_qs_probe(cs, card);
}

static int __init
elsa_qs3000_probe(struct IsdnCardState *cs, struct IsdnCard *card)
{
	cs->subtyp = ELSA_QS3000;
	return elsa_qs_probe(cs, card);
}

static int __init
elsa_pcmcia_probe(struct IsdnCardState *cs, struct IsdnCard *card)
{
	u8 val;

	cs->irq = card->para[0];
	cs->hw.elsa.base = card->para[1];
	cs->hw.elsa.ale = cs->hw.elsa.base + 0;
	val = readreg(cs, cs->hw.elsa.base + 2, IPAC_ID);
	if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
		cs->subtyp = ELSA_PCMCIA_IPAC;
		cs->hw.elsa.isac = cs->hw.elsa.base + 2;
	} else {
		cs->subtyp = ELSA_PCMCIA;
		cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE_PCM;
		cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC_PCM;
		cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
	}
	cs->hw.elsa.timer = 0;
	cs->hw.elsa.trig = 0;
	cs->hw.elsa.ctrl = 0;
	printk(KERN_INFO "Elsa: %s defined at %#lx IRQ %d\n",
	       Elsa_Types[cs->subtyp], cs->hw.elsa.base, cs->irq);
	elsa_arcofi_init(cs);
	elsa_reset(cs);
	if (cs->subtyp == ELSA_PCMCIA_IPAC) {
		cs->card_ops = &elsa_ipac_ops;
		if (ipac_setup(cs, &ipac_dc_ops, &ipac_bc_ops))
			goto err;
	} else {
		cs->card_ops = &elsa_ops;
		if (hscxisac_setup(cs, &isac_ops, &hscx_ops))
			goto err;
	}
	return 0;
 err:
	elsa_release(cs);
	return -EBUSY;
}

static int __init
elsa_qs_pci_probe(struct IsdnCardState *cs, struct pci_dev *pdev,
		  int subtyp)
{
	int bytecnt = 2;
	u8 pci_rev;

	if (pci_enable_device(pdev))
		goto err;

	cs->subtyp = subtyp;
	cs->irq = pdev->irq;
	cs->irq_flags |= SA_SHIRQ;
	cs->hw.elsa.cfg = pci_resource_start(pdev, 1);
	cs->hw.elsa.base = pci_resource_start(pdev, 3);
	pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev);
	if (cs->hw.elsa.cfg & 0x80 && pci_rev == 1) {
		printk(KERN_INFO "Elsa: PLX9050 rev1 workaround activated\n");
		__set_bit(FLG_BUGGY_PLX9050, &cs->HW_Flags);
	}
	cs->hw.elsa.ale  = cs->hw.elsa.base;
	cs->hw.elsa.isac = cs->hw.elsa.base +1;
	cs->hw.elsa.hscx = cs->hw.elsa.base +1; 
	printk(KERN_INFO "Elsa: %s defined at %#lx/%#x IRQ %d\n",
	       Elsa_Types[cs->subtyp], cs->hw.elsa.base, cs->hw.elsa.cfg,
	       cs->irq);
	switch (cs->subtyp) {
	case ELSA_QS3000PCI: bytecnt = 16; break;
	}
	if (!request_io(&cs->rs, cs->hw.elsa.base, bytecnt, "elsa isdn"))
		goto err;
	if (!request_io(&cs->rs, cs->hw.elsa.cfg, 0x80, "elsa isdn pci"))
		goto err;
	elsa_arcofi_init(cs);
	elsa_timer_init(cs);
	elsa_reset(cs);
	cs->card_ops = &elsa_ipac_ops;
	if (ipac_setup(cs, &ipac_dc_ops, &ipac_bc_ops))
		goto err;
	return 0;
 err:
	elsa_release(cs);
	return -EBUSY;
Linus Torvalds's avatar
Linus Torvalds committed
999 1000 1001 1002 1003
}

static 	struct pci_dev *dev_qs1000 __devinitdata = NULL;
static 	struct pci_dev *dev_qs3000 __devinitdata = NULL;

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
#ifdef __ISAPNP__
static struct isapnp_device_id elsa_ids[] __initdata = {
	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133), 
	  (unsigned long) "Elsa QS1000" },
	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134), 
	  (unsigned long) "Elsa QS3000" },
	{ 0, }
};

static struct isapnp_device_id *pdev = &elsa_ids[0];
1016
static struct pnp_card *pnp_c __devinitdata = NULL;
1017 1018
#endif

Linus Torvalds's avatar
Linus Torvalds committed
1019 1020 1021 1022 1023 1024 1025
int __devinit
setup_elsa(struct IsdnCard *card)
{
	char tmp[64];

	strcpy(tmp, Elsa_revision);
	printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
1026 1027 1028 1029 1030 1031

	if (card->typ == ISDN_CTYPE_ELSA) {
		if (elsa_probe(card->cs, card))
			return 0;
		return 1;
	} else if (card->typ == ISDN_CTYPE_ELSA_PNP) {
1032 1033
#ifdef __ISAPNP__
		if (!card->para[1] && isapnp_present()) {
1034 1035
			struct pnp_card *pb;
			struct pnp_dev *pd;
1036
			
1037
			while(pdev->card_vendor) {
1038 1039 1040
				if ((pb = pnp_find_card(pdev->card_vendor,
							pdev->card_device,
							pnp_c))) {
1041 1042
					pnp_c = pb;
					pd = NULL;
1043 1044 1045 1046
					if ((pd = pnp_find_dev(pnp_c,
							       pdev->vendor,
							       pdev->function,
							       pd))) {
1047 1048
						printk(KERN_INFO "HiSax: %s detected\n",
							(char *)pdev->driver_data);
1049 1050 1051 1052
						if (pnp_device_attach(pd) < 0) {
							printk(KERN_ERR "Elsa PnP: attach failed\n");
							return 0;
						}
1053
						if (pnp_activate_dev(pd) < 0) {
1054 1055 1056 1057 1058 1059
							pnp_device_detach(pd);
							printk(KERN_ERR "Elsa PnP: activate failed\n");
							return 0;
						}
						if (!pnp_port_valid(pd, 0) ||
						    !pnp_irq_valid(pd, 0)) {
1060
							printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
1061 1062
							       pnp_irq(pd, 0), pnp_port_start(pd, 0));
							pnp_device_detach(pd);
1063 1064
							return(0);
						}
1065 1066
						card->para[1] = pnp_port_start(pd, 0);
						card->para[0] = pnp_irq(pd, 0);
1067 1068 1069 1070 1071 1072 1073 1074 1075
						if (pdev->function == ISAPNP_FUNCTION(0x133)) {
							if (elsa_qs1000_probe(card->cs, card))
								return 0;
							return 1;
						} else {
							if (elsa_qs3000_probe(card->cs, card))
								return 0;
							return 1;
						}
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
						break;
					} else {
						printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
						return(0);
					}
				}
				pdev++;
				pnp_c=NULL;
			} 
			if (!pdev->card_vendor) {
				printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
				return(0);
			}
		}
#endif
1091 1092 1093 1094 1095 1096 1097 1098 1099
		if (elsa_qs1000_probe(card->cs, card))
			return 0;
		return 1;

	} else if (card->typ == ISDN_CTYPE_ELSA_PCMCIA) {
		if (elsa_pcmcia_probe(card->cs, card))
			return 0;
		return 1;
	} else if (card->typ == ISDN_CTYPE_ELSA_PCI) {
Linus Torvalds's avatar
Linus Torvalds committed
1100 1101 1102
#if CONFIG_PCI
		if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA,
			PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1103 1104 1105 1106
			if (elsa_qs_pci_probe(card->cs, dev_qs1000,
					      ELSA_QS1000PCI))
				return 0;
			return 1;
Linus Torvalds's avatar
Linus Torvalds committed
1107 1108
		} else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA,
			PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1109 1110 1111 1112
			if (elsa_qs_pci_probe(card->cs, dev_qs3000,
					      ELSA_QS3000PCI))
				return 0;
			return 1;
Linus Torvalds's avatar
Linus Torvalds committed
1113 1114
		} else {
			printk(KERN_WARNING "Elsa: No PCI card found\n");
1115
			return 0;
Linus Torvalds's avatar
Linus Torvalds committed
1116 1117 1118
		}
#endif /* CONFIG_PCI */
	}
1119
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
1120
}