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/init.h>
22 #include <linux/pci.h>
23 #include <linux/isapnp.h>
25 extern const char *CardType[];
26 static const char *niccy_revision = "$Revision: 1.21.2.4 $";
28 #define byteout(addr,val) outb(val,addr)
29 #define bytein(addr) inb(addr)
31 #define ISAC_PCI_DATA 0
32 #define HSCX_PCI_DATA 1
33 #define ISAC_PCI_ADDR 2
34 #define HSCX_PCI_ADDR 3
43 #define PCI_IRQ_CTRL_REG 0x38
44 #define PCI_IRQ_ENABLE 0x1f00
45 #define PCI_IRQ_DISABLE 0xff0000
46 #define PCI_IRQ_ASSERT 0x800000
49 readreg(unsigned int ale, unsigned int adr, u_char off)
59 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
62 insb(adr, data, size);
67 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
74 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
77 outsb(adr, data, size);
80 /* Interface functions */
83 ReadISAC(struct IsdnCardState *cs, u_char offset)
85 return (readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset));
89 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
91 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset, value);
95 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
97 readfifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
101 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
103 writefifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
107 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
109 return (readreg(cs->hw.niccy.hscx_ale,
110 cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0)));
114 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
116 writereg(cs->hw.niccy.hscx_ale,
117 cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0), value);
120 #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
121 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
122 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
123 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
125 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
126 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
128 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
129 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
131 #include "hscx_irq.c"
134 niccy_interrupt(int intno, void *dev_id, struct pt_regs *regs)
136 struct IsdnCardState *cs = dev_id;
140 spin_lock_irqsave(&cs->lock, flags);
141 if (cs->subtyp == NICCY_PCI) {
143 ival = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
144 if (!(ival & PCI_IRQ_ASSERT)) { /* IRQ not for us (shared) */
145 spin_unlock_irqrestore(&cs->lock, flags);
148 outl(ival, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
150 val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_ISTA + 0x40);
153 hscx_int_main(cs, val);
154 val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
157 isac_interrupt(cs, val);
158 val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_ISTA + 0x40);
160 if (cs->debug & L1_DEB_HSCX)
161 debugl1(cs, "HSCX IntStat after IntRoutine");
164 val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
166 if (cs->debug & L1_DEB_ISAC)
167 debugl1(cs, "ISAC IntStat after IntRoutine");
170 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0xFF);
171 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40, 0xFF);
172 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0xFF);
173 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0);
174 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0);
175 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40, 0);
176 spin_unlock_irqrestore(&cs->lock, flags);
181 release_io_niccy(struct IsdnCardState *cs)
183 if (cs->subtyp == NICCY_PCI) {
186 val = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
187 val &= PCI_IRQ_DISABLE;
188 outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
189 release_region(cs->hw.niccy.cfg_reg, 0x40);
190 release_region(cs->hw.niccy.isac, 4);
192 release_region(cs->hw.niccy.isac, 2);
193 release_region(cs->hw.niccy.isac_ale, 2);
198 niccy_reset(struct IsdnCardState *cs)
200 if (cs->subtyp == NICCY_PCI) {
203 val = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
204 val |= PCI_IRQ_ENABLE;
205 outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
211 niccy_card_msg(struct IsdnCardState *cs, int mt, void *arg)
217 spin_lock_irqsave(&cs->lock, flags);
219 spin_unlock_irqrestore(&cs->lock, flags);
222 release_io_niccy(cs);
225 spin_lock_irqsave(&cs->lock, flags);
227 spin_unlock_irqrestore(&cs->lock, flags);
235 static struct pci_dev *niccy_dev __initdata = NULL;
237 static struct pnp_card *pnp_c __devinitdata = NULL;
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)
251 if (!card->para[1] && isapnp_present()) {
252 struct pnp_dev *pnp_d = NULL;
255 if ((pnp_c = pnp_find_card(
256 ISAPNP_VENDOR('S', 'D', 'A'),
257 ISAPNP_FUNCTION(0x0150), pnp_c))) {
258 if (!(pnp_d = pnp_find_dev(pnp_c,
259 ISAPNP_VENDOR('S', 'D', 'A'),
260 ISAPNP_FUNCTION(0x0150), pnp_d))) {
261 printk(KERN_ERR "NiccyPnP: PnP error card found, no device\n");
264 pnp_disable_dev(pnp_d);
265 err = pnp_activate_dev(pnp_d);
267 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
271 card->para[1] = pnp_port_start(pnp_d, 0);
272 card->para[2] = pnp_port_start(pnp_d, 1);
273 card->para[0] = pnp_irq(pnp_d, 0);
274 if (!card->para[0] || !card->para[1] || !card->para[2]) {
275 printk(KERN_ERR "NiccyPnP:some resources are missing %ld/%lx/%lx\n",
276 card->para[0], card->para[1], card->para[2]);
277 pnp_disable_dev(pnp_d);
281 printk(KERN_INFO "NiccyPnP: no ISAPnP card found\n");
286 cs->hw.niccy.isac = card->para[1] + ISAC_PNP;
287 cs->hw.niccy.hscx = card->para[1] + HSCX_PNP;
288 cs->hw.niccy.isac_ale = card->para[2] + ISAC_PNP;
289 cs->hw.niccy.hscx_ale = card->para[2] + HSCX_PNP;
290 cs->hw.niccy.cfg_reg = 0;
291 cs->subtyp = NICCY_PNP;
292 cs->irq = card->para[0];
293 if (!request_region(cs->hw.niccy.isac, 2, "niccy data")) {
295 "HiSax: %s data port %x-%x already in use\n",
298 cs->hw.niccy.isac + 1);
301 if (!request_region(cs->hw.niccy.isac_ale, 2, "niccy addr")) {
303 "HiSax: %s address port %x-%x already in use\n",
305 cs->hw.niccy.isac_ale,
306 cs->hw.niccy.isac_ale + 1);
307 release_region(cs->hw.niccy.isac, 2);
314 if ((niccy_dev = pci_find_device(PCI_VENDOR_ID_SATSAGEM,
315 PCI_DEVICE_ID_SATSAGEM_NICCY, niccy_dev))) {
316 if (pci_enable_device(niccy_dev))
319 if (!niccy_dev->irq) {
320 printk(KERN_WARNING "Niccy: No IRQ for PCI card found\n");
323 cs->irq = niccy_dev->irq;
324 cs->hw.niccy.cfg_reg = pci_resource_start(niccy_dev, 0);
325 if (!cs->hw.niccy.cfg_reg) {
326 printk(KERN_WARNING "Niccy: No IO-Adr for PCI cfg found\n");
329 pci_ioaddr = pci_resource_start(niccy_dev, 1);
331 printk(KERN_WARNING "Niccy: No IO-Adr for PCI card found\n");
334 cs->subtyp = NICCY_PCI;
336 printk(KERN_WARNING "Niccy: No PCI card found\n");
339 cs->irq_flags |= IRQF_SHARED;
340 cs->hw.niccy.isac = pci_ioaddr + ISAC_PCI_DATA;
341 cs->hw.niccy.isac_ale = pci_ioaddr + ISAC_PCI_ADDR;
342 cs->hw.niccy.hscx = pci_ioaddr + HSCX_PCI_DATA;
343 cs->hw.niccy.hscx_ale = pci_ioaddr + HSCX_PCI_ADDR;
344 if (!request_region(cs->hw.niccy.isac, 4, "niccy")) {
346 "HiSax: %s data port %x-%x already in use\n",
349 cs->hw.niccy.isac + 4);
352 if (!request_region(cs->hw.niccy.cfg_reg, 0x40, "niccy pci")) {
354 "HiSax: %s pci port %x-%x already in use\n",
356 cs->hw.niccy.cfg_reg,
357 cs->hw.niccy.cfg_reg + 0x40);
358 release_region(cs->hw.niccy.isac, 4);
362 printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n");
363 printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n");
365 #endif /* CONFIG_PCI */
367 printk(KERN_INFO "HiSax: %s %s config irq:%d data:0x%X ale:0x%X\n",
368 CardType[cs->typ], (cs->subtyp==1) ? "PnP":"PCI",
369 cs->irq, cs->hw.niccy.isac, cs->hw.niccy.isac_ale);
371 cs->readisac = &ReadISAC;
372 cs->writeisac = &WriteISAC;
373 cs->readisacfifo = &ReadISACfifo;
374 cs->writeisacfifo = &WriteISACfifo;
375 cs->BC_Read_Reg = &ReadHSCX;
376 cs->BC_Write_Reg = &WriteHSCX;
377 cs->BC_Send_Data = &hscx_fill_fifo;
378 cs->cardmsg = &niccy_card_msg;
379 cs->irq_func = &niccy_interrupt;
380 ISACVersion(cs, "Niccy:");
381 if (HscxVersion(cs, "Niccy:")) {
383 "Niccy: wrong HSCX versions check IO address\n");
384 release_io_niccy(cs);