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 * neccessary 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 #define __NO_VERSION__
64 #include <linux/config.h>
68 #include "amd7930_fn.h"
70 #include <linux/interrupt.h>
71 #include <linux/ppp_defs.h>
72 #include <linux/pci.h>
73 #include <linux/init.h>
78 const char *enternow_pci_rev = "$Revision: 1.1.2.1 $";
81 /* *************************** I/O-Interface functions ************************************* */
84 /* cs->readisac, macro rByteAMD */
86 ReadByteAmd7930(struct IsdnCardState *cs, BYTE offset)
88 /* direktes Register */
90 return (InByte(cs->hw.njet.isac + 4*offset));
92 /* indirektes Register */
94 OutByte(cs->hw.njet.isac + 4*AMD_CR, offset);
95 return(InByte(cs->hw.njet.isac + 4*AMD_DR));
99 /* cs->writeisac, macro wByteAMD */
101 WriteByteAmd7930(struct IsdnCardState *cs, BYTE offset, BYTE value)
103 /* direktes Register */
105 OutByte(cs->hw.njet.isac + 4*offset, value);
107 /* indirektes Register */
109 OutByte(cs->hw.njet.isac + 4*AMD_CR, offset);
110 OutByte(cs->hw.njet.isac + 4*AMD_DR, value);
116 enpci_setIrqMask(struct IsdnCardState *cs, BYTE val) {
118 OutByte(cs->hw.njet.base+NETJET_IRQMASK1, 0x00);
120 OutByte(cs->hw.njet.base+NETJET_IRQMASK1, TJ_AMD_IRQ);
124 static BYTE dummyrr(struct IsdnCardState *cs, int chan, BYTE off)
129 static void dummywr(struct IsdnCardState *cs, int chan, BYTE off, BYTE value)
135 /* ******************************************************************************** */
139 reset_enpci(struct IsdnCardState *cs)
143 if (cs->debug & L1_DEB_ISAC)
144 debugl1(cs, "enter:now PCI: reset");
148 /* Reset on, (also for AMD) */
149 cs->hw.njet.ctrl_reg = 0x07;
150 OutByte(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
151 set_current_state(TASK_UNINTERRUPTIBLE);
153 schedule_timeout((80*HZ)/1000);
155 cs->hw.njet.ctrl_reg = 0x70;
156 OutByte(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
157 set_current_state(TASK_UNINTERRUPTIBLE);
159 schedule_timeout((80*HZ)/1000);
160 restore_flags(flags);
161 cs->hw.njet.auxd = 0; // LED-status
162 cs->hw.njet.dmactrl = 0;
163 OutByte(cs->hw.njet.base + NETJET_AUXCTRL, ~TJ_AMD_IRQ);
164 OutByte(cs->hw.njet.base + NETJET_IRQMASK1, TJ_AMD_IRQ);
165 OutByte(cs->hw.njet.auxa, cs->hw.njet.auxd); // LED off
171 enpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
175 if (cs->debug & L1_DEB_ISAC)
176 debugl1(cs, "enter:now PCI: card_msg: 0x%04X", mt);
184 release_io_netjet(cs);
193 /* TEI assigned, LED1 on */
194 cs->hw.njet.auxd = TJ_AMD_IRQ << 1;
195 OutByte(cs->hw.njet.base + NETJET_AUXDATA, cs->hw.njet.auxd);
198 /* TEI removed, LEDs off */
199 cs->hw.njet.auxd = 0;
200 OutByte(cs->hw.njet.base + NETJET_AUXDATA, 0x00);
203 /* activate B-channel */
206 if (cs->debug & L1_DEB_ISAC)
207 debugl1(cs, "enter:now PCI: assign phys. BC %d in AMD LMR1", *chan);
209 cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 | (*chan + 1)), "MDL_BC_ASSIGN");
210 /* at least one b-channel in use, LED 2 on */
211 cs->hw.njet.auxd |= TJ_AMD_IRQ << 2;
212 OutByte(cs->hw.njet.base + NETJET_AUXDATA, cs->hw.njet.auxd);
215 /* deactivate B-channel */
218 if (cs->debug & L1_DEB_ISAC)
219 debugl1(cs, "enter:now PCI: release phys. BC %d in Amd LMR1", *chan);
221 cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 & ~(*chan + 1)), "MDL_BC_RELEASE");
222 /* no b-channel active -> LED2 off */
223 if (!(cs->dc.amd7930.lmr1 & 3)) {
224 cs->hw.njet.auxd &= ~(TJ_AMD_IRQ << 2);
225 OutByte(cs->hw.njet.base + NETJET_AUXDATA, cs->hw.njet.auxd);
237 enpci_interrupt(int intno, void *dev_id, struct pt_regs *regs)
239 struct IsdnCardState *cs = dev_id;
245 printk(KERN_WARNING "enter:now PCI: Spurious interrupt!\n");
249 sval = InByte(cs->hw.njet.base + NETJET_IRQSTAT1);
251 /* AMD threw an interrupt */
252 if (!(sval & TJ_AMD_IRQ)) {
253 /* read and clear interrupt-register */
254 ir = ReadByteAmd7930(cs, 0x00);
255 Amd7930_interrupt(cs, ir);
258 /* DMA-Interrupt: B-channel-stuff */
259 /* set bits in sval to indicate which page is free */
263 /* set bits in sval to indicate which page is free */
264 if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
265 inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
266 /* the 2nd write page is free */
268 else /* the 1st write page is free */
270 if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
271 inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
272 /* the 2nd read page is free */
274 else /* the 1st read page is free */
276 if (sval != cs->hw.njet.last_is0) /* we have a DMA interrupt */
278 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
279 restore_flags(flags);
282 cs->hw.njet.irqstat0 = sval;
283 restore_flags(flags);
284 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
285 (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
286 /* we have a read dma int */
288 if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
289 (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
290 /* we have a write dma int */
292 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
294 restore_flags(flags);
298 static struct pci_dev *dev_netjet __initdata = NULL;
300 /* called by config.c */
302 setup_enternow_pci(struct IsdnCard *card)
305 struct IsdnCardState *cs = card->cs;
311 #error "not running on big endian machines now"
313 strcpy(tmp, enternow_pci_rev);
314 printk(KERN_INFO "HiSax: Formula-n Europe AG enter:now ISDN PCI driver Rev. %s\n", HiSax_getrev(tmp));
315 if (cs->typ != ISDN_CTYPE_ENTERNOW)
317 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
321 if (!pci_present()) {
322 printk(KERN_ERR "enter:now PCI: no PCI bus present\n");
325 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
326 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
327 if (pci_enable_device(dev_netjet))
329 cs->irq = dev_netjet->irq;
331 printk(KERN_WARNING "enter:now PCI: No IRQ for PCI card found\n");
334 cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
335 if (!cs->hw.njet.base) {
336 printk(KERN_WARNING "enter:now PCI: No IO-Adr for PCI card found\n");
339 /* checks Sub-Vendor ID because system crashes with Traverse-Card */
340 if ((dev_netjet->subsystem_vendor != 0x55) ||
341 (dev_netjet->subsystem_device != 0x02)) {
342 printk(KERN_WARNING "enter:now: You tried to load this driver with an incompatible TigerJet-card\n");
343 printk(KERN_WARNING "Use type=20 for Traverse NetJet PCI Card.\n");
347 printk(KERN_WARNING "enter:now PCI: No PCI card found\n");
351 cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
352 cs->hw.njet.isac = cs->hw.njet.base + 0xC0; // Fenster zum AMD
358 cs->hw.njet.ctrl_reg = 0x07; // geƤndert von 0xff
359 OutByte(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
361 set_current_state(TASK_UNINTERRUPTIBLE);
363 schedule_timeout((50*HZ)/1000);
365 cs->hw.njet.ctrl_reg = 0x30; /* Reset Off and status read clear */
366 OutByte(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
368 set_current_state(TASK_UNINTERRUPTIBLE);
369 schedule_timeout((10*HZ)/1000); /* Timeout 10ms */
371 restore_flags(flags);
373 cs->hw.njet.auxd = 0x00; // war 0xc0
374 cs->hw.njet.dmactrl = 0;
376 OutByte(cs->hw.njet.base + NETJET_AUXCTRL, ~TJ_AMD_IRQ);
377 OutByte(cs->hw.njet.base + NETJET_IRQMASK1, TJ_AMD_IRQ);
378 OutByte(cs->hw.njet.auxa, cs->hw.njet.auxd);
384 printk(KERN_WARNING "enter:now PCI: NO_PCI_BIOS\n");
385 printk(KERN_WARNING "enter:now PCI: unable to config Formula-n enter:now ISDN PCI ab\n");
388 #endif /* CONFIG_PCI */
393 "enter:now PCI: PCI card configured at 0x%lx IRQ %d\n",
394 cs->hw.njet.base, cs->irq);
395 if (check_region(cs->hw.njet.base, bytecnt)) {
397 "HiSax: %s config port %lx-%lx already in use\n",
400 cs->hw.njet.base + bytecnt);
403 request_region(cs->hw.njet.base, bytecnt, "Fn_ISDN");
406 cs->hw.njet.last_is0 = 0;
408 cs->readisac = &ReadByteAmd7930;
410 cs->writeisac = &WriteByteAmd7930;
411 cs->dc.amd7930.setIrqMask = &enpci_setIrqMask;
413 cs->BC_Read_Reg = &dummyrr;
414 cs->BC_Write_Reg = &dummywr;
415 cs->BC_Send_Data = &netjet_fill_dma;
416 cs->cardmsg = &enpci_card_msg;
417 cs->irq_func = &enpci_interrupt;
418 cs->irq_flags |= SA_SHIRQ;