1 /* $Id: elsa.c,v 1.1.4.1 2001/11/20 14:19:35 kai Exp $
2 *
3 * low level stuff for Elsa isdn cards
4 *
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * For changes and modifications please read
12 * ../../../Documentation/isdn/HiSax.cert
13 *
14 * Thanks to Elsa GmbH for documents and information
15 *
16 * Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
17 * for ELSA PCMCIA support
18 *
19 */
20
21 #define __NO_VERSION__
22 #include <linux/init.h>
23 #include <linux/config.h>
24 #include "hisax.h"
25 #include "arcofi.h"
26 #include "isac.h"
27 #include "ipac.h"
28 #include "hscx.h"
29 #include "isdnl1.h"
30 #include <linux/pci.h>
31 #include <linux/isapnp.h>
32 #include <linux/serial.h>
33 #include <linux/serial_reg.h>
34
35 extern const char *CardType[];
36
37 const char *Elsa_revision = "$Revision: 1.1.4.1 $";
38 const char *Elsa_Types[] =
39 {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
40 "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
41 "PCMCIA-IPAC" };
42
43 const char *ITACVer[] =
44 {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
45 "B1", "A1"};
46
47 #define byteout(addr,val) outb(val,addr)
48 #define bytein(addr) inb(addr)
49
50 #define ELSA_ISAC 0
51 #define ELSA_ISAC_PCM 1
52 #define ELSA_ITAC 1
53 #define ELSA_HSCX 2
54 #define ELSA_ALE 3
55 #define ELSA_ALE_PCM 4
56 #define ELSA_CONTROL 4
57 #define ELSA_CONFIG 5
58 #define ELSA_START_TIMER 6
59 #define ELSA_TRIG_IRQ 7
60
61 #define ELSA_PC 1
62 #define ELSA_PCC8 2
63 #define ELSA_PCC16 3
64 #define ELSA_PCF 4
65 #define ELSA_PCFPRO 5
66 #define ELSA_PCMCIA 6
67 #define ELSA_QS1000 7
68 #define ELSA_QS3000 8
69 #define ELSA_QS1000PCI 9
70 #define ELSA_QS3000PCI 10
71 #define ELSA_PCMCIA_IPAC 11
72
73 /* PCI stuff */
74 #define ELSA_PCI_IRQ_MASK 0x04
75
76 /* ITAC Registeradressen (only Microlink PC) */
77 #define ITAC_SYS 0x34
78 #define ITAC_ISEN 0x48
79 #define ITAC_RFIE 0x4A
80 #define ITAC_XFIE 0x4C
81 #define ITAC_SCIE 0x4E
82 #define ITAC_STIE 0x46
83
84 /*** ***
85 *** Makros als Befehle fuer die Kartenregister ***
86 *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
87 *** ***/
88
89 /* Config-Register (Read) */
90 #define ELSA_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
91 #define ELSA_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
92 #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
93 #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
94 #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
95
96 /* Control-Register (Write) */
97 #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
98 #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
99 #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
100 #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
101
102 /* ALE-Register (Read) */
103 #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
104 #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
105
106 /* Status Flags */
107 #define ELSA_TIMER_AKTIV 1
108 #define ELSA_BAD_PWR 2
109 #define ELSA_ASSIGN 4
110
111 #define RS_ISR_PASS_LIMIT 256
112 #define _INLINE_ inline
113 #define FLG_MODEM_ACTIVE 1
114 /* IPAC AUX */
115 #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
116 #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
117
118 #if ARCOFI_USE
119 static struct arcofi_msg ARCOFI_XOP_F =
120 {NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
121 static struct arcofi_msg ARCOFI_XOP_1 =
122 {&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
123 static struct arcofi_msg ARCOFI_SOP_F =
124 {&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
125 static struct arcofi_msg ARCOFI_COP_9 =
126 {&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
127 static struct arcofi_msg ARCOFI_COP_8 =
128 {&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
129 static struct arcofi_msg ARCOFI_COP_7 =
130 {&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
131 static struct arcofi_msg ARCOFI_COP_6 =
132 {&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
133 static struct arcofi_msg ARCOFI_COP_5 =
134 {&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
135 static struct arcofi_msg ARCOFI_VERSION =
136 {NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
137 static struct arcofi_msg ARCOFI_XOP_0 =
138 {NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
139
140 static void set_arcofi(struct IsdnCardState *cs, int bc);
141
142 #include "elsa_ser.c"
143 #endif /* ARCOFI_USE */
144
145 static inline u_char
readreg(unsigned int ale,unsigned int adr,u_char off)146 readreg(unsigned int ale, unsigned int adr, u_char off)
147 {
148 register u_char ret;
149 long flags;
150
151 save_flags(flags);
152 cli();
153 byteout(ale, off);
154 ret = bytein(adr);
155 restore_flags(flags);
156 return (ret);
157 }
158
159 static inline void
readfifo(unsigned int ale,unsigned int adr,u_char off,u_char * data,int size)160 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
161 {
162 /* fifo read without cli because it's allready done */
163
164 byteout(ale, off);
165 insb(adr, data, size);
166 }
167
168
169 static inline void
writereg(unsigned int ale,unsigned int adr,u_char off,u_char data)170 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
171 {
172 long flags;
173
174 save_flags(flags);
175 cli();
176 byteout(ale, off);
177 byteout(adr, data);
178 restore_flags(flags);
179 }
180
181 static inline void
writefifo(unsigned int ale,unsigned int adr,u_char off,u_char * data,int size)182 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
183 {
184 /* fifo write without cli because it's allready done */
185 byteout(ale, off);
186 outsb(adr, data, size);
187 }
188
189 /* Interface functions */
190
191 static u_char
ReadISAC(struct IsdnCardState * cs,u_char offset)192 ReadISAC(struct IsdnCardState *cs, u_char offset)
193 {
194 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
195 }
196
197 static void
WriteISAC(struct IsdnCardState * cs,u_char offset,u_char value)198 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
199 {
200 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
201 }
202
203 static void
ReadISACfifo(struct IsdnCardState * cs,u_char * data,int size)204 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
205 {
206 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
207 }
208
209 static void
WriteISACfifo(struct IsdnCardState * cs,u_char * data,int size)210 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
211 {
212 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
213 }
214
215 static u_char
ReadISAC_IPAC(struct IsdnCardState * cs,u_char offset)216 ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
217 {
218 return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset+0x80));
219 }
220
221 static void
WriteISAC_IPAC(struct IsdnCardState * cs,u_char offset,u_char value)222 WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
223 {
224 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset|0x80, value);
225 }
226
227 static void
ReadISACfifo_IPAC(struct IsdnCardState * cs,u_char * data,int size)228 ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
229 {
230 readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
231 }
232
233 static void
WriteISACfifo_IPAC(struct IsdnCardState * cs,u_char * data,int size)234 WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
235 {
236 writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
237 }
238
239 static u_char
ReadHSCX(struct IsdnCardState * cs,int hscx,u_char offset)240 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
241 {
242 return (readreg(cs->hw.elsa.ale,
243 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
244 }
245
246 static void
WriteHSCX(struct IsdnCardState * cs,int hscx,u_char offset,u_char value)247 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
248 {
249 writereg(cs->hw.elsa.ale,
250 cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
251 }
252
253 static inline u_char
readitac(struct IsdnCardState * cs,u_char off)254 readitac(struct IsdnCardState *cs, u_char off)
255 {
256 register u_char ret;
257 long flags;
258
259 save_flags(flags);
260 cli();
261 byteout(cs->hw.elsa.ale, off);
262 ret = bytein(cs->hw.elsa.itac);
263 restore_flags(flags);
264 return (ret);
265 }
266
267 static inline void
writeitac(struct IsdnCardState * cs,u_char off,u_char data)268 writeitac(struct IsdnCardState *cs, u_char off, u_char data)
269 {
270 long flags;
271
272 save_flags(flags);
273 cli();
274 byteout(cs->hw.elsa.ale, off);
275 byteout(cs->hw.elsa.itac, data);
276 restore_flags(flags);
277 }
278
279 static inline int
TimerRun(struct IsdnCardState * cs)280 TimerRun(struct IsdnCardState *cs)
281 {
282 register u_char v;
283
284 v = bytein(cs->hw.elsa.cfg);
285 if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
286 return (0 == (v & ELSA_TIMER_RUN));
287 else if (cs->subtyp == ELSA_PCC8)
288 return (v & ELSA_TIMER_RUN_PCC8);
289 return (v & ELSA_TIMER_RUN);
290 }
291 /*
292 * fast interrupt HSCX stuff goes here
293 */
294
295 #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
296 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
297 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
298 cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
299
300 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
301 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
302
303 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
304 cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
305
306 #include "hscx_irq.c"
307
308 static void
elsa_interrupt(int intno,void * dev_id,struct pt_regs * regs)309 elsa_interrupt(int intno, void *dev_id, struct pt_regs *regs)
310 {
311 struct IsdnCardState *cs = dev_id;
312 u_char val;
313 int icnt=5;
314
315 if (!cs) {
316 printk(KERN_WARNING "Elsa: Spurious interrupt!\n");
317 return;
318 }
319 if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
320 /* The card tends to generate interrupts while being removed
321 causing us to just crash the kernel. bad. */
322 printk(KERN_WARNING "Elsa: card not available!\n");
323 return;
324 }
325 #if ARCOFI_USE
326 if (cs->hw.elsa.MFlag) {
327 val = serial_inp(cs, UART_IIR);
328 if (!(val & UART_IIR_NO_INT)) {
329 debugl1(cs,"IIR %02x", val);
330 rs_interrupt_elsa(intno, cs);
331 }
332 }
333 #endif
334 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
335 Start_HSCX:
336 if (val) {
337 hscx_int_main(cs, val);
338 }
339 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
340 Start_ISAC:
341 if (val) {
342 isac_interrupt(cs, val);
343 }
344 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
345 if (val && icnt) {
346 if (cs->debug & L1_DEB_HSCX)
347 debugl1(cs, "HSCX IntStat after IntRoutine");
348 icnt--;
349 goto Start_HSCX;
350 }
351 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
352 if (val && icnt) {
353 if (cs->debug & L1_DEB_ISAC)
354 debugl1(cs, "ISAC IntStat after IntRoutine");
355 icnt--;
356 goto Start_ISAC;
357 }
358 if (!icnt)
359 printk(KERN_WARNING"ELSA IRQ LOOP\n");
360 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
361 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
362 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
363 if (cs->hw.elsa.status & ELSA_TIMER_AKTIV) {
364 if (!TimerRun(cs)) {
365 /* Timer Restart */
366 byteout(cs->hw.elsa.timer, 0);
367 cs->hw.elsa.counter++;
368 }
369 }
370 #if ARCOFI_USE
371 if (cs->hw.elsa.MFlag) {
372 val = serial_inp(cs, UART_MCR);
373 val ^= 0x8;
374 serial_outp(cs, UART_MCR, val);
375 val = serial_inp(cs, UART_MCR);
376 val ^= 0x8;
377 serial_outp(cs, UART_MCR, val);
378 }
379 #endif
380 if (cs->hw.elsa.trig)
381 byteout(cs->hw.elsa.trig, 0x00);
382 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
383 writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
384 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
385 }
386
387 static void
elsa_interrupt_ipac(int intno,void * dev_id,struct pt_regs * regs)388 elsa_interrupt_ipac(int intno, void *dev_id, struct pt_regs *regs)
389 {
390 struct IsdnCardState *cs = dev_id;
391 u_char ista,val;
392 int icnt=5;
393
394 if (!cs) {
395 printk(KERN_WARNING "Elsa: Spurious interrupt!\n");
396 return;
397 }
398 if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
399 val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
400 if (!(val & ELSA_PCI_IRQ_MASK))
401 return;
402 }
403 #if ARCOFI_USE
404 if (cs->hw.elsa.MFlag) {
405 val = serial_inp(cs, UART_IIR);
406 if (!(val & UART_IIR_NO_INT)) {
407 debugl1(cs,"IIR %02x", val);
408 rs_interrupt_elsa(intno, cs);
409 }
410 }
411 #endif
412 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
413 Start_IPAC:
414 if (cs->debug & L1_DEB_IPAC)
415 debugl1(cs, "IPAC ISTA %02X", ista);
416 if (ista & 0x0f) {
417 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
418 if (ista & 0x01)
419 val |= 0x01;
420 if (ista & 0x04)
421 val |= 0x02;
422 if (ista & 0x08)
423 val |= 0x04;
424 if (val)
425 hscx_int_main(cs, val);
426 }
427 if (ista & 0x20) {
428 val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
429 if (val) {
430 isac_interrupt(cs, val);
431 }
432 }
433 if (ista & 0x10) {
434 val = 0x01;
435 isac_interrupt(cs, val);
436 }
437 ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
438 if ((ista & 0x3f) && icnt) {
439 icnt--;
440 goto Start_IPAC;
441 }
442 if (!icnt)
443 printk(KERN_WARNING "ELSA IRQ LOOP\n");
444 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
445 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
446 }
447
448 void
release_io_elsa(struct IsdnCardState * cs)449 release_io_elsa(struct IsdnCardState *cs)
450 {
451 int bytecnt = 8;
452
453 del_timer(&cs->hw.elsa.tl);
454 #if ARCOFI_USE
455 clear_arcofi(cs);
456 #endif
457 if (cs->hw.elsa.ctrl)
458 byteout(cs->hw.elsa.ctrl, 0); /* LEDs Out */
459 if (cs->subtyp == ELSA_QS1000PCI) {
460 byteout(cs->hw.elsa.cfg + 0x4c, 0x01); /* disable IRQ */
461 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
462 bytecnt = 2;
463 release_region(cs->hw.elsa.cfg, 0x80);
464 }
465 if (cs->subtyp == ELSA_QS3000PCI) {
466 byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
467 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
468 release_region(cs->hw.elsa.cfg, 0x80);
469 }
470 if (cs->subtyp == ELSA_PCMCIA_IPAC) {
471 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
472 }
473 if ((cs->subtyp == ELSA_PCFPRO) ||
474 (cs->subtyp == ELSA_QS3000) ||
475 (cs->subtyp == ELSA_PCF) ||
476 (cs->subtyp == ELSA_QS3000PCI)) {
477 bytecnt = 16;
478 #if ARCOFI_USE
479 release_modem(cs);
480 #endif
481 }
482 if (cs->hw.elsa.base)
483 release_region(cs->hw.elsa.base, bytecnt);
484 }
485
486 static void
reset_elsa(struct IsdnCardState * cs)487 reset_elsa(struct IsdnCardState *cs)
488 {
489 long flags;
490
491 if (cs->hw.elsa.timer) {
492 /* Wait 1 Timer */
493 byteout(cs->hw.elsa.timer, 0);
494 while (TimerRun(cs));
495 cs->hw.elsa.ctrl_reg |= 0x50;
496 cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET; /* Reset On */
497 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
498 /* Wait 1 Timer */
499 byteout(cs->hw.elsa.timer, 0);
500 while (TimerRun(cs));
501 cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET; /* Reset Off */
502 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
503 /* Wait 1 Timer */
504 byteout(cs->hw.elsa.timer, 0);
505 while (TimerRun(cs));
506 if (cs->hw.elsa.trig)
507 byteout(cs->hw.elsa.trig, 0xff);
508 }
509 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
510 save_flags(flags);
511 sti();
512 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
513 set_current_state(TASK_UNINTERRUPTIBLE);
514 schedule_timeout((10*HZ)/1000); /* Timeout 10ms */
515 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
516 set_current_state(TASK_UNINTERRUPTIBLE);
517 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
518 schedule_timeout((10*HZ)/1000); /* Timeout 10ms */
519 restore_flags(flags);
520 if (cs->subtyp != ELSA_PCMCIA_IPAC) {
521 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
522 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
523 } else {
524 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
525 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
526 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
527 }
528 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
529 if (cs->subtyp == ELSA_QS1000PCI)
530 byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
531 else if (cs->subtyp == ELSA_QS3000PCI)
532 byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
533 }
534 }
535
536 #if ARCOFI_USE
537
538 static void
set_arcofi(struct IsdnCardState * cs,int bc)539 set_arcofi(struct IsdnCardState *cs, int bc) {
540 cs->dc.isac.arcofi_bc = bc;
541 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
542 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
543 }
544
545 static int
check_arcofi(struct IsdnCardState * cs)546 check_arcofi(struct IsdnCardState *cs)
547 {
548 int arcofi_present = 0;
549 char tmp[40];
550 char *t;
551 u_char *p;
552
553 if (!cs->dc.isac.mon_tx)
554 if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
555 if (cs->debug & L1_DEB_WARN)
556 debugl1(cs, "ISAC MON TX out of buffers!");
557 return(0);
558 }
559 cs->dc.isac.arcofi_bc = 0;
560 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
561 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
562 if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
563 debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
564 p = cs->dc.isac.mon_rx;
565 t = tmp;
566 t += sprintf(tmp, "Arcofi data");
567 QuickHex(t, p, cs->dc.isac.mon_rxp);
568 debugl1(cs, tmp);
569 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
570 switch(cs->dc.isac.mon_rx[1]) {
571 case 0x80:
572 debugl1(cs, "Arcofi 2160 detected");
573 arcofi_present = 1;
574 break;
575 case 0x82:
576 debugl1(cs, "Arcofi 2165 detected");
577 arcofi_present = 2;
578 break;
579 case 0x84:
580 debugl1(cs, "Arcofi 2163 detected");
581 arcofi_present = 3;
582 break;
583 default:
584 debugl1(cs, "unknown Arcofi response");
585 break;
586 }
587 } else
588 debugl1(cs, "undefined Monitor response");
589 cs->dc.isac.mon_rxp = 0;
590 } else if (cs->dc.isac.mon_tx) {
591 debugl1(cs, "Arcofi not detected");
592 }
593 if (arcofi_present) {
594 if (cs->subtyp==ELSA_QS1000) {
595 cs->subtyp = ELSA_QS3000;
596 printk(KERN_INFO
597 "Elsa: %s detected modem at 0x%lx\n",
598 Elsa_Types[cs->subtyp],
599 cs->hw.elsa.base+8);
600 release_region(cs->hw.elsa.base, 8);
601 if (check_region(cs->hw.elsa.base, 16)) {
602 printk(KERN_WARNING
603 "HiSax: %s config port %lx-%lx already in use\n",
604 Elsa_Types[cs->subtyp],
605 cs->hw.elsa.base + 8,
606 cs->hw.elsa.base + 16);
607 } else
608 request_region(cs->hw.elsa.base, 16,
609 "elsa isdn modem");
610 } else if (cs->subtyp==ELSA_PCC16) {
611 cs->subtyp = ELSA_PCF;
612 printk(KERN_INFO
613 "Elsa: %s detected modem at 0x%lx\n",
614 Elsa_Types[cs->subtyp],
615 cs->hw.elsa.base+8);
616 release_region(cs->hw.elsa.base, 8);
617 if (check_region(cs->hw.elsa.base, 16)) {
618 printk(KERN_WARNING
619 "HiSax: %s config port %lx-%lx already in use\n",
620 Elsa_Types[cs->subtyp],
621 cs->hw.elsa.base + 8,
622 cs->hw.elsa.base + 16);
623 } else
624 request_region(cs->hw.elsa.base, 16,
625 "elsa isdn modem");
626 } else
627 printk(KERN_INFO
628 "Elsa: %s detected modem at 0x%lx\n",
629 Elsa_Types[cs->subtyp],
630 cs->hw.elsa.base+8);
631 arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
632 interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
633 return(1);
634 }
635 return(0);
636 }
637 #endif /* ARCOFI_USE */
638
639 static void
elsa_led_handler(struct IsdnCardState * cs)640 elsa_led_handler(struct IsdnCardState *cs)
641 {
642 int blink = 0;
643
644 if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
645 return;
646 del_timer(&cs->hw.elsa.tl);
647 if (cs->hw.elsa.status & ELSA_ASSIGN)
648 cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
649 else if (cs->hw.elsa.status & ELSA_BAD_PWR)
650 cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
651 else {
652 cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
653 blink = 250;
654 }
655 if (cs->hw.elsa.status & 0xf000)
656 cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
657 else if (cs->hw.elsa.status & 0x0f00) {
658 cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
659 blink = 500;
660 } else
661 cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
662
663 if ((cs->subtyp == ELSA_QS1000PCI) ||
664 (cs->subtyp == ELSA_QS3000PCI)) {
665 u_char led = 0xff;
666 if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
667 led ^= ELSA_IPAC_LINE_LED;
668 if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
669 led ^= ELSA_IPAC_STAT_LED;
670 writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
671 } else
672 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
673 if (blink) {
674 init_timer(&cs->hw.elsa.tl);
675 cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
676 add_timer(&cs->hw.elsa.tl);
677 }
678 }
679
680 static int
Elsa_card_msg(struct IsdnCardState * cs,int mt,void * arg)681 Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
682 {
683 int ret = 0;
684 long flags;
685
686 switch (mt) {
687 case CARD_RESET:
688 reset_elsa(cs);
689 return(0);
690 case CARD_RELEASE:
691 release_io_elsa(cs);
692 return(0);
693 case CARD_INIT:
694 cs->debug |= L1_DEB_IPAC;
695 inithscxisac(cs, 1);
696 if ((cs->subtyp == ELSA_QS1000) ||
697 (cs->subtyp == ELSA_QS3000))
698 {
699 byteout(cs->hw.elsa.timer, 0);
700 }
701 if (cs->hw.elsa.trig)
702 byteout(cs->hw.elsa.trig, 0xff);
703 inithscxisac(cs, 2);
704 return(0);
705 case CARD_TEST:
706 if ((cs->subtyp == ELSA_PCMCIA) ||
707 (cs->subtyp == ELSA_PCMCIA_IPAC) ||
708 (cs->subtyp == ELSA_QS1000PCI)) {
709 return(0);
710 } else if (cs->subtyp == ELSA_QS3000PCI) {
711 ret = 0;
712 } else {
713 save_flags(flags);
714 cs->hw.elsa.counter = 0;
715 sti();
716 cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
717 cs->hw.elsa.status |= ELSA_TIMER_AKTIV;
718 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
719 byteout(cs->hw.elsa.timer, 0);
720 set_current_state(TASK_UNINTERRUPTIBLE);
721 schedule_timeout((110*HZ)/1000);
722 restore_flags(flags);
723 cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
724 byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
725 cs->hw.elsa.status &= ~ELSA_TIMER_AKTIV;
726 printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
727 cs->hw.elsa.counter);
728 if ((cs->hw.elsa.counter > 10) &&
729 (cs->hw.elsa.counter < 16)) {
730 printk(KERN_INFO "Elsa: timer and irq OK\n");
731 ret = 0;
732 } else {
733 printk(KERN_WARNING
734 "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
735 cs->hw.elsa.counter, cs->irq);
736 ret = 1;
737 }
738 }
739 #if ARCOFI_USE
740 if (check_arcofi(cs)) {
741 init_modem(cs);
742 }
743 #endif
744 elsa_led_handler(cs);
745 return(ret);
746 case (MDL_REMOVE | REQUEST):
747 cs->hw.elsa.status &= 0;
748 break;
749 case (MDL_ASSIGN | REQUEST):
750 cs->hw.elsa.status |= ELSA_ASSIGN;
751 break;
752 case MDL_INFO_SETUP:
753 if ((long) arg)
754 cs->hw.elsa.status |= 0x0200;
755 else
756 cs->hw.elsa.status |= 0x0100;
757 break;
758 case MDL_INFO_CONN:
759 if ((long) arg)
760 cs->hw.elsa.status |= 0x2000;
761 else
762 cs->hw.elsa.status |= 0x1000;
763 break;
764 case MDL_INFO_REL:
765 if ((long) arg) {
766 cs->hw.elsa.status &= ~0x2000;
767 cs->hw.elsa.status &= ~0x0200;
768 } else {
769 cs->hw.elsa.status &= ~0x1000;
770 cs->hw.elsa.status &= ~0x0100;
771 }
772 break;
773 #if ARCOFI_USE
774 case CARD_AUX_IND:
775 if (cs->hw.elsa.MFlag) {
776 int len;
777 u_char *msg;
778
779 if (!arg)
780 return(0);
781 msg = arg;
782 len = *msg;
783 msg++;
784 modem_write_cmd(cs, msg, len);
785 }
786 break;
787 #endif
788 }
789 if (cs->typ == ISDN_CTYPE_ELSA) {
790 int pwr = bytein(cs->hw.elsa.ale);
791 if (pwr & 0x08)
792 cs->hw.elsa.status |= ELSA_BAD_PWR;
793 else
794 cs->hw.elsa.status &= ~ELSA_BAD_PWR;
795 }
796 elsa_led_handler(cs);
797 return(ret);
798 }
799
800 static unsigned char
probe_elsa_adr(unsigned int adr,int typ)801 probe_elsa_adr(unsigned int adr, int typ)
802 {
803 int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
804 pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
805 long flags;
806
807 /* In case of the elsa pcmcia card, this region is in use,
808 reserved for us by the card manager. So we do not check it
809 here, it would fail. */
810 if (typ != ISDN_CTYPE_ELSA_PCMCIA && check_region(adr, 8)) {
811 printk(KERN_WARNING
812 "Elsa: Probing Port 0x%x: already in use\n",
813 adr);
814 return (0);
815 }
816 save_flags(flags);
817 cli();
818 for (i = 0; i < 16; i++) {
819 in1 = inb(adr + ELSA_CONFIG); /* 'toggelt' bei */
820 in2 = inb(adr + ELSA_CONFIG); /* jedem Zugriff */
821 p16_1 += 0x04 & in1;
822 p16_2 += 0x04 & in2;
823 p8_1 += 0x02 & in1;
824 p8_2 += 0x02 & in2;
825 pc_1 += 0x01 & in1;
826 pc_2 += 0x01 & in2;
827 pfp_1 += 0x40 & in1;
828 pfp_2 += 0x40 & in2;
829 }
830 restore_flags(flags);
831 printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
832 if (65 == ++p16_1 * ++p16_2) {
833 printk(" PCC-16/PCF found\n");
834 return (ELSA_PCC16);
835 } else if (1025 == ++pfp_1 * ++pfp_2) {
836 printk(" PCF-Pro found\n");
837 return (ELSA_PCFPRO);
838 } else if (33 == ++p8_1 * ++p8_2) {
839 printk(" PCC8 found\n");
840 return (ELSA_PCC8);
841 } else if (17 == ++pc_1 * ++pc_2) {
842 printk(" PC found\n");
843 return (ELSA_PC);
844 } else {
845 printk(" failed\n");
846 return (0);
847 }
848 }
849
850 static unsigned int
probe_elsa(struct IsdnCardState * cs)851 probe_elsa(struct IsdnCardState *cs)
852 {
853 int i;
854 unsigned int CARD_portlist[] =
855 {0x160, 0x170, 0x260, 0x360, 0};
856
857 for (i = 0; CARD_portlist[i]; i++) {
858 if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
859 break;
860 }
861 return (CARD_portlist[i]);
862 }
863
864 static struct pci_dev *dev_qs1000 __devinitdata = NULL;
865 static struct pci_dev *dev_qs3000 __devinitdata = NULL;
866
867 #ifdef __ISAPNP__
868 static struct isapnp_device_id elsa_ids[] __initdata = {
869 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
870 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
871 (unsigned long) "Elsa QS1000" },
872 { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
873 ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
874 (unsigned long) "Elsa QS3000" },
875 { 0, }
876 };
877
878 static struct isapnp_device_id *pdev = &elsa_ids[0];
879 static struct pci_bus *pnp_c __devinitdata = NULL;
880 #endif
881
882 int __devinit
setup_elsa(struct IsdnCard * card)883 setup_elsa(struct IsdnCard *card)
884 {
885 long flags;
886 int bytecnt;
887 u_char val;
888 struct IsdnCardState *cs = card->cs;
889 char tmp[64];
890
891 strcpy(tmp, Elsa_revision);
892 printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
893 cs->hw.elsa.ctrl_reg = 0;
894 cs->hw.elsa.status = 0;
895 cs->hw.elsa.MFlag = 0;
896 cs->subtyp = 0;
897 if (cs->typ == ISDN_CTYPE_ELSA) {
898 cs->hw.elsa.base = card->para[0];
899 printk(KERN_INFO "Elsa: Microlink IO probing\n");
900 if (cs->hw.elsa.base) {
901 if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
902 cs->typ))) {
903 printk(KERN_WARNING
904 "Elsa: no Elsa Microlink at %#lx\n",
905 cs->hw.elsa.base);
906 return (0);
907 }
908 } else
909 cs->hw.elsa.base = probe_elsa(cs);
910 if (cs->hw.elsa.base) {
911 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
912 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
913 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
914 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
915 cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
916 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
917 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
918 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
919 val = bytein(cs->hw.elsa.cfg);
920 if (cs->subtyp == ELSA_PC) {
921 const u_char CARD_IrqTab[8] =
922 {7, 3, 5, 9, 0, 0, 0, 0};
923 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
924 } else if (cs->subtyp == ELSA_PCC8) {
925 const u_char CARD_IrqTab[8] =
926 {7, 3, 5, 9, 0, 0, 0, 0};
927 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
928 } else {
929 const u_char CARD_IrqTab[8] =
930 {15, 10, 15, 3, 11, 5, 11, 9};
931 cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
932 }
933 val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
934 if (val < 3)
935 val |= 8;
936 val += 'A' - 3;
937 if (val == 'B' || val == 'C')
938 val ^= 1;
939 if ((cs->subtyp == ELSA_PCFPRO) && (val = 'G'))
940 val = 'C';
941 printk(KERN_INFO
942 "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
943 Elsa_Types[cs->subtyp],
944 cs->hw.elsa.base,
945 val, cs->irq);
946 val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
947 if (val) {
948 printk(KERN_WARNING
949 "Elsa: Microlink S0 bus power bad\n");
950 cs->hw.elsa.status |= ELSA_BAD_PWR;
951 }
952 } else {
953 printk(KERN_WARNING
954 "No Elsa Microlink found\n");
955 return (0);
956 }
957 } else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
958 #ifdef __ISAPNP__
959 if (!card->para[1] && isapnp_present()) {
960 struct pci_bus *pb;
961 struct pci_dev *pd;
962
963 while(pdev->card_vendor) {
964 if ((pb = isapnp_find_card(pdev->card_vendor,
965 pdev->card_device, pnp_c))) {
966 pnp_c = pb;
967 pd = NULL;
968 if ((pd = isapnp_find_dev(pnp_c,
969 pdev->vendor, pdev->function, pd))) {
970 printk(KERN_INFO "HiSax: %s detected\n",
971 (char *)pdev->driver_data);
972 pd->prepare(pd);
973 pd->deactivate(pd);
974 pd->activate(pd);
975 card->para[1] =
976 pd->resource[0].start;
977 card->para[0] =
978 pd->irq_resource[0].start;
979 if (!card->para[0] || !card->para[1]) {
980 printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
981 card->para[0], card->para[1]);
982 pd->deactivate(pd);
983 return(0);
984 }
985 if (pdev->function == ISAPNP_FUNCTION(0x133))
986 cs->subtyp = ELSA_QS1000;
987 else
988 cs->subtyp = ELSA_QS3000;
989 break;
990 } else {
991 printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
992 return(0);
993 }
994 }
995 pdev++;
996 pnp_c=NULL;
997 }
998 if (!pdev->card_vendor) {
999 printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
1000 return(0);
1001 }
1002 }
1003 #endif
1004 if (card->para[1] && card->para[0]) {
1005 cs->hw.elsa.base = card->para[1];
1006 cs->irq = card->para[0];
1007 if (!cs->subtyp)
1008 cs->subtyp = ELSA_QS1000;
1009 } else {
1010 printk(KERN_ERR "Elsa PnP: no parameter\n");
1011 }
1012 cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
1013 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
1014 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
1015 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
1016 cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
1017 cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
1018 cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
1019 printk(KERN_INFO
1020 "Elsa: %s defined at %#lx IRQ %d\n",
1021 Elsa_Types[cs->subtyp],
1022 cs->hw.elsa.base,
1023 cs->irq);
1024 } else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA) {
1025 cs->hw.elsa.base = card->para[1];
1026 cs->irq = card->para[0];
1027 val = readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2, IPAC_ID);
1028 if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
1029 cs->subtyp = ELSA_PCMCIA_IPAC;
1030 cs->hw.elsa.ale = cs->hw.elsa.base + 0;
1031 cs->hw.elsa.isac = cs->hw.elsa.base + 2;
1032 cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
1033 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1034 } else {
1035 cs->subtyp = ELSA_PCMCIA;
1036 cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE_PCM;
1037 cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC_PCM;
1038 cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
1039 }
1040 cs->hw.elsa.timer = 0;
1041 cs->hw.elsa.trig = 0;
1042 cs->hw.elsa.ctrl = 0;
1043 printk(KERN_INFO
1044 "Elsa: %s defined at %#lx IRQ %d\n",
1045 Elsa_Types[cs->subtyp],
1046 cs->hw.elsa.base,
1047 cs->irq);
1048 } else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
1049 #if CONFIG_PCI
1050 if (!pci_present()) {
1051 printk(KERN_ERR "Elsa: no PCI bus present\n");
1052 return(0);
1053 }
1054 cs->subtyp = 0;
1055 if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1056 PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1057 if (pci_enable_device(dev_qs1000))
1058 return(0);
1059 cs->subtyp = ELSA_QS1000PCI;
1060 cs->irq = dev_qs1000->irq;
1061 cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
1062 cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1063 } else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA,
1064 PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1065 if (pci_enable_device(dev_qs3000))
1066 return(0);
1067 cs->subtyp = ELSA_QS3000PCI;
1068 cs->irq = dev_qs3000->irq;
1069 cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
1070 cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
1071 } else {
1072 printk(KERN_WARNING "Elsa: No PCI card found\n");
1073 return(0);
1074 }
1075 if (!cs->irq) {
1076 printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
1077 return(0);
1078 }
1079
1080 if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
1081 printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
1082 return(0);
1083 }
1084 if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
1085 printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
1086 printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
1087 printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
1088 printk(KERN_WARNING "Elsa: Waiting 5 sec to sync discs\n");
1089 save_flags(flags);
1090 sti();
1091 HZDELAY(500); /* wait 500*10 ms */
1092 restore_flags(flags);
1093 }
1094 cs->hw.elsa.ale = cs->hw.elsa.base;
1095 cs->hw.elsa.isac = cs->hw.elsa.base +1;
1096 cs->hw.elsa.hscx = cs->hw.elsa.base +1;
1097 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
1098 cs->hw.elsa.timer = 0;
1099 cs->hw.elsa.trig = 0;
1100 cs->irq_flags |= SA_SHIRQ;
1101 printk(KERN_INFO
1102 "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
1103 Elsa_Types[cs->subtyp],
1104 cs->hw.elsa.base,
1105 cs->hw.elsa.cfg,
1106 cs->irq);
1107 #else
1108 printk(KERN_WARNING "Elsa: Elsa PCI and NO_PCI_BIOS\n");
1109 printk(KERN_WARNING "Elsa: unable to config Elsa PCI\n");
1110 return (0);
1111 #endif /* CONFIG_PCI */
1112 } else
1113 return (0);
1114
1115 switch (cs->subtyp) {
1116 case ELSA_PC:
1117 case ELSA_PCC8:
1118 case ELSA_PCC16:
1119 case ELSA_QS1000:
1120 case ELSA_PCMCIA:
1121 case ELSA_PCMCIA_IPAC:
1122 bytecnt = 8;
1123 break;
1124 case ELSA_PCFPRO:
1125 case ELSA_PCF:
1126 case ELSA_QS3000:
1127 case ELSA_QS3000PCI:
1128 bytecnt = 16;
1129 break;
1130 case ELSA_QS1000PCI:
1131 bytecnt = 2;
1132 break;
1133 default:
1134 printk(KERN_WARNING
1135 "Unknown ELSA subtype %d\n", cs->subtyp);
1136 return (0);
1137 }
1138 /* In case of the elsa pcmcia card, this region is in use,
1139 reserved for us by the card manager. So we do not check it
1140 here, it would fail. */
1141 if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && check_region(cs->hw.elsa.base, bytecnt)) {
1142 printk(KERN_WARNING
1143 "HiSax: %s config port %#lx-%#lx already in use\n",
1144 CardType[card->typ],
1145 cs->hw.elsa.base,
1146 cs->hw.elsa.base + bytecnt);
1147 return (0);
1148 } else {
1149 request_region(cs->hw.elsa.base, bytecnt, "elsa isdn");
1150 }
1151 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
1152 if (check_region(cs->hw.elsa.cfg, 0x80)) {
1153 printk(KERN_WARNING
1154 "HiSax: %s pci port %x-%x already in use\n",
1155 CardType[card->typ],
1156 cs->hw.elsa.cfg,
1157 cs->hw.elsa.cfg + 0x80);
1158 release_region(cs->hw.elsa.base, bytecnt);
1159 return (0);
1160 } else {
1161 request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci");
1162 }
1163 }
1164 #if ARCOFI_USE
1165 init_arcofi(cs);
1166 #endif
1167 cs->hw.elsa.tl.function = (void *) elsa_led_handler;
1168 cs->hw.elsa.tl.data = (long) cs;
1169 init_timer(&cs->hw.elsa.tl);
1170 /* Teste Timer */
1171 if (cs->hw.elsa.timer) {
1172 byteout(cs->hw.elsa.trig, 0xff);
1173 byteout(cs->hw.elsa.timer, 0);
1174 if (!TimerRun(cs)) {
1175 byteout(cs->hw.elsa.timer, 0); /* 2. Versuch */
1176 if (!TimerRun(cs)) {
1177 printk(KERN_WARNING
1178 "Elsa: timer do not start\n");
1179 release_io_elsa(cs);
1180 return (0);
1181 }
1182 }
1183 save_flags(flags);
1184 sti();
1185 HZDELAY(1); /* wait >=10 ms */
1186 restore_flags(flags);
1187 if (TimerRun(cs)) {
1188 printk(KERN_WARNING "Elsa: timer do not run down\n");
1189 release_io_elsa(cs);
1190 return (0);
1191 }
1192 printk(KERN_INFO "Elsa: timer OK; resetting card\n");
1193 }
1194 cs->BC_Read_Reg = &ReadHSCX;
1195 cs->BC_Write_Reg = &WriteHSCX;
1196 cs->BC_Send_Data = &hscx_fill_fifo;
1197 cs->cardmsg = &Elsa_card_msg;
1198 reset_elsa(cs);
1199 if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
1200 cs->readisac = &ReadISAC_IPAC;
1201 cs->writeisac = &WriteISAC_IPAC;
1202 cs->readisacfifo = &ReadISACfifo_IPAC;
1203 cs->writeisacfifo = &WriteISACfifo_IPAC;
1204 cs->irq_func = &elsa_interrupt_ipac;
1205 val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
1206 printk(KERN_INFO "Elsa: IPAC version %x\n", val);
1207 } else {
1208 cs->readisac = &ReadISAC;
1209 cs->writeisac = &WriteISAC;
1210 cs->readisacfifo = &ReadISACfifo;
1211 cs->writeisacfifo = &WriteISACfifo;
1212 cs->irq_func = &elsa_interrupt;
1213 ISACVersion(cs, "Elsa:");
1214 if (HscxVersion(cs, "Elsa:")) {
1215 printk(KERN_WARNING
1216 "Elsa: wrong HSCX versions check IO address\n");
1217 release_io_elsa(cs);
1218 return (0);
1219 }
1220 }
1221 if (cs->subtyp == ELSA_PC) {
1222 val = readitac(cs, ITAC_SYS);
1223 printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
1224 writeitac(cs, ITAC_ISEN, 0);
1225 writeitac(cs, ITAC_RFIE, 0);
1226 writeitac(cs, ITAC_XFIE, 0);
1227 writeitac(cs, ITAC_SCIE, 0);
1228 writeitac(cs, ITAC_STIE, 0);
1229 }
1230 return (1);
1231 }
1232