1 /* $Id: nj_u.c,v 2.14.2.3 2004/01/13 14:31:26 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/init.h>
12 #include <linux/pci.h>
13 #include <linux/interrupt.h>
14 #include <linux/ppp_defs.h>
17 static const char *NETjet_U_revision
= "$Revision: 2.14.2.3 $";
19 static u_char
dummyrr(struct IsdnCardState
*cs
, int chan
, u_char off
)
24 static void dummywr(struct IsdnCardState
*cs
, int chan
, u_char off
, u_char value
)
29 netjet_u_interrupt(int intno
, void *dev_id
)
31 struct IsdnCardState
*cs
= dev_id
;
35 spin_lock_irqsave(&cs
->lock
, flags
);
36 if (!((sval
= bytein(cs
->hw
.njet
.base
+ NETJET_IRQSTAT1
)) &
38 val
= NETjet_ReadIC(cs
, ICC_ISTA
);
39 if (cs
->debug
& L1_DEB_ISAC
)
40 debugl1(cs
, "tiger: i1 %x %x", sval
, val
);
42 icc_interrupt(cs
, val
);
43 NETjet_WriteIC(cs
, ICC_MASK
, 0xFF);
44 NETjet_WriteIC(cs
, ICC_MASK
, 0x0);
47 /* start new code 13/07/00 GE */
48 /* set bits in sval to indicate which page is free */
49 if (inl(cs
->hw
.njet
.base
+ NETJET_DMA_WRITE_ADR
) <
50 inl(cs
->hw
.njet
.base
+ NETJET_DMA_WRITE_IRQ
))
51 /* the 2nd write page is free */
53 else /* the 1st write page is free */
55 if (inl(cs
->hw
.njet
.base
+ NETJET_DMA_READ_ADR
) <
56 inl(cs
->hw
.njet
.base
+ NETJET_DMA_READ_IRQ
))
57 /* the 2nd read page is free */
59 else /* the 1st read page is free */
61 if (sval
!= cs
->hw
.njet
.last_is0
) /* we have a DMA interrupt */
63 if (test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
64 spin_unlock_irqrestore(&cs
->lock
, flags
);
67 cs
->hw
.njet
.irqstat0
= sval
;
68 if ((cs
->hw
.njet
.irqstat0
& NETJET_IRQM0_READ
) !=
69 (cs
->hw
.njet
.last_is0
& NETJET_IRQM0_READ
))
70 /* we have a read dma int */
72 if ((cs
->hw
.njet
.irqstat0
& NETJET_IRQM0_WRITE
) !=
73 (cs
->hw
.njet
.last_is0
& NETJET_IRQM0_WRITE
))
74 /* we have a write dma int */
76 /* end new code 13/07/00 GE */
77 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
79 spin_unlock_irqrestore(&cs
->lock
, flags
);
84 reset_netjet_u(struct IsdnCardState
*cs
)
86 cs
->hw
.njet
.ctrl_reg
= 0xff; /* Reset On */
87 byteout(cs
->hw
.njet
.base
+ NETJET_CTRL
, cs
->hw
.njet
.ctrl_reg
);
89 cs
->hw
.njet
.ctrl_reg
= 0x40; /* Reset Off and status read clear */
90 /* now edge triggered for TJ320 GE 13/07/00 */
91 byteout(cs
->hw
.njet
.base
+ NETJET_CTRL
, cs
->hw
.njet
.ctrl_reg
);
93 cs
->hw
.njet
.auxd
= 0xC0;
94 cs
->hw
.njet
.dmactrl
= 0;
95 byteout(cs
->hw
.njet
.auxa
, 0);
96 byteout(cs
->hw
.njet
.base
+ NETJET_AUXCTRL
, ~NETJET_ISACIRQ
);
97 byteout(cs
->hw
.njet
.base
+ NETJET_IRQMASK1
, NETJET_ISACIRQ
);
98 byteout(cs
->hw
.njet
.auxa
, cs
->hw
.njet
.auxd
);
102 NETjet_U_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
108 spin_lock_irqsave(&cs
->lock
, flags
);
110 spin_unlock_irqrestore(&cs
->lock
, flags
);
113 release_io_netjet(cs
);
116 spin_lock_irqsave(&cs
->lock
, flags
);
119 clear_pending_icc_ints(cs
);
121 /* Reenable all IRQ */
122 cs
->writeisac(cs
, ICC_MASK
, 0);
123 spin_unlock_irqrestore(&cs
->lock
, flags
);
131 static int nju_pci_probe(struct pci_dev
*dev_netjet
, struct IsdnCardState
*cs
)
133 if (pci_enable_device(dev_netjet
))
135 pci_set_master(dev_netjet
);
136 cs
->irq
= dev_netjet
->irq
;
138 printk(KERN_WARNING
"NETspider-U: No IRQ for PCI card found\n");
141 cs
->hw
.njet
.base
= pci_resource_start(dev_netjet
, 0);
142 if (!cs
->hw
.njet
.base
) {
143 printk(KERN_WARNING
"NETspider-U: No IO-Adr for PCI card found\n");
150 static int nju_cs_init(struct IsdnCard
*card
, struct IsdnCardState
*cs
)
152 cs
->hw
.njet
.auxa
= cs
->hw
.njet
.base
+ NETJET_AUXDATA
;
153 cs
->hw
.njet
.isac
= cs
->hw
.njet
.base
| NETJET_ISAC_OFF
;
156 cs
->hw
.njet
.ctrl_reg
= 0xff; /* Reset On */
157 byteout(cs
->hw
.njet
.base
+ NETJET_CTRL
, cs
->hw
.njet
.ctrl_reg
);
160 cs
->hw
.njet
.ctrl_reg
= 0x00; /* Reset Off and status read clear */
161 byteout(cs
->hw
.njet
.base
+ NETJET_CTRL
, cs
->hw
.njet
.ctrl_reg
);
164 cs
->hw
.njet
.auxd
= 0xC0;
165 cs
->hw
.njet
.dmactrl
= 0;
167 byteout(cs
->hw
.njet
.auxa
, 0);
168 byteout(cs
->hw
.njet
.base
+ NETJET_AUXCTRL
, ~NETJET_ISACIRQ
);
169 byteout(cs
->hw
.njet
.base
+ NETJET_IRQMASK1
, NETJET_ISACIRQ
);
170 byteout(cs
->hw
.njet
.auxa
, cs
->hw
.njet
.auxd
);
172 switch (((NETjet_ReadIC(cs
, ICC_RBCH
) >> 5) & 3))
175 return 1; /* end loop */
178 printk(KERN_WARNING
"NETspider-U: NETjet-S PCI card found\n");
179 return -1; /* continue looping */
182 printk(KERN_WARNING
"NETspider-U: No PCI card found\n");
183 return 0; /* end loop & function */
185 return 1; /* end loop */
188 static int nju_cs_init_rest(struct IsdnCard
*card
, struct IsdnCardState
*cs
)
190 const int bytecnt
= 256;
193 "NETspider-U: PCI card configured at %#lx IRQ %d\n",
194 cs
->hw
.njet
.base
, cs
->irq
);
195 if (!request_region(cs
->hw
.njet
.base
, bytecnt
, "netspider-u isdn")) {
197 "HiSax: NETspider-U config port %#lx-%#lx "
200 cs
->hw
.njet
.base
+ bytecnt
);
204 cs
->readisac
= &NETjet_ReadIC
;
205 cs
->writeisac
= &NETjet_WriteIC
;
206 cs
->readisacfifo
= &NETjet_ReadICfifo
;
207 cs
->writeisacfifo
= &NETjet_WriteICfifo
;
208 cs
->BC_Read_Reg
= &dummyrr
;
209 cs
->BC_Write_Reg
= &dummywr
;
210 cs
->BC_Send_Data
= &netjet_fill_dma
;
211 cs
->cardmsg
= &NETjet_U_card_msg
;
212 cs
->irq_func
= &netjet_u_interrupt
;
213 cs
->irq_flags
|= IRQF_SHARED
;
214 ICCVersion(cs
, "NETspider-U:");
219 static struct pci_dev
*dev_netjet
= NULL
;
221 int setup_netjet_u(struct IsdnCard
*card
)
224 struct IsdnCardState
*cs
= card
->cs
;
228 #error "not running on big endian machines now"
231 strcpy(tmp
, NETjet_U_revision
);
232 printk(KERN_INFO
"HiSax: Traverse Tech. NETspider-U driver Rev. %s\n", HiSax_getrev(tmp
));
233 if (cs
->typ
!= ISDN_CTYPE_NETJET_U
)
235 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
239 if ((dev_netjet
= hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET
,
240 PCI_DEVICE_ID_TIGERJET_300
, dev_netjet
))) {
241 ret
= nju_pci_probe(dev_netjet
, cs
);
245 printk(KERN_WARNING
"NETspider-U: No PCI card found\n");
249 ret
= nju_cs_init(card
, cs
);
254 /* ret < 0 == continue looping */
257 return nju_cs_init_rest(card
, cs
);