1 /* $Id: bkm_a8.c,v 1.22.2.4 2004/01/15 14:02:34 keil 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.
14 #include <linux/init.h>
20 #include <linux/pci.h>
23 #define ATTEMPT_PCI_REMAPPING /* Required for PLX rev 1 */
25 static const char sct_quadro_revision
[] = "$Revision: 1.22.2.4 $";
27 static const char *sct_quadro_subtypes
[] =
37 #define wordout(addr,val) outw(val,addr)
38 #define wordin(addr) inw(addr)
41 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
45 ret
= wordin(adr
) & 0xFF;
50 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
54 for (i
= 0; i
< size
; i
++)
55 data
[i
] = wordin(adr
) & 0xFF;
60 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
67 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
71 for (i
= 0; i
< size
; i
++)
72 wordout(adr
, data
[i
]);
75 /* Interface functions */
78 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
80 return (readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
| 0x80));
84 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
86 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
| 0x80, value
);
90 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
92 readfifo(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, 0x80, data
, size
);
96 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
98 writefifo(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, 0x80, data
, size
);
103 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
105 return (readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
+ (hscx
? 0x40 : 0)));
109 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
111 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, offset
+ (hscx
? 0x40 : 0), value
);
114 /* Set the specific ipac to active */
116 set_ipac_active(struct IsdnCardState
*cs
, u_int active
)
119 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
,
120 active
? 0xc0 : 0xff);
124 * fast interrupt HSCX stuff goes here
127 #define READHSCX(cs, nr, reg) readreg(cs->hw.ax.base, \
128 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0))
129 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.ax.base, \
130 cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0), data)
131 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.base, \
132 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
133 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ax.base, \
134 cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
136 #include "hscx_irq.c"
139 bkm_interrupt_ipac(int intno
, void *dev_id
)
141 struct IsdnCardState
*cs
= dev_id
;
142 u_char ista
, val
, icnt
= 5;
145 spin_lock_irqsave(&cs
->lock
, flags
);
146 ista
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ISTA
);
147 if (!(ista
& 0x3f)) { /* not this IPAC */
148 spin_unlock_irqrestore(&cs
->lock
, flags
);
152 if (cs
->debug
& L1_DEB_IPAC
)
153 debugl1(cs
, "IPAC ISTA %02X", ista
);
155 val
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, HSCX_ISTA
+ 0x40);
163 hscx_int_main(cs
, val
);
167 val
= 0xfe & readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, ISAC_ISTA
| 0x80);
169 isac_interrupt(cs
, val
);
174 isac_interrupt(cs
, val
);
176 ista
= readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ISTA
);
177 if ((ista
& 0x3f) && icnt
) {
182 printk(KERN_WARNING
"HiSax: Scitel Quadro (%s) IRQ LOOP\n",
183 sct_quadro_subtypes
[cs
->subtyp
]);
184 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
, 0xFF);
185 writereg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_MASK
, 0xC0);
186 spin_unlock_irqrestore(&cs
->lock
, flags
);
191 release_io_sct_quadro(struct IsdnCardState
*cs
)
193 release_region(cs
->hw
.ax
.base
& 0xffffffc0, 128);
194 if (cs
->subtyp
== SCT_1
)
195 release_region(cs
->hw
.ax
.plx_adr
, 64);
199 enable_bkm_int(struct IsdnCardState
*cs
, unsigned bEnable
)
201 if (cs
->typ
== ISDN_CTYPE_SCT_QUADRO
) {
203 wordout(cs
->hw
.ax
.plx_adr
+ 0x4C, (wordin(cs
->hw
.ax
.plx_adr
+ 0x4C) | 0x41));
205 wordout(cs
->hw
.ax
.plx_adr
+ 0x4C, (wordin(cs
->hw
.ax
.plx_adr
+ 0x4C) & ~0x41));
210 reset_bkm(struct IsdnCardState
*cs
)
212 if (cs
->subtyp
== SCT_1
) {
213 wordout(cs
->hw
.ax
.plx_adr
+ 0x50, (wordin(cs
->hw
.ax
.plx_adr
+ 0x50) & ~4));
215 /* Remove the soft reset */
216 wordout(cs
->hw
.ax
.plx_adr
+ 0x50, (wordin(cs
->hw
.ax
.plx_adr
+ 0x50) | 4));
222 BKM_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
228 spin_lock_irqsave(&cs
->lock
, flags
);
230 set_ipac_active(cs
, 0);
231 enable_bkm_int(cs
, 0);
233 spin_unlock_irqrestore(&cs
->lock
, flags
);
237 spin_lock_irqsave(&cs
->lock
, flags
);
238 set_ipac_active(cs
, 0);
239 enable_bkm_int(cs
, 0);
240 spin_unlock_irqrestore(&cs
->lock
, flags
);
241 release_io_sct_quadro(cs
);
244 spin_lock_irqsave(&cs
->lock
, flags
);
245 cs
->debug
|= L1_DEB_IPAC
;
246 set_ipac_active(cs
, 1);
249 enable_bkm_int(cs
, 1);
250 spin_unlock_irqrestore(&cs
->lock
, flags
);
259 sct_alloc_io(u_int adr
, u_int len
)
261 if (!request_region(adr
, len
, "scitel")) {
263 "HiSax: Scitel port %#x-%#x already in use\n",
270 static struct pci_dev
*dev_a8 __devinitdata
= NULL
;
271 static u16 sub_vendor_id __devinitdata
= 0;
272 static u16 sub_sys_id __devinitdata
= 0;
273 static u_char pci_bus __devinitdata
= 0;
274 static u_char pci_device_fn __devinitdata
= 0;
275 static u_char pci_irq __devinitdata
= 0;
278 setup_sct_quadro(struct IsdnCard
*card
)
280 struct IsdnCardState
*cs
= card
->cs
;
283 u_int pci_ioaddr1
, pci_ioaddr2
, pci_ioaddr3
, pci_ioaddr4
, pci_ioaddr5
;
285 strcpy(tmp
, sct_quadro_revision
);
286 printk(KERN_INFO
"HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp
));
287 if (cs
->typ
== ISDN_CTYPE_SCT_QUADRO
) {
288 cs
->subtyp
= SCT_1
; /* Preset */
292 /* Identify subtype by para[0] */
293 if (card
->para
[0] >= SCT_1
&& card
->para
[0] <= SCT_4
)
294 cs
->subtyp
= card
->para
[0];
296 printk(KERN_WARNING
"HiSax: Scitel Quadro: Invalid "
297 "subcontroller in configuration, default to 1\n");
300 if ((cs
->subtyp
!= SCT_1
) && ((sub_sys_id
!= PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO
) ||
301 (sub_vendor_id
!= PCI_VENDOR_ID_BERKOM
)))
303 if (cs
->subtyp
== SCT_1
) {
304 while ((dev_a8
= pci_find_device(PCI_VENDOR_ID_PLX
,
305 PCI_DEVICE_ID_PLX_9050
, dev_a8
))) {
307 sub_vendor_id
= dev_a8
->subsystem_vendor
;
308 sub_sys_id
= dev_a8
->subsystem_device
;
309 if ((sub_sys_id
== PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO
) &&
310 (sub_vendor_id
== PCI_VENDOR_ID_BERKOM
)) {
311 if (pci_enable_device(dev_a8
))
313 pci_ioaddr1
= pci_resource_start(dev_a8
, 1);
314 pci_irq
= dev_a8
->irq
;
315 pci_bus
= dev_a8
->bus
->number
;
316 pci_device_fn
= dev_a8
->devfn
;
322 printk(KERN_WARNING
"HiSax: Scitel Quadro (%s): "
324 sct_quadro_subtypes
[cs
->subtyp
]);
327 #ifdef ATTEMPT_PCI_REMAPPING
328 /* HACK: PLX revision 1 bug: PLX address bit 7 must not be set */
329 if ((pci_ioaddr1
& 0x80) && (dev_a8
->revision
== 1)) {
330 printk(KERN_WARNING
"HiSax: Scitel Quadro (%s): "
331 "PLX rev 1, remapping required!\n",
332 sct_quadro_subtypes
[cs
->subtyp
]);
333 /* Restart PCI negotiation */
334 pci_write_config_dword(dev_a8
, PCI_BASE_ADDRESS_1
, (u_int
) - 1);
335 /* Move up by 0x80 byte */
337 pci_ioaddr1
&= PCI_BASE_ADDRESS_IO_MASK
;
338 pci_write_config_dword(dev_a8
, PCI_BASE_ADDRESS_1
, pci_ioaddr1
);
339 dev_a8
->resource
[ 1].start
= pci_ioaddr1
;
341 #endif /* End HACK */
343 if (!pci_irq
) { /* IRQ range check ?? */
344 printk(KERN_WARNING
"HiSax: Scitel Quadro (%s): No IRQ\n",
345 sct_quadro_subtypes
[cs
->subtyp
]);
348 pci_read_config_dword(dev_a8
, PCI_BASE_ADDRESS_1
, &pci_ioaddr1
);
349 pci_read_config_dword(dev_a8
, PCI_BASE_ADDRESS_2
, &pci_ioaddr2
);
350 pci_read_config_dword(dev_a8
, PCI_BASE_ADDRESS_3
, &pci_ioaddr3
);
351 pci_read_config_dword(dev_a8
, PCI_BASE_ADDRESS_4
, &pci_ioaddr4
);
352 pci_read_config_dword(dev_a8
, PCI_BASE_ADDRESS_5
, &pci_ioaddr5
);
353 if (!pci_ioaddr1
|| !pci_ioaddr2
|| !pci_ioaddr3
|| !pci_ioaddr4
|| !pci_ioaddr5
) {
354 printk(KERN_WARNING
"HiSax: Scitel Quadro (%s): "
355 "No IO base address(es)\n",
356 sct_quadro_subtypes
[cs
->subtyp
]);
359 pci_ioaddr1
&= PCI_BASE_ADDRESS_IO_MASK
;
360 pci_ioaddr2
&= PCI_BASE_ADDRESS_IO_MASK
;
361 pci_ioaddr3
&= PCI_BASE_ADDRESS_IO_MASK
;
362 pci_ioaddr4
&= PCI_BASE_ADDRESS_IO_MASK
;
363 pci_ioaddr5
&= PCI_BASE_ADDRESS_IO_MASK
;
366 cs
->irq_flags
|= IRQF_SHARED
;
367 /* pci_ioaddr1 is unique to all subdevices */
368 /* pci_ioaddr2 is for the fourth subdevice only */
369 /* pci_ioaddr3 is for the third subdevice only */
370 /* pci_ioaddr4 is for the second subdevice only */
371 /* pci_ioaddr5 is for the first subdevice only */
372 cs
->hw
.ax
.plx_adr
= pci_ioaddr1
;
373 /* Enter all ipac_base addresses */
376 cs
->hw
.ax
.base
= pci_ioaddr5
+ 0x00;
377 if (sct_alloc_io(pci_ioaddr1
, 128))
379 if (sct_alloc_io(pci_ioaddr5
, 64))
381 /* disable all IPAC */
382 writereg(pci_ioaddr5
, pci_ioaddr5
+ 4,
384 writereg(pci_ioaddr4
+ 0x08, pci_ioaddr4
+ 0x0c,
386 writereg(pci_ioaddr3
+ 0x10, pci_ioaddr3
+ 0x14,
388 writereg(pci_ioaddr2
+ 0x20, pci_ioaddr2
+ 0x24,
392 cs
->hw
.ax
.base
= pci_ioaddr4
+ 0x08;
393 if (sct_alloc_io(pci_ioaddr4
, 64))
397 cs
->hw
.ax
.base
= pci_ioaddr3
+ 0x10;
398 if (sct_alloc_io(pci_ioaddr3
, 64))
402 cs
->hw
.ax
.base
= pci_ioaddr2
+ 0x20;
403 if (sct_alloc_io(pci_ioaddr2
, 64))
407 /* For isac and hscx data path */
408 cs
->hw
.ax
.data_adr
= cs
->hw
.ax
.base
+ 4;
410 printk(KERN_INFO
"HiSax: Scitel Quadro (%s) configured at "
411 "0x%.4lX, 0x%.4lX, 0x%.4lX and IRQ %d\n",
412 sct_quadro_subtypes
[cs
->subtyp
],
418 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
420 cs
->readisac
= &ReadISAC
;
421 cs
->writeisac
= &WriteISAC
;
422 cs
->readisacfifo
= &ReadISACfifo
;
423 cs
->writeisacfifo
= &WriteISACfifo
;
425 cs
->BC_Read_Reg
= &ReadHSCX
;
426 cs
->BC_Write_Reg
= &WriteHSCX
;
427 cs
->BC_Send_Data
= &hscx_fill_fifo
;
428 cs
->cardmsg
= &BKM_card_msg
;
429 cs
->irq_func
= &bkm_interrupt_ipac
;
431 printk(KERN_INFO
"HiSax: Scitel Quadro (%s): IPAC Version %d\n",
432 sct_quadro_subtypes
[cs
->subtyp
],
433 readreg(cs
->hw
.ax
.base
, cs
->hw
.ax
.data_adr
, IPAC_ID
));