1 /* enternow_pci.c,v 0.99 2001/10/02
3 * enternow_pci.c Card-specific routines for
4 * Formula-n enter:now ISDN PCI ab
5 * Gerdes AG Power ISDN PCI
6 * Woerltronic SA 16 PCI
7 * (based on HiSax driver by Karsten Keil)
9 * Author Christoph Ersfeld <info@formula-n.de>
10 * Formula-n Europe AG (www.formula-n.com)
11 * previously Gerdes AG
14 * This file is (c) under GNU PUBLIC LICENSE
17 * This driver interfaces to netjet.c which performs B-channel
20 * Version 0.99 is the first release of this driver and there are
21 * certainly a few bugs.
22 * It isn't testet on linux 2.4 yet, so consider this code to be
25 * Please don't report me any malfunction without sending
26 * (compressed) debug-logs.
27 * It would be nearly impossible to retrace it.
29 * Log D-channel-processing as follows:
31 * 1. Load hisax with card-specific parameters, this example ist for
32 * Formula-n enter:now ISDN PCI and compatible
33 * (f.e. Gerdes Power ISDN PCI)
35 * modprobe hisax type=41 protocol=2 id=gerdes
37 * if you chose an other value for id, you need to modify the
42 * hisaxctrl gerdes 1 0x3ff
43 * hisaxctrl gerdes 11 0x4f
44 * cat /dev/isdnctrl >> ~/log &
46 * Please take also a look into /var/log/messages if there is
47 * anything importand concerning HISAX.
51 * Programming the driver for Formula-n enter:now ISDN PCI and
52 * necessary the driver for the used Amd 7930 D-channel-controller
53 * was spnsored by Formula-n Europe AG.
54 * Thanks to Karsten Keil and Petr Novak, who gave me support in
55 * Hisax-specific questions.
56 * I want so say special thanks to Carl-Friedrich Braun, who had to
57 * answer a lot of questions about generally ISDN and about handling
63 #include <linux/config.h>
67 #include "amd7930_fn.h"
68 #include <linux/interrupt.h>
69 #include <linux/ppp_defs.h>
70 #include <linux/pci.h>
71 #include <linux/init.h>
76 static const char *enternow_pci_rev = "$Revision: 1.1.4.5 $";
79 /* für PowerISDN PCI */
80 #define TJ_AMD_IRQ 0x20
85 /* Das Fenster zum AMD...
86 * Ab Adresse hw.njet.base + TJ_AMD_PORT werden vom AMD jeweils 8 Bit in
87 * den TigerJet i/o-Raum gemappt
88 * -> 0x01 des AMD bei hw.njet.base + 0C4 */
89 #define TJ_AMD_PORT 0xC0
93 /* *************************** I/O-Interface functions ************************************* */
96 /* cs->readisac, macro rByteAMD */
98 ReadByteAmd7930(struct IsdnCardState *cs, unsigned char offset)
100 /* direktes Register */
102 return (inb(cs->hw.njet.isac + 4*offset));
104 /* indirektes Register */
106 outb(offset, cs->hw.njet.isac + 4*AMD_CR);
107 return(inb(cs->hw.njet.isac + 4*AMD_DR));
111 /* cs->writeisac, macro wByteAMD */
113 WriteByteAmd7930(struct IsdnCardState *cs, unsigned char offset, unsigned char value)
115 /* direktes Register */
117 outb(value, cs->hw.njet.isac + 4*offset);
119 /* indirektes Register */
121 outb(offset, cs->hw.njet.isac + 4*AMD_CR);
122 outb(value, cs->hw.njet.isac + 4*AMD_DR);
128 enpci_setIrqMask(struct IsdnCardState *cs, unsigned char val) {
130 outb(0x00, cs->hw.njet.base+NETJET_IRQMASK1);
132 outb(TJ_AMD_IRQ, cs->hw.njet.base+NETJET_IRQMASK1);
136 static unsigned char dummyrr(struct IsdnCardState *cs, int chan, unsigned char off)
141 static void dummywr(struct IsdnCardState *cs, int chan, unsigned char off, unsigned char value)
147 /* ******************************************************************************** */
151 reset_enpci(struct IsdnCardState *cs)
153 if (cs->debug & L1_DEB_ISAC)
154 debugl1(cs, "enter:now PCI: reset");
156 /* Reset on, (also for AMD) */
157 cs->hw.njet.ctrl_reg = 0x07;
158 outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
161 cs->hw.njet.ctrl_reg = 0x30;
162 outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
165 cs->hw.njet.auxd = 0; // LED-status
166 cs->hw.njet.dmactrl = 0;
167 outb(~TJ_AMD_IRQ, cs->hw.njet.base + NETJET_AUXCTRL);
168 outb(TJ_AMD_IRQ, cs->hw.njet.base + NETJET_IRQMASK1);
169 outb(cs->hw.njet.auxd, cs->hw.njet.auxa); // LED off
174 enpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
179 if (cs->debug & L1_DEB_ISAC)
180 debugl1(cs, "enter:now PCI: card_msg: 0x%04X", mt);
184 spin_lock_irqsave(&cs->lock, flags);
187 spin_unlock_irqrestore(&cs->lock, flags);
190 release_io_netjet(cs);
195 /* irq must be on here */
201 /* TEI assigned, LED1 on */
202 cs->hw.njet.auxd = TJ_AMD_IRQ << 1;
203 outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
206 /* TEI removed, LEDs off */
207 cs->hw.njet.auxd = 0;
208 outb(0x00, cs->hw.njet.base + NETJET_AUXDATA);
211 /* activate B-channel */
212 chan = (unsigned char *)arg;
214 if (cs->debug & L1_DEB_ISAC)
215 debugl1(cs, "enter:now PCI: assign phys. BC %d in AMD LMR1", *chan);
217 cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 | (*chan + 1)), "MDL_BC_ASSIGN");
218 /* at least one b-channel in use, LED 2 on */
219 cs->hw.njet.auxd |= TJ_AMD_IRQ << 2;
220 outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
223 /* deactivate B-channel */
224 chan = (unsigned char *)arg;
226 if (cs->debug & L1_DEB_ISAC)
227 debugl1(cs, "enter:now PCI: release phys. BC %d in Amd LMR1", *chan);
229 cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 & ~(*chan + 1)), "MDL_BC_RELEASE");
230 /* no b-channel active -> LED2 off */
231 if (!(cs->dc.amd7930.lmr1 & 3)) {
232 cs->hw.njet.auxd &= ~(TJ_AMD_IRQ << 2);
233 outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
244 enpci_interrupt(int intno, void *dev_id, struct pt_regs *regs)
246 struct IsdnCardState *cs = dev_id;
247 unsigned char s0val, s1val, ir;
250 spin_lock_irqsave(&cs->lock, flags);
251 s1val = inb(cs->hw.njet.base + NETJET_IRQSTAT1);
253 /* AMD threw an interrupt */
254 if (!(s1val & TJ_AMD_IRQ)) {
255 /* read and clear interrupt-register */
256 ir = ReadByteAmd7930(cs, 0x00);
257 Amd7930_interrupt(cs, ir);
261 s0val = inb(cs->hw.njet.base + NETJET_IRQSTAT0);
262 if ((s0val | s1val)==0) { // shared IRQ
263 spin_unlock_irqrestore(&cs->lock, flags);
267 outb(s0val, cs->hw.njet.base + NETJET_IRQSTAT0);
269 /* DMA-Interrupt: B-channel-stuff */
270 /* set bits in sval to indicate which page is free */
271 if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
272 inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
273 /* the 2nd write page is free */
275 else /* the 1st write page is free */
277 if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
278 inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
279 /* the 2nd read page is free */
280 s0val = s0val | 0x02;
281 else /* the 1st read page is free */
282 s0val = s0val | 0x01;
283 if (s0val != cs->hw.njet.last_is0) /* we have a DMA interrupt */
285 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
286 spin_unlock_irqrestore(&cs->lock, flags);
289 cs->hw.njet.irqstat0 = s0val;
290 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
291 (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
292 /* we have a read dma int */
294 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
295 (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
296 /* we have a write dma int */
298 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
300 spin_unlock_irqrestore(&cs->lock, flags);
305 static struct pci_dev *dev_netjet __initdata = NULL;
307 /* called by config.c */
309 setup_enternow_pci(struct IsdnCard *card)
312 struct IsdnCardState *cs = card->cs;
317 #error "not running on big endian machines now"
319 strcpy(tmp, enternow_pci_rev);
320 printk(KERN_INFO "HiSax: Formula-n Europe AG enter:now ISDN PCI driver Rev. %s\n", HiSax_getrev(tmp));
321 if (cs->typ != ISDN_CTYPE_ENTERNOW)
323 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
327 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
328 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
329 if (pci_enable_device(dev_netjet))
331 cs->irq = dev_netjet->irq;
333 printk(KERN_WARNING "enter:now PCI: No IRQ for PCI card found\n");
336 cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
337 if (!cs->hw.njet.base) {
338 printk(KERN_WARNING "enter:now PCI: No IO-Adr for PCI card found\n");
341 /* checks Sub-Vendor ID because system crashes with Traverse-Card */
342 if ((dev_netjet->subsystem_vendor != 0x55) ||
343 (dev_netjet->subsystem_device != 0x02)) {
344 printk(KERN_WARNING "enter:now: You tried to load this driver with an incompatible TigerJet-card\n");
345 printk(KERN_WARNING "Use type=20 for Traverse NetJet PCI Card.\n");
349 printk(KERN_WARNING "enter:now PCI: No PCI card found\n");
353 cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
354 cs->hw.njet.isac = cs->hw.njet.base + 0xC0; // Fenster zum AMD
357 cs->hw.njet.ctrl_reg = 0x07; // geändert von 0xff
358 outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
362 cs->hw.njet.ctrl_reg = 0x30; /* Reset Off and status read clear */
363 outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
366 cs->hw.njet.auxd = 0x00; // war 0xc0
367 cs->hw.njet.dmactrl = 0;
369 outb(~TJ_AMD_IRQ, cs->hw.njet.base + NETJET_AUXCTRL);
370 outb(TJ_AMD_IRQ, cs->hw.njet.base + NETJET_IRQMASK1);
371 outb(cs->hw.njet.auxd, cs->hw.njet.auxa);
377 printk(KERN_WARNING "enter:now PCI: NO_PCI_BIOS\n");
378 printk(KERN_WARNING "enter:now PCI: unable to config Formula-n enter:now ISDN PCI ab\n");
381 #endif /* CONFIG_PCI */
386 "enter:now PCI: PCI card configured at 0x%lx IRQ %d\n",
387 cs->hw.njet.base, cs->irq);
388 if (!request_region(cs->hw.njet.base, bytecnt, "Fn_ISDN")) {
390 "HiSax: %s config port %lx-%lx already in use\n",
393 cs->hw.njet.base + bytecnt);
397 cs->hw.njet.last_is0 = 0;
399 cs->readisac = &ReadByteAmd7930;
401 cs->writeisac = &WriteByteAmd7930;
402 cs->dc.amd7930.setIrqMask = &enpci_setIrqMask;
404 cs->BC_Read_Reg = &dummyrr;
405 cs->BC_Write_Reg = &dummywr;
406 cs->BC_Send_Data = &netjet_fill_dma;
407 cs->cardmsg = &enpci_card_msg;
408 cs->irq_func = &enpci_interrupt;
409 cs->irq_flags |= SA_SHIRQ;