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 extern const char *CardType[];
25 static const char *niccy_revision = "$Revision: 1.21.2.4 $";
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
47 static inline u_char readreg(unsigned int ale, unsigned int adr, u_char off)
56 static inline void readfifo(unsigned int ale, unsigned int adr, u_char off,
57 u_char *data, int size)
60 insb(adr, data, size);
63 static inline void writereg(unsigned int ale, unsigned int adr, u_char off,
70 static inline void writefifo(unsigned int ale, unsigned int adr, u_char off,
71 u_char *data, int size)
74 outsb(adr, data, size);
77 /* Interface functions */
79 static u_char ReadISAC(struct IsdnCardState *cs, u_char offset)
81 return readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset);
84 static void WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
86 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset, value);
89 static void ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
91 readfifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
94 static void WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
96 writefifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
99 static u_char ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
101 return readreg(cs->hw.niccy.hscx_ale,
102 cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0));
105 static void WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset,
108 writereg(cs->hw.niccy.hscx_ale,
109 cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0), value);
112 #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
113 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
114 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
115 cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
117 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
118 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
120 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
121 cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
123 #include "hscx_irq.c"
125 static irqreturn_t niccy_interrupt(int intno, void *dev_id)
127 struct IsdnCardState *cs = dev_id;
131 spin_lock_irqsave(&cs->lock, flags);
132 if (cs->subtyp == NICCY_PCI) {
134 ival = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
135 if (!(ival & PCI_IRQ_ASSERT)) { /* IRQ not for us (shared) */
136 spin_unlock_irqrestore(&cs->lock, flags);
139 outl(ival, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
141 val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx,
145 hscx_int_main(cs, val);
146 val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
149 isac_interrupt(cs, val);
150 val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx,
153 if (cs->debug & L1_DEB_HSCX)
154 debugl1(cs, "HSCX IntStat after IntRoutine");
157 val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
159 if (cs->debug & L1_DEB_ISAC)
160 debugl1(cs, "ISAC IntStat after IntRoutine");
163 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0xFF);
164 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40,
166 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0xFF);
167 writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0);
168 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0);
169 writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40,0);
170 spin_unlock_irqrestore(&cs->lock, flags);
174 static void release_io_niccy(struct IsdnCardState *cs)
176 if (cs->subtyp == NICCY_PCI) {
179 val = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
180 val &= PCI_IRQ_DISABLE;
181 outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
182 release_region(cs->hw.niccy.cfg_reg, 0x40);
183 release_region(cs->hw.niccy.isac, 4);
185 release_region(cs->hw.niccy.isac, 2);
186 release_region(cs->hw.niccy.isac_ale, 2);
190 static void niccy_reset(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_ENABLE;
197 outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
202 static int niccy_card_msg(struct IsdnCardState *cs, int mt, void *arg)
208 spin_lock_irqsave(&cs->lock, flags);
210 spin_unlock_irqrestore(&cs->lock, flags);
213 release_io_niccy(cs);
216 spin_lock_irqsave(&cs->lock, flags);
218 spin_unlock_irqrestore(&cs->lock, flags);
227 static struct pnp_card *pnp_c __devinitdata = NULL;
230 int __devinit setup_niccy(struct IsdnCard *card)
232 struct IsdnCardState *cs = card->cs;
235 strcpy(tmp, niccy_revision);
236 printk(KERN_INFO "HiSax: Niccy driver Rev. %s\n", HiSax_getrev(tmp));
237 if (cs->typ != ISDN_CTYPE_NICCY)
240 if (!card->para[1] && isapnp_present()) {
241 struct pnp_dev *pnp_d = NULL;
244 pnp_c = pnp_find_card(ISAPNP_VENDOR('S', 'D', 'A'),
245 ISAPNP_FUNCTION(0x0150), pnp_c);
247 pnp_d = pnp_find_dev(pnp_c,
248 ISAPNP_VENDOR('S', 'D', 'A'),
249 ISAPNP_FUNCTION(0x0150), pnp_d);
251 printk(KERN_ERR "NiccyPnP: PnP error card "
252 "found, no device\n");
255 pnp_disable_dev(pnp_d);
256 err = pnp_activate_dev(pnp_d);
258 printk(KERN_WARNING "%s: pnp_activate_dev "
259 "ret(%d)\n", __FUNCTION__, err);
262 card->para[1] = pnp_port_start(pnp_d, 0);
263 card->para[2] = pnp_port_start(pnp_d, 1);
264 card->para[0] = pnp_irq(pnp_d, 0);
265 if (!card->para[0] || !card->para[1] ||
267 printk(KERN_ERR "NiccyPnP:some resources are "
268 "missing %ld/%lx/%lx\n",
269 card->para[0], card->para[1],
271 pnp_disable_dev(pnp_d);
275 printk(KERN_INFO "NiccyPnP: no ISAPnP card found\n");
279 cs->hw.niccy.isac = card->para[1] + ISAC_PNP;
280 cs->hw.niccy.hscx = card->para[1] + HSCX_PNP;
281 cs->hw.niccy.isac_ale = card->para[2] + ISAC_PNP;
282 cs->hw.niccy.hscx_ale = card->para[2] + HSCX_PNP;
283 cs->hw.niccy.cfg_reg = 0;
284 cs->subtyp = NICCY_PNP;
285 cs->irq = card->para[0];
286 if (!request_region(cs->hw.niccy.isac, 2, "niccy data")) {
287 printk(KERN_WARNING "HiSax: %s data port %x-%x "
288 "already in use\n", CardType[card->typ],
289 cs->hw.niccy.isac, cs->hw.niccy.isac + 1);
292 if (!request_region(cs->hw.niccy.isac_ale, 2, "niccy addr")) {
293 printk(KERN_WARNING "HiSax: %s address port %x-%x "
294 "already in use\n", CardType[card->typ],
295 cs->hw.niccy.isac_ale,
296 cs->hw.niccy.isac_ale + 1);
297 release_region(cs->hw.niccy.isac, 2);
301 #ifdef CONFIG_PCI_LEGACY
302 static struct pci_dev *niccy_dev __devinitdata;
306 if ((niccy_dev = pci_find_device(PCI_VENDOR_ID_SATSAGEM,
307 PCI_DEVICE_ID_SATSAGEM_NICCY,
309 if (pci_enable_device(niccy_dev))
312 if (!niccy_dev->irq) {
314 "Niccy: No IRQ for PCI card found\n");
317 cs->irq = niccy_dev->irq;
318 cs->hw.niccy.cfg_reg = pci_resource_start(niccy_dev, 0);
319 if (!cs->hw.niccy.cfg_reg) {
321 "Niccy: No IO-Adr for PCI cfg found\n");
324 pci_ioaddr = pci_resource_start(niccy_dev, 1);
327 "Niccy: No IO-Adr for PCI card found\n");
330 cs->subtyp = NICCY_PCI;
332 printk(KERN_WARNING "Niccy: No PCI card found\n");
335 cs->irq_flags |= IRQF_SHARED;
336 cs->hw.niccy.isac = pci_ioaddr + ISAC_PCI_DATA;
337 cs->hw.niccy.isac_ale = pci_ioaddr + ISAC_PCI_ADDR;
338 cs->hw.niccy.hscx = pci_ioaddr + HSCX_PCI_DATA;
339 cs->hw.niccy.hscx_ale = pci_ioaddr + HSCX_PCI_ADDR;
340 if (!request_region(cs->hw.niccy.isac, 4, "niccy")) {
342 "HiSax: %s data port %x-%x already in use\n",
344 cs->hw.niccy.isac, cs->hw.niccy.isac + 4);
347 if (!request_region(cs->hw.niccy.cfg_reg, 0x40, "niccy pci")) {
349 "HiSax: %s pci port %x-%x already in use\n",
351 cs->hw.niccy.cfg_reg,
352 cs->hw.niccy.cfg_reg + 0x40);
353 release_region(cs->hw.niccy.isac, 4);
357 printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n");
358 printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n");
360 #endif /* CONFIG_PCI_LEGACY */
362 printk(KERN_INFO "HiSax: %s %s config irq:%d data:0x%X ale:0x%X\n",
363 CardType[cs->typ], (cs->subtyp == 1) ? "PnP" : "PCI",
364 cs->irq, cs->hw.niccy.isac, cs->hw.niccy.isac_ale);
366 cs->readisac = &ReadISAC;
367 cs->writeisac = &WriteISAC;
368 cs->readisacfifo = &ReadISACfifo;
369 cs->writeisacfifo = &WriteISACfifo;
370 cs->BC_Read_Reg = &ReadHSCX;
371 cs->BC_Write_Reg = &WriteHSCX;
372 cs->BC_Send_Data = &hscx_fill_fifo;
373 cs->cardmsg = &niccy_card_msg;
374 cs->irq_func = &niccy_interrupt;
375 ISACVersion(cs, "Niccy:");
376 if (HscxVersion(cs, "Niccy:")) {
377 printk(KERN_WARNING "Niccy: wrong HSCX versions check IO "
379 release_io_niccy(cs);