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

#include <linux/init.h>
22
#include <linux/slab.h>
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32 33
#include "hisax.h"
#include "arcofi.h"
#include "isac.h"
#include "ipac.h"
#include "hscx.h"
#include "isdnl1.h"
#include <linux/pci.h>
#include <linux/isapnp.h>
#include <linux/serial.h>
#include <linux/serial_reg.h>

34 35
static const char *Elsa_revision = "$Revision: 2.32.2.4 $";
static const char *Elsa_Types[] =
L
Linus Torvalds 已提交
36
{"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
37
 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
L
Linus Torvalds 已提交
38 39
 "PCMCIA-IPAC" };

40
static const char *ITACVer[] =
L
Linus Torvalds 已提交
41 42 43
{"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
 "B1", "A1"};

44
#define byteout(addr, val) outb(val, addr)
L
Linus Torvalds 已提交
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
#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) */
87 88
#define ELIRQF_TIMER_RUN       0x02	/* Bit 1 des Config-Reg     */
#define ELIRQF_TIMER_RUN_PCC8  0x01	/* Bit 0 des Config-Reg  bei PCC */
L
Linus Torvalds 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#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 */
104
#define ELIRQF_TIMER_AKTIV 1
L
Linus Torvalds 已提交
105 106 107 108 109 110 111 112 113 114 115
#define ELSA_BAD_PWR     2
#define ELSA_ASSIGN      4

#define RS_ISR_PASS_LIMIT 256
#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 =
116
{NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
L
Linus Torvalds 已提交
117
static struct arcofi_msg ARCOFI_XOP_1 =
118 119 120
{&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}};
L
Linus Torvalds 已提交
121
static struct arcofi_msg ARCOFI_COP_9 =
122
{&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
L
Linus Torvalds 已提交
123
static struct arcofi_msg ARCOFI_COP_8 =
124
{&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
L
Linus Torvalds 已提交
125
static struct arcofi_msg ARCOFI_COP_7 =
126
{&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
L
Linus Torvalds 已提交
127
static struct arcofi_msg ARCOFI_COP_6 =
128
{&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
L
Linus Torvalds 已提交
129
static struct arcofi_msg ARCOFI_COP_5 =
130
{&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
L
Linus Torvalds 已提交
131
static struct arcofi_msg ARCOFI_VERSION =
132
{NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
L
Linus Torvalds 已提交
133
static struct arcofi_msg ARCOFI_XOP_0 =
134
{NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
L
Linus Torvalds 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

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

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

static inline u_char
readreg(unsigned int ale, unsigned int adr, u_char off)
{
	register u_char ret;

	byteout(ale, off);
	ret = bytein(adr);
	return (ret);
}

static inline void
152
readfifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
L
Linus Torvalds 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166
{
	byteout(ale, off);
	insb(adr, data, size);
}


static inline void
writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
{
	byteout(ale, off);
	byteout(adr, data);
}

static inline void
167
writefifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
L
Linus Torvalds 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
{
	byteout(ale, off);
	outsb(adr, data, size);
}

/* Interface functions */

static u_char
ReadISAC(struct IsdnCardState *cs, u_char offset)
{
	return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
}

static void
WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
{
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
}

static void
188
ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
L
Linus Torvalds 已提交
189 190 191 192 193
{
	readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
}

static void
194
WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
L
Linus Torvalds 已提交
195 196 197 198 199 200 201
{
	writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
}

static u_char
ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
{
202
	return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset + 0x80));
L
Linus Torvalds 已提交
203 204 205 206 207
}

static void
WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
{
208
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset | 0x80, value);
L
Linus Torvalds 已提交
209 210 211
}

static void
212
ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
L
Linus Torvalds 已提交
213 214 215 216 217
{
	readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
}

static void
218
WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
L
Linus Torvalds 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
{
	writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
}

static u_char
ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
{
	return (readreg(cs->hw.elsa.ale,
			cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
}

static void
WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
{
	writereg(cs->hw.elsa.ale,
		 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
}

static inline u_char
readitac(struct IsdnCardState *cs, u_char off)
{
	register u_char ret;

	byteout(cs->hw.elsa.ale, off);
	ret = bytein(cs->hw.elsa.itac);
	return (ret);
}

static inline void
writeitac(struct IsdnCardState *cs, u_char off, u_char data)
{
	byteout(cs->hw.elsa.ale, off);
	byteout(cs->hw.elsa.itac, data);
}

static inline int
TimerRun(struct IsdnCardState *cs)
{
	register u_char v;

	v = bytein(cs->hw.elsa.cfg);
	if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
261
		return (0 == (v & ELIRQF_TIMER_RUN));
L
Linus Torvalds 已提交
262
	else if (cs->subtyp == ELSA_PCC8)
263 264
		return (v & ELIRQF_TIMER_RUN_PCC8);
	return (v & ELIRQF_TIMER_RUN);
L
Linus Torvalds 已提交
265 266 267 268 269
}
/*
 * fast interrupt HSCX stuff goes here
 */

270 271 272 273
#define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale,			\
				      cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
#define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale,		\
					      cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
L
Linus Torvalds 已提交
274

275 276
#define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale,	\
						cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
L
Linus Torvalds 已提交
277

278 279
#define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale,	\
						  cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
L
Linus Torvalds 已提交
280 281 282 283

#include "hscx_irq.c"

static irqreturn_t
284
elsa_interrupt(int intno, void *dev_id)
L
Linus Torvalds 已提交
285 286 287 288
{
	struct IsdnCardState *cs = dev_id;
	u_long flags;
	u_char val;
289
	int icnt = 5;
L
Linus Torvalds 已提交
290 291

	if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
292 293
		/* The card tends to generate interrupts while being removed
		   causing us to just crash the kernel. bad. */
L
Linus Torvalds 已提交
294 295 296 297 298 299 300 301
		printk(KERN_WARNING "Elsa: card not available!\n");
		return IRQ_NONE;
	}
	spin_lock_irqsave(&cs->lock, flags);
#if ARCOFI_USE
	if (cs->hw.elsa.MFlag) {
		val = serial_inp(cs, UART_IIR);
		if (!(val & UART_IIR_NO_INT)) {
302
			debugl1(cs, "IIR %02x", val);
J
Jeff Garzik 已提交
303
			rs_interrupt_elsa(cs);
L
Linus Torvalds 已提交
304 305 306 307
		}
	}
#endif
	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
308
Start_HSCX:
L
Linus Torvalds 已提交
309 310 311 312
	if (val) {
		hscx_int_main(cs, val);
	}
	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
313
Start_ISAC:
L
Linus Torvalds 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
	if (val) {
		isac_interrupt(cs, val);
	}
	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
	if (val && icnt) {
		if (cs->debug & L1_DEB_HSCX)
			debugl1(cs, "HSCX IntStat after IntRoutine");
		icnt--;
		goto Start_HSCX;
	}
	val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
	if (val && icnt) {
		if (cs->debug & L1_DEB_ISAC)
			debugl1(cs, "ISAC IntStat after IntRoutine");
		icnt--;
		goto Start_ISAC;
	}
	if (!icnt)
		printk(KERN_WARNING"ELSA IRQ LOOP\n");
	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
336
	if (cs->hw.elsa.status & ELIRQF_TIMER_AKTIV) {
L
Linus Torvalds 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
		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);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
	spin_unlock_irqrestore(&cs->lock, flags);
	return IRQ_HANDLED;
}

static irqreturn_t
363
elsa_interrupt_ipac(int intno, void *dev_id)
L
Linus Torvalds 已提交
364 365 366
{
	struct IsdnCardState *cs = dev_id;
	u_long flags;
367 368
	u_char ista, val;
	int icnt = 5;
L
Linus Torvalds 已提交
369 370 371 372 373 374 375 376 377 378 379 380 381

	spin_lock_irqsave(&cs->lock, flags);
	if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
		val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
		if (!(val & ELSA_PCI_IRQ_MASK)) {
			spin_unlock_irqrestore(&cs->lock, flags);
			return IRQ_NONE;
		}
	}
#if ARCOFI_USE
	if (cs->hw.elsa.MFlag) {
		val = serial_inp(cs, UART_IIR);
		if (!(val & UART_IIR_NO_INT)) {
382
			debugl1(cs, "IIR %02x", val);
J
Jeff Garzik 已提交
383
			rs_interrupt_elsa(cs);
L
Linus Torvalds 已提交
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
		}
	}
#endif
	ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
Start_IPAC:
	if (cs->debug & L1_DEB_IPAC)
		debugl1(cs, "IPAC ISTA %02X", ista);
	if (ista & 0x0f) {
		val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
		if (ista & 0x01)
			val |= 0x01;
		if (ista & 0x04)
			val |= 0x02;
		if (ista & 0x08)
			val |= 0x04;
		if (val)
			hscx_int_main(cs, val);
	}
	if (ista & 0x20) {
		val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
		if (val) {
			isac_interrupt(cs, val);
		}
	}
	if (ista & 0x10) {
		val = 0x01;
		isac_interrupt(cs, val);
	}
	ista  = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
	if ((ista & 0x3f) && icnt) {
		icnt--;
		goto Start_IPAC;
	}
	if (!icnt)
		printk(KERN_WARNING "ELSA IRQ LOOP\n");
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
	writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
	spin_unlock_irqrestore(&cs->lock, flags);
	return IRQ_HANDLED;
}

425
static void
L
Linus Torvalds 已提交
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
release_io_elsa(struct IsdnCardState *cs)
{
	int bytecnt = 8;

	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 */
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
		bytecnt = 2;
		release_region(cs->hw.elsa.cfg, 0x80);
	}
	if (cs->subtyp == ELSA_QS3000PCI) {
		byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
		release_region(cs->hw.elsa.cfg, 0x80);
	}
447
	if (cs->subtyp == ELSA_PCMCIA_IPAC) {
L
Linus Torvalds 已提交
448
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
449
	}
L
Linus Torvalds 已提交
450
	if ((cs->subtyp == ELSA_PCFPRO) ||
451 452 453
	    (cs->subtyp == ELSA_QS3000) ||
	    (cs->subtyp == ELSA_PCF) ||
	    (cs->subtyp == ELSA_QS3000PCI)) {
L
Linus Torvalds 已提交
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 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
		bytecnt = 16;
#if ARCOFI_USE
		release_modem(cs);
#endif
	}
	if (cs->hw.elsa.base)
		release_region(cs->hw.elsa.base, bytecnt);
}

static void
reset_elsa(struct IsdnCardState *cs)
{
	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)) {
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
		mdelay(10);
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
		mdelay(10);
		if (cs->subtyp != ELSA_PCMCIA_IPAC) {
			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
		} else {
			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
			writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
		}
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
		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 */
	}
}

#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);
512 513
	wait_event_interruptible(cs->dc.isac.arcofi_wait,
				 cs->dc.isac.arcofi_state == ARCOFI_NOP);
L
Linus Torvalds 已提交
514 515 516 517 518 519 520 521 522 523 524
}

static int
check_arcofi(struct IsdnCardState *cs)
{
	int arcofi_present = 0;
	char tmp[40];
	char *t;
	u_char *p;

	if (!cs->dc.isac.mon_tx)
525
		if (!(cs->dc.isac.mon_tx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
L
Linus Torvalds 已提交
526 527
			if (cs->debug & L1_DEB_WARN)
				debugl1(cs, "ISAC MON TX out of buffers!");
528
			return (0);
L
Linus Torvalds 已提交
529 530 531
		}
	cs->dc.isac.arcofi_bc = 0;
	arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
532 533
	wait_event_interruptible(cs->dc.isac.arcofi_wait,
				 cs->dc.isac.arcofi_state == ARCOFI_NOP);
L
Linus Torvalds 已提交
534
	if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
535 536 537 538 539
		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);
540
		debugl1(cs, "%s", tmp);
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
		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;
L
Linus Torvalds 已提交
562 563 564 565
	} else if (cs->dc.isac.mon_tx) {
		debugl1(cs, "Arcofi not detected");
	}
	if (arcofi_present) {
566
		if (cs->subtyp == ELSA_QS1000) {
L
Linus Torvalds 已提交
567 568
			cs->subtyp = ELSA_QS3000;
			printk(KERN_INFO
569 570 571
			       "Elsa: %s detected modem at 0x%lx\n",
			       Elsa_Types[cs->subtyp],
			       cs->hw.elsa.base + 8);
L
Linus Torvalds 已提交
572 573 574
			release_region(cs->hw.elsa.base, 8);
			if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
				printk(KERN_WARNING
575 576 577 578
				       "HiSax: %s config port %lx-%lx already in use\n",
				       Elsa_Types[cs->subtyp],
				       cs->hw.elsa.base + 8,
				       cs->hw.elsa.base + 16);
L
Linus Torvalds 已提交
579
			}
580
		} else if (cs->subtyp == ELSA_PCC16) {
L
Linus Torvalds 已提交
581 582
			cs->subtyp = ELSA_PCF;
			printk(KERN_INFO
583 584 585
			       "Elsa: %s detected modem at 0x%lx\n",
			       Elsa_Types[cs->subtyp],
			       cs->hw.elsa.base + 8);
L
Linus Torvalds 已提交
586 587 588
			release_region(cs->hw.elsa.base, 8);
			if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
				printk(KERN_WARNING
589 590 591 592
				       "HiSax: %s config port %lx-%lx already in use\n",
				       Elsa_Types[cs->subtyp],
				       cs->hw.elsa.base + 8,
				       cs->hw.elsa.base + 16);
L
Linus Torvalds 已提交
593 594 595
			}
		} else
			printk(KERN_INFO
596 597 598
			       "Elsa: %s detected modem at 0x%lx\n",
			       Elsa_Types[cs->subtyp],
			       cs->hw.elsa.base + 8);
L
Linus Torvalds 已提交
599
		arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
600 601
		wait_event_interruptible(cs->dc.isac.arcofi_wait,
				 cs->dc.isac.arcofi_state == ARCOFI_NOP);
602
		return (1);
L
Linus Torvalds 已提交
603
	}
604
	return (0);
L
Linus Torvalds 已提交
605 606 607 608
}
#endif /* ARCOFI_USE */

static void
609
elsa_led_handler(struct timer_list *t)
L
Linus Torvalds 已提交
610
{
611
	struct IsdnCardState *cs = from_timer(cs, t, hw.elsa.tl);
L
Linus Torvalds 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
	int blink = 0;

	if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
		return;
	del_timer(&cs->hw.elsa.tl);
	if (cs->hw.elsa.status & ELSA_ASSIGN)
		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;
	}
	if (cs->hw.elsa.status & 0xf000)
		cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
	else if (cs->hw.elsa.status & 0x0f00) {
		cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
		blink = 500;
	} else
		cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;

	if ((cs->subtyp == ELSA_QS1000PCI) ||
634
	    (cs->subtyp == ELSA_QS3000PCI)) {
L
Linus Torvalds 已提交
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
		u_char led = 0xff;
		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;
		writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
	} else
		byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
	if (blink) {
		cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
		add_timer(&cs->hw.elsa.tl);
	}
}

static int
Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
{
	int ret = 0;
	u_long flags;

	switch (mt) {
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
	case CARD_RESET:
		spin_lock_irqsave(&cs->lock, flags);
		reset_elsa(cs);
		spin_unlock_irqrestore(&cs->lock, flags);
		return (0);
	case CARD_RELEASE:
		release_io_elsa(cs);
		return (0);
	case CARD_INIT:
		spin_lock_irqsave(&cs->lock, flags);
		cs->debug |= L1_DEB_IPAC;
		reset_elsa(cs);
		inithscxisac(cs, 1);
		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, 2);
		spin_unlock_irqrestore(&cs->lock, flags);
		return (0);
	case CARD_TEST:
		if ((cs->subtyp == ELSA_PCMCIA) ||
		    (cs->subtyp == ELSA_PCMCIA_IPAC) ||
		    (cs->subtyp == ELSA_QS1000PCI)) {
			return (0);
		} else if (cs->subtyp == ELSA_QS3000PCI) {
			ret = 0;
		} else {
L
Linus Torvalds 已提交
687
			spin_lock_irqsave(&cs->lock, flags);
688 689 690 691 692
			cs->hw.elsa.counter = 0;
			cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
			cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
			byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
			byteout(cs->hw.elsa.timer, 0);
L
Linus Torvalds 已提交
693
			spin_unlock_irqrestore(&cs->lock, flags);
694
			msleep(110);
L
Linus Torvalds 已提交
695
			spin_lock_irqsave(&cs->lock, flags);
696 697 698
			cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
			byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
			cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
L
Linus Torvalds 已提交
699
			spin_unlock_irqrestore(&cs->lock, flags);
700 701 702 703 704
			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");
L
Linus Torvalds 已提交
705 706
				ret = 0;
			} else {
707 708 709 710
				printk(KERN_WARNING
				       "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
				       cs->hw.elsa.counter, cs->irq);
				ret = 1;
L
Linus Torvalds 已提交
711
			}
712
		}
L
Linus Torvalds 已提交
713
#if ARCOFI_USE
714 715 716
		if (check_arcofi(cs)) {
			init_modem(cs);
		}
L
Linus Torvalds 已提交
717
#endif
718
		elsa_led_handler(&cs->hw.elsa.tl);
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
		return (ret);
	case (MDL_REMOVE | REQUEST):
		cs->hw.elsa.status &= 0;
		break;
	case (MDL_ASSIGN | REQUEST):
		cs->hw.elsa.status |= ELSA_ASSIGN;
		break;
	case MDL_INFO_SETUP:
		if ((long) arg)
			cs->hw.elsa.status |= 0x0200;
		else
			cs->hw.elsa.status |= 0x0100;
		break;
	case MDL_INFO_CONN:
		if ((long) arg)
			cs->hw.elsa.status |= 0x2000;
		else
			cs->hw.elsa.status |= 0x1000;
		break;
	case MDL_INFO_REL:
		if ((long) arg) {
			cs->hw.elsa.status &= ~0x2000;
			cs->hw.elsa.status &= ~0x0200;
		} else {
			cs->hw.elsa.status &= ~0x1000;
			cs->hw.elsa.status &= ~0x0100;
		}
		break;
L
Linus Torvalds 已提交
747
#if ARCOFI_USE
748 749 750 751 752 753 754 755 756 757 758 759 760
	case CARD_AUX_IND:
		if (cs->hw.elsa.MFlag) {
			int len;
			u_char *msg;

			if (!arg)
				return (0);
			msg = arg;
			len = *msg;
			msg++;
			modem_write_cmd(cs, msg, len);
		}
		break;
L
Linus Torvalds 已提交
761 762 763 764 765 766 767 768 769
#endif
	}
	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;
	}
770
	elsa_led_handler(&cs->hw.elsa.tl);
771
	return (ret);
L
Linus Torvalds 已提交
772 773 774 775 776 777
}

static unsigned char
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,
778
		pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
L
Linus Torvalds 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 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

	/* 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. */
	if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
		if (request_region(adr, 8, "elsa card")) {
			release_region(adr, 8);
		} else {
			printk(KERN_WARNING
			       "Elsa: Probing Port 0x%x: already in use\n", adr);
			return (0);
		}
	}
	for (i = 0; i < 16; i++) {
		in1 = inb(adr + ELSA_CONFIG);	/* 'toggelt' bei */
		in2 = inb(adr + ELSA_CONFIG);	/* jedem Zugriff */
		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;
	}
	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);
	}
}

static unsigned int
probe_elsa(struct IsdnCardState *cs)
{
	int i;
	unsigned int CARD_portlist[] =
828
		{0x160, 0x170, 0x260, 0x360, 0};
L
Linus Torvalds 已提交
829 830 831 832 833 834 835 836

	for (i = 0; CARD_portlist[i]; i++) {
		if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
			break;
	}
	return (CARD_portlist[i]);
}

837
static int setup_elsa_isa(struct IsdnCard *card)
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
{
	struct IsdnCardState *cs = card->cs;
	u_char val;

	cs->hw.elsa.base = card->para[0];
	printk(KERN_INFO "Elsa: Microlink IO probing\n");
	if (cs->hw.elsa.base) {
		if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
						  cs->typ))) {
			printk(KERN_WARNING
			       "Elsa: no Elsa Microlink at %#lx\n",
			       cs->hw.elsa.base);
			return (0);
		}
	} else
		cs->hw.elsa.base = probe_elsa(cs);

	if (!cs->hw.elsa.base) {
		printk(KERN_WARNING
		       "No Elsa Microlink found\n");
		return (0);
	}

	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 u_char CARD_IrqTab[8] =
872
			{7, 3, 5, 9, 0, 0, 0, 0};
873 874 875
		cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
	} else if (cs->subtyp == ELSA_PCC8) {
		const u_char CARD_IrqTab[8] =
876
			{7, 3, 5, 9, 0, 0, 0, 0};
877 878 879
		cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
	} else {
		const u_char CARD_IrqTab[8] =
880
			{15, 10, 15, 3, 11, 5, 11, 9};
881 882 883 884 885 886 887 888
		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;
R
Roel Kluin 已提交
889
	if ((cs->subtyp == ELSA_PCFPRO) && (val == 'G'))
890 891 892 893 894 895 896 897 898
		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
899
		       "Elsa: Microlink S0 bus power bad\n");
900 901 902 903 904
		cs->hw.elsa.status |= ELSA_BAD_PWR;
	}

	return (1);
}
L
Linus Torvalds 已提交
905 906

#ifdef __ISAPNP__
907
static struct isapnp_device_id elsa_ids[] = {
L
Linus Torvalds 已提交
908
	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
909
	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
L
Linus Torvalds 已提交
910 911
	  (unsigned long) "Elsa QS1000" },
	{ ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
912
	  ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
L
Linus Torvalds 已提交
913 914 915 916
	  (unsigned long) "Elsa QS3000" },
	{ 0, }
};

917 918
static struct isapnp_device_id *ipid = &elsa_ids[0];
static struct pnp_card *pnp_c = NULL;
919
#endif	/* __ISAPNP__ */
L
Linus Torvalds 已提交
920

921
static int setup_elsa_isapnp(struct IsdnCard *card)
L
Linus Torvalds 已提交
922 923 924 925
{
	struct IsdnCardState *cs = card->cs;

#ifdef __ISAPNP__
926 927
	if (!card->para[1] && isapnp_present()) {
		struct pnp_dev *pnp_d;
928
		while (ipid->card_vendor) {
929
			if ((pnp_c = pnp_find_card(ipid->card_vendor,
930
						   ipid->card_device, pnp_c))) {
931 932
				pnp_d = NULL;
				if ((pnp_d = pnp_find_dev(pnp_c,
933
							  ipid->vendor, ipid->function, pnp_d))) {
934 935 936
					int err;

					printk(KERN_INFO "HiSax: %s detected\n",
937
					       (char *)ipid->driver_data);
938 939
					pnp_disable_dev(pnp_d);
					err = pnp_activate_dev(pnp_d);
940
					if (err < 0) {
941
						printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
942 943
						       __func__, err);
						return (0);
944 945 946 947
					}
					card->para[1] = pnp_port_start(pnp_d, 0);
					card->para[0] = pnp_irq(pnp_d, 0);

948
					if (card->para[0] == -1 || !card->para[1]) {
949
						printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
950
						       card->para[0], card->para[1]);
L
Linus Torvalds 已提交
951
						pnp_disable_dev(pnp_d);
952
						return (0);
L
Linus Torvalds 已提交
953
					}
954 955 956 957 958 959 960
					if (ipid->function == ISAPNP_FUNCTION(0x133))
						cs->subtyp = ELSA_QS1000;
					else
						cs->subtyp = ELSA_QS3000;
					break;
				} else {
					printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
961
					return (0);
L
Linus Torvalds 已提交
962 963
				}
			}
964
			ipid++;
965 966
			pnp_c = NULL;
		}
967 968
		if (!ipid->card_vendor) {
			printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
969
			return (0);
L
Linus Torvalds 已提交
970
		}
971 972 973
	}
#endif	/* __ISAPNP__ */

974
	if (card->para[1] && card->para[0]) {
L
Linus Torvalds 已提交
975 976
		cs->hw.elsa.base = card->para[1];
		cs->irq = card->para[0];
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
		if (!cs->subtyp)
			cs->subtyp = ELSA_QS1000;
	} else {
		printk(KERN_ERR "Elsa PnP: no parameter\n");
	}
	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);

	return (1);
}

998
static void setup_elsa_pcmcia(struct IsdnCard *card)
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
{
	struct IsdnCardState *cs = card->cs;
	u_char val;

	cs->hw.elsa.base = card->para[1];
	cs->irq = card->para[0];
	val = readreg(cs->hw.elsa.base + 0, 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.ale = cs->hw.elsa.base + 0;
		cs->hw.elsa.isac = cs->hw.elsa.base + 2;
		cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
		test_and_set_bit(HW_IPAC, &cs->HW_Flags);
	} 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;
	cs->irq_flags |= IRQF_SHARED;
	printk(KERN_INFO
	       "Elsa: %s defined at %#lx IRQ %d\n",
	       Elsa_Types[cs->subtyp],
	       cs->hw.elsa.base,
	       cs->irq);
}

1029
#ifdef CONFIG_PCI
1030 1031
static	struct pci_dev *dev_qs1000 = NULL;
static	struct pci_dev *dev_qs3000 = NULL;
1032

1033
static int setup_elsa_pci(struct IsdnCard *card)
1034 1035 1036 1037
{
	struct IsdnCardState *cs = card->cs;

	cs->subtyp = 0;
1038
	if ((dev_qs1000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
1039
						PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1040
		if (pci_enable_device(dev_qs1000))
1041
			return (0);
1042 1043 1044 1045
		cs->subtyp = ELSA_QS1000PCI;
		cs->irq = dev_qs1000->irq;
		cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
		cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1046
	} else if ((dev_qs3000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
1047
						       PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1048
		if (pci_enable_device(dev_qs3000))
1049
			return (0);
1050 1051 1052 1053 1054 1055
		cs->subtyp = ELSA_QS3000PCI;
		cs->irq = dev_qs3000->irq;
		cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
		cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
	} else {
		printk(KERN_WARNING "Elsa: No PCI card found\n");
1056
		return (0);
1057 1058 1059
	}
	if (!cs->irq) {
		printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
1060
		return (0);
1061 1062 1063 1064
	}

	if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
		printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
1065
		return (0);
1066 1067 1068 1069 1070 1071 1072
	}
	if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
		printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
		printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
		printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
	}
	cs->hw.elsa.ale  = cs->hw.elsa.base;
1073 1074
	cs->hw.elsa.isac = cs->hw.elsa.base + 1;
	cs->hw.elsa.hscx = cs->hw.elsa.base + 1;
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
	test_and_set_bit(HW_IPAC, &cs->HW_Flags);
	cs->hw.elsa.timer = 0;
	cs->hw.elsa.trig  = 0;
	cs->irq_flags |= IRQF_SHARED;
	printk(KERN_INFO
	       "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
	       Elsa_Types[cs->subtyp],
	       cs->hw.elsa.base,
	       cs->hw.elsa.cfg,
	       cs->irq);

	return (1);
}
L
Linus Torvalds 已提交
1088 1089

#else
1090

1091
static int setup_elsa_pci(struct IsdnCard *card)
1092 1093 1094
{
	return (1);
}
1095
#endif /* CONFIG_PCI */
1096

1097
static int setup_elsa_common(struct IsdnCard *card)
1098 1099 1100 1101
{
	struct IsdnCardState *cs = card->cs;
	u_char val;
	int bytecnt;
L
Linus Torvalds 已提交
1102 1103

	switch (cs->subtyp) {
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
	case ELSA_PC:
	case ELSA_PCC8:
	case ELSA_PCC16:
	case ELSA_QS1000:
	case ELSA_PCMCIA:
	case ELSA_PCMCIA_IPAC:
		bytecnt = 8;
		break;
	case ELSA_PCFPRO:
	case ELSA_PCF:
	case ELSA_QS3000:
	case ELSA_QS3000PCI:
		bytecnt = 16;
		break;
	case ELSA_QS1000PCI:
		bytecnt = 2;
		break;
	default:
		printk(KERN_WARNING
		       "Unknown ELSA subtype %d\n", cs->subtyp);
		return (0);
L
Linus Torvalds 已提交
1125 1126 1127 1128 1129 1130
	}
	/* 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. */
	if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
		printk(KERN_WARNING
1131
		       "HiSax: ELSA config port %#lx-%#lx already in use\n",
L
Linus Torvalds 已提交
1132 1133 1134 1135 1136 1137 1138
		       cs->hw.elsa.base,
		       cs->hw.elsa.base + bytecnt);
		return (0);
	}
	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
		if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
			printk(KERN_WARNING
1139
			       "HiSax: ELSA pci port %x-%x already in use\n",
1140 1141
			       cs->hw.elsa.cfg,
			       cs->hw.elsa.cfg + 0x80);
L
Linus Torvalds 已提交
1142 1143 1144 1145 1146 1147 1148 1149
			release_region(cs->hw.elsa.base, bytecnt);
			return (0);
		}
	}
#if ARCOFI_USE
	init_arcofi(cs);
#endif
	setup_isac(cs);
1150
	timer_setup(&cs->hw.elsa.tl, elsa_led_handler, 0);
L
Linus Torvalds 已提交
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
	/* Teste Timer */
	if (cs->hw.elsa.timer) {
		byteout(cs->hw.elsa.trig, 0xff);
		byteout(cs->hw.elsa.timer, 0);
		if (!TimerRun(cs)) {
			byteout(cs->hw.elsa.timer, 0);	/* 2. Versuch */
			if (!TimerRun(cs)) {
				printk(KERN_WARNING
				       "Elsa: timer do not start\n");
				release_io_elsa(cs);
				return (0);
			}
		}
1164
		HZDELAY((HZ / 100) + 1);	/* wait >=10 ms */
L
Linus Torvalds 已提交
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
		if (TimerRun(cs)) {
			printk(KERN_WARNING "Elsa: timer do not run down\n");
			release_io_elsa(cs);
			return (0);
		}
		printk(KERN_INFO "Elsa: timer OK; resetting card\n");
	}
	cs->BC_Read_Reg = &ReadHSCX;
	cs->BC_Write_Reg = &WriteHSCX;
	cs->BC_Send_Data = &hscx_fill_fifo;
	cs->cardmsg = &Elsa_card_msg;
	if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
		cs->readisac = &ReadISAC_IPAC;
		cs->writeisac = &WriteISAC_IPAC;
		cs->readisacfifo = &ReadISACfifo_IPAC;
		cs->writeisacfifo = &WriteISACfifo_IPAC;
		cs->irq_func = &elsa_interrupt_ipac;
		val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
		printk(KERN_INFO "Elsa: IPAC version %x\n", val);
	} else {
		cs->readisac = &ReadISAC;
		cs->writeisac = &WriteISAC;
		cs->readisacfifo = &ReadISACfifo;
		cs->writeisacfifo = &WriteISACfifo;
		cs->irq_func = &elsa_interrupt;
		ISACVersion(cs, "Elsa:");
		if (HscxVersion(cs, "Elsa:")) {
			printk(KERN_WARNING
1193
			       "Elsa: wrong HSCX versions check IO address\n");
L
Linus Torvalds 已提交
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
			release_io_elsa(cs);
			return (0);
		}
	}
	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 (1);
}
1209

1210
int setup_elsa(struct IsdnCard *card)
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
{
	int rc;
	struct IsdnCardState *cs = card->cs;
	char tmp[64];

	strcpy(tmp, Elsa_revision);
	printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
	cs->hw.elsa.ctrl_reg = 0;
	cs->hw.elsa.status = 0;
	cs->hw.elsa.MFlag = 0;
	cs->subtyp = 0;

	if (cs->typ == ISDN_CTYPE_ELSA) {
		rc = setup_elsa_isa(card);
		if (!rc)
			return (0);

	} else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
		rc = setup_elsa_isapnp(card);
		if (!rc)
			return (0);

	} else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA)
		setup_elsa_pcmcia(card);

	else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
		rc = setup_elsa_pci(card);
		if (!rc)
			return (0);

1241
	} else
1242 1243 1244 1245
		return (0);

	return setup_elsa_common(card);
}