Linux 2.6.21.1
[linux/fpc-iii.git] / drivers / isdn / hisax / nj_u.c
blob8202cf34ecae729a9f2641f55fc991696f00cd83
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.
6 */
8 #include <linux/init.h>
9 #include "hisax.h"
10 #include "icc.h"
11 #include "isdnl1.h"
12 #include <linux/pci.h>
13 #include <linux/interrupt.h>
14 #include <linux/ppp_defs.h>
15 #include "netjet.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)
21 return(5);
24 static void dummywr(struct IsdnCardState *cs, int chan, u_char off, u_char value)
28 static irqreturn_t
29 netjet_u_interrupt(int intno, void *dev_id)
31 struct IsdnCardState *cs = dev_id;
32 u_char val, sval;
33 u_long flags;
35 spin_lock_irqsave(&cs->lock, flags);
36 if (!((sval = bytein(cs->hw.njet.base + NETJET_IRQSTAT1)) &
37 NETJET_ISACIRQ)) {
38 val = NETjet_ReadIC(cs, ICC_ISTA);
39 if (cs->debug & L1_DEB_ISAC)
40 debugl1(cs, "tiger: i1 %x %x", sval, val);
41 if (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 */
52 sval = 0x08;
53 else /* the 1st write page is free */
54 sval = 0x04;
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 */
58 sval = sval | 0x02;
59 else /* the 1st read page is free */
60 sval = sval | 0x01;
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);
65 return IRQ_HANDLED;
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 */
71 read_tiger(cs);
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 */
75 write_tiger(cs);
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);
80 return IRQ_HANDLED;
83 static void
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);
88 mdelay(10);
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);
92 mdelay(10);
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);
101 static int
102 NETjet_U_card_msg(struct IsdnCardState *cs, int mt, void *arg)
104 u_long flags;
106 switch (mt) {
107 case CARD_RESET:
108 spin_lock_irqsave(&cs->lock, flags);
109 reset_netjet_u(cs);
110 spin_unlock_irqrestore(&cs->lock, flags);
111 return(0);
112 case CARD_RELEASE:
113 release_io_netjet(cs);
114 return(0);
115 case CARD_INIT:
116 spin_lock_irqsave(&cs->lock, flags);
117 inittiger(cs);
118 reset_netjet_u(cs);
119 clear_pending_icc_ints(cs);
120 initicc(cs);
121 /* Reenable all IRQ */
122 cs->writeisac(cs, ICC_MASK, 0);
123 spin_unlock_irqrestore(&cs->lock, flags);
124 return(0);
125 case CARD_TEST:
126 return(0);
128 return(0);
131 static struct pci_dev *dev_netjet __devinitdata = NULL;
133 int __devinit
134 setup_netjet_u(struct IsdnCard *card)
136 int bytecnt;
137 struct IsdnCardState *cs = card->cs;
138 char tmp[64];
139 #ifdef CONFIG_PCI
140 #endif
141 #ifdef __BIG_ENDIAN
142 #error "not running on big endian machines now"
143 #endif
144 strcpy(tmp, NETjet_U_revision);
145 printk(KERN_INFO "HiSax: Traverse Tech. NETspider-U driver Rev. %s\n", HiSax_getrev(tmp));
146 if (cs->typ != ISDN_CTYPE_NETJET_U)
147 return(0);
148 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
150 #ifdef CONFIG_PCI
152 for ( ;; )
154 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
155 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
156 if (pci_enable_device(dev_netjet))
157 return(0);
158 pci_set_master(dev_netjet);
159 cs->irq = dev_netjet->irq;
160 if (!cs->irq) {
161 printk(KERN_WARNING "NETspider-U: No IRQ for PCI card found\n");
162 return(0);
164 cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
165 if (!cs->hw.njet.base) {
166 printk(KERN_WARNING "NETspider-U: No IO-Adr for PCI card found\n");
167 return(0);
169 } else {
170 printk(KERN_WARNING "NETspider-U: No PCI card found\n");
171 return(0);
174 cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
175 cs->hw.njet.isac = cs->hw.njet.base | NETJET_ISAC_OFF;
176 mdelay(10);
178 cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
179 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
180 mdelay(10);
182 cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
183 byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
184 mdelay(10);
186 cs->hw.njet.auxd = 0xC0;
187 cs->hw.njet.dmactrl = 0;
189 byteout(cs->hw.njet.auxa, 0);
190 byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
191 byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
192 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
194 switch ( ( ( NETjet_ReadIC( cs, ICC_RBCH ) >> 5 ) & 3 ) )
196 case 3 :
197 break;
199 case 0 :
200 printk( KERN_WARNING "NETspider-U: NETjet-S PCI card found\n" );
201 continue;
203 default :
204 printk( KERN_WARNING "NETspider-U: No PCI card found\n" );
205 return 0;
207 break;
209 #else
211 printk(KERN_WARNING "NETspider-U: NO_PCI_BIOS\n");
212 printk(KERN_WARNING "NETspider-U: unable to config NETspider-U PCI\n");
213 return (0);
215 #endif /* CONFIG_PCI */
217 bytecnt = 256;
219 printk(KERN_INFO
220 "NETspider-U: PCI card configured at %#lx IRQ %d\n",
221 cs->hw.njet.base, cs->irq);
222 if (!request_region(cs->hw.njet.base, bytecnt, "netspider-u isdn")) {
223 printk(KERN_WARNING
224 "HiSax: %s config port %#lx-%#lx already in use\n",
225 CardType[card->typ],
226 cs->hw.njet.base,
227 cs->hw.njet.base + bytecnt);
228 return (0);
230 setup_icc(cs);
231 cs->readisac = &NETjet_ReadIC;
232 cs->writeisac = &NETjet_WriteIC;
233 cs->readisacfifo = &NETjet_ReadICfifo;
234 cs->writeisacfifo = &NETjet_WriteICfifo;
235 cs->BC_Read_Reg = &dummyrr;
236 cs->BC_Write_Reg = &dummywr;
237 cs->BC_Send_Data = &netjet_fill_dma;
238 cs->cardmsg = &NETjet_U_card_msg;
239 cs->irq_func = &netjet_u_interrupt;
240 cs->irq_flags |= IRQF_SHARED;
241 ICCVersion(cs, "NETspider-U:");
242 return (1);