1 /* $Id: niccy.c,v 1.21.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for Dr. Neuhaus NICCY PnP and NICCY PCI and
4 * compatible (SAGEM cybermodem)
7 * Copyright by Karsten Keil <keil@isdn4linux.de>
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
12 * Thanks to Dr. Neuhaus and SAGEM for information
17 #include <linux/config.h>
18 #include <linux/init.h>
23 #include <linux/pci.h>
24 #include <linux/isapnp.h>
26 extern const char *CardType
[];
27 const char *niccy_revision
= "$Revision: 1.21.2.4 $";
29 #define byteout(addr,val) outb(val,addr)
30 #define bytein(addr) inb(addr)
32 #define ISAC_PCI_DATA 0
33 #define HSCX_PCI_DATA 1
34 #define ISAC_PCI_ADDR 2
35 #define HSCX_PCI_ADDR 3
44 #define PCI_IRQ_CTRL_REG 0x38
45 #define PCI_IRQ_ENABLE 0x1f00
46 #define PCI_IRQ_DISABLE 0xff0000
47 #define PCI_IRQ_ASSERT 0x800000
50 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
60 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
63 insb(adr
, data
, size
);
68 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
75 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
78 outsb(adr
, data
, size
);
81 /* Interface functions */
84 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
86 return (readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
));
90 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
92 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
, value
);
96 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
98 readfifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
102 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
104 writefifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
108 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
110 return (readreg(cs
->hw
.niccy
.hscx_ale
,
111 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0)));
115 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
117 writereg(cs
->hw
.niccy
.hscx_ale
,
118 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
121 #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
122 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
123 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
124 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
126 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
127 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
129 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
130 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
132 #include "hscx_irq.c"
135 niccy_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
137 struct IsdnCardState
*cs
= dev_id
;
141 spin_lock_irqsave(&cs
->lock
, flags
);
142 if (cs
->subtyp
== NICCY_PCI
) {
144 ival
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
145 if (!(ival
& PCI_IRQ_ASSERT
)) { /* IRQ not for us (shared) */
146 spin_unlock_irqrestore(&cs
->lock
, flags
);
149 outl(ival
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
151 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_ISTA
+ 0x40);
154 hscx_int_main(cs
, val
);
155 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
158 isac_interrupt(cs
, val
);
159 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_ISTA
+ 0x40);
161 if (cs
->debug
& L1_DEB_HSCX
)
162 debugl1(cs
, "HSCX IntStat after IntRoutine");
165 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
167 if (cs
->debug
& L1_DEB_ISAC
)
168 debugl1(cs
, "ISAC IntStat after IntRoutine");
171 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0xFF);
172 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
173 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0xFF);
174 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0);
175 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0);
176 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40, 0);
177 spin_unlock_irqrestore(&cs
->lock
, flags
);
182 release_io_niccy(struct IsdnCardState
*cs
)
184 if (cs
->subtyp
== NICCY_PCI
) {
187 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
188 val
&= PCI_IRQ_DISABLE
;
189 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
190 release_region(cs
->hw
.niccy
.cfg_reg
, 0x40);
191 release_region(cs
->hw
.niccy
.isac
, 4);
193 release_region(cs
->hw
.niccy
.isac
, 2);
194 release_region(cs
->hw
.niccy
.isac_ale
, 2);
199 niccy_reset(struct IsdnCardState
*cs
)
201 if (cs
->subtyp
== NICCY_PCI
) {
204 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
205 val
|= PCI_IRQ_ENABLE
;
206 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
212 niccy_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
218 spin_lock_irqsave(&cs
->lock
, flags
);
220 spin_unlock_irqrestore(&cs
->lock
, flags
);
223 release_io_niccy(cs
);
226 spin_lock_irqsave(&cs
->lock
, flags
);
228 spin_unlock_irqrestore(&cs
->lock
, flags
);
236 static struct pci_dev
*niccy_dev __initdata
= NULL
;
238 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
242 setup_niccy(struct IsdnCard
*card
)
244 struct IsdnCardState
*cs
= card
->cs
;
247 strcpy(tmp
, niccy_revision
);
248 printk(KERN_INFO
"HiSax: Niccy driver Rev. %s\n", HiSax_getrev(tmp
));
249 if (cs
->typ
!= ISDN_CTYPE_NICCY
)
252 if (!card
->para
[1] && isapnp_present()) {
253 struct pnp_dev
*pnp_d
= NULL
;
256 if ((pnp_c
= pnp_find_card(
257 ISAPNP_VENDOR('S', 'D', 'A'),
258 ISAPNP_FUNCTION(0x0150), pnp_c
))) {
259 if (!(pnp_d
= pnp_find_dev(pnp_c
,
260 ISAPNP_VENDOR('S', 'D', 'A'),
261 ISAPNP_FUNCTION(0x0150), pnp_d
))) {
262 printk(KERN_ERR
"NiccyPnP: PnP error card found, no device\n");
265 pnp_disable_dev(pnp_d
);
266 err
= pnp_activate_dev(pnp_d
);
268 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
272 card
->para
[1] = pnp_port_start(pnp_d
, 0);
273 card
->para
[2] = pnp_port_start(pnp_d
, 1);
274 card
->para
[0] = pnp_irq(pnp_d
, 0);
275 if (!card
->para
[0] || !card
->para
[1] || !card
->para
[2]) {
276 printk(KERN_ERR
"NiccyPnP:some resources are missing %ld/%lx/%lx\n",
277 card
->para
[0], card
->para
[1], card
->para
[2]);
278 pnp_disable_dev(pnp_d
);
282 printk(KERN_INFO
"NiccyPnP: no ISAPnP card found\n");
287 cs
->hw
.niccy
.isac
= card
->para
[1] + ISAC_PNP
;
288 cs
->hw
.niccy
.hscx
= card
->para
[1] + HSCX_PNP
;
289 cs
->hw
.niccy
.isac_ale
= card
->para
[2] + ISAC_PNP
;
290 cs
->hw
.niccy
.hscx_ale
= card
->para
[2] + HSCX_PNP
;
291 cs
->hw
.niccy
.cfg_reg
= 0;
292 cs
->subtyp
= NICCY_PNP
;
293 cs
->irq
= card
->para
[0];
294 if (!request_region(cs
->hw
.niccy
.isac
, 2, "niccy data")) {
296 "HiSax: %s data port %x-%x already in use\n",
299 cs
->hw
.niccy
.isac
+ 1);
302 if (!request_region(cs
->hw
.niccy
.isac_ale
, 2, "niccy addr")) {
304 "HiSax: %s address port %x-%x already in use\n",
306 cs
->hw
.niccy
.isac_ale
,
307 cs
->hw
.niccy
.isac_ale
+ 1);
308 release_region(cs
->hw
.niccy
.isac
, 2);
315 if ((niccy_dev
= pci_find_device(PCI_VENDOR_ID_SATSAGEM
,
316 PCI_DEVICE_ID_SATSAGEM_NICCY
, niccy_dev
))) {
317 if (pci_enable_device(niccy_dev
))
320 if (!niccy_dev
->irq
) {
321 printk(KERN_WARNING
"Niccy: No IRQ for PCI card found\n");
324 cs
->irq
= niccy_dev
->irq
;
325 cs
->hw
.niccy
.cfg_reg
= pci_resource_start(niccy_dev
, 0);
326 if (!cs
->hw
.niccy
.cfg_reg
) {
327 printk(KERN_WARNING
"Niccy: No IO-Adr for PCI cfg found\n");
330 pci_ioaddr
= pci_resource_start(niccy_dev
, 1);
332 printk(KERN_WARNING
"Niccy: No IO-Adr for PCI card found\n");
335 cs
->subtyp
= NICCY_PCI
;
337 printk(KERN_WARNING
"Niccy: No PCI card found\n");
340 cs
->irq_flags
|= SA_SHIRQ
;
341 cs
->hw
.niccy
.isac
= pci_ioaddr
+ ISAC_PCI_DATA
;
342 cs
->hw
.niccy
.isac_ale
= pci_ioaddr
+ ISAC_PCI_ADDR
;
343 cs
->hw
.niccy
.hscx
= pci_ioaddr
+ HSCX_PCI_DATA
;
344 cs
->hw
.niccy
.hscx_ale
= pci_ioaddr
+ HSCX_PCI_ADDR
;
345 if (!request_region(cs
->hw
.niccy
.isac
, 4, "niccy")) {
347 "HiSax: %s data port %x-%x already in use\n",
350 cs
->hw
.niccy
.isac
+ 4);
353 if (!request_region(cs
->hw
.niccy
.cfg_reg
, 0x40, "niccy pci")) {
355 "HiSax: %s pci port %x-%x already in use\n",
357 cs
->hw
.niccy
.cfg_reg
,
358 cs
->hw
.niccy
.cfg_reg
+ 0x40);
359 release_region(cs
->hw
.niccy
.isac
, 4);
363 printk(KERN_WARNING
"Niccy: io0 0 and NO_PCI_BIOS\n");
364 printk(KERN_WARNING
"Niccy: unable to config NICCY PCI\n");
366 #endif /* CONFIG_PCI */
368 printk(KERN_INFO
"HiSax: %s %s config irq:%d data:0x%X ale:0x%X\n",
369 CardType
[cs
->typ
], (cs
->subtyp
==1) ? "PnP":"PCI",
370 cs
->irq
, cs
->hw
.niccy
.isac
, cs
->hw
.niccy
.isac_ale
);
372 cs
->readisac
= &ReadISAC
;
373 cs
->writeisac
= &WriteISAC
;
374 cs
->readisacfifo
= &ReadISACfifo
;
375 cs
->writeisacfifo
= &WriteISACfifo
;
376 cs
->BC_Read_Reg
= &ReadHSCX
;
377 cs
->BC_Write_Reg
= &WriteHSCX
;
378 cs
->BC_Send_Data
= &hscx_fill_fifo
;
379 cs
->cardmsg
= &niccy_card_msg
;
380 cs
->irq_func
= &niccy_interrupt
;
381 ISACVersion(cs
, "Niccy:");
382 if (HscxVersion(cs
, "Niccy:")) {
384 "Niccy: wrong HSCX versions check IO address\n");
385 release_io_niccy(cs
);