[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / isdn / hisax / asuscom.c
blob7546e2e4a94ea766b09140a874aef6f1cc93e5fc
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
5 * Author Karsten Keil
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>
17 #include "hisax.h"
18 #include "isac.h"
19 #include "ipac.h"
20 #include "hscx.h"
21 #include "isdnl1.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)
30 #define ASUS_ISAC 0
31 #define ASUS_HSCX 1
32 #define ASUS_ADR 2
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
40 #define ASUS_IPAC 2
42 /* CARD_ADR (Write) */
43 #define ASUS_RESET 0x80 /* Bit 7 Reset-Leitung */
45 static inline u_char
46 readreg(unsigned int ale, unsigned int adr, u_char off)
48 register u_char ret;
50 byteout(ale, off);
51 ret = bytein(adr);
52 return (ret);
55 static inline void
56 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
58 byteout(ale, off);
59 insb(adr, data, size);
63 static inline void
64 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
66 byteout(ale, off);
67 byteout(adr, data);
70 static inline void
71 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
73 byteout(ale, off);
74 outsb(adr, data, size);
77 /* Interface functions */
79 static u_char
80 ReadISAC(struct IsdnCardState *cs, u_char offset)
82 return (readreg(cs->hw.asus.adr, cs->hw.asus.isac, offset));
85 static void
86 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
88 writereg(cs->hw.asus.adr, cs->hw.asus.isac, offset, value);
91 static void
92 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
94 readfifo(cs->hw.asus.adr, cs->hw.asus.isac, 0, data, size);
97 static void
98 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
100 writefifo(cs->hw.asus.adr, cs->hw.asus.isac, 0, data, size);
103 static u_char
104 ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
106 return (readreg(cs->hw.asus.adr, cs->hw.asus.isac, offset|0x80));
109 static void
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);
115 static void
116 ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
118 readfifo(cs->hw.asus.adr, cs->hw.asus.isac, 0x80, data, size);
121 static void
122 WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
124 writefifo(cs->hw.asus.adr, cs->hw.asus.isac, 0x80, data, size);
127 static u_char
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)));
134 static void
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"
158 static irqreturn_t
159 asuscom_interrupt(int intno, void *dev_id, struct pt_regs *regs)
161 struct IsdnCardState *cs = dev_id;
162 u_char val;
163 u_long flags;
165 spin_lock_irqsave(&cs->lock, flags);
166 val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
167 Start_HSCX:
168 if (val)
169 hscx_int_main(cs, val);
170 val = readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA);
171 Start_ISAC:
172 if (val)
173 isac_interrupt(cs, val);
174 val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
175 if (val) {
176 if (cs->debug & L1_DEB_HSCX)
177 debugl1(cs, "HSCX IntStat after IntRoutine");
178 goto Start_HSCX;
180 val = readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA);
181 if (val) {
182 if (cs->debug & L1_DEB_ISAC)
183 debugl1(cs, "ISAC IntStat after IntRoutine");
184 goto Start_ISAC;
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);
193 return IRQ_HANDLED;
196 static irqreturn_t
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;
201 u_long flags;
203 spin_lock_irqsave(&cs->lock, flags);
204 ista = readreg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_ISTA);
205 Start_IPAC:
206 if (cs->debug & L1_DEB_IPAC)
207 debugl1(cs, "IPAC ISTA %02X", ista);
208 if (ista & 0x0f) {
209 val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
210 if (ista & 0x01)
211 val |= 0x01;
212 if (ista & 0x04)
213 val |= 0x02;
214 if (ista & 0x08)
215 val |= 0x04;
216 if (val)
217 hscx_int_main(cs, val);
219 if (ista & 0x20) {
220 val = 0xfe & readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA | 0x80);
221 if (val) {
222 isac_interrupt(cs, val);
225 if (ista & 0x10) {
226 val = 0x01;
227 isac_interrupt(cs, val);
229 ista = readreg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_ISTA);
230 if ((ista & 0x3f) && icnt) {
231 icnt--;
232 goto Start_IPAC;
234 if (!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);
239 return IRQ_HANDLED;
242 void
243 release_io_asuscom(struct IsdnCardState *cs)
245 int bytecnt = 8;
247 if (cs->hw.asus.cfg_reg)
248 release_region(cs->hw.asus.cfg_reg, bytecnt);
251 static void
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);
256 else
257 byteout(cs->hw.asus.adr, ASUS_RESET); /* Reset On */
258 mdelay(10);
259 if (cs->subtyp == ASUS_IPAC)
260 writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_POTA2, 0x0);
261 else
262 byteout(cs->hw.asus.adr, 0); /* Reset Off */
263 mdelay(10);
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);
273 static int
274 Asus_card_msg(struct IsdnCardState *cs, int mt, void *arg)
276 u_long flags;
278 switch (mt) {
279 case CARD_RESET:
280 spin_lock_irqsave(&cs->lock, flags);
281 reset_asuscom(cs);
282 spin_unlock_irqrestore(&cs->lock, flags);
283 return(0);
284 case CARD_RELEASE:
285 release_io_asuscom(cs);
286 return(0);
287 case CARD_INIT:
288 spin_lock_irqsave(&cs->lock, flags);
289 cs->debug |= L1_DEB_IPAC;
290 inithscxisac(cs, 3);
291 spin_unlock_irqrestore(&cs->lock, flags);
292 return(0);
293 case CARD_TEST:
294 return(0);
296 return(0);
299 #ifdef __ISAPNP__
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" },
313 { 0, }
316 static struct isapnp_device_id *ipid __initdata = &asus_ids[0];
317 static struct pnp_card *pnp_c __devinitdata = NULL;
318 #endif
320 int __init
321 setup_asuscom(struct IsdnCard *card)
323 int bytecnt;
324 struct IsdnCardState *cs = card->cs;
325 u_char val;
326 char tmp[64];
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)
331 return (0);
332 #ifdef __ISAPNP__
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))) {
338 pnp_d = NULL;
339 if ((pnp_d = pnp_find_dev(pnp_c,
340 ipid->vendor, ipid->function, pnp_d))) {
341 int err;
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);
347 if (err<0) {
348 printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
349 __FUNCTION__, err);
350 return(0);
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);
358 return(0);
360 break;
361 } else {
362 printk(KERN_ERR "AsusPnP: PnP error card found, no device\n");
365 ipid++;
366 pnp_c = NULL;
368 if (!ipid->card_vendor) {
369 printk(KERN_INFO "AsusPnP: no ISAPnP card found\n");
370 return(0);
373 #endif
374 bytecnt = 8;
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")) {
378 printk(KERN_WARNING
379 "HiSax: %s config port %x-%x already in use\n",
380 CardType[card->typ],
381 cs->hw.asus.cfg_reg,
382 cs->hw.asus.cfg_reg + bytecnt);
383 return (0);
385 printk(KERN_INFO "ISDNLink: defined at 0x%x IRQ %d\n",
386 cs->hw.asus.cfg_reg, cs->irq);
387 setup_isac(cs);
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);
406 } else {
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:")) {
420 printk(KERN_WARNING
421 "ISDNLink: wrong HSCX versions check IO address\n");
422 release_io_asuscom(cs);
423 return (0);
426 return (1);