1 /* $Id: teles3.c,v 2.19.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for Teles 16.3 & PNP isdn cards
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Thanks to Jan den Ouden
16 #include <linux/init.h>
17 #include <linux/isapnp.h>
23 static const char *teles3_revision = "$Revision: 2.19.2.4 $";
25 #define byteout(addr, val) outb(val, addr)
26 #define bytein(addr) inb(addr)
29 readreg(unsigned int adr, u_char off)
31 return (bytein(adr + off));
35 writereg(unsigned int adr, u_char off, u_char data)
37 byteout(adr + off, data);
42 read_fifo(unsigned int adr, u_char *data, int size)
44 insb(adr, data, size);
48 write_fifo(unsigned int adr, u_char *data, int size)
50 outsb(adr, data, size);
53 /* Interface functions */
56 ReadISAC(struct IsdnCardState *cs, u_char offset)
58 return (readreg(cs->hw.teles3.isac, offset));
62 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
64 writereg(cs->hw.teles3.isac, offset, value);
68 ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
70 read_fifo(cs->hw.teles3.isacfifo, data, size);
74 WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
76 write_fifo(cs->hw.teles3.isacfifo, data, size);
80 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
82 return (readreg(cs->hw.teles3.hscx[hscx], offset));
86 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
88 writereg(cs->hw.teles3.hscx[hscx], offset, value);
92 * fast interrupt HSCX stuff goes here
95 #define READHSCX(cs, nr, reg) readreg(cs->hw.teles3.hscx[nr], reg)
96 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.teles3.hscx[nr], reg, data)
97 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.teles3.hscxfifo[nr], ptr, cnt)
98 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.teles3.hscxfifo[nr], ptr, cnt)
100 #include "hscx_irq.c"
103 teles3_interrupt(int intno, void *dev_id)
106 struct IsdnCardState *cs = dev_id;
111 spin_lock_irqsave(&cs->lock, flags);
112 val = readreg(cs->hw.teles3.hscx[1], HSCX_ISTA);
115 hscx_int_main(cs, val);
116 val = readreg(cs->hw.teles3.isac, ISAC_ISTA);
119 isac_interrupt(cs, val);
121 val = readreg(cs->hw.teles3.hscx[1], HSCX_ISTA);
122 if (val && count < MAXCOUNT) {
123 if (cs->debug & L1_DEB_HSCX)
124 debugl1(cs, "HSCX IntStat after IntRoutine");
127 val = readreg(cs->hw.teles3.isac, ISAC_ISTA);
128 if (val && count < MAXCOUNT) {
129 if (cs->debug & L1_DEB_ISAC)
130 debugl1(cs, "ISAC IntStat after IntRoutine");
133 if (count >= MAXCOUNT)
134 printk(KERN_WARNING "Teles3: more than %d loops in teles3_interrupt\n", count);
135 writereg(cs->hw.teles3.hscx[0], HSCX_MASK, 0xFF);
136 writereg(cs->hw.teles3.hscx[1], HSCX_MASK, 0xFF);
137 writereg(cs->hw.teles3.isac, ISAC_MASK, 0xFF);
138 writereg(cs->hw.teles3.isac, ISAC_MASK, 0x0);
139 writereg(cs->hw.teles3.hscx[0], HSCX_MASK, 0x0);
140 writereg(cs->hw.teles3.hscx[1], HSCX_MASK, 0x0);
141 spin_unlock_irqrestore(&cs->lock, flags);
146 release_ioregs(struct IsdnCardState *cs, int mask)
149 release_region(cs->hw.teles3.isac + 32, 32);
151 release_region(cs->hw.teles3.hscx[0] + 32, 32);
153 release_region(cs->hw.teles3.hscx[1] + 32, 32);
157 release_io_teles3(struct IsdnCardState *cs)
159 if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
160 release_region(cs->hw.teles3.hscx[1], 96);
162 if (cs->hw.teles3.cfg_reg) {
163 if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
164 release_region(cs->hw.teles3.cfg_reg, 1);
166 release_region(cs->hw.teles3.cfg_reg, 8);
169 release_ioregs(cs, 0x7);
174 reset_teles3(struct IsdnCardState *cs)
178 if (cs->typ != ISDN_CTYPE_TELESPCMCIA) {
179 if ((cs->hw.teles3.cfg_reg) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA)) {
209 byteout(cs->hw.teles3.cfg_reg + 4, irqcfg);
210 HZDELAY(HZ / 10 + 1);
211 byteout(cs->hw.teles3.cfg_reg + 4, irqcfg | 1);
212 HZDELAY(HZ / 10 + 1);
213 } else if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
214 byteout(cs->hw.teles3.cfg_reg, 0xff);
216 byteout(cs->hw.teles3.cfg_reg, 0x00);
219 /* Reset off for 16.3 PnP , thanks to Georg Acher */
220 byteout(cs->hw.teles3.isac + 0x3c, 0);
222 byteout(cs->hw.teles3.isac + 0x3c, 1);
230 Teles_card_msg(struct IsdnCardState *cs, int mt, void *arg)
236 spin_lock_irqsave(&cs->lock, flags);
238 spin_unlock_irqrestore(&cs->lock, flags);
241 release_io_teles3(cs);
244 spin_lock_irqsave(&cs->lock, flags);
246 spin_unlock_irqrestore(&cs->lock, flags);
256 static struct isapnp_device_id teles_ids[] = {
257 { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2110),
258 ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2110),
259 (unsigned long) "Teles 16.3 PnP" },
260 { ISAPNP_VENDOR('C', 'T', 'X'), ISAPNP_FUNCTION(0x0),
261 ISAPNP_VENDOR('C', 'T', 'X'), ISAPNP_FUNCTION(0x0),
262 (unsigned long) "Creatix 16.3 PnP" },
263 { ISAPNP_VENDOR('C', 'P', 'Q'), ISAPNP_FUNCTION(0x1002),
264 ISAPNP_VENDOR('C', 'P', 'Q'), ISAPNP_FUNCTION(0x1002),
265 (unsigned long) "Compaq ISDN S0" },
269 static struct isapnp_device_id *ipid = &teles_ids[0];
270 static struct pnp_card *pnp_c = NULL;
273 int setup_teles3(struct IsdnCard *card)
276 struct IsdnCardState *cs = card->cs;
279 strcpy(tmp, teles3_revision);
280 printk(KERN_INFO "HiSax: Teles IO driver Rev. %s\n", HiSax_getrev(tmp));
281 if ((cs->typ != ISDN_CTYPE_16_3) && (cs->typ != ISDN_CTYPE_PNP)
282 && (cs->typ != ISDN_CTYPE_TELESPCMCIA) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA))
286 if (!card->para[1] && isapnp_present()) {
287 struct pnp_dev *pnp_d;
288 while (ipid->card_vendor) {
289 if ((pnp_c = pnp_find_card(ipid->card_vendor,
290 ipid->card_device, pnp_c))) {
292 if ((pnp_d = pnp_find_dev(pnp_c,
293 ipid->vendor, ipid->function, pnp_d))) {
296 printk(KERN_INFO "HiSax: %s detected\n",
297 (char *)ipid->driver_data);
298 pnp_disable_dev(pnp_d);
299 err = pnp_activate_dev(pnp_d);
301 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
305 card->para[3] = pnp_port_start(pnp_d, 2);
306 card->para[2] = pnp_port_start(pnp_d, 1);
307 card->para[1] = pnp_port_start(pnp_d, 0);
308 card->para[0] = pnp_irq(pnp_d, 0);
309 if (!card->para[0] || !card->para[1] || !card->para[2]) {
310 printk(KERN_ERR "Teles PnP:some resources are missing %ld/%lx/%lx\n",
311 card->para[0], card->para[1], card->para[2]);
312 pnp_disable_dev(pnp_d);
317 printk(KERN_ERR "Teles PnP: PnP error card found, no device\n");
323 if (!ipid->card_vendor) {
324 printk(KERN_INFO "Teles PnP: no ISAPnP card found\n");
329 if (cs->typ == ISDN_CTYPE_16_3) {
330 cs->hw.teles3.cfg_reg = card->para[1];
331 switch (cs->hw.teles3.cfg_reg) {
335 cs->hw.teles3.cfg_reg |= 0xc00;
338 cs->hw.teles3.isac = cs->hw.teles3.cfg_reg - 0x420;
339 cs->hw.teles3.hscx[0] = cs->hw.teles3.cfg_reg - 0xc20;
340 cs->hw.teles3.hscx[1] = cs->hw.teles3.cfg_reg - 0x820;
341 } else if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
342 cs->hw.teles3.cfg_reg = 0;
343 cs->hw.teles3.hscx[0] = card->para[1] - 0x20;
344 cs->hw.teles3.hscx[1] = card->para[1];
345 cs->hw.teles3.isac = card->para[1] + 0x20;
346 } else if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
347 cs->hw.teles3.cfg_reg = card->para[3];
348 cs->hw.teles3.isac = card->para[2] - 32;
349 cs->hw.teles3.hscx[0] = card->para[1] - 32;
350 cs->hw.teles3.hscx[1] = card->para[1];
352 cs->hw.teles3.cfg_reg = 0;
353 cs->hw.teles3.isac = card->para[1] - 32;
354 cs->hw.teles3.hscx[0] = card->para[2] - 32;
355 cs->hw.teles3.hscx[1] = card->para[2];
357 cs->irq = card->para[0];
358 cs->hw.teles3.isacfifo = cs->hw.teles3.isac + 0x3e;
359 cs->hw.teles3.hscxfifo[0] = cs->hw.teles3.hscx[0] + 0x3e;
360 cs->hw.teles3.hscxfifo[1] = cs->hw.teles3.hscx[1] + 0x3e;
361 if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
362 if (!request_region(cs->hw.teles3.hscx[1], 96, "HiSax Teles PCMCIA")) {
364 "HiSax: %s ports %x-%x already in use\n",
366 cs->hw.teles3.hscx[1],
367 cs->hw.teles3.hscx[1] + 96);
370 cs->irq_flags |= IRQF_SHARED; /* cardbus can share */
372 if (cs->hw.teles3.cfg_reg) {
373 if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
374 if (!request_region(cs->hw.teles3.cfg_reg, 1, "teles3 cfg")) {
376 "HiSax: %s config port %x already in use\n",
378 cs->hw.teles3.cfg_reg);
382 if (!request_region(cs->hw.teles3.cfg_reg, 8, "teles3 cfg")) {
384 "HiSax: %s config port %x-%x already in use\n",
386 cs->hw.teles3.cfg_reg,
387 cs->hw.teles3.cfg_reg + 8);
392 if (!request_region(cs->hw.teles3.isac + 32, 32, "HiSax isac")) {
394 "HiSax: %s isac ports %x-%x already in use\n",
396 cs->hw.teles3.isac + 32,
397 cs->hw.teles3.isac + 64);
398 if (cs->hw.teles3.cfg_reg) {
399 if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
400 release_region(cs->hw.teles3.cfg_reg, 1);
402 release_region(cs->hw.teles3.cfg_reg, 8);
407 if (!request_region(cs->hw.teles3.hscx[0] + 32, 32, "HiSax hscx A")) {
409 "HiSax: %s hscx A ports %x-%x already in use\n",
411 cs->hw.teles3.hscx[0] + 32,
412 cs->hw.teles3.hscx[0] + 64);
413 if (cs->hw.teles3.cfg_reg) {
414 if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
415 release_region(cs->hw.teles3.cfg_reg, 1);
417 release_region(cs->hw.teles3.cfg_reg, 8);
420 release_ioregs(cs, 1);
423 if (!request_region(cs->hw.teles3.hscx[1] + 32, 32, "HiSax hscx B")) {
425 "HiSax: %s hscx B ports %x-%x already in use\n",
427 cs->hw.teles3.hscx[1] + 32,
428 cs->hw.teles3.hscx[1] + 64);
429 if (cs->hw.teles3.cfg_reg) {
430 if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
431 release_region(cs->hw.teles3.cfg_reg, 1);
433 release_region(cs->hw.teles3.cfg_reg, 8);
436 release_ioregs(cs, 3);
440 if ((cs->hw.teles3.cfg_reg) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA)) {
441 if ((val = bytein(cs->hw.teles3.cfg_reg + 0)) != 0x51) {
442 printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
443 cs->hw.teles3.cfg_reg + 0, val);
444 release_io_teles3(cs);
447 if ((val = bytein(cs->hw.teles3.cfg_reg + 1)) != 0x93) {
448 printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
449 cs->hw.teles3.cfg_reg + 1, val);
450 release_io_teles3(cs);
453 val = bytein(cs->hw.teles3.cfg_reg + 2);/* 0x1e=without AB
458 * 0x46 16.3 with AB + Video (Teles-Vision)
460 if (val != 0x46 && val != 0x39 && val != 0x38 && val != 0x1c && val != 0x1e && val != 0x1f) {
461 printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
462 cs->hw.teles3.cfg_reg + 2, val);
463 release_io_teles3(cs);
468 "HiSax: %s config irq:%d isac:0x%X cfg:0x%X\n",
469 CardType[cs->typ], cs->irq,
470 cs->hw.teles3.isac + 32, cs->hw.teles3.cfg_reg);
472 "HiSax: hscx A:0x%X hscx B:0x%X\n",
473 cs->hw.teles3.hscx[0] + 32, cs->hw.teles3.hscx[1] + 32);
476 if (reset_teles3(cs)) {
477 printk(KERN_WARNING "Teles3: wrong IRQ\n");
478 release_io_teles3(cs);
481 cs->readisac = &ReadISAC;
482 cs->writeisac = &WriteISAC;
483 cs->readisacfifo = &ReadISACfifo;
484 cs->writeisacfifo = &WriteISACfifo;
485 cs->BC_Read_Reg = &ReadHSCX;
486 cs->BC_Write_Reg = &WriteHSCX;
487 cs->BC_Send_Data = &hscx_fill_fifo;
488 cs->cardmsg = &Teles_card_msg;
489 cs->irq_func = &teles3_interrupt;
490 ISACVersion(cs, "Teles3:");
491 if (HscxVersion(cs, "Teles3:")) {
493 "Teles3: wrong HSCX versions check IO address\n");
494 release_io_teles3(cs);