1 /* $Id: nj_s.c,v 2.13.2.4 2004/01/16 01:53:48 keil Exp $
3 * This software may be used and distributed according to the terms
4 * of the GNU General Public License, incorporated herein by reference.
8 #include <linux/config.h>
9 #include <linux/init.h>
13 #include <linux/pci.h>
14 #include <linux/interrupt.h>
15 #include <linux/ppp_defs.h>
18 static const char *NETjet_S_revision = "$Revision: 2.13.2.4 $";
20 static u_char dummyrr(struct IsdnCardState *cs, int chan, u_char off)
25 static void dummywr(struct IsdnCardState *cs, int chan, u_char off, u_char value)
30 netjet_s_interrupt(int intno, void *dev_id, struct pt_regs *regs)
32 struct IsdnCardState *cs = dev_id;
33 u_char val, s1val, s0val;
36 spin_lock_irqsave(&cs->lock, flags);
37 s1val = bytein(cs->hw.njet.base + NETJET_IRQSTAT1);
38 if (!(s1val & NETJET_ISACIRQ)) {
39 val = NETjet_ReadIC(cs, ISAC_ISTA);
40 if (cs->debug & L1_DEB_ISAC)
41 debugl1(cs, "tiger: i1 %x %x", s1val, val);
43 isac_interrupt(cs, val);
44 NETjet_WriteIC(cs, ISAC_MASK, 0xFF);
45 NETjet_WriteIC(cs, ISAC_MASK, 0x0);
51 * read/write stat0 is better, because lower IRQ rate
52 * Note the IRQ is on for 125 us if a condition match
53 * thats long on modern CPU and so the IRQ is reentered
56 s0val = bytein(cs->hw.njet.base + NETJET_IRQSTAT0);
57 if ((s0val | s1val)==0) { // shared IRQ
58 spin_unlock_irqrestore(&cs->lock, flags);
62 byteout(cs->hw.njet.base + NETJET_IRQSTAT0, s0val);
63 /* start new code 13/07/00 GE */
64 /* set bits in sval to indicate which page is free */
65 if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
66 inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
67 /* the 2nd write page is free */
69 else /* the 1st write page is free */
71 if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
72 inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
73 /* the 2nd read page is free */
75 else /* the 1st read page is free */
77 if (s0val != cs->hw.njet.last_is0) /* we have a DMA interrupt */
79 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
80 printk(KERN_WARNING "nj LOCK_ATOMIC s0val %x->%x\n",
81 cs->hw.njet.last_is0, s0val);
82 spin_unlock_irqrestore(&cs->lock, flags);
85 cs->hw.njet.irqstat0 = s0val;
86 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
87 (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
88 /* we have a read dma int */
90 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
91 (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
92 /* we have a write dma int */
94 /* end new code 13/07/00 GE */
95 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
97 spin_unlock_irqrestore(&cs->lock, flags);
102 reset_netjet_s(struct IsdnCardState *cs)
104 cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
105 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
107 /* now edge triggered for TJ320 GE 13/07/00 */
108 /* see comment in IRQ function */
109 if (cs->subtyp) /* TJ320 */
110 cs->hw.njet.ctrl_reg = 0x40; /* Reset Off and status read clear */
112 cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
113 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
115 cs->hw.njet.auxd = 0;
116 cs->hw.njet.dmactrl = 0;
117 byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
118 byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
119 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
123 NETjet_S_card_msg(struct IsdnCardState *cs, int mt, void *arg)
129 spin_lock_irqsave(&cs->lock, flags);
131 spin_unlock_irqrestore(&cs->lock, flags);
134 release_io_netjet(cs);
139 spin_lock_irqsave(&cs->lock, flags);
140 clear_pending_isac_ints(cs);
142 /* Reenable all IRQ */
143 cs->writeisac(cs, ISAC_MASK, 0);
144 spin_unlock_irqrestore(&cs->lock, flags);
152 static struct pci_dev *dev_netjet __initdata = NULL;
155 setup_netjet_s(struct IsdnCard *card)
158 struct IsdnCardState *cs = card->cs;
162 #error "not running on big endian machines now"
164 strcpy(tmp, NETjet_S_revision);
165 printk(KERN_INFO "HiSax: Traverse Tech. NETjet-S driver Rev. %s\n", HiSax_getrev(tmp));
166 if (cs->typ != ISDN_CTYPE_NETJET_S)
168 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
174 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
175 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
176 if (pci_enable_device(dev_netjet))
178 pci_set_master(dev_netjet);
179 cs->irq = dev_netjet->irq;
181 printk(KERN_WARNING "NETjet-S: No IRQ for PCI card found\n");
184 cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
185 if (!cs->hw.njet.base) {
186 printk(KERN_WARNING "NETjet-S: No IO-Adr for PCI card found\n");
189 /* the TJ300 and TJ320 must be detected, the IRQ handling is different
190 * unfortunatly the chips use the same device ID, but the TJ320 has
191 * the bit20 in status PCI cfg register set
193 pci_read_config_dword(dev_netjet, 0x04, &cfg);
194 if (cfg & 0x00100000)
195 cs->subtyp = 1; /* TJ320 */
197 cs->subtyp = 0; /* TJ300 */
198 /* 2001/10/04 Christoph Ersfeld, Formula-n Europe AG www.formula-n.com */
199 if ((dev_netjet->subsystem_vendor == 0x55) &&
200 (dev_netjet->subsystem_device == 0x02)) {
201 printk(KERN_WARNING "Netjet: You tried to load this driver with an incompatible TigerJet-card\n");
202 printk(KERN_WARNING "Use type=41 for Formula-n enter:now ISDN PCI and compatible\n");
207 printk(KERN_WARNING "NETjet-S: No PCI card found\n");
211 cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
212 cs->hw.njet.isac = cs->hw.njet.base | NETJET_ISAC_OFF;
214 cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
215 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
218 cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
219 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
222 cs->hw.njet.auxd = 0xC0;
223 cs->hw.njet.dmactrl = 0;
225 byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
226 byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
227 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
229 switch ( ( ( NETjet_ReadIC( cs, ISAC_RBCH ) >> 5 ) & 3 ) )
235 printk( KERN_WARNING "NETjet-S: NETspider-U PCI card found\n" );
239 printk( KERN_WARNING "NETjet-S: No PCI card found\n" );
246 printk(KERN_WARNING "NETjet-S: NO_PCI_BIOS\n");
247 printk(KERN_WARNING "NETjet-S: unable to config NETJET-S PCI\n");
250 #endif /* CONFIG_PCI */
255 "NETjet-S: %s card configured at %#lx IRQ %d\n",
256 cs->subtyp ? "TJ320" : "TJ300", cs->hw.njet.base, cs->irq);
257 if (!request_region(cs->hw.njet.base, bytecnt, "netjet-s isdn")) {
259 "HiSax: %s config port %#lx-%#lx already in use\n",
262 cs->hw.njet.base + bytecnt);
265 cs->readisac = &NETjet_ReadIC;
266 cs->writeisac = &NETjet_WriteIC;
267 cs->readisacfifo = &NETjet_ReadICfifo;
268 cs->writeisacfifo = &NETjet_WriteICfifo;
269 cs->BC_Read_Reg = &dummyrr;
270 cs->BC_Write_Reg = &dummywr;
271 cs->BC_Send_Data = &netjet_fill_dma;
273 cs->cardmsg = &NETjet_S_card_msg;
274 cs->irq_func = &netjet_s_interrupt;
275 cs->irq_flags |= SA_SHIRQ;
276 ISACVersion(cs, "NETjet-S:");