1 /* $Id: asuscom.c,v 1.14.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for ASUSCOM NETWORK INC. ISDNLink cards
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Thanks to ASUSCOM NETWORK INC. Taiwan and Dynalink NL for information
15 #include <linux/init.h>
16 #include <linux/isapnp.h>
23 extern const char *CardType
[];
25 const char *Asuscom_revision
= "$Revision: 1.14.2.4 $";
27 #define byteout(addr,val) outb(val,addr)
28 #define bytein(addr) inb(addr)
33 #define ASUS_CTRL_U7 3
34 #define ASUS_CTRL_POTS 5
36 #define ASUS_IPAC_ALE 0
37 #define ASUS_IPAC_DATA 1
39 #define ASUS_ISACHSCX 1
42 /* CARD_ADR (Write) */
43 #define ASUS_RESET 0x80 /* Bit 7 Reset-Leitung */
46 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
56 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
59 insb(adr
, data
, size
);
64 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
71 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
74 outsb(adr
, data
, size
);
77 /* Interface functions */
80 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
82 return (readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, offset
));
86 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
88 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, offset
, value
);
92 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
94 readfifo(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, 0, data
, size
);
98 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
100 writefifo(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, 0, data
, size
);
104 ReadISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
)
106 return (readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, offset
|0x80));
110 WriteISAC_IPAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
112 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, offset
|0x80, value
);
116 ReadISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
118 readfifo(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, 0x80, data
, size
);
122 WriteISACfifo_IPAC(struct IsdnCardState
*cs
, u_char
* data
, int size
)
124 writefifo(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, 0x80, data
, size
);
128 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
130 return (readreg(cs
->hw
.asus
.adr
,
131 cs
->hw
.asus
.hscx
, offset
+ (hscx
? 0x40 : 0)));
135 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
137 writereg(cs
->hw
.asus
.adr
,
138 cs
->hw
.asus
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
142 * fast interrupt HSCX stuff goes here
145 #define READHSCX(cs, nr, reg) readreg(cs->hw.asus.adr, \
146 cs->hw.asus.hscx, reg + (nr ? 0x40 : 0))
147 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.asus.adr, \
148 cs->hw.asus.hscx, reg + (nr ? 0x40 : 0), data)
150 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.asus.adr, \
151 cs->hw.asus.hscx, (nr ? 0x40 : 0), ptr, cnt)
153 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.asus.adr, \
154 cs->hw.asus.hscx, (nr ? 0x40 : 0), ptr, cnt)
156 #include "hscx_irq.c"
159 asuscom_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
161 struct IsdnCardState
*cs
= dev_id
;
165 spin_lock_irqsave(&cs
->lock
, flags
);
166 val
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_ISTA
+ 0x40);
169 hscx_int_main(cs
, val
);
170 val
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, ISAC_ISTA
);
173 isac_interrupt(cs
, val
);
174 val
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_ISTA
+ 0x40);
176 if (cs
->debug
& L1_DEB_HSCX
)
177 debugl1(cs
, "HSCX IntStat after IntRoutine");
180 val
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, ISAC_ISTA
);
182 if (cs
->debug
& L1_DEB_ISAC
)
183 debugl1(cs
, "ISAC IntStat after IntRoutine");
186 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_MASK
, 0xFF);
187 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
188 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, ISAC_MASK
, 0xFF);
189 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, ISAC_MASK
, 0x0);
190 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_MASK
, 0x0);
191 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_MASK
+ 0x40, 0x0);
192 spin_unlock_irqrestore(&cs
->lock
, flags
);
197 asuscom_interrupt_ipac(int intno
, void *dev_id
, struct pt_regs
*regs
)
199 struct IsdnCardState
*cs
= dev_id
;
200 u_char ista
, val
, icnt
= 5;
203 spin_lock_irqsave(&cs
->lock
, flags
);
204 ista
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_ISTA
);
206 if (cs
->debug
& L1_DEB_IPAC
)
207 debugl1(cs
, "IPAC ISTA %02X", ista
);
209 val
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.hscx
, HSCX_ISTA
+ 0x40);
217 hscx_int_main(cs
, val
);
220 val
= 0xfe & readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, ISAC_ISTA
| 0x80);
222 isac_interrupt(cs
, val
);
227 isac_interrupt(cs
, val
);
229 ista
= readreg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_ISTA
);
230 if ((ista
& 0x3f) && icnt
) {
235 printk(KERN_WARNING
"ASUS IRQ LOOP\n");
236 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_MASK
, 0xFF);
237 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_MASK
, 0xC0);
238 spin_unlock_irqrestore(&cs
->lock
, flags
);
243 release_io_asuscom(struct IsdnCardState
*cs
)
247 if (cs
->hw
.asus
.cfg_reg
)
248 release_region(cs
->hw
.asus
.cfg_reg
, bytecnt
);
252 reset_asuscom(struct IsdnCardState
*cs
)
254 if (cs
->subtyp
== ASUS_IPAC
)
255 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_POTA2
, 0x20);
257 byteout(cs
->hw
.asus
.adr
, ASUS_RESET
); /* Reset On */
259 if (cs
->subtyp
== ASUS_IPAC
)
260 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_POTA2
, 0x0);
262 byteout(cs
->hw
.asus
.adr
, 0); /* Reset Off */
264 if (cs
->subtyp
== ASUS_IPAC
) {
265 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_CONF
, 0x0);
266 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_ACFG
, 0xff);
267 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_AOE
, 0x0);
268 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_MASK
, 0xc0);
269 writereg(cs
->hw
.asus
.adr
, cs
->hw
.asus
.isac
, IPAC_PCFG
, 0x12);
274 Asus_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
280 spin_lock_irqsave(&cs
->lock
, flags
);
282 spin_unlock_irqrestore(&cs
->lock
, flags
);
285 release_io_asuscom(cs
);
288 spin_lock_irqsave(&cs
->lock
, flags
);
289 cs
->debug
|= L1_DEB_IPAC
;
291 spin_unlock_irqrestore(&cs
->lock
, flags
);
300 static struct isapnp_device_id asus_ids
[] __initdata
= {
301 { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
302 ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
303 (unsigned long) "Asus1688 PnP" },
304 { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1690),
305 ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1690),
306 (unsigned long) "Asus1690 PnP" },
307 { ISAPNP_VENDOR('S', 'I', 'E'), ISAPNP_FUNCTION(0x0020),
308 ISAPNP_VENDOR('S', 'I', 'E'), ISAPNP_FUNCTION(0x0020),
309 (unsigned long) "Isurf2 PnP" },
310 { ISAPNP_VENDOR('E', 'L', 'F'), ISAPNP_FUNCTION(0x0000),
311 ISAPNP_VENDOR('E', 'L', 'F'), ISAPNP_FUNCTION(0x0000),
312 (unsigned long) "Iscas TE320" },
316 static struct isapnp_device_id
*ipid __initdata
= &asus_ids
[0];
317 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
321 setup_asuscom(struct IsdnCard
*card
)
324 struct IsdnCardState
*cs
= card
->cs
;
328 strcpy(tmp
, Asuscom_revision
);
329 printk(KERN_INFO
"HiSax: Asuscom ISDNLink driver Rev. %s\n", HiSax_getrev(tmp
));
330 if (cs
->typ
!= ISDN_CTYPE_ASUSCOM
)
333 if (!card
->para
[1] && isapnp_present()) {
334 struct pnp_dev
*pnp_d
;
335 while(ipid
->card_vendor
) {
336 if ((pnp_c
= pnp_find_card(ipid
->card_vendor
,
337 ipid
->card_device
, pnp_c
))) {
339 if ((pnp_d
= pnp_find_dev(pnp_c
,
340 ipid
->vendor
, ipid
->function
, pnp_d
))) {
343 printk(KERN_INFO
"HiSax: %s detected\n",
344 (char *)ipid
->driver_data
);
345 pnp_disable_dev(pnp_d
);
346 err
= pnp_activate_dev(pnp_d
);
348 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
352 card
->para
[1] = pnp_port_start(pnp_d
, 0);
353 card
->para
[0] = pnp_irq(pnp_d
, 0);
354 if (!card
->para
[0] || !card
->para
[1]) {
355 printk(KERN_ERR
"AsusPnP:some resources are missing %ld/%lx\n",
356 card
->para
[0], card
->para
[1]);
357 pnp_disable_dev(pnp_d
);
362 printk(KERN_ERR
"AsusPnP: PnP error card found, no device\n");
368 if (!ipid
->card_vendor
) {
369 printk(KERN_INFO
"AsusPnP: no ISAPnP card found\n");
375 cs
->hw
.asus
.cfg_reg
= card
->para
[1];
376 cs
->irq
= card
->para
[0];
377 if (!request_region(cs
->hw
.asus
.cfg_reg
, bytecnt
, "asuscom isdn")) {
379 "HiSax: %s config port %x-%x already in use\n",
382 cs
->hw
.asus
.cfg_reg
+ bytecnt
);
385 printk(KERN_INFO
"ISDNLink: defined at 0x%x IRQ %d\n",
386 cs
->hw
.asus
.cfg_reg
, cs
->irq
);
388 cs
->BC_Read_Reg
= &ReadHSCX
;
389 cs
->BC_Write_Reg
= &WriteHSCX
;
390 cs
->BC_Send_Data
= &hscx_fill_fifo
;
391 cs
->cardmsg
= &Asus_card_msg
;
392 val
= readreg(cs
->hw
.asus
.cfg_reg
+ ASUS_IPAC_ALE
,
393 cs
->hw
.asus
.cfg_reg
+ ASUS_IPAC_DATA
, IPAC_ID
);
394 if ((val
== 1) || (val
== 2)) {
395 cs
->subtyp
= ASUS_IPAC
;
396 cs
->hw
.asus
.adr
= cs
->hw
.asus
.cfg_reg
+ ASUS_IPAC_ALE
;
397 cs
->hw
.asus
.isac
= cs
->hw
.asus
.cfg_reg
+ ASUS_IPAC_DATA
;
398 cs
->hw
.asus
.hscx
= cs
->hw
.asus
.cfg_reg
+ ASUS_IPAC_DATA
;
399 test_and_set_bit(HW_IPAC
, &cs
->HW_Flags
);
400 cs
->readisac
= &ReadISAC_IPAC
;
401 cs
->writeisac
= &WriteISAC_IPAC
;
402 cs
->readisacfifo
= &ReadISACfifo_IPAC
;
403 cs
->writeisacfifo
= &WriteISACfifo_IPAC
;
404 cs
->irq_func
= &asuscom_interrupt_ipac
;
405 printk(KERN_INFO
"Asus: IPAC version %x\n", val
);
407 cs
->subtyp
= ASUS_ISACHSCX
;
408 cs
->hw
.asus
.adr
= cs
->hw
.asus
.cfg_reg
+ ASUS_ADR
;
409 cs
->hw
.asus
.isac
= cs
->hw
.asus
.cfg_reg
+ ASUS_ISAC
;
410 cs
->hw
.asus
.hscx
= cs
->hw
.asus
.cfg_reg
+ ASUS_HSCX
;
411 cs
->hw
.asus
.u7
= cs
->hw
.asus
.cfg_reg
+ ASUS_CTRL_U7
;
412 cs
->hw
.asus
.pots
= cs
->hw
.asus
.cfg_reg
+ ASUS_CTRL_POTS
;
413 cs
->readisac
= &ReadISAC
;
414 cs
->writeisac
= &WriteISAC
;
415 cs
->readisacfifo
= &ReadISACfifo
;
416 cs
->writeisacfifo
= &WriteISACfifo
;
417 cs
->irq_func
= &asuscom_interrupt
;
418 ISACVersion(cs
, "ISDNLink:");
419 if (HscxVersion(cs
, "ISDNLink:")) {
421 "ISDNLink: wrong HSCX versions check IO address\n");
422 release_io_asuscom(cs
);