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/config.h>
15 #include <linux/init.h>
21 #include <linux/pci.h>
24 extern const char *CardType[];
26 static const char *bkm_a4t_revision = "$Revision: 1.22.2.4 $";
30 readreg(unsigned int ale, unsigned long adr, u_char off)
33 unsigned int *po = (unsigned int *) adr; /* Postoffice */
35 *po = (GCS_2 | PO_WRITE | off);
37 *po = (ale | PO_READ);
40 return ((unsigned char) ret);
45 readfifo(unsigned int ale, unsigned long adr, u_char off, u_char * data, int size)
48 for (i = 0; i < size; i++)
49 *data++ = readreg(ale, adr, off);
54 writereg(unsigned int ale, unsigned long adr, u_char off, u_char data)
56 unsigned int *po = (unsigned int *) adr; /* Postoffice */
57 *po = (GCS_2 | PO_WRITE | off);
59 *po = (ale | PO_WRITE | data);
65 writefifo(unsigned int ale, unsigned long adr, u_char off, u_char * data, int size)
69 for (i = 0; i < size; i++)
70 writereg(ale, adr, off, *data++);
74 /* Interface functions */
77 ReadISAC(struct IsdnCardState *cs, u_char offset)
79 return (readreg(cs->hw.ax.isac_ale, cs->hw.ax.isac_adr, offset));
83 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
85 writereg(cs->hw.ax.isac_ale, cs->hw.ax.isac_adr, offset, value);
89 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
91 readfifo(cs->hw.ax.isac_ale, cs->hw.ax.isac_adr, 0, data, size);
95 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
97 writefifo(cs->hw.ax.isac_ale, cs->hw.ax.isac_adr, 0, data, size);
101 ReadJADE(struct IsdnCardState *cs, int jade, u_char offset)
103 return (readreg(cs->hw.ax.jade_ale, cs->hw.ax.jade_adr, offset + (jade == -1 ? 0 : (jade ? 0xC0 : 0x80))));
107 WriteJADE(struct IsdnCardState *cs, int jade, u_char offset, u_char value)
109 writereg(cs->hw.ax.jade_ale, cs->hw.ax.jade_adr, offset + (jade == -1 ? 0 : (jade ? 0xC0 : 0x80)), value);
113 * fast interrupt JADE stuff goes here
116 #define READJADE(cs, nr, reg) readreg(cs->hw.ax.jade_ale,\
117 cs->hw.ax.jade_adr, reg + (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)))
118 #define WRITEJADE(cs, nr, reg, data) writereg(cs->hw.ax.jade_ale,\
119 cs->hw.ax.jade_adr, reg + (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), data)
121 #define READJADEFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.jade_ale,\
122 cs->hw.ax.jade_adr, (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), ptr, cnt)
123 #define WRITEJADEFIFO(cs, nr, ptr, cnt) writefifo( cs->hw.ax.jade_ale,\
124 cs->hw.ax.jade_adr, (nr == -1 ? 0 : (nr ? 0xC0 : 0x80)), ptr, cnt)
126 #include "jade_irq.c"
129 bkm_interrupt(int intno, void *dev_id, struct pt_regs *regs)
131 struct IsdnCardState *cs = dev_id;
134 I20_REGISTER_FILE *pI20_Regs;
136 spin_lock_irqsave(&cs->lock, flags);
137 pI20_Regs = (I20_REGISTER_FILE *) (cs->hw.ax.base);
139 /* ISDN interrupt pending? */
140 if (pI20_Regs->i20IntStatus & intISDN) {
141 /* Reset the ISDN interrupt */
142 pI20_Regs->i20IntStatus = intISDN;
143 /* Disable ISDN interrupt */
144 pI20_Regs->i20IntCtrl &= ~intISDN;
145 /* Channel A first */
146 val = readreg(cs->hw.ax.jade_ale, cs->hw.ax.jade_adr, jade_HDLC_ISR + 0x80);
148 jade_int_main(cs, val, 0);
151 val = readreg(cs->hw.ax.jade_ale, cs->hw.ax.jade_adr, jade_HDLC_ISR + 0xC0);
153 jade_int_main(cs, val, 1);
156 val = readreg(cs->hw.ax.isac_ale, cs->hw.ax.isac_adr, ISAC_ISTA);
158 isac_interrupt(cs, val);
160 /* Reenable ISDN interrupt */
161 pI20_Regs->i20IntCtrl |= intISDN;
162 spin_unlock_irqrestore(&cs->lock, flags);
165 spin_unlock_irqrestore(&cs->lock, flags);
171 release_io_bkm(struct IsdnCardState *cs)
173 if (cs->hw.ax.base) {
174 iounmap((void *) cs->hw.ax.base);
180 enable_bkm_int(struct IsdnCardState *cs, unsigned bEnable)
182 if (cs->typ == ISDN_CTYPE_BKM_A4T) {
183 I20_REGISTER_FILE *pI20_Regs = (I20_REGISTER_FILE *) (cs->hw.ax.base);
185 pI20_Regs->i20IntCtrl |= (intISDN | intPCI);
187 /* CAUTION: This disables the video capture driver too */
188 pI20_Regs->i20IntCtrl &= ~(intISDN | intPCI);
193 reset_bkm(struct IsdnCardState *cs)
195 if (cs->typ == ISDN_CTYPE_BKM_A4T) {
196 I20_REGISTER_FILE *pI20_Regs = (I20_REGISTER_FILE *) (cs->hw.ax.base);
197 /* Issue the I20 soft reset */
198 pI20_Regs->i20SysControl = 0xFF; /* all in */
200 /* Remove the soft reset */
201 pI20_Regs->i20SysControl = sysRESET | 0xFF;
203 /* Set our configuration */
204 pI20_Regs->i20SysControl = sysRESET | sysCFG;
205 /* Issue ISDN reset */
206 pI20_Regs->i20GuestControl = guestWAIT_CFG |
214 /* Remove RESET state from ISDN */
215 pI20_Regs->i20GuestControl &= ~(g_A4T_ISAC_RES |
223 BKM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
230 spin_lock_irqsave(&cs->lock, flags);
231 enable_bkm_int(cs, 0);
233 spin_unlock_irqrestore(&cs->lock, flags);
237 spin_lock_irqsave(&cs->lock, flags);
238 enable_bkm_int(cs, 0);
240 spin_unlock_irqrestore(&cs->lock, flags);
244 spin_lock_irqsave(&cs->lock, flags);
245 clear_pending_isac_ints(cs);
246 clear_pending_jade_ints(cs);
250 enable_bkm_int(cs, 1);
251 spin_unlock_irqrestore(&cs->lock, flags);
259 static struct pci_dev *dev_a4t __initdata = NULL;
262 setup_bkm_a4t(struct IsdnCard *card)
264 struct IsdnCardState *cs = card->cs;
266 u_int pci_memaddr = 0, found = 0;
267 I20_REGISTER_FILE *pI20_Regs;
271 strcpy(tmp, bkm_a4t_revision);
272 printk(KERN_INFO "HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp));
273 if (cs->typ == ISDN_CTYPE_BKM_A4T) {
274 cs->subtyp = BKM_A4T;
279 while ((dev_a4t = pci_find_device(PCI_VENDOR_ID_ZORAN,
280 PCI_DEVICE_ID_ZORAN_36120, dev_a4t))) {
284 sub_vendor = dev_a4t->subsystem_vendor;
285 sub_sys = dev_a4t->subsystem_device;
286 if ((sub_sys == PCI_DEVICE_ID_BERKOM_A4T) && (sub_vendor == PCI_VENDOR_ID_BERKOM)) {
287 if (pci_enable_device(dev_a4t))
290 pci_memaddr = pci_resource_start(dev_a4t, 0);
291 cs->irq = dev_a4t->irq;
296 printk(KERN_WARNING "HiSax: %s: Card not found\n", CardType[card->typ]);
299 if (!cs->irq) { /* IRQ range check ?? */
300 printk(KERN_WARNING "HiSax: %s: No IRQ\n", CardType[card->typ]);
304 printk(KERN_WARNING "HiSax: %s: No Memory base address\n", CardType[card->typ]);
307 cs->hw.ax.base = (long) ioremap(pci_memaddr, 4096);
308 /* Check suspecious address */
309 pI20_Regs = (I20_REGISTER_FILE *) (cs->hw.ax.base);
310 if ((pI20_Regs->i20IntStatus & 0x8EFFFFFF) != 0) {
311 printk(KERN_WARNING "HiSax: %s address %lx-%lx suspecious\n",
312 CardType[card->typ], cs->hw.ax.base, cs->hw.ax.base + 4096);
313 iounmap((void *) cs->hw.ax.base);
317 cs->hw.ax.isac_adr = cs->hw.ax.base + PO_OFFSET;
318 cs->hw.ax.jade_adr = cs->hw.ax.base + PO_OFFSET;
319 cs->hw.ax.isac_ale = GCS_1;
320 cs->hw.ax.jade_ale = GCS_3;
322 printk(KERN_WARNING "HiSax: %s: NO_PCI_BIOS\n", CardType[card->typ]);
323 printk(KERN_WARNING "HiSax: %s: unable to configure\n", CardType[card->typ]);
325 #endif /* CONFIG_PCI */
326 printk(KERN_INFO "HiSax: %s: Card configured at 0x%lX IRQ %d\n",
327 CardType[card->typ], cs->hw.ax.base, cs->irq);
330 cs->readisac = &ReadISAC;
331 cs->writeisac = &WriteISAC;
332 cs->readisacfifo = &ReadISACfifo;
333 cs->writeisacfifo = &WriteISACfifo;
334 cs->BC_Read_Reg = &ReadJADE;
335 cs->BC_Write_Reg = &WriteJADE;
336 cs->BC_Send_Data = &jade_fill_fifo;
337 cs->cardmsg = &BKM_card_msg;
338 cs->irq_func = &bkm_interrupt;
339 cs->irq_flags |= SA_SHIRQ;
340 ISACVersion(cs, "Telekom A4T:");
342 JadeVersion(cs, "Telekom A4T:");