1 /* $Id: bkm_a8.c,v 1.1.1.1 2005/04/11 02:50:23 jack Exp $
3 * low level stuff for Scitel Quadro (4*S0, passive)
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.
13 #define __NO_VERSION__
15 #include <linux/config.h>
16 #include <linux/init.h>
22 #include <linux/pci.h>
27 #define ATTEMPT_PCI_REMAPPING /* Required for PLX rev 1 */
29 extern const char *CardType[];
31 const char sct_quadro_revision[] = "$Revision: 1.1.1.1 $";
33 static const char *sct_quadro_subtypes[] =
43 #define wordout(addr,val) outw(val,addr)
44 #define wordin(addr) inw(addr)
47 readreg(unsigned int ale, unsigned int adr, u_char off)
54 ret = wordin(adr) & 0xFF;
60 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
62 /* fifo read without cli because it's allready done */
65 for (i = 0; i < size; i++)
66 data[i] = wordin(adr) & 0xFF;
71 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
82 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
84 /* fifo write without cli because it's allready done */
87 for (i = 0; i < size; i++)
88 wordout(adr, data[i]);
91 /* Interface functions */
94 ReadISAC(struct IsdnCardState *cs, u_char offset)
96 return (readreg(cs->hw.ax.base, cs->hw.ax.data_adr, offset | 0x80));
100 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
102 writereg(cs->hw.ax.base, cs->hw.ax.data_adr, offset | 0x80, value);
106 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
108 readfifo(cs->hw.ax.base, cs->hw.ax.data_adr, 0x80, data, size);
112 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
114 writefifo(cs->hw.ax.base, cs->hw.ax.data_adr, 0x80, data, size);
119 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
121 return (readreg(cs->hw.ax.base, cs->hw.ax.data_adr, offset + (hscx ? 0x40 : 0)));
125 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
127 writereg(cs->hw.ax.base, cs->hw.ax.data_adr, offset + (hscx ? 0x40 : 0), value);
130 /* Set the specific ipac to active */
132 set_ipac_active(struct IsdnCardState *cs, u_int active)
135 writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK,
136 active ? 0xc0 : 0xff);
140 * fast interrupt HSCX stuff goes here
143 #define READHSCX(cs, nr, reg) readreg(cs->hw.ax.base, \
144 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0))
145 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.ax.base, \
146 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0), data)
147 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.base, \
148 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
149 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ax.base, \
150 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
152 #include "hscx_irq.c"
155 bkm_interrupt_ipac(int intno, void *dev_id, struct pt_regs *regs)
157 struct IsdnCardState *cs = dev_id;
158 u_char ista, val, icnt = 5;
161 printk(KERN_WARNING "HiSax: Scitel Quadro: Spurious interrupt!\n");
164 ista = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ISTA);
165 if (!(ista & 0x3f)) /* not this IPAC */
168 if (cs->debug & L1_DEB_IPAC)
169 debugl1(cs, "IPAC ISTA %02X", ista);
171 val = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, HSCX_ISTA + 0x40);
179 hscx_int_main(cs, val);
183 val = 0xfe & readreg(cs->hw.ax.base, cs->hw.ax.data_adr, ISAC_ISTA | 0x80);
185 isac_interrupt(cs, val);
190 isac_interrupt(cs, val);
192 ista = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ISTA);
193 if ((ista & 0x3f) && icnt) {
198 printk(KERN_WARNING "HiSax: %s (%s) IRQ LOOP\n",
200 sct_quadro_subtypes[cs->subtyp]);
201 writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK, 0xFF);
202 writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK, 0xC0);
207 release_io_sct_quadro(struct IsdnCardState *cs)
209 release_region(cs->hw.ax.base & 0xffffffc0, 128);
210 if (cs->subtyp == SCT_1)
211 release_region(cs->hw.ax.plx_adr, 64);
215 enable_bkm_int(struct IsdnCardState *cs, unsigned bEnable)
217 if (cs->typ == ISDN_CTYPE_SCT_QUADRO) {
219 wordout(cs->hw.ax.plx_adr + 0x4C, (wordin(cs->hw.ax.plx_adr + 0x4C) | 0x41));
221 wordout(cs->hw.ax.plx_adr + 0x4C, (wordin(cs->hw.ax.plx_adr + 0x4C) & ~0x41));
226 reset_bkm(struct IsdnCardState *cs)
230 if (cs->subtyp == SCT_1) {
231 wordout(cs->hw.ax.plx_adr + 0x50, (wordin(cs->hw.ax.plx_adr + 0x50) & ~4));
234 set_current_state(TASK_UNINTERRUPTIBLE);
235 schedule_timeout((10 * HZ) / 1000);
236 /* Remove the soft reset */
237 wordout(cs->hw.ax.plx_adr + 0x50, (wordin(cs->hw.ax.plx_adr + 0x50) | 4));
238 set_current_state(TASK_UNINTERRUPTIBLE);
239 schedule_timeout((10 * HZ) / 1000);
240 restore_flags(flags);
245 BKM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
250 set_ipac_active(cs, 0);
251 enable_bkm_int(cs, 0);
256 set_ipac_active(cs, 0);
257 enable_bkm_int(cs, 0);
258 release_io_sct_quadro(cs);
261 cs->debug |= L1_DEB_IPAC;
262 set_ipac_active(cs, 1);
265 enable_bkm_int(cs, 1);
274 sct_alloc_io(u_int adr, u_int len)
276 if (check_region(adr, len)) {
278 "HiSax: Scitel port %#x-%#x already in use\n",
282 request_region(adr, len, "scitel");
287 static struct pci_dev *dev_a8 __initdata = NULL;
288 static u16 sub_vendor_id __initdata = 0;
289 static u16 sub_sys_id __initdata = 0;
290 static u_char pci_bus __initdata = 0;
291 static u_char pci_device_fn __initdata = 0;
292 static u_char pci_irq __initdata = 0;
294 #endif /* CONFIG_PCI */
297 setup_sct_quadro(struct IsdnCard *card)
300 struct IsdnCardState *cs = card->cs;
304 u_int pci_ioaddr1, pci_ioaddr2, pci_ioaddr3, pci_ioaddr4, pci_ioaddr5;
306 strcpy(tmp, sct_quadro_revision);
307 printk(KERN_INFO "HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp));
308 if (cs->typ == ISDN_CTYPE_SCT_QUADRO) {
309 cs->subtyp = SCT_1; /* Preset */
313 /* Identify subtype by para[0] */
314 if (card->para[0] >= SCT_1 && card->para[0] <= SCT_4)
315 cs->subtyp = card->para[0];
317 printk(KERN_WARNING "HiSax: %s: Invalid subcontroller in configuration, default to 1\n",
318 CardType[card->typ]);
321 if ((cs->subtyp != SCT_1) && ((sub_sys_id != PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) ||
322 (sub_vendor_id != PCI_VENDOR_ID_BERKOM)))
324 if (cs->subtyp == SCT_1) {
325 if (!pci_present()) {
326 printk(KERN_ERR "bkm_a4t: no PCI bus present\n");
329 while ((dev_a8 = pci_find_device(PCI_VENDOR_ID_PLX,
330 PCI_DEVICE_ID_PLX_9050, dev_a8))) {
332 sub_vendor_id = dev_a8->subsystem_vendor;
333 sub_sys_id = dev_a8->subsystem_device;
334 if ((sub_sys_id == PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) &&
335 (sub_vendor_id == PCI_VENDOR_ID_BERKOM)) {
336 if (pci_enable_device(dev_a8))
338 pci_ioaddr1 = pci_resource_start(dev_a8, 1);
339 pci_irq = dev_a8->irq;
340 pci_bus = dev_a8->bus->number;
341 pci_device_fn = dev_a8->devfn;
347 printk(KERN_WARNING "HiSax: %s (%s): Card not found\n",
349 sct_quadro_subtypes[cs->subtyp]);
352 #ifdef ATTEMPT_PCI_REMAPPING
353 /* HACK: PLX revision 1 bug: PLX address bit 7 must not be set */
354 pcibios_read_config_byte(pci_bus, pci_device_fn,
355 PCI_REVISION_ID, &pci_rev_id);
356 if ((pci_ioaddr1 & 0x80) && (pci_rev_id == 1)) {
357 printk(KERN_WARNING "HiSax: %s (%s): PLX rev 1, remapping required!\n",
359 sct_quadro_subtypes[cs->subtyp]);
360 /* Restart PCI negotiation */
361 pcibios_write_config_dword(pci_bus, pci_device_fn,
362 PCI_BASE_ADDRESS_1, (u_int) - 1);
363 /* Move up by 0x80 byte */
365 pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
366 pcibios_write_config_dword(pci_bus, pci_device_fn,
367 PCI_BASE_ADDRESS_1, pci_ioaddr1);
368 dev_a8->resource[ 1].start = pci_ioaddr1;
370 #endif /* End HACK */
372 if (!pci_irq) { /* IRQ range check ?? */
373 printk(KERN_WARNING "HiSax: %s (%s): No IRQ\n",
375 sct_quadro_subtypes[cs->subtyp]);
378 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_1, &pci_ioaddr1);
379 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_2, &pci_ioaddr2);
380 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_3, &pci_ioaddr3);
381 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_4, &pci_ioaddr4);
382 pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_5, &pci_ioaddr5);
383 if (!pci_ioaddr1 || !pci_ioaddr2 || !pci_ioaddr3 || !pci_ioaddr4 || !pci_ioaddr5) {
384 printk(KERN_WARNING "HiSax: %s (%s): No IO base address(es)\n",
386 sct_quadro_subtypes[cs->subtyp]);
389 pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
390 pci_ioaddr2 &= PCI_BASE_ADDRESS_IO_MASK;
391 pci_ioaddr3 &= PCI_BASE_ADDRESS_IO_MASK;
392 pci_ioaddr4 &= PCI_BASE_ADDRESS_IO_MASK;
393 pci_ioaddr5 &= PCI_BASE_ADDRESS_IO_MASK;
396 cs->irq_flags |= SA_SHIRQ;
397 /* pci_ioaddr1 is unique to all subdevices */
398 /* pci_ioaddr2 is for the fourth subdevice only */
399 /* pci_ioaddr3 is for the third subdevice only */
400 /* pci_ioaddr4 is for the second subdevice only */
401 /* pci_ioaddr5 is for the first subdevice only */
402 cs->hw.ax.plx_adr = pci_ioaddr1;
403 /* Enter all ipac_base addresses */
406 cs->hw.ax.base = pci_ioaddr5 + 0x00;
407 if (sct_alloc_io(pci_ioaddr1, 128))
409 if (sct_alloc_io(pci_ioaddr5, 64))
411 /* disable all IPAC */
412 writereg(pci_ioaddr5, pci_ioaddr5 + 4,
414 writereg(pci_ioaddr4 + 0x08, pci_ioaddr4 + 0x0c,
416 writereg(pci_ioaddr3 + 0x10, pci_ioaddr3 + 0x14,
418 writereg(pci_ioaddr2 + 0x20, pci_ioaddr2 + 0x24,
422 cs->hw.ax.base = pci_ioaddr4 + 0x08;
423 if (sct_alloc_io(pci_ioaddr4, 64))
427 cs->hw.ax.base = pci_ioaddr3 + 0x10;
428 if (sct_alloc_io(pci_ioaddr3, 64))
432 cs->hw.ax.base = pci_ioaddr2 + 0x20;
433 if (sct_alloc_io(pci_ioaddr2, 64))
437 /* For isac and hscx data path */
438 cs->hw.ax.data_adr = cs->hw.ax.base + 4;
440 printk(KERN_INFO "HiSax: %s (%s) configured at 0x%.4lX, 0x%.4lX, 0x%.4lX and IRQ %d\n",
442 sct_quadro_subtypes[cs->subtyp],
448 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
450 cs->readisac = &ReadISAC;
451 cs->writeisac = &WriteISAC;
452 cs->readisacfifo = &ReadISACfifo;
453 cs->writeisacfifo = &WriteISACfifo;
455 cs->BC_Read_Reg = &ReadHSCX;
456 cs->BC_Write_Reg = &WriteHSCX;
457 cs->BC_Send_Data = &hscx_fill_fifo;
458 cs->cardmsg = &BKM_card_msg;
459 cs->irq_func = &bkm_interrupt_ipac;
461 printk(KERN_INFO "HiSax: %s (%s): IPAC Version %d\n",
463 sct_quadro_subtypes[cs->subtyp],
464 readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ID));
467 printk(KERN_ERR "HiSax: bkm_a8 only supported on PCI Systems\n");
468 #endif /* CONFIG_PCI */