1 /* $Id: bkm_a4t.c,v 1.22.2.4 2004/01/14 16:04:48 keil Exp $
3 * low level stuff for T-Berkom A4T
5 * Author Roland Klabunde
6 * Copyright by Roland Klabunde <R.Klabunde@Berkom.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/init.h>
20 #include <linux/pci.h>
23 static const char *bkm_a4t_revision
= "$Revision: 1.22.2.4 $";
27 readreg(unsigned int ale
, unsigned long adr
, u_char off
)
30 unsigned int *po
= (unsigned int *) adr
; /* Postoffice */
32 *po
= (GCS_2
| PO_WRITE
| off
);
34 *po
= (ale
| PO_READ
);
37 return ((unsigned char) ret
);
42 readfifo(unsigned int ale
, unsigned long adr
, u_char off
, u_char
*data
, int size
)
45 for (i
= 0; i
< size
; i
++)
46 *data
++ = readreg(ale
, adr
, off
);
51 writereg(unsigned int ale
, unsigned long adr
, u_char off
, u_char data
)
53 unsigned int *po
= (unsigned int *) adr
; /* Postoffice */
54 *po
= (GCS_2
| PO_WRITE
| off
);
56 *po
= (ale
| PO_WRITE
| data
);
62 writefifo(unsigned int ale
, unsigned long adr
, u_char off
, u_char
*data
, int size
)
66 for (i
= 0; i
< size
; i
++)
67 writereg(ale
, adr
, off
, *data
++);
71 /* Interface functions */
74 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
76 return (readreg(cs
->hw
.ax
.isac_ale
, cs
->hw
.ax
.isac_adr
, offset
));
80 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
82 writereg(cs
->hw
.ax
.isac_ale
, cs
->hw
.ax
.isac_adr
, offset
, value
);
86 ReadISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
88 readfifo(cs
->hw
.ax
.isac_ale
, cs
->hw
.ax
.isac_adr
, 0, data
, size
);
92 WriteISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
94 writefifo(cs
->hw
.ax
.isac_ale
, cs
->hw
.ax
.isac_adr
, 0, data
, size
);
98 ReadJADE(struct IsdnCardState
*cs
, int jade
, u_char offset
)
100 return (readreg(cs
->hw
.ax
.jade_ale
, cs
->hw
.ax
.jade_adr
, offset
+ (jade
== -1 ? 0 : (jade
? 0xC0 : 0x80))));
104 WriteJADE(struct IsdnCardState
*cs
, int jade
, u_char offset
, u_char value
)
106 writereg(cs
->hw
.ax
.jade_ale
, cs
->hw
.ax
.jade_adr
, offset
+ (jade
== -1 ? 0 : (jade
? 0xC0 : 0x80)), value
);
110 * fast interrupt JADE stuff goes here
113 #define READJADE(cs, nr, reg) readreg(cs->hw.ax.jade_ale, \
114 cs->hw.ax.jade_adr, reg + (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)))
115 #define WRITEJADE(cs, nr, reg, data) writereg(cs->hw.ax.jade_ale, \
116 cs->hw.ax.jade_adr, reg + (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), data)
118 #define READJADEFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.jade_ale, \
119 cs->hw.ax.jade_adr, (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), ptr, cnt)
120 #define WRITEJADEFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ax.jade_ale, \
121 cs->hw.ax.jade_adr, (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), ptr, cnt)
123 #include "jade_irq.c"
126 bkm_interrupt(int intno
, void *dev_id
)
128 struct IsdnCardState
*cs
= dev_id
;
131 I20_REGISTER_FILE
*pI20_Regs
;
133 spin_lock_irqsave(&cs
->lock
, flags
);
134 pI20_Regs
= (I20_REGISTER_FILE
*) (cs
->hw
.ax
.base
);
136 /* ISDN interrupt pending? */
137 if (pI20_Regs
->i20IntStatus
& intISDN
) {
138 /* Reset the ISDN interrupt */
139 pI20_Regs
->i20IntStatus
= intISDN
;
140 /* Disable ISDN interrupt */
141 pI20_Regs
->i20IntCtrl
&= ~intISDN
;
142 /* Channel A first */
143 val
= readreg(cs
->hw
.ax
.jade_ale
, cs
->hw
.ax
.jade_adr
, jade_HDLC_ISR
+ 0x80);
145 jade_int_main(cs
, val
, 0);
148 val
= readreg(cs
->hw
.ax
.jade_ale
, cs
->hw
.ax
.jade_adr
, jade_HDLC_ISR
+ 0xC0);
150 jade_int_main(cs
, val
, 1);
153 val
= readreg(cs
->hw
.ax
.isac_ale
, cs
->hw
.ax
.isac_adr
, ISAC_ISTA
);
155 isac_interrupt(cs
, val
);
157 /* Reenable ISDN interrupt */
158 pI20_Regs
->i20IntCtrl
|= intISDN
;
159 spin_unlock_irqrestore(&cs
->lock
, flags
);
162 spin_unlock_irqrestore(&cs
->lock
, flags
);
168 release_io_bkm(struct IsdnCardState
*cs
)
170 if (cs
->hw
.ax
.base
) {
171 iounmap((void *) cs
->hw
.ax
.base
);
177 enable_bkm_int(struct IsdnCardState
*cs
, unsigned bEnable
)
179 if (cs
->typ
== ISDN_CTYPE_BKM_A4T
) {
180 I20_REGISTER_FILE
*pI20_Regs
= (I20_REGISTER_FILE
*) (cs
->hw
.ax
.base
);
182 pI20_Regs
->i20IntCtrl
|= (intISDN
| intPCI
);
184 /* CAUTION: This disables the video capture driver too */
185 pI20_Regs
->i20IntCtrl
&= ~(intISDN
| intPCI
);
190 reset_bkm(struct IsdnCardState
*cs
)
192 if (cs
->typ
== ISDN_CTYPE_BKM_A4T
) {
193 I20_REGISTER_FILE
*pI20_Regs
= (I20_REGISTER_FILE
*) (cs
->hw
.ax
.base
);
194 /* Issue the I20 soft reset */
195 pI20_Regs
->i20SysControl
= 0xFF; /* all in */
197 /* Remove the soft reset */
198 pI20_Regs
->i20SysControl
= sysRESET
| 0xFF;
200 /* Set our configuration */
201 pI20_Regs
->i20SysControl
= sysRESET
| sysCFG
;
202 /* Issue ISDN reset */
203 pI20_Regs
->i20GuestControl
= guestWAIT_CFG
|
211 /* Remove RESET state from ISDN */
212 pI20_Regs
->i20GuestControl
&= ~(g_A4T_ISAC_RES
|
220 BKM_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
227 spin_lock_irqsave(&cs
->lock
, flags
);
228 enable_bkm_int(cs
, 0);
230 spin_unlock_irqrestore(&cs
->lock
, flags
);
234 spin_lock_irqsave(&cs
->lock
, flags
);
235 enable_bkm_int(cs
, 0);
237 spin_unlock_irqrestore(&cs
->lock
, flags
);
241 spin_lock_irqsave(&cs
->lock
, flags
);
242 clear_pending_isac_ints(cs
);
243 clear_pending_jade_ints(cs
);
247 enable_bkm_int(cs
, 1);
248 spin_unlock_irqrestore(&cs
->lock
, flags
);
256 static int a4t_pci_probe(struct pci_dev
*dev_a4t
, struct IsdnCardState
*cs
,
257 u_int
*found
, u_int
*pci_memaddr
)
262 sub_vendor
= dev_a4t
->subsystem_vendor
;
263 sub_sys
= dev_a4t
->subsystem_device
;
264 if ((sub_sys
== PCI_DEVICE_ID_BERKOM_A4T
) && (sub_vendor
== PCI_VENDOR_ID_BERKOM
)) {
265 if (pci_enable_device(dev_a4t
))
266 return (0); /* end loop & function */
268 *pci_memaddr
= pci_resource_start(dev_a4t
, 0);
269 cs
->irq
= dev_a4t
->irq
;
270 return (1); /* end loop */
273 return (-1); /* continue looping */
276 static int a4t_cs_init(struct IsdnCard
*card
, struct IsdnCardState
*cs
,
279 I20_REGISTER_FILE
*pI20_Regs
;
281 if (!cs
->irq
) { /* IRQ range check ?? */
282 printk(KERN_WARNING
"HiSax: Telekom A4T: No IRQ\n");
285 cs
->hw
.ax
.base
= (long) ioremap(pci_memaddr
, 4096);
286 /* Check suspecious address */
287 pI20_Regs
= (I20_REGISTER_FILE
*) (cs
->hw
.ax
.base
);
288 if ((pI20_Regs
->i20IntStatus
& 0x8EFFFFFF) != 0) {
289 printk(KERN_WARNING
"HiSax: Telekom A4T address "
290 "%lx-%lx suspicious\n",
291 cs
->hw
.ax
.base
, cs
->hw
.ax
.base
+ 4096);
292 iounmap((void *) cs
->hw
.ax
.base
);
296 cs
->hw
.ax
.isac_adr
= cs
->hw
.ax
.base
+ PO_OFFSET
;
297 cs
->hw
.ax
.jade_adr
= cs
->hw
.ax
.base
+ PO_OFFSET
;
298 cs
->hw
.ax
.isac_ale
= GCS_1
;
299 cs
->hw
.ax
.jade_ale
= GCS_3
;
301 printk(KERN_INFO
"HiSax: Telekom A4T: Card configured at "
303 cs
->hw
.ax
.base
, cs
->irq
);
306 cs
->readisac
= &ReadISAC
;
307 cs
->writeisac
= &WriteISAC
;
308 cs
->readisacfifo
= &ReadISACfifo
;
309 cs
->writeisacfifo
= &WriteISACfifo
;
310 cs
->BC_Read_Reg
= &ReadJADE
;
311 cs
->BC_Write_Reg
= &WriteJADE
;
312 cs
->BC_Send_Data
= &jade_fill_fifo
;
313 cs
->cardmsg
= &BKM_card_msg
;
314 cs
->irq_func
= &bkm_interrupt
;
315 cs
->irq_flags
|= IRQF_SHARED
;
316 ISACVersion(cs
, "Telekom A4T:");
318 JadeVersion(cs
, "Telekom A4T:");
323 static struct pci_dev
*dev_a4t
= NULL
;
325 int setup_bkm_a4t(struct IsdnCard
*card
)
327 struct IsdnCardState
*cs
= card
->cs
;
329 u_int pci_memaddr
= 0, found
= 0;
332 strcpy(tmp
, bkm_a4t_revision
);
333 printk(KERN_INFO
"HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp
));
334 if (cs
->typ
== ISDN_CTYPE_BKM_A4T
) {
335 cs
->subtyp
= BKM_A4T
;
339 while ((dev_a4t
= hisax_find_pci_device(PCI_VENDOR_ID_ZORAN
,
340 PCI_DEVICE_ID_ZORAN_36120
, dev_a4t
))) {
341 ret
= a4t_pci_probe(dev_a4t
, cs
, &found
, &pci_memaddr
);
348 printk(KERN_WARNING
"HiSax: Telekom A4T: Card not found\n");
352 printk(KERN_WARNING
"HiSax: Telekom A4T: "
353 "No Memory base address\n");
357 return a4t_cs_init(card
, cs
, pci_memaddr
);