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 extern const char *CardType[];
23 static const char *gazel_revision = "$Revision: 2.19.2.4 $";
30 #define PLX_CNTRL 0x50 /* registre de controle PLX */
31 #define RESET_GAZEL 0x4
32 #define RESET_9050 0x40000000
33 #define PLX_INCSR 0x4C /* registre d'IT du 9050 */
34 #define INT_ISAC_EN 0x8 /* 1 = enable IT isac */
35 #define INT_ISAC 0x20 /* 1 = IT isac en cours */
36 #define INT_HSCX_EN 0x1 /* 1 = enable IT hscx */
37 #define INT_HSCX 0x4 /* 1 = IT hscx en cours */
38 #define INT_PCI_EN 0x40 /* 1 = enable IT PCI */
39 #define INT_IPAC_EN 0x3 /* enable IT ipac */
42 #define byteout(addr,val) outb(val,addr)
43 #define bytein(addr) inb(addr)
46 readreg(unsigned int adr, u_short off)
48 return bytein(adr + off);
52 writereg(unsigned int adr, u_short off, u_char data)
54 byteout(adr + off, data);
59 read_fifo(unsigned int adr, u_char * data, int size)
61 insb(adr, data, size);
65 write_fifo(unsigned int adr, u_char * data, int size)
67 outsb(adr, data, size);
71 readreg_ipac(unsigned int adr, u_short off)
76 ret = bytein(adr + 4);
81 writereg_ipac(unsigned int adr, u_short off, u_char data)
84 byteout(adr + 4, data);
89 read_fifo_ipac(unsigned int adr, u_short off, u_char * data, int size)
92 insb(adr + 4, data, size);
96 write_fifo_ipac(unsigned int adr, u_short off, u_char * data, int size)
99 outsb(adr + 4, data, size);
102 /* Interface functions */
105 ReadISAC(struct IsdnCardState *cs, u_char offset)
107 u_short off2 = offset;
109 switch (cs->subtyp) {
111 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
113 return (readreg(cs->hw.gazel.isac, off2));
116 return (readreg_ipac(cs->hw.gazel.ipac, 0x80 + off2));
122 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
124 u_short off2 = offset;
126 switch (cs->subtyp) {
128 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
130 writereg(cs->hw.gazel.isac, off2, value);
134 writereg_ipac(cs->hw.gazel.ipac, 0x80 + off2, value);
140 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
142 switch (cs->subtyp) {
145 read_fifo(cs->hw.gazel.isacfifo, data, size);
149 read_fifo_ipac(cs->hw.gazel.ipac, 0x80, data, size);
155 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
157 switch (cs->subtyp) {
160 write_fifo(cs->hw.gazel.isacfifo, data, size);
164 write_fifo_ipac(cs->hw.gazel.ipac, 0x80, data, size);
170 ReadHSCXfifo(struct IsdnCardState *cs, int hscx, u_char * data, int size)
172 switch (cs->subtyp) {
175 read_fifo(cs->hw.gazel.hscxfifo[hscx], data, size);
179 read_fifo_ipac(cs->hw.gazel.ipac, hscx * 0x40, data, size);
185 WriteHSCXfifo(struct IsdnCardState *cs, int hscx, u_char * data, int size)
187 switch (cs->subtyp) {
190 write_fifo(cs->hw.gazel.hscxfifo[hscx], data, size);
194 write_fifo_ipac(cs->hw.gazel.ipac, hscx * 0x40, data, size);
200 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
202 u_short off2 = offset;
204 switch (cs->subtyp) {
206 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
208 return (readreg(cs->hw.gazel.hscx[hscx], off2));
211 return (readreg_ipac(cs->hw.gazel.ipac, hscx * 0x40 + off2));
217 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
219 u_short off2 = offset;
221 switch (cs->subtyp) {
223 off2 = ((off2 << 8 & 0xf000) | (off2 & 0xf));
225 writereg(cs->hw.gazel.hscx[hscx], off2, value);
229 writereg_ipac(cs->hw.gazel.ipac, hscx * 0x40 + off2, value);
235 * fast interrupt HSCX stuff goes here
238 #define READHSCX(cs, nr, reg) ReadHSCX(cs, nr, reg)
239 #define WRITEHSCX(cs, nr, reg, data) WriteHSCX(cs, nr, reg, data)
240 #define READHSCXFIFO(cs, nr, ptr, cnt) ReadHSCXfifo(cs, nr, ptr, cnt)
241 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) WriteHSCXfifo(cs, nr, ptr, cnt)
243 #include "hscx_irq.c"
246 gazel_interrupt(int intno, void *dev_id, struct pt_regs *regs)
249 struct IsdnCardState *cs = dev_id;
250 u_char valisac, valhscx;
254 spin_lock_irqsave(&cs->lock, flags);
256 valhscx = ReadHSCX(cs, 1, HSCX_ISTA);
258 hscx_int_main(cs, valhscx);
259 valisac = ReadISAC(cs, ISAC_ISTA);
261 isac_interrupt(cs, valisac);
263 } while ((valhscx || valisac) && (count < MAXCOUNT));
265 WriteHSCX(cs, 0, HSCX_MASK, 0xFF);
266 WriteHSCX(cs, 1, HSCX_MASK, 0xFF);
267 WriteISAC(cs, ISAC_MASK, 0xFF);
268 WriteISAC(cs, ISAC_MASK, 0x0);
269 WriteHSCX(cs, 0, HSCX_MASK, 0x0);
270 WriteHSCX(cs, 1, HSCX_MASK, 0x0);
271 spin_unlock_irqrestore(&cs->lock, flags);
277 gazel_interrupt_ipac(int intno, void *dev_id, struct pt_regs *regs)
279 struct IsdnCardState *cs = dev_id;
284 spin_lock_irqsave(&cs->lock, flags);
285 ista = ReadISAC(cs, IPAC_ISTA - 0x80);
288 val = ReadHSCX(cs, 1, HSCX_ISTA);
296 hscx_int_main(cs, val);
300 val = 0xfe & ReadISAC(cs, ISAC_ISTA);
302 isac_interrupt(cs, val);
307 isac_interrupt(cs, val);
309 ista = ReadISAC(cs, IPAC_ISTA - 0x80);
312 while ((ista & 0x3f) && (count < MAXCOUNT));
314 WriteISAC(cs, IPAC_MASK - 0x80, 0xFF);
315 WriteISAC(cs, IPAC_MASK - 0x80, 0xC0);
316 spin_unlock_irqrestore(&cs->lock, flags);
321 release_io_gazel(struct IsdnCardState *cs)
325 switch (cs->subtyp) {
327 for (i = 0x0000; i < 0xC000; i += 0x1000)
328 release_region(i + cs->hw.gazel.hscx[0], 16);
329 release_region(0xC000 + cs->hw.gazel.hscx[0], 1);
333 release_region(cs->hw.gazel.hscx[0], 0x100);
334 release_region(cs->hw.gazel.cfg_reg, 0x80);
338 release_region(cs->hw.gazel.ipac, 0x8);
339 release_region(cs->hw.gazel.cfg_reg, 0x80);
343 release_region(cs->hw.gazel.ipac, 8);
349 reset_gazel(struct IsdnCardState *cs)
351 unsigned long plxcntrl, addr = cs->hw.gazel.cfg_reg;
353 switch (cs->subtyp) {
355 writereg(addr, 0, 0);
357 writereg(addr, 0, 1);
361 plxcntrl = inl(addr + PLX_CNTRL);
362 plxcntrl |= (RESET_9050 + RESET_GAZEL);
363 outl(plxcntrl, addr + PLX_CNTRL);
364 plxcntrl &= ~(RESET_9050 + RESET_GAZEL);
366 outl(plxcntrl, addr + PLX_CNTRL);
368 outb(INT_ISAC_EN + INT_HSCX_EN + INT_PCI_EN, addr + PLX_INCSR);
371 plxcntrl = inl(addr + PLX_CNTRL);
372 plxcntrl |= (RESET_9050 + RESET_GAZEL);
373 outl(plxcntrl, addr + PLX_CNTRL);
374 plxcntrl &= ~(RESET_9050 + RESET_GAZEL);
375 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x20);
377 outl(plxcntrl, addr + PLX_CNTRL);
379 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x00);
380 WriteISAC(cs, IPAC_ACFG - 0x80, 0xff);
381 WriteISAC(cs, IPAC_AOE - 0x80, 0x0);
382 WriteISAC(cs, IPAC_MASK - 0x80, 0xff);
383 WriteISAC(cs, IPAC_CONF - 0x80, 0x1);
384 outb(INT_IPAC_EN + INT_PCI_EN, addr + PLX_INCSR);
385 WriteISAC(cs, IPAC_MASK - 0x80, 0xc0);
388 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x20);
390 WriteISAC(cs, IPAC_POTA2 - 0x80, 0x00);
391 WriteISAC(cs, IPAC_ACFG - 0x80, 0xff);
392 WriteISAC(cs, IPAC_AOE - 0x80, 0x0);
393 WriteISAC(cs, IPAC_MASK - 0x80, 0xff);
394 WriteISAC(cs, IPAC_CONF - 0x80, 0x1);
395 WriteISAC(cs, IPAC_MASK - 0x80, 0xc0);
402 Gazel_card_msg(struct IsdnCardState *cs, int mt, void *arg)
408 spin_lock_irqsave(&cs->lock, flags);
410 spin_unlock_irqrestore(&cs->lock, flags);
413 release_io_gazel(cs);
416 spin_lock_irqsave(&cs->lock, flags);
418 if ((cs->subtyp==R647)||(cs->subtyp==R685)) {
420 for (i=0;i<(2+MAX_WAITING_CALLS);i++) {
421 cs->bcs[i].hw.hscx.tsaxr0 = 0x1f;
422 cs->bcs[i].hw.hscx.tsaxr1 = 0x23;
425 spin_unlock_irqrestore(&cs->lock, flags);
434 reserve_regions(struct IsdnCard *card, struct IsdnCardState *cs)
436 unsigned int i, j, base = 0, adr = 0, len = 0;
438 switch (cs->subtyp) {
440 base = cs->hw.gazel.hscx[0];
441 if (!request_region(adr = (0xC000 + base), len = 1, "gazel"))
443 for (i = 0x0000; i < 0xC000; i += 0x1000) {
444 if (!request_region(adr = (i + base), len = 16, "gazel"))
448 for (j = 0; j < i; j+= 0x1000)
449 release_region(j + base, 16);
450 release_region(0xC000 + base, 1);
456 if (!request_region(adr = cs->hw.gazel.hscx[0], len = 0x100, "gazel"))
458 if (!request_region(adr = cs->hw.gazel.cfg_reg, len = 0x80, "gazel")) {
459 release_region(cs->hw.gazel.hscx[0],0x100);
465 if (!request_region(adr = cs->hw.gazel.ipac, len = 0x8, "gazel"))
467 if (!request_region(adr = cs->hw.gazel.cfg_reg, len = 0x80, "gazel")) {
468 release_region(cs->hw.gazel.ipac, 8);
474 if (!request_region(adr = cs->hw.gazel.ipac, len = 0x8, "gazel"))
482 printk(KERN_WARNING "Gazel: %s io ports 0x%x-0x%x already in use\n",
483 CardType[cs->typ], adr, adr + len);
488 setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs)
490 printk(KERN_INFO "Gazel: ISA PnP card automatic recognition\n");
491 // we got an irq parameter, assume it is an ISA card
492 // R742 decodes address even in not started...
493 // R647 returns FF if not present or not started
494 // eventually needs improvment
495 if (readreg_ipac(card->para[1], IPAC_ID) == 1)
501 cs->hw.gazel.cfg_reg = card->para[1] + 0xC000;
502 cs->hw.gazel.ipac = card->para[1];
503 cs->hw.gazel.isac = card->para[1] + 0x8000;
504 cs->hw.gazel.hscx[0] = card->para[1];
505 cs->hw.gazel.hscx[1] = card->para[1] + 0x4000;
506 cs->irq = card->para[0];
507 cs->hw.gazel.isacfifo = cs->hw.gazel.isac;
508 cs->hw.gazel.hscxfifo[0] = cs->hw.gazel.hscx[0];
509 cs->hw.gazel.hscxfifo[1] = cs->hw.gazel.hscx[1];
511 switch (cs->subtyp) {
513 printk(KERN_INFO "Gazel: Card ISA R647/R648 found\n");
514 cs->dc.isac.adf2 = 0x87;
516 "Gazel: config irq:%d isac:0x%X cfg:0x%X\n",
517 cs->irq, cs->hw.gazel.isac, cs->hw.gazel.cfg_reg);
519 "Gazel: hscx A:0x%X hscx B:0x%X\n",
520 cs->hw.gazel.hscx[0], cs->hw.gazel.hscx[1]);
524 printk(KERN_INFO "Gazel: Card ISA R742 found\n");
525 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
527 "Gazel: config irq:%d ipac:0x%X\n",
528 cs->irq, cs->hw.gazel.ipac);
535 static struct pci_dev *dev_tel __initdata = NULL;
538 setup_gazelpci(struct IsdnCardState *cs)
540 u_int pci_ioaddr0 = 0, pci_ioaddr1 = 0;
541 u_char pci_irq = 0, found;
542 u_int nbseek, seekcard;
544 printk(KERN_WARNING "Gazel: PCI card automatic recognition\n");
547 seekcard = PCI_DEVICE_ID_PLX_R685;
548 for (nbseek = 0; nbseek < 4; nbseek++) {
549 if ((dev_tel = pci_find_device(PCI_VENDOR_ID_PLX,
550 seekcard, dev_tel))) {
551 if (pci_enable_device(dev_tel))
553 pci_irq = dev_tel->irq;
554 pci_ioaddr0 = pci_resource_start(dev_tel, 1);
555 pci_ioaddr1 = pci_resource_start(dev_tel, 2);
562 case PCI_DEVICE_ID_PLX_R685:
563 seekcard = PCI_DEVICE_ID_PLX_R753;
565 case PCI_DEVICE_ID_PLX_R753:
566 seekcard = PCI_DEVICE_ID_PLX_DJINN_ITOO;
568 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
569 seekcard = PCI_DEVICE_ID_PLX_OLITEC;
575 printk(KERN_WARNING "Gazel: No PCI card found\n");
579 printk(KERN_WARNING "Gazel: No IRQ for PCI card found\n");
582 cs->hw.gazel.pciaddr[0] = pci_ioaddr0;
583 cs->hw.gazel.pciaddr[1] = pci_ioaddr1;
585 pci_ioaddr1 &= 0xfffe;
586 cs->hw.gazel.cfg_reg = pci_ioaddr0 & 0xfffe;
587 cs->hw.gazel.ipac = pci_ioaddr1;
588 cs->hw.gazel.isac = pci_ioaddr1 + 0x80;
589 cs->hw.gazel.hscx[0] = pci_ioaddr1;
590 cs->hw.gazel.hscx[1] = pci_ioaddr1 + 0x40;
591 cs->hw.gazel.isacfifo = cs->hw.gazel.isac;
592 cs->hw.gazel.hscxfifo[0] = cs->hw.gazel.hscx[0];
593 cs->hw.gazel.hscxfifo[1] = cs->hw.gazel.hscx[1];
595 cs->irq_flags |= SA_SHIRQ;
598 case PCI_DEVICE_ID_PLX_R685:
599 printk(KERN_INFO "Gazel: Card PCI R685 found\n");
601 cs->dc.isac.adf2 = 0x87;
603 "Gazel: config irq:%d isac:0x%X cfg:0x%X\n",
604 cs->irq, cs->hw.gazel.isac, cs->hw.gazel.cfg_reg);
606 "Gazel: hscx A:0x%X hscx B:0x%X\n",
607 cs->hw.gazel.hscx[0], cs->hw.gazel.hscx[1]);
609 case PCI_DEVICE_ID_PLX_R753:
610 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
611 case PCI_DEVICE_ID_PLX_OLITEC:
612 printk(KERN_INFO "Gazel: Card PCI R753 found\n");
614 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
616 "Gazel: config irq:%d ipac:0x%X cfg:0x%X\n",
617 cs->irq, cs->hw.gazel.ipac, cs->hw.gazel.cfg_reg);
625 setup_gazel(struct IsdnCard *card)
627 struct IsdnCardState *cs = card->cs;
631 strcpy(tmp, gazel_revision);
632 printk(KERN_INFO "Gazel: Driver Revision %s\n", HiSax_getrev(tmp));
634 if (cs->typ != ISDN_CTYPE_GAZEL)
638 if (setup_gazelisa(card, cs))
643 if (setup_gazelpci(cs))
646 printk(KERN_WARNING "Gazel: Card PCI requested and NO_PCI_BIOS, unable to config\n");
648 #endif /* CONFIG_PCI */
651 if (reserve_regions(card, cs)) {
654 if (reset_gazel(cs)) {
655 printk(KERN_WARNING "Gazel: wrong IRQ\n");
656 release_io_gazel(cs);
659 cs->readisac = &ReadISAC;
660 cs->writeisac = &WriteISAC;
661 cs->readisacfifo = &ReadISACfifo;
662 cs->writeisacfifo = &WriteISACfifo;
663 cs->BC_Read_Reg = &ReadHSCX;
664 cs->BC_Write_Reg = &WriteHSCX;
665 cs->BC_Send_Data = &hscx_fill_fifo;
666 cs->cardmsg = &Gazel_card_msg;
668 switch (cs->subtyp) {
671 cs->irq_func = &gazel_interrupt;
672 ISACVersion(cs, "Gazel:");
673 if (HscxVersion(cs, "Gazel:")) {
675 "Gazel: wrong HSCX versions check IO address\n");
676 release_io_gazel(cs);
682 cs->irq_func = &gazel_interrupt_ipac;
683 val = ReadISAC(cs, IPAC_ID - 0x80);
684 printk(KERN_INFO "Gazel: IPAC version %x\n", val);