1 /* $Id: gazel.c,v 2.19.2.4 2004/01/14 16:04:48 keil Exp $
3 * low level stuff for Gazel isdn cards
6 * based on source code from Karsten Keil
7 * Copyright by BeWan Systems
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/init.h>
20 #include <linux/pci.h>
22 static const char *gazel_revision = "$Revision: 2.19.2.4 $";
29 #define PLX_CNTRL 0x50 /* registre de controle PLX */
30 #define RESET_GAZEL 0x4
31 #define RESET_9050 0x40000000
32 #define PLX_INCSR 0x4C /* registre d'IT du 9050 */
33 #define INT_ISAC_EN 0x8 /* 1 = enable IT isac */
34 #define INT_ISAC 0x20 /* 1 = IT isac en cours */
35 #define INT_HSCX_EN 0x1 /* 1 = enable IT hscx */
36 #define INT_HSCX 0x4 /* 1 = IT hscx en cours */
37 #define INT_PCI_EN 0x40 /* 1 = enable IT PCI */
38 #define INT_IPAC_EN 0x3 /* enable IT ipac */
41 #define byteout(addr, val) outb(val, addr)
42 #define bytein(addr) inb(addr)
45 readreg(unsigned int adr, u_short off)
47 return bytein(adr + off);
51 writereg(unsigned int adr, u_short off, u_char data)
53 byteout(adr + off, data);
58 read_fifo(unsigned int adr, u_char *data, int size)
60 insb(adr, data, size);
64 write_fifo(unsigned int adr, u_char *data, int size)
66 outsb(adr, data, size);
70 readreg_ipac(unsigned int adr, u_short off)
75 ret = bytein(adr + 4);
80 writereg_ipac(unsigned int adr, u_short off, u_char data)
83 byteout(adr + 4, data);
88 read_fifo_ipac(unsigned int adr, u_short off, u_char *data, int size)
91 insb(adr + 4, data, size);
95 write_fifo_ipac(unsigned int adr, u_short off, u_char *data, int size)
98 outsb(adr + 4, data, size);
101 /* Interface functions */
104 ReadISAC(struct IsdnCardState *cs, u_char offset)
106 u_short off2 = offset;
108 switch (cs->subtyp) {
110 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
112 return (readreg(cs->hw.gazel.isac, off2));
115 return (readreg_ipac(cs->hw.gazel.ipac, 0x80 + off2));
121 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
123 u_short off2 = offset;
125 switch (cs->subtyp) {
127 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
129 writereg(cs->hw.gazel.isac, off2, value);
133 writereg_ipac(cs->hw.gazel.ipac, 0x80 + off2, value);
139 ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
141 switch (cs->subtyp) {
144 read_fifo(cs->hw.gazel.isacfifo, data, size);
148 read_fifo_ipac(cs->hw.gazel.ipac, 0x80, data, size);
154 WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
156 switch (cs->subtyp) {
159 write_fifo(cs->hw.gazel.isacfifo, data, size);
163 write_fifo_ipac(cs->hw.gazel.ipac, 0x80, data, size);
169 ReadHSCXfifo(struct IsdnCardState *cs, int hscx, u_char *data, int size)
171 switch (cs->subtyp) {
174 read_fifo(cs->hw.gazel.hscxfifo[hscx], data, size);
178 read_fifo_ipac(cs->hw.gazel.ipac, hscx * 0x40, data, size);
184 WriteHSCXfifo(struct IsdnCardState *cs, int hscx, u_char *data, int size)
186 switch (cs->subtyp) {
189 write_fifo(cs->hw.gazel.hscxfifo[hscx], data, size);
193 write_fifo_ipac(cs->hw.gazel.ipac, hscx * 0x40, data, size);
199 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
201 u_short off2 = offset;
203 switch (cs->subtyp) {
205 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
207 return (readreg(cs->hw.gazel.hscx[hscx], off2));
210 return (readreg_ipac(cs->hw.gazel.ipac, hscx * 0x40 + off2));
216 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
218 u_short off2 = offset;
220 switch (cs->subtyp) {
222 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
224 writereg(cs->hw.gazel.hscx[hscx], off2, value);
228 writereg_ipac(cs->hw.gazel.ipac, hscx * 0x40 + off2, value);
234 * fast interrupt HSCX stuff goes here
237 #define READHSCX(cs, nr, reg) ReadHSCX(cs, nr, reg)
238 #define WRITEHSCX(cs, nr, reg, data) WriteHSCX(cs, nr, reg, data)
239 #define READHSCXFIFO(cs, nr, ptr, cnt) ReadHSCXfifo(cs, nr, ptr, cnt)
240 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) WriteHSCXfifo(cs, nr, ptr, cnt)
242 #include "hscx_irq.c"
245 gazel_interrupt(int intno, void *dev_id)
248 struct IsdnCardState *cs = dev_id;
249 u_char valisac, valhscx;
253 spin_lock_irqsave(&cs->lock, flags);
255 valhscx = ReadHSCX(cs, 1, HSCX_ISTA);
257 hscx_int_main(cs, valhscx);
258 valisac = ReadISAC(cs, ISAC_ISTA);
260 isac_interrupt(cs, valisac);
262 } while ((valhscx || valisac) && (count < MAXCOUNT));
264 WriteHSCX(cs, 0, HSCX_MASK, 0xFF);
265 WriteHSCX(cs, 1, HSCX_MASK, 0xFF);
266 WriteISAC(cs, ISAC_MASK, 0xFF);
267 WriteISAC(cs, ISAC_MASK, 0x0);
268 WriteHSCX(cs, 0, HSCX_MASK, 0x0);
269 WriteHSCX(cs, 1, HSCX_MASK, 0x0);
270 spin_unlock_irqrestore(&cs->lock, flags);
276 gazel_interrupt_ipac(int intno, void *dev_id)
278 struct IsdnCardState *cs = dev_id;
283 spin_lock_irqsave(&cs->lock, flags);
284 ista = ReadISAC(cs, IPAC_ISTA - 0x80);
287 val = ReadHSCX(cs, 1, HSCX_ISTA);
295 hscx_int_main(cs, val);
299 val = 0xfe & ReadISAC(cs, ISAC_ISTA);
301 isac_interrupt(cs, val);
306 isac_interrupt(cs, val);
308 ista = ReadISAC(cs, IPAC_ISTA - 0x80);
311 while ((ista & 0x3f) && (count < MAXCOUNT));
313 WriteISAC(cs, IPAC_MASK - 0x80, 0xFF);
314 WriteISAC(cs, IPAC_MASK - 0x80, 0xC0);
315 spin_unlock_irqrestore(&cs->lock, flags);
320 release_io_gazel(struct IsdnCardState *cs)
324 switch (cs->subtyp) {
326 for (i = 0x0000; i < 0xC000; i += 0x1000)
327 release_region(i + cs->hw.gazel.hscx[0], 16);
328 release_region(0xC000 + cs->hw.gazel.hscx[0], 1);
332 release_region(cs->hw.gazel.hscx[0], 0x100);
333 release_region(cs->hw.gazel.cfg_reg, 0x80);
337 release_region(cs->hw.gazel.ipac, 0x8);
338 release_region(cs->hw.gazel.cfg_reg, 0x80);
342 release_region(cs->hw.gazel.ipac, 8);
348 reset_gazel(struct IsdnCardState *cs)
350 unsigned long plxcntrl, addr = cs->hw.gazel.cfg_reg;
352 switch (cs->subtyp) {
354 writereg(addr, 0, 0);
356 writereg(addr, 0, 1);
360 plxcntrl = inl(addr + PLX_CNTRL);
361 plxcntrl |= (RESET_9050 + RESET_GAZEL);
362 outl(plxcntrl, addr + PLX_CNTRL);
363 plxcntrl &= ~(RESET_9050 + RESET_GAZEL);
365 outl(plxcntrl, addr + PLX_CNTRL);
367 outb(INT_ISAC_EN + INT_HSCX_EN + INT_PCI_EN, addr + PLX_INCSR);
370 plxcntrl = inl(addr + PLX_CNTRL);
371 plxcntrl |= (RESET_9050 + RESET_GAZEL);
372 outl(plxcntrl, addr + PLX_CNTRL);
373 plxcntrl &= ~(RESET_9050 + RESET_GAZEL);
374 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x20);
376 outl(plxcntrl, addr + PLX_CNTRL);
378 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x00);
379 WriteISAC(cs, IPAC_ACFG - 0x80, 0xff);
380 WriteISAC(cs, IPAC_AOE - 0x80, 0x0);
381 WriteISAC(cs, IPAC_MASK - 0x80, 0xff);
382 WriteISAC(cs, IPAC_CONF - 0x80, 0x1);
383 outb(INT_IPAC_EN + INT_PCI_EN, addr + PLX_INCSR);
384 WriteISAC(cs, IPAC_MASK - 0x80, 0xc0);
387 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x20);
389 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x00);
390 WriteISAC(cs, IPAC_ACFG - 0x80, 0xff);
391 WriteISAC(cs, IPAC_AOE - 0x80, 0x0);
392 WriteISAC(cs, IPAC_MASK - 0x80, 0xff);
393 WriteISAC(cs, IPAC_CONF - 0x80, 0x1);
394 WriteISAC(cs, IPAC_MASK - 0x80, 0xc0);
401 Gazel_card_msg(struct IsdnCardState *cs, int mt, void *arg)
407 spin_lock_irqsave(&cs->lock, flags);
409 spin_unlock_irqrestore(&cs->lock, flags);
412 release_io_gazel(cs);
415 spin_lock_irqsave(&cs->lock, flags);
417 if ((cs->subtyp == R647) || (cs->subtyp == R685)) {
419 for (i = 0; i < (2 + MAX_WAITING_CALLS); i++) {
420 cs->bcs[i].hw.hscx.tsaxr0 = 0x1f;
421 cs->bcs[i].hw.hscx.tsaxr1 = 0x23;
424 spin_unlock_irqrestore(&cs->lock, flags);
433 reserve_regions(struct IsdnCard *card, struct IsdnCardState *cs)
435 unsigned int i, j, base = 0, adr = 0, len = 0;
437 switch (cs->subtyp) {
439 base = cs->hw.gazel.hscx[0];
440 if (!request_region(adr = (0xC000 + base), len = 1, "gazel"))
442 for (i = 0x0000; i < 0xC000; i += 0x1000) {
443 if (!request_region(adr = (i + base), len = 16, "gazel"))
447 for (j = 0; j < i; j += 0x1000)
448 release_region(j + base, 16);
449 release_region(0xC000 + base, 1);
455 if (!request_region(adr = cs->hw.gazel.hscx[0], len = 0x100, "gazel"))
457 if (!request_region(adr = cs->hw.gazel.cfg_reg, len = 0x80, "gazel")) {
458 release_region(cs->hw.gazel.hscx[0], 0x100);
464 if (!request_region(adr = cs->hw.gazel.ipac, len = 0x8, "gazel"))
466 if (!request_region(adr = cs->hw.gazel.cfg_reg, len = 0x80, "gazel")) {
467 release_region(cs->hw.gazel.ipac, 8);
473 if (!request_region(adr = cs->hw.gazel.ipac, len = 0x8, "gazel"))
481 printk(KERN_WARNING "Gazel: io ports 0x%x-0x%x already in use\n",
486 static int setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs)
488 printk(KERN_INFO "Gazel: ISA PnP card automatic recognition\n");
489 // we got an irq parameter, assume it is an ISA card
490 // R742 decodes address even in not started...
491 // R647 returns FF if not present or not started
492 // eventually needs improvment
493 if (readreg_ipac(card->para[1], IPAC_ID) == 1)
499 cs->hw.gazel.cfg_reg = card->para[1] + 0xC000;
500 cs->hw.gazel.ipac = card->para[1];
501 cs->hw.gazel.isac = card->para[1] + 0x8000;
502 cs->hw.gazel.hscx[0] = card->para[1];
503 cs->hw.gazel.hscx[1] = card->para[1] + 0x4000;
504 cs->irq = card->para[0];
505 cs->hw.gazel.isacfifo = cs->hw.gazel.isac;
506 cs->hw.gazel.hscxfifo[0] = cs->hw.gazel.hscx[0];
507 cs->hw.gazel.hscxfifo[1] = cs->hw.gazel.hscx[1];
509 switch (cs->subtyp) {
511 printk(KERN_INFO "Gazel: Card ISA R647/R648 found\n");
512 cs->dc.isac.adf2 = 0x87;
514 "Gazel: config irq:%d isac:0x%X cfg:0x%X\n",
515 cs->irq, cs->hw.gazel.isac, cs->hw.gazel.cfg_reg);
517 "Gazel: hscx A:0x%X hscx B:0x%X\n",
518 cs->hw.gazel.hscx[0], cs->hw.gazel.hscx[1]);
522 printk(KERN_INFO "Gazel: Card ISA R742 found\n");
523 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
525 "Gazel: config irq:%d ipac:0x%X\n",
526 cs->irq, cs->hw.gazel.ipac);
534 static struct pci_dev *dev_tel = NULL;
536 static int setup_gazelpci(struct IsdnCardState *cs)
538 u_int pci_ioaddr0 = 0, pci_ioaddr1 = 0;
539 u_char pci_irq = 0, found;
540 u_int nbseek, seekcard;
542 printk(KERN_WARNING "Gazel: PCI card automatic recognition\n");
545 seekcard = PCI_DEVICE_ID_PLX_R685;
546 for (nbseek = 0; nbseek < 4; nbseek++) {
547 if ((dev_tel = hisax_find_pci_device(PCI_VENDOR_ID_PLX,
548 seekcard, dev_tel))) {
549 if (pci_enable_device(dev_tel))
551 pci_irq = dev_tel->irq;
552 pci_ioaddr0 = pci_resource_start(dev_tel, 1);
553 pci_ioaddr1 = pci_resource_start(dev_tel, 2);
560 case PCI_DEVICE_ID_PLX_R685:
561 seekcard = PCI_DEVICE_ID_PLX_R753;
563 case PCI_DEVICE_ID_PLX_R753:
564 seekcard = PCI_DEVICE_ID_PLX_DJINN_ITOO;
566 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
567 seekcard = PCI_DEVICE_ID_PLX_OLITEC;
573 printk(KERN_WARNING "Gazel: No PCI card found\n");
577 printk(KERN_WARNING "Gazel: No IRQ for PCI card found\n");
580 cs->hw.gazel.pciaddr[0] = pci_ioaddr0;
581 cs->hw.gazel.pciaddr[1] = pci_ioaddr1;
583 pci_ioaddr1 &= 0xfffe;
584 cs->hw.gazel.cfg_reg = pci_ioaddr0 & 0xfffe;
585 cs->hw.gazel.ipac = pci_ioaddr1;
586 cs->hw.gazel.isac = pci_ioaddr1 + 0x80;
587 cs->hw.gazel.hscx[0] = pci_ioaddr1;
588 cs->hw.gazel.hscx[1] = pci_ioaddr1 + 0x40;
589 cs->hw.gazel.isacfifo = cs->hw.gazel.isac;
590 cs->hw.gazel.hscxfifo[0] = cs->hw.gazel.hscx[0];
591 cs->hw.gazel.hscxfifo[1] = cs->hw.gazel.hscx[1];
593 cs->irq_flags |= IRQF_SHARED;
596 case PCI_DEVICE_ID_PLX_R685:
597 printk(KERN_INFO "Gazel: Card PCI R685 found\n");
599 cs->dc.isac.adf2 = 0x87;
601 "Gazel: config irq:%d isac:0x%X cfg:0x%X\n",
602 cs->irq, cs->hw.gazel.isac, cs->hw.gazel.cfg_reg);
604 "Gazel: hscx A:0x%X hscx B:0x%X\n",
605 cs->hw.gazel.hscx[0], cs->hw.gazel.hscx[1]);
607 case PCI_DEVICE_ID_PLX_R753:
608 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
609 case PCI_DEVICE_ID_PLX_OLITEC:
610 printk(KERN_INFO "Gazel: Card PCI R753 found\n");
612 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
614 "Gazel: config irq:%d ipac:0x%X cfg:0x%X\n",
615 cs->irq, cs->hw.gazel.ipac, cs->hw.gazel.cfg_reg);
621 #endif /* CONFIG_PCI */
623 int setup_gazel(struct IsdnCard *card)
625 struct IsdnCardState *cs = card->cs;
629 strcpy(tmp, gazel_revision);
630 printk(KERN_INFO "Gazel: Driver Revision %s\n", HiSax_getrev(tmp));
632 if (cs->typ != ISDN_CTYPE_GAZEL)
636 if (setup_gazelisa(card, cs))
641 if (setup_gazelpci(cs))
644 printk(KERN_WARNING "Gazel: Card PCI requested and NO_PCI_BIOS, unable to config\n");
646 #endif /* CONFIG_PCI */
649 if (reserve_regions(card, cs)) {
652 if (reset_gazel(cs)) {
653 printk(KERN_WARNING "Gazel: wrong IRQ\n");
654 release_io_gazel(cs);
657 cs->readisac = &ReadISAC;
658 cs->writeisac = &WriteISAC;
659 cs->readisacfifo = &ReadISACfifo;
660 cs->writeisacfifo = &WriteISACfifo;
661 cs->BC_Read_Reg = &ReadHSCX;
662 cs->BC_Write_Reg = &WriteHSCX;
663 cs->BC_Send_Data = &hscx_fill_fifo;
664 cs->cardmsg = &Gazel_card_msg;
666 switch (cs->subtyp) {
669 cs->irq_func = &gazel_interrupt;
670 ISACVersion(cs, "Gazel:");
671 if (HscxVersion(cs, "Gazel:")) {
673 "Gazel: wrong HSCX versions check IO address\n");
674 release_io_gazel(cs);
680 cs->irq_func = &gazel_interrupt_ipac;
681 val = ReadISAC(cs, IPAC_ID - 0x80);
682 printk(KERN_INFO "Gazel: IPAC version %x\n", val);