1 /* $Id: bkm_a8.c,v 1.14.6.2 2000/11/29 16:00:14 kai Exp $
2 * bkm_a8.c low level stuff for Scitel Quadro (4*S0, passive)
3 * derived from the original file sedlbauer.c
4 * derived from the original file niccy.c
5 * derived from the original file netjet.c
7 * Author Roland Klabunde (R.Klabunde@Berkom.de)
9 * This file is (c) under GNU PUBLIC LICENSE
12 #define __NO_VERSION__
14 #include <linux/config.h>
15 #include <linux/init.h>
21 #include <linux/pci.h>
26 #define ATTEMPT_PCI_REMAPPING /* Required for PLX rev 1 */
28 extern const char *CardType
[];
30 const char sct_quadro_revision
[] = "$Revision: 1.14.6.2 $";
32 static const char *sct_quadro_subtypes
[] =
42 #define wordout(addr,val) outw(val,addr)
43 #define wordin(addr) inw(addr)
46 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
53 ret
= wordin(adr
) & 0xFF;
59 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
61 /* fifo read without cli because it's allready done */
64 for (i
= 0; i
< size
; i
++)
65 data
[i
] = wordin(adr
) & 0xFF;
70 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
81 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
83 /* fifo write without cli because it's allready done */
86 for (i
= 0; i
< size
; i
++)
87 wordout(adr
, data
[i
]);
90 /* Interface functions */
93 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
95 return (readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
| 0x80));
99 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
101 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
| 0x80, value
);
105 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
107 readfifo(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, 0x80, data
, size
);
111 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
113 writefifo(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, 0x80, data
, size
);
118 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
120 return (readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
+ (hscx
? 0x40 : 0)));
124 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
126 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
+ (hscx
? 0x40 : 0), value
);
129 /* Set the specific ipac to active */
131 set_ipac_active(struct IsdnCardState
*cs
, u_int active
)
134 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
,
135 active
? 0xc0 : 0xff);
139 * fast interrupt HSCX stuff goes here
142 #define READHSCX(cs, nr, reg) readreg(cs->hw.ax.base, \
143 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0))
144 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.ax.base, \
145 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0), data)
146 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.base, \
147 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
148 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ax.base, \
149 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
151 #include "hscx_irq.c"
154 bkm_interrupt_ipac(int intno
, void *dev_id
, struct pt_regs
*regs
)
156 struct IsdnCardState
*cs
= dev_id
;
157 u_char ista
, val
, icnt
= 5;
160 printk(KERN_WARNING
"HiSax: Scitel Quadro: Spurious interrupt!\n");
163 ista
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ISTA
);
164 if (!(ista
& 0x3f)) /* not this IPAC */
167 if (cs
->debug
& L1_DEB_IPAC
)
168 debugl1(cs
, "IPAC ISTA %02X", ista
);
170 val
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, HSCX_ISTA
+ 0x40);
178 hscx_int_main(cs
, val
);
182 val
= 0xfe & readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, ISAC_ISTA
| 0x80);
184 isac_interrupt(cs
, val
);
189 isac_interrupt(cs
, val
);
191 ista
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ISTA
);
192 if ((ista
& 0x3f) && icnt
) {
197 printk(KERN_WARNING
"HiSax: %s (%s) IRQ LOOP\n",
199 sct_quadro_subtypes
[cs
->subtyp
]);
200 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
, 0xFF);
201 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
, 0xC0);
206 release_io_sct_quadro(struct IsdnCardState
*cs
)
208 release_region(cs
->hw
.ax
.base
& 0xffffffc0, 256);
209 if (cs
->subtyp
== SCT_1
)
210 release_region(cs
->hw
.ax
.plx_adr
, 256);
214 enable_bkm_int(struct IsdnCardState
*cs
, unsigned bEnable
)
216 if (cs
->typ
== ISDN_CTYPE_SCT_QUADRO
) {
218 wordout(cs
->hw
.ax
.plx_adr
+ 0x4C, (wordin(cs
->hw
.ax
.plx_adr
+ 0x4C) | 0x41));
220 wordout(cs
->hw
.ax
.plx_adr
+ 0x4C, (wordin(cs
->hw
.ax
.plx_adr
+ 0x4C) & ~0x41));
225 reset_bkm(struct IsdnCardState
*cs
)
229 if (cs
->subtyp
== SCT_1
) {
230 wordout(cs
->hw
.ax
.plx_adr
+ 0x50, (wordin(cs
->hw
.ax
.plx_adr
+ 0x50) & ~4));
233 set_current_state(TASK_UNINTERRUPTIBLE
);
234 schedule_timeout((10 * HZ
) / 1000);
235 /* Remove the soft reset */
236 wordout(cs
->hw
.ax
.plx_adr
+ 0x50, (wordin(cs
->hw
.ax
.plx_adr
+ 0x50) | 4));
237 set_current_state(TASK_UNINTERRUPTIBLE
);
238 schedule_timeout((10 * HZ
) / 1000);
239 restore_flags(flags
);
244 BKM_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
249 set_ipac_active(cs
, 0);
250 enable_bkm_int(cs
, 0);
255 set_ipac_active(cs
, 0);
256 enable_bkm_int(cs
, 0);
257 release_io_sct_quadro(cs
);
260 cs
->debug
|= L1_DEB_IPAC
;
261 set_ipac_active(cs
, 1);
264 enable_bkm_int(cs
, 1);
273 sct_alloc_io(u_int adr
, u_int len
)
275 if (check_region(adr
, len
)) {
277 "HiSax: Scitel port %#x-%#x already in use\n",
281 request_region(adr
, len
, "scitel");
286 static struct pci_dev
*dev_a8 __initdata
= NULL
;
287 static u16 sub_vendor_id __initdata
= 0;
288 static u16 sub_sys_id __initdata
= 0;
289 static u_char pci_bus __initdata
= 0;
290 static u_char pci_device_fn __initdata
= 0;
291 static u_char pci_irq __initdata
= 0;
293 #endif /* CONFIG_PCI */
296 setup_sct_quadro(struct IsdnCard
*card
)
299 struct IsdnCardState
*cs
= card
->cs
;
303 u_int pci_ioaddr1
, pci_ioaddr2
, pci_ioaddr3
, pci_ioaddr4
, pci_ioaddr5
;
305 strcpy(tmp
, sct_quadro_revision
);
306 printk(KERN_INFO
"HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp
));
307 if (cs
->typ
== ISDN_CTYPE_SCT_QUADRO
) {
308 cs
->subtyp
= SCT_1
; /* Preset */
312 /* Identify subtype by para[0] */
313 if (card
->para
[0] >= SCT_1
&& card
->para
[0] <= SCT_4
)
314 cs
->subtyp
= card
->para
[0];
316 printk(KERN_WARNING
"HiSax: %s: Invalid subcontroller in configuration, default to 1\n",
317 CardType
[card
->typ
]);
320 if ((cs
->subtyp
!= SCT_1
) && ((sub_sys_id
!= PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO
) ||
321 (sub_vendor_id
!= PCI_VENDOR_ID_BERKOM
)))
323 if (cs
->subtyp
== SCT_1
) {
324 if (!pci_present()) {
325 printk(KERN_ERR
"bkm_a4t: no PCI bus present\n");
328 while ((dev_a8
= pci_find_device(PCI_VENDOR_ID_PLX
,
329 PCI_DEVICE_ID_PLX_9050
, dev_a8
))) {
331 sub_vendor_id
= dev_a8
->subsystem_vendor
;
332 sub_sys_id
= dev_a8
->subsystem_device
;
333 if ((sub_sys_id
== PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO
) &&
334 (sub_vendor_id
== PCI_VENDOR_ID_BERKOM
)) {
335 if (pci_enable_device(dev_a8
))
337 pci_ioaddr1
= pci_resource_start(dev_a8
, 1);
338 pci_irq
= dev_a8
->irq
;
339 pci_bus
= dev_a8
->bus
->number
;
340 pci_device_fn
= dev_a8
->devfn
;
346 printk(KERN_WARNING
"HiSax: %s (%s): Card not found\n",
348 sct_quadro_subtypes
[cs
->subtyp
]);
351 #ifdef ATTEMPT_PCI_REMAPPING
352 /* HACK: PLX revision 1 bug: PLX address bit 7 must not be set */
353 pcibios_read_config_byte(pci_bus
, pci_device_fn
,
354 PCI_REVISION_ID
, &pci_rev_id
);
355 if ((pci_ioaddr1
& 0x80) && (pci_rev_id
== 1)) {
356 printk(KERN_WARNING
"HiSax: %s (%s): PLX rev 1, remapping required!\n",
358 sct_quadro_subtypes
[cs
->subtyp
]);
359 /* Restart PCI negotiation */
360 pcibios_write_config_dword(pci_bus
, pci_device_fn
,
361 PCI_BASE_ADDRESS_1
, (u_int
) - 1);
362 /* Move up by 0x80 byte */
364 pci_ioaddr1
&= PCI_BASE_ADDRESS_IO_MASK
;
365 pcibios_write_config_dword(pci_bus
, pci_device_fn
,
366 PCI_BASE_ADDRESS_1
, pci_ioaddr1
);
367 dev_a8
->resource
[ 1].start
= pci_ioaddr1
;
369 #endif /* End HACK */
371 if (!pci_irq
) { /* IRQ range check ?? */
372 printk(KERN_WARNING
"HiSax: %s (%s): No IRQ\n",
374 sct_quadro_subtypes
[cs
->subtyp
]);
377 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_1
, &pci_ioaddr1
);
378 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_2
, &pci_ioaddr2
);
379 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_3
, &pci_ioaddr3
);
380 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_4
, &pci_ioaddr4
);
381 pcibios_read_config_dword(pci_bus
, pci_device_fn
, PCI_BASE_ADDRESS_5
, &pci_ioaddr5
);
382 if (!pci_ioaddr1
|| !pci_ioaddr2
|| !pci_ioaddr3
|| !pci_ioaddr4
|| !pci_ioaddr5
) {
383 printk(KERN_WARNING
"HiSax: %s (%s): No IO base address(es)\n",
385 sct_quadro_subtypes
[cs
->subtyp
]);
388 pci_ioaddr1
&= PCI_BASE_ADDRESS_IO_MASK
;
389 pci_ioaddr2
&= PCI_BASE_ADDRESS_IO_MASK
;
390 pci_ioaddr3
&= PCI_BASE_ADDRESS_IO_MASK
;
391 pci_ioaddr4
&= PCI_BASE_ADDRESS_IO_MASK
;
392 pci_ioaddr5
&= PCI_BASE_ADDRESS_IO_MASK
;
395 cs
->irq_flags
|= SA_SHIRQ
;
396 /* pci_ioaddr1 is unique to all subdevices */
397 /* pci_ioaddr2 is for the fourth subdevice only */
398 /* pci_ioaddr3 is for the third subdevice only */
399 /* pci_ioaddr4 is for the second subdevice only */
400 /* pci_ioaddr5 is for the first subdevice only */
401 cs
->hw
.ax
.plx_adr
= pci_ioaddr1
;
402 /* Enter all ipac_base addresses */
405 cs
->hw
.ax
.base
= pci_ioaddr5
+ 0x00;
406 if (sct_alloc_io(pci_ioaddr1
, 256))
408 if (sct_alloc_io(pci_ioaddr5
, 256))
410 /* disable all IPAC */
411 writereg(pci_ioaddr5
, pci_ioaddr5
+ 4,
413 writereg(pci_ioaddr4
+ 0x08, pci_ioaddr4
+ 0x0c,
415 writereg(pci_ioaddr3
+ 0x10, pci_ioaddr3
+ 0x14,
417 writereg(pci_ioaddr2
+ 0x20, pci_ioaddr2
+ 0x24,
421 cs
->hw
.ax
.base
= pci_ioaddr4
+ 0x08;
422 if (sct_alloc_io(pci_ioaddr4
, 256))
426 cs
->hw
.ax
.base
= pci_ioaddr3
+ 0x10;
427 if (sct_alloc_io(pci_ioaddr3
, 256))
431 cs
->hw
.ax
.base
= pci_ioaddr2
+ 0x20;
432 if (sct_alloc_io(pci_ioaddr2
, 256))
436 /* For isac and hscx data path */
437 cs
->hw
.ax
.data_adr
= cs
->hw
.ax
.base
+ 4;
439 printk(KERN_INFO
"HiSax: %s (%s) configured at 0x%.4X, 0x%.4X, 0x%.4X and IRQ %d\n",
441 sct_quadro_subtypes
[cs
->subtyp
],
447 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
449 cs
->readisac
= &ReadISAC
;
450 cs
->writeisac
= &WriteISAC
;
451 cs
->readisacfifo
= &ReadISACfifo
;
452 cs
->writeisacfifo
= &WriteISACfifo
;
454 cs
->BC_Read_Reg
= &ReadHSCX
;
455 cs
->BC_Write_Reg
= &WriteHSCX
;
456 cs
->BC_Send_Data
= &hscx_fill_fifo
;
457 cs
->cardmsg
= &BKM_card_msg
;
458 cs
->irq_func
= &bkm_interrupt_ipac
;
460 printk(KERN_INFO
"HiSax: %s (%s): IPAC Version %d\n",
462 sct_quadro_subtypes
[cs
->subtyp
],
463 readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ID
));
466 printk(KERN_ERR
"HiSax: bkm_a8 only supported on PCI Systems\n");
467 #endif /* CONFIG_PCI */