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
16 #include <linux/init.h>
21 #include <linux/pci.h>
22 #include <linux/isapnp.h>
24 static const char *niccy_revision
= "$Revision: 1.21.2.4 $";
26 #define byteout(addr, val) outb(val, addr)
27 #define bytein(addr) inb(addr)
29 #define ISAC_PCI_DATA 0
30 #define HSCX_PCI_DATA 1
31 #define ISAC_PCI_ADDR 2
32 #define HSCX_PCI_ADDR 3
41 #define PCI_IRQ_CTRL_REG 0x38
42 #define PCI_IRQ_ENABLE 0x1f00
43 #define PCI_IRQ_DISABLE 0xff0000
44 #define PCI_IRQ_ASSERT 0x800000
46 static inline u_char
readreg(unsigned int ale
, unsigned int adr
, u_char off
)
55 static inline void readfifo(unsigned int ale
, unsigned int adr
, u_char off
,
56 u_char
*data
, int size
)
59 insb(adr
, data
, size
);
62 static inline void writereg(unsigned int ale
, unsigned int adr
, u_char off
,
69 static inline void writefifo(unsigned int ale
, unsigned int adr
, u_char off
,
70 u_char
*data
, int size
)
73 outsb(adr
, data
, size
);
76 /* Interface functions */
78 static u_char
ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
80 return readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
);
83 static void WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
85 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, offset
, value
);
88 static void ReadISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
90 readfifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
93 static void WriteISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
95 writefifo(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, 0, data
, size
);
98 static u_char
ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
100 return readreg(cs
->hw
.niccy
.hscx_ale
,
101 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0));
104 static void WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
,
107 writereg(cs
->hw
.niccy
.hscx_ale
,
108 cs
->hw
.niccy
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
111 #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
112 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
113 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
114 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
116 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
117 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
119 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
120 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
122 #include "hscx_irq.c"
124 static irqreturn_t
niccy_interrupt(int intno
, void *dev_id
)
126 struct IsdnCardState
*cs
= dev_id
;
130 spin_lock_irqsave(&cs
->lock
, flags
);
131 if (cs
->subtyp
== NICCY_PCI
) {
133 ival
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
134 if (!(ival
& PCI_IRQ_ASSERT
)) { /* IRQ not for us (shared) */
135 spin_unlock_irqrestore(&cs
->lock
, flags
);
138 outl(ival
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
140 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
,
144 hscx_int_main(cs
, val
);
145 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
148 isac_interrupt(cs
, val
);
149 val
= readreg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
,
152 if (cs
->debug
& L1_DEB_HSCX
)
153 debugl1(cs
, "HSCX IntStat after IntRoutine");
156 val
= readreg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_ISTA
);
158 if (cs
->debug
& L1_DEB_ISAC
)
159 debugl1(cs
, "ISAC IntStat after IntRoutine");
162 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0xFF);
163 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40,
165 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0xFF);
166 writereg(cs
->hw
.niccy
.isac_ale
, cs
->hw
.niccy
.isac
, ISAC_MASK
, 0);
167 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
, 0);
168 writereg(cs
->hw
.niccy
.hscx_ale
, cs
->hw
.niccy
.hscx
, HSCX_MASK
+ 0x40, 0);
169 spin_unlock_irqrestore(&cs
->lock
, flags
);
173 static void release_io_niccy(struct IsdnCardState
*cs
)
175 if (cs
->subtyp
== NICCY_PCI
) {
178 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
179 val
&= PCI_IRQ_DISABLE
;
180 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
181 release_region(cs
->hw
.niccy
.cfg_reg
, 0x40);
182 release_region(cs
->hw
.niccy
.isac
, 4);
184 release_region(cs
->hw
.niccy
.isac
, 2);
185 release_region(cs
->hw
.niccy
.isac_ale
, 2);
189 static void niccy_reset(struct IsdnCardState
*cs
)
191 if (cs
->subtyp
== NICCY_PCI
) {
194 val
= inl(cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
195 val
|= PCI_IRQ_ENABLE
;
196 outl(val
, cs
->hw
.niccy
.cfg_reg
+ PCI_IRQ_CTRL_REG
);
201 static int niccy_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
207 spin_lock_irqsave(&cs
->lock
, flags
);
209 spin_unlock_irqrestore(&cs
->lock
, flags
);
212 release_io_niccy(cs
);
215 spin_lock_irqsave(&cs
->lock
, flags
);
217 spin_unlock_irqrestore(&cs
->lock
, flags
);
226 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
229 int __devinit
setup_niccy(struct IsdnCard
*card
)
231 struct IsdnCardState
*cs
= card
->cs
;
234 strcpy(tmp
, niccy_revision
);
235 printk(KERN_INFO
"HiSax: Niccy driver Rev. %s\n", HiSax_getrev(tmp
));
236 if (cs
->typ
!= ISDN_CTYPE_NICCY
)
239 if (!card
->para
[1] && isapnp_present()) {
240 struct pnp_dev
*pnp_d
= NULL
;
243 pnp_c
= pnp_find_card(ISAPNP_VENDOR('S', 'D', 'A'),
244 ISAPNP_FUNCTION(0x0150), pnp_c
);
246 pnp_d
= pnp_find_dev(pnp_c
,
247 ISAPNP_VENDOR('S', 'D', 'A'),
248 ISAPNP_FUNCTION(0x0150), pnp_d
);
250 printk(KERN_ERR
"NiccyPnP: PnP error card "
251 "found, no device\n");
254 pnp_disable_dev(pnp_d
);
255 err
= pnp_activate_dev(pnp_d
);
257 printk(KERN_WARNING
"%s: pnp_activate_dev "
258 "ret(%d)\n", __func__
, err
);
261 card
->para
[1] = pnp_port_start(pnp_d
, 0);
262 card
->para
[2] = pnp_port_start(pnp_d
, 1);
263 card
->para
[0] = pnp_irq(pnp_d
, 0);
264 if (!card
->para
[0] || !card
->para
[1] ||
266 printk(KERN_ERR
"NiccyPnP:some resources are "
267 "missing %ld/%lx/%lx\n",
268 card
->para
[0], card
->para
[1],
270 pnp_disable_dev(pnp_d
);
274 printk(KERN_INFO
"NiccyPnP: no ISAPnP card found\n");
278 cs
->hw
.niccy
.isac
= card
->para
[1] + ISAC_PNP
;
279 cs
->hw
.niccy
.hscx
= card
->para
[1] + HSCX_PNP
;
280 cs
->hw
.niccy
.isac_ale
= card
->para
[2] + ISAC_PNP
;
281 cs
->hw
.niccy
.hscx_ale
= card
->para
[2] + HSCX_PNP
;
282 cs
->hw
.niccy
.cfg_reg
= 0;
283 cs
->subtyp
= NICCY_PNP
;
284 cs
->irq
= card
->para
[0];
285 if (!request_region(cs
->hw
.niccy
.isac
, 2, "niccy data")) {
286 printk(KERN_WARNING
"HiSax: NICCY data port %x-%x "
288 cs
->hw
.niccy
.isac
, cs
->hw
.niccy
.isac
+ 1);
291 if (!request_region(cs
->hw
.niccy
.isac_ale
, 2, "niccy addr")) {
292 printk(KERN_WARNING
"HiSax: NICCY address port %x-%x "
294 cs
->hw
.niccy
.isac_ale
,
295 cs
->hw
.niccy
.isac_ale
+ 1);
296 release_region(cs
->hw
.niccy
.isac
, 2);
301 static struct pci_dev
*niccy_dev __devinitdata
;
305 if ((niccy_dev
= hisax_find_pci_device(PCI_VENDOR_ID_SATSAGEM
,
306 PCI_DEVICE_ID_SATSAGEM_NICCY
,
308 if (pci_enable_device(niccy_dev
))
311 if (!niccy_dev
->irq
) {
313 "Niccy: No IRQ for PCI card found\n");
316 cs
->irq
= niccy_dev
->irq
;
317 cs
->hw
.niccy
.cfg_reg
= pci_resource_start(niccy_dev
, 0);
318 if (!cs
->hw
.niccy
.cfg_reg
) {
320 "Niccy: No IO-Adr for PCI cfg found\n");
323 pci_ioaddr
= pci_resource_start(niccy_dev
, 1);
326 "Niccy: No IO-Adr for PCI card found\n");
329 cs
->subtyp
= NICCY_PCI
;
331 printk(KERN_WARNING
"Niccy: No PCI card found\n");
334 cs
->irq_flags
|= IRQF_SHARED
;
335 cs
->hw
.niccy
.isac
= pci_ioaddr
+ ISAC_PCI_DATA
;
336 cs
->hw
.niccy
.isac_ale
= pci_ioaddr
+ ISAC_PCI_ADDR
;
337 cs
->hw
.niccy
.hscx
= pci_ioaddr
+ HSCX_PCI_DATA
;
338 cs
->hw
.niccy
.hscx_ale
= pci_ioaddr
+ HSCX_PCI_ADDR
;
339 if (!request_region(cs
->hw
.niccy
.isac
, 4, "niccy")) {
341 "HiSax: NICCY data port %x-%x already in use\n",
342 cs
->hw
.niccy
.isac
, cs
->hw
.niccy
.isac
+ 4);
345 if (!request_region(cs
->hw
.niccy
.cfg_reg
, 0x40, "niccy pci")) {
347 "HiSax: NICCY pci port %x-%x already in use\n",
348 cs
->hw
.niccy
.cfg_reg
,
349 cs
->hw
.niccy
.cfg_reg
+ 0x40);
350 release_region(cs
->hw
.niccy
.isac
, 4);
354 printk(KERN_WARNING
"Niccy: io0 0 and NO_PCI_BIOS\n");
355 printk(KERN_WARNING
"Niccy: unable to config NICCY PCI\n");
357 #endif /* CONFIG_PCI */
359 printk(KERN_INFO
"HiSax: NICCY %s config irq:%d data:0x%X ale:0x%X\n",
360 (cs
->subtyp
== 1) ? "PnP" : "PCI",
361 cs
->irq
, cs
->hw
.niccy
.isac
, cs
->hw
.niccy
.isac_ale
);
363 cs
->readisac
= &ReadISAC
;
364 cs
->writeisac
= &WriteISAC
;
365 cs
->readisacfifo
= &ReadISACfifo
;
366 cs
->writeisacfifo
= &WriteISACfifo
;
367 cs
->BC_Read_Reg
= &ReadHSCX
;
368 cs
->BC_Write_Reg
= &WriteHSCX
;
369 cs
->BC_Send_Data
= &hscx_fill_fifo
;
370 cs
->cardmsg
= &niccy_card_msg
;
371 cs
->irq_func
= &niccy_interrupt
;
372 ISACVersion(cs
, "Niccy:");
373 if (HscxVersion(cs
, "Niccy:")) {
374 printk(KERN_WARNING
"Niccy: wrong HSCX versions check IO "
376 release_io_niccy(cs
);