1 /* $Id: niccy.c,v 1.15.6.1 2000/11/28 12:02:46 kai Exp $
3 * niccy.c low level stuff for Dr. Neuhaus NICCY PnP and NICCY PCI and
4 * compatible (SAGEM cybermodem)
8 * Thanks to Dr. Neuhaus and SAGEM for informations
10 * This file is (c) under GNU PUBLIC LICENSE
15 #define __NO_VERSION__
16 #include <linux/config.h>
17 #include <linux/init.h>
22 #include <linux/pci.h>
24 extern const char *CardType
[];
25 const char *niccy_revision
= "$Revision: 1.15.6.1 $";
27 #define byteout(addr,val) outb(val,addr)
28 #define bytein(addr) inb(addr)
30 #define ISAC_PCI_DATA 0
31 #define HSCX_PCI_DATA 1
32 #define ISAC_PCI_ADDR 2
33 #define HSCX_PCI_ADDR 3
42 #define PCI_IRQ_CTRL_REG 0x38
43 #define PCI_IRQ_ENABLE 0x1f00
44 #define PCI_IRQ_DISABLE 0xff0000
45 #define PCI_IRQ_ASSERT 0x800000
48 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
62 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
64 /* fifo read without cli because it's allready done */
67 insb(adr
, data
, size
);
72 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
84 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
86 /* fifo write without cli because it's allready done */
88 outsb(adr
, data
, size
);
91 /* Interface functions */
94 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
96 return (readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
));
100 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
102 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
, value
);
106 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
108 readfifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
112 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
114 writefifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
118 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
120 return (readreg(cs
->hw
.niccy
.hscx_ale
,
121 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0)));
125 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
127 writereg(cs
->hw
.niccy
.hscx_ale
,
128 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
131 #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
132 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
133 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
134 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
136 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
137 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
139 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
140 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
142 #include "hscx_irq.c"
145 niccy_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
147 struct IsdnCardState
*cs
= dev_id
;
151 printk(KERN_WARNING
"Niccy: Spurious interrupt!\n");
154 if (cs
->subtyp
== NICCY_PCI
) {
156 ival
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
157 if (!(ival
& PCI_IRQ_ASSERT
)) /* IRQ not for us (shared) */
159 outl(ival
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
161 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_ISTA
+ 0x40);
164 hscx_int_main(cs
, val
);
165 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
168 isac_interrupt(cs
, val
);
169 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_ISTA
+ 0x40);
171 if (cs
->debug
& L1_DEB_HSCX
)
172 debugl1(cs
, "HSCX IntStat after IntRoutine");
175 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
177 if (cs
->debug
& L1_DEB_ISAC
)
178 debugl1(cs
, "ISAC IntStat after IntRoutine");
181 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0xFF);
182 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
183 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0xFF);
184 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0);
185 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0);
186 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40, 0);
190 release_io_niccy(struct IsdnCardState
*cs
)
192 if (cs
->subtyp
== NICCY_PCI
) {
195 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
196 val
&= PCI_IRQ_DISABLE
;
197 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
198 release_region(cs
->hw
.niccy
.cfg_reg
, 0x80);
199 release_region(cs
->hw
.niccy
.isac
, 4);
201 release_region(cs
->hw
.niccy
.isac
, 2);
202 release_region(cs
->hw
.niccy
.isac_ale
, 2);
207 niccy_reset(struct IsdnCardState
*cs
)
209 if (cs
->subtyp
== NICCY_PCI
) {
212 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
213 val
|= PCI_IRQ_ENABLE
;
214 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
220 niccy_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
227 release_io_niccy(cs
);
238 static struct pci_dev
*niccy_dev __initdata
;
241 setup_niccy(struct IsdnCard
*card
)
243 struct IsdnCardState
*cs
= card
->cs
;
246 strcpy(tmp
, niccy_revision
);
247 printk(KERN_INFO
"HiSax: Niccy driver Rev. %s\n", HiSax_getrev(tmp
));
248 if (cs
->typ
!= ISDN_CTYPE_NICCY
)
252 cs
->hw
.niccy
.isac
= card
->para
[1] + ISAC_PNP
;
253 cs
->hw
.niccy
.hscx
= card
->para
[1] + HSCX_PNP
;
254 cs
->hw
.niccy
.isac_ale
= card
->para
[2] + ISAC_PNP
;
255 cs
->hw
.niccy
.hscx_ale
= card
->para
[2] + HSCX_PNP
;
256 cs
->hw
.niccy
.cfg_reg
= 0;
257 cs
->subtyp
= NICCY_PNP
;
258 cs
->irq
= card
->para
[0];
259 if (check_region((cs
->hw
.niccy
.isac
), 2)) {
261 "HiSax: %s data port %x-%x already in use\n",
264 cs
->hw
.niccy
.isac
+ 1);
267 request_region(cs
->hw
.niccy
.isac
, 2, "niccy data");
268 if (check_region((cs
->hw
.niccy
.isac_ale
), 2)) {
270 "HiSax: %s address port %x-%x already in use\n",
272 cs
->hw
.niccy
.isac_ale
,
273 cs
->hw
.niccy
.isac_ale
+ 1);
274 release_region(cs
->hw
.niccy
.isac
, 2);
277 request_region(cs
->hw
.niccy
.isac_ale
, 2, "niccy addr");
281 if (!pci_present()) {
282 printk(KERN_ERR
"Niccy: no PCI bus present\n");
286 if ((niccy_dev
= pci_find_device(PCI_VENDOR_ID_SATSAGEM
,
287 PCI_DEVICE_ID_SATSAGEM_NICCY
, niccy_dev
))) {
288 if (pci_enable_device(niccy_dev
))
291 if (!niccy_dev
->irq
) {
292 printk(KERN_WARNING
"Niccy: No IRQ for PCI card found\n");
295 cs
->irq
= niccy_dev
->irq
;
296 cs
->hw
.niccy
.cfg_reg
= pci_resource_start(niccy_dev
, 0);
297 if (!cs
->hw
.niccy
.cfg_reg
) {
298 printk(KERN_WARNING
"Niccy: No IO-Adr for PCI cfg found\n");
301 pci_ioaddr
= pci_resource_start(niccy_dev
, 1);
303 printk(KERN_WARNING
"Niccy: No IO-Adr for PCI card found\n");
306 cs
->subtyp
= NICCY_PCI
;
308 printk(KERN_WARNING
"Niccy: No PCI card found\n");
311 cs
->irq_flags
|= SA_SHIRQ
;
312 cs
->hw
.niccy
.isac
= pci_ioaddr
+ ISAC_PCI_DATA
;
313 cs
->hw
.niccy
.isac_ale
= pci_ioaddr
+ ISAC_PCI_ADDR
;
314 cs
->hw
.niccy
.hscx
= pci_ioaddr
+ HSCX_PCI_DATA
;
315 cs
->hw
.niccy
.hscx_ale
= pci_ioaddr
+ HSCX_PCI_ADDR
;
316 if (check_region((cs
->hw
.niccy
.isac
), 4)) {
318 "HiSax: %s data port %x-%x already in use\n",
321 cs
->hw
.niccy
.isac
+ 4);
324 request_region(cs
->hw
.niccy
.isac
, 4, "niccy");
325 if (check_region(cs
->hw
.niccy
.cfg_reg
, 0x80)) {
327 "HiSax: %s pci port %x-%x already in use\n",
329 cs
->hw
.niccy
.cfg_reg
,
330 cs
->hw
.niccy
.cfg_reg
+ 0x80);
331 release_region(cs
->hw
.niccy
.isac
, 4);
334 request_region(cs
->hw
.niccy
.cfg_reg
, 0x80, "niccy pci");
337 printk(KERN_WARNING
"Niccy: io0 0 and NO_PCI_BIOS\n");
338 printk(KERN_WARNING
"Niccy: unable to config NICCY PCI\n");
340 #endif /* CONFIG_PCI */
343 "HiSax: %s %s config irq:%d data:0x%X ale:0x%X\n",
344 CardType
[cs
->typ
], (cs
->subtyp
==1) ? "PnP":"PCI",
345 cs
->irq
, cs
->hw
.niccy
.isac
, cs
->hw
.niccy
.isac_ale
);
346 cs
->readisac
= &ReadISAC
;
347 cs
->writeisac
= &WriteISAC
;
348 cs
->readisacfifo
= &ReadISACfifo
;
349 cs
->writeisacfifo
= &WriteISACfifo
;
350 cs
->BC_Read_Reg
= &ReadHSCX
;
351 cs
->BC_Write_Reg
= &WriteHSCX
;
352 cs
->BC_Send_Data
= &hscx_fill_fifo
;
353 cs
->cardmsg
= &niccy_card_msg
;
354 cs
->irq_func
= &niccy_interrupt
;
355 ISACVersion(cs
, "Niccy:");
356 if (HscxVersion(cs
, "Niccy:")) {
358 "Niccy: wrong HSCX versions check IO address\n");
359 release_io_niccy(cs
);