1 /******************************************************************************
2  *    ixj.h
3  *
4  *
5  * Device Driver for Quicknet Technologies, Inc.'s Telephony cards
6  * including the Internet PhoneJACK, Internet PhoneJACK Lite,
7  * Internet PhoneJACK PCI, Internet LineJACK, Internet PhoneCARD and
8  * SmartCABLE
9  *
10  *    (c) Copyright 1999-2001  Quicknet Technologies, Inc.
11  *
12  *    This program is free software; you can redistribute it and/or
13  *    modify it under the terms of the GNU General Public License
14  *    as published by the Free Software Foundation; either version
15  *    2 of the License, or (at your option) any later version.
16  *
17  * Author:          Ed Okerson, <eokerson@quicknet.net>
18  *
19  * Contributors:    Greg Herlein, <gherlein@quicknet.net>
20  *                  David W. Erhart, <derhart@quicknet.net>
21  *                  John Sellers, <jsellers@quicknet.net>
22  *                  Mike Preston, <mpreston@quicknet.net>
23  *
24  * More information about the hardware related to this driver can be found
25  * at our website:    http://www.quicknet.net
26  *
27  * Fixes:
28  *
29  * IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR
30  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
31  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET
32  * TECHNOLOGIES, INC.HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
37  * ON AN "AS IS" BASIS, AND QUICKNET TECHNOLOGIES, INC. HAS NO OBLIGATION
38  * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
39  *
40  *****************************************************************************/
41 static char ixj_h_rcsid[] = "$Id: ixj.h,v 4.1 2001/08/04 14:49:27 craigs Exp $";
42 
43 #define IXJ_VERSION 3031
44 
45 #include <linux/types.h>
46 
47 #include <linux/ixjuser.h>
48 #include <linux/phonedev.h>
49 
50 typedef __u16 WORD;
51 typedef __u32 DWORD;
52 typedef __u8 BYTE;
53 typedef __u8 BOOL;
54 
55 #ifndef IXJMAX
56 #define IXJMAX 16
57 #endif
58 
59 #define TRUE 1
60 #define FALSE 0
61 
62 #ifndef min
63 #define min(a,b) (((a)<(b))?(a):(b))
64 #endif
65 #ifndef max
66 #define max(a,b) (((a)>(b))?(a):(b))
67 #endif
68 
69 /******************************************************************************
70 *
71 *  This structure when unioned with the structures below makes simple byte
72 *  access to the registers easier.
73 *
74 ******************************************************************************/
75 typedef struct {
76 	unsigned char low;
77 	unsigned char high;
78 } BYTES;
79 
80 typedef union {
81         BYTES bytes;
82         short word;
83 } IXJ_WORD;
84 
85 typedef struct{
86 	unsigned int b0:1;
87 	unsigned int b1:1;
88 	unsigned int b2:1;
89 	unsigned int b3:1;
90 	unsigned int b4:1;
91 	unsigned int b5:1;
92 	unsigned int b6:1;
93 	unsigned int b7:1;
94 } IXJ_CBITS;
95 
96 typedef union{
97 	IXJ_CBITS cbits;
98 	  char  cbyte;
99 } IXJ_CBYTE;
100 
101 /******************************************************************************
102 *
103 *  This structure represents the Hardware Control Register of the CT8020/8021
104 *  The CT8020 is used in the Internet PhoneJACK, and the 8021 in the
105 *  Internet LineJACK
106 *
107 ******************************************************************************/
108 typedef struct {
109 	unsigned int rxrdy:1;
110 	unsigned int txrdy:1;
111 	unsigned int status:1;
112 	unsigned int auxstatus:1;
113 	unsigned int rxdma:1;
114 	unsigned int txdma:1;
115 	unsigned int rxburst:1;
116 	unsigned int txburst:1;
117 	unsigned int dmadir:1;
118 	unsigned int cont:1;
119 	unsigned int irqn:1;
120 	unsigned int t:5;
121 } HCRBIT;
122 
123 typedef union {
124 	HCRBIT bits;
125 	BYTES bytes;
126 } HCR;
127 
128 /******************************************************************************
129 *
130 *  This structure represents the Hardware Status Register of the CT8020/8021
131 *  The CT8020 is used in the Internet PhoneJACK, and the 8021 in the
132 *  Internet LineJACK
133 *
134 ******************************************************************************/
135 typedef struct {
136 	unsigned int controlrdy:1;
137 	unsigned int auxctlrdy:1;
138 	unsigned int statusrdy:1;
139 	unsigned int auxstatusrdy:1;
140 	unsigned int rxrdy:1;
141 	unsigned int txrdy:1;
142 	unsigned int restart:1;
143 	unsigned int irqn:1;
144 	unsigned int rxdma:1;
145 	unsigned int txdma:1;
146 	unsigned int cohostshutdown:1;
147 	unsigned int t:5;
148 } HSRBIT;
149 
150 typedef union {
151 	HSRBIT bits;
152 	BYTES bytes;
153 } HSR;
154 
155 /******************************************************************************
156 *
157 *  This structure represents the General Purpose IO Register of the CT8020/8021
158 *  The CT8020 is used in the Internet PhoneJACK, and the 8021 in the
159 *  Internet LineJACK
160 *
161 ******************************************************************************/
162 typedef struct {
163 	unsigned int x:1;
164 	unsigned int gpio1:1;
165 	unsigned int gpio2:1;
166 	unsigned int gpio3:1;
167 	unsigned int gpio4:1;
168 	unsigned int gpio5:1;
169 	unsigned int gpio6:1;
170 	unsigned int gpio7:1;
171 	unsigned int xread:1;
172 	unsigned int gpio1read:1;
173 	unsigned int gpio2read:1;
174 	unsigned int gpio3read:1;
175 	unsigned int gpio4read:1;
176 	unsigned int gpio5read:1;
177 	unsigned int gpio6read:1;
178 	unsigned int gpio7read:1;
179 } GPIOBIT;
180 
181 typedef union {
182 	GPIOBIT bits;
183 	BYTES bytes;
184 	unsigned short word;
185 } GPIO;
186 
187 /******************************************************************************
188 *
189 *  This structure represents the Line Monitor status response
190 *
191 ******************************************************************************/
192 typedef struct {
193 	unsigned int digit:4;
194 	unsigned int cpf_valid:1;
195 	unsigned int dtmf_valid:1;
196 	unsigned int peak:1;
197 	unsigned int z:1;
198 	unsigned int f0:1;
199 	unsigned int f1:1;
200 	unsigned int f2:1;
201 	unsigned int f3:1;
202 	unsigned int frame:4;
203 } LMON;
204 
205 typedef union {
206 	LMON bits;
207 	BYTES bytes;
208 } DTMF;
209 
210 typedef struct {
211 	unsigned int z:7;
212 	unsigned int dtmf_en:1;
213 	unsigned int y:4;
214 	unsigned int F3:1;
215 	unsigned int F2:1;
216 	unsigned int F1:1;
217 	unsigned int F0:1;
218 } CP;
219 
220 typedef union {
221 	CP bits;
222 	BYTES bytes;
223 } CPTF;
224 
225 /******************************************************************************
226 *
227 *  This structure represents the Status Control Register on the Internet
228 *  LineJACK
229 *
230 ******************************************************************************/
231 typedef struct {
232 	unsigned int c0:1;
233 	unsigned int c1:1;
234 	unsigned int stereo:1;
235 	unsigned int daafsyncen:1;
236 	unsigned int led1:1;
237 	unsigned int led2:1;
238 	unsigned int led3:1;
239 	unsigned int led4:1;
240 } PSCRWI;			/* Internet LineJACK and Internet PhoneJACK Lite */
241 
242 typedef struct {
243 	unsigned int eidp:1;
244 	unsigned int eisd:1;
245 	unsigned int x:6;
246 } PSCRWP;			/* Internet PhoneJACK PCI */
247 
248 typedef union {
249 	PSCRWI bits;
250 	PSCRWP pcib;
251 	char byte;
252 } PLD_SCRW;
253 
254 typedef struct {
255 	unsigned int c0:1;
256 	unsigned int c1:1;
257 	unsigned int x:1;
258 	unsigned int d0ee:1;
259 	unsigned int mixerbusy:1;
260 	unsigned int sci:1;
261 	unsigned int dspflag:1;
262 	unsigned int daaflag:1;
263 } PSCRRI;
264 
265 typedef struct {
266 	unsigned int eidp:1;
267 	unsigned int eisd:1;
268 	unsigned int x:4;
269 	unsigned int dspflag:1;
270 	unsigned int det:1;
271 } PSCRRP;
272 
273 typedef union {
274 	PSCRRI bits;
275 	PSCRRP pcib;
276 	char byte;
277 } PLD_SCRR;
278 
279 /******************************************************************************
280 *
281 *  These structures represents the SLIC Control Register on the
282 *  Internet LineJACK
283 *
284 ******************************************************************************/
285 typedef struct {
286 	unsigned int c1:1;
287 	unsigned int c2:1;
288 	unsigned int c3:1;
289 	unsigned int b2en:1;
290 	unsigned int spken:1;
291 	unsigned int rly1:1;
292 	unsigned int rly2:1;
293 	unsigned int rly3:1;
294 } PSLICWRITE;
295 
296 typedef struct {
297 	unsigned int state:3;
298 	unsigned int b2en:1;
299 	unsigned int spken:1;
300 	unsigned int c3:1;
301 	unsigned int potspstn:1;
302 	unsigned int det:1;
303 } PSLICREAD;
304 
305 typedef struct {
306 	unsigned int c1:1;
307 	unsigned int c2:1;
308 	unsigned int c3:1;
309 	unsigned int b2en:1;
310 	unsigned int e1:1;
311 	unsigned int mic:1;
312 	unsigned int spk:1;
313 	unsigned int x:1;
314 } PSLICPCI;
315 
316 typedef union {
317 	PSLICPCI pcib;
318 	PSLICWRITE bits;
319 	PSLICREAD slic;
320 	char byte;
321 } PLD_SLICW;
322 
323 typedef union {
324 	PSLICPCI pcib;
325 	PSLICREAD bits;
326 	char byte;
327 } PLD_SLICR;
328 
329 /******************************************************************************
330 *
331 *  These structures represents the Clock Control Register on the
332 *  Internet LineJACK
333 *
334 ******************************************************************************/
335 typedef struct {
336 	unsigned int clk0:1;
337 	unsigned int clk1:1;
338 	unsigned int clk2:1;
339 	unsigned int x0:1;
340 	unsigned int slic_e1:1;
341 	unsigned int x1:1;
342 	unsigned int x2:1;
343 	unsigned int x3:1;
344 } PCLOCK;
345 
346 typedef union {
347 	PCLOCK bits;
348 	char byte;
349 } PLD_CLOCK;
350 
351 /******************************************************************************
352 *
353 *  These structures deal with the mixer on the Internet LineJACK
354 *
355 ******************************************************************************/
356 
357 typedef struct {
358 	unsigned short vol[10];
359 	unsigned int recsrc;
360 	unsigned int modcnt;
361 	unsigned short micpreamp;
362 } MIX;
363 
364 /******************************************************************************
365 *
366 *  These structures deal with the control logic on the Internet PhoneCARD
367 *
368 ******************************************************************************/
369 typedef struct {
370 	unsigned int x0:4;	/* unused bits */
371 
372 	unsigned int ed:1;	/* Event Detect */
373 
374 	unsigned int drf:1;	/* SmartCABLE Removal Flag 1=no cable */
375 
376 	unsigned int dspf:1;	/* DSP Flag 1=DSP Ready */
377 
378 	unsigned int crr:1;	/* Control Register Ready */
379 
380 } COMMAND_REG1;
381 
382 typedef union {
383 	COMMAND_REG1 bits;
384 	unsigned char byte;
385 } PCMCIA_CR1;
386 
387 typedef struct {
388 	unsigned int x0:4;	/* unused bits */
389 
390 	unsigned int rstc:1;	/* SmartCABLE Reset */
391 
392 	unsigned int pwr:1;	/* SmartCABLE Power */
393 
394 	unsigned int x1:2;	/* unused bits */
395 
396 } COMMAND_REG2;
397 
398 typedef union {
399 	COMMAND_REG2 bits;
400 	unsigned char byte;
401 } PCMCIA_CR2;
402 
403 typedef struct {
404 	unsigned int addr:5;	/* R/W SmartCABLE Register Address */
405 
406 	unsigned int rw:1;	/* Read / Write flag */
407 
408 	unsigned int dev:2;	/* 2 bit SmartCABLE Device Address */
409 
410 } CONTROL_REG;
411 
412 typedef union {
413 	CONTROL_REG bits;
414 	unsigned char byte;
415 } PCMCIA_SCCR;
416 
417 typedef struct {
418 	unsigned int hsw:1;
419 	unsigned int det:1;
420 	unsigned int led2:1;
421 	unsigned int led1:1;
422 	unsigned int ring1:1;
423 	unsigned int ring0:1;
424 	unsigned int x:1;
425 	unsigned int powerdown:1;
426 } PCMCIA_SLIC_REG;
427 
428 typedef union {
429 	PCMCIA_SLIC_REG bits;
430 	unsigned char byte;
431 } PCMCIA_SLIC;
432 
433 typedef struct {
434 	unsigned int cpd:1;	/* Chip Power Down */
435 
436 	unsigned int mpd:1;	/* MIC Bias Power Down */
437 
438 	unsigned int hpd:1;	/* Handset Drive Power Down */
439 
440 	unsigned int lpd:1;	/* Line Drive Power Down */
441 
442 	unsigned int spd:1;	/* Speaker Drive Power Down */
443 
444 	unsigned int x:2;	/* unused bits */
445 
446 	unsigned int sr:1;	/* Software Reset */
447 
448 } Si3CONTROL1;
449 
450 typedef union {
451 	Si3CONTROL1 bits;
452 	unsigned char byte;
453 } Si3C1;
454 
455 typedef struct {
456 	unsigned int al:1;	/* Analog Loopback DAC analog -> ADC analog */
457 
458 	unsigned int dl2:1;	/* Digital Loopback DAC -> ADC one bit */
459 
460 	unsigned int dl1:1;	/* Digital Loopback ADC -> DAC one bit */
461 
462 	unsigned int pll:1;	/* 1 = div 10, 0 = div 5 */
463 
464 	unsigned int hpd:1;	/* HPF disable */
465 
466 	unsigned int x:3;	/* unused bits */
467 
468 } Si3CONTROL2;
469 
470 typedef union {
471 	Si3CONTROL2 bits;
472 	unsigned char byte;
473 } Si3C2;
474 
475 typedef struct {
476 	unsigned int iir:1;	/* 1 enables IIR, 0 enables FIR */
477 
478 	unsigned int him:1;	/* Handset Input Mute */
479 
480 	unsigned int mcm:1;	/* MIC In Mute */
481 
482 	unsigned int mcg:2;	/* MIC In Gain */
483 
484 	unsigned int lim:1;	/* Line In Mute */
485 
486 	unsigned int lig:2;	/* Line In Gain */
487 
488 } Si3RXGAIN;
489 
490 typedef union {
491 	Si3RXGAIN bits;
492 	unsigned char byte;
493 } Si3RXG;
494 
495 typedef struct {
496 	unsigned int hom:1;	/* Handset Out Mute */
497 
498 	unsigned int lom:1;	/* Line Out Mute */
499 
500 	unsigned int rxg:5;	/* RX PGA Gain */
501 
502 	unsigned int x:1;	/* unused bit */
503 
504 } Si3ADCVOLUME;
505 
506 typedef union {
507 	Si3ADCVOLUME bits;
508 	unsigned char byte;
509 } Si3ADC;
510 
511 typedef struct {
512 	unsigned int srm:1;	/* Speaker Right Mute */
513 
514 	unsigned int slm:1;	/* Speaker Left Mute */
515 
516 	unsigned int txg:5;	/* TX PGA Gain */
517 
518 	unsigned int x:1;	/* unused bit */
519 
520 } Si3DACVOLUME;
521 
522 typedef union {
523 	Si3DACVOLUME bits;
524 	unsigned char byte;
525 } Si3DAC;
526 
527 typedef struct {
528 	unsigned int x:5;	/* unused bit */
529 
530 	unsigned int losc:1;	/* Line Out Short Circuit */
531 
532 	unsigned int srsc:1;	/* Speaker Right Short Circuit */
533 
534 	unsigned int slsc:1;	/* Speaker Left Short Circuit */
535 
536 } Si3STATUSREPORT;
537 
538 typedef union {
539 	Si3STATUSREPORT bits;
540 	unsigned char byte;
541 } Si3STAT;
542 
543 typedef struct {
544 	unsigned int sot:2;	/* Speaker Out Attenuation */
545 
546 	unsigned int lot:2;	/* Line Out Attenuation */
547 
548 	unsigned int x:4;	/* unused bits */
549 
550 } Si3ANALOGATTN;
551 
552 typedef union {
553 	Si3ANALOGATTN bits;
554 	unsigned char byte;
555 } Si3AATT;
556 
557 /******************************************************************************
558 *
559 *  These structures deal with the DAA on the Internet LineJACK
560 *
561 ******************************************************************************/
562 
563 typedef struct _DAA_REGS {
564 	/*----------------------------------------------- */
565 	/* SOP Registers */
566 	/* */
567 	BYTE bySOP;
568 
569 	union _SOP_REGS {
570 		struct _SOP {
571 			union	/* SOP - CR0 Register */
572 			 {
573 				BYTE reg;
574 				struct _CR0_BITREGS {
575 					BYTE CLK_EXT:1;		/* cr0[0:0] */
576 
577 					BYTE RIP:1;	/* cr0[1:1] */
578 
579 					BYTE AR:1;	/* cr0[2:2] */
580 
581 					BYTE AX:1;	/* cr0[3:3] */
582 
583 					BYTE FRR:1;	/* cr0[4:4] */
584 
585 					BYTE FRX:1;	/* cr0[5:5] */
586 
587 					BYTE IM:1;	/* cr0[6:6] */
588 
589 					BYTE TH:1;	/* cr0[7:7] */
590 
591 				} bitreg;
592 			} cr0;
593 
594 			union	/* SOP - CR1 Register */
595 			 {
596 				BYTE reg;
597 				struct _CR1_REGS {
598 					BYTE RM:1;	/* cr1[0:0] */
599 
600 					BYTE RMR:1;	/* cr1[1:1] */
601 
602 					BYTE No_auto:1;		/* cr1[2:2] */
603 
604 					BYTE Pulse:1;	/* cr1[3:3] */
605 
606 					BYTE P_Tone1:1;		/* cr1[4:4] */
607 
608 					BYTE P_Tone2:1;		/* cr1[5:5] */
609 
610 					BYTE E_Tone1:1;		/* cr1[6:6] */
611 
612 					BYTE E_Tone2:1;		/* cr1[7:7] */
613 
614 				} bitreg;
615 			} cr1;
616 
617 			union	/* SOP - CR2 Register */
618 			 {
619 				BYTE reg;
620 				struct _CR2_REGS {
621 					BYTE Call_II:1;		/* CR2[0:0] */
622 
623 					BYTE Call_I:1;	/* CR2[1:1] */
624 
625 					BYTE Call_en:1;		/* CR2[2:2] */
626 
627 					BYTE Call_pon:1;	/* CR2[3:3] */
628 
629 					BYTE IDR:1;	/* CR2[4:4] */
630 
631 					BYTE COT_R:3;	/* CR2[5:7] */
632 
633 				} bitreg;
634 			} cr2;
635 
636 			union	/* SOP - CR3 Register */
637 			 {
638 				BYTE reg;
639 				struct _CR3_REGS {
640 					BYTE DHP_X:1;	/* CR3[0:0] */
641 
642 					BYTE DHP_R:1;	/* CR3[1:1] */
643 
644 					BYTE Cal_pctl:1;	/* CR3[2:2] */
645 
646 					BYTE SEL:1;	/* CR3[3:3] */
647 
648 					BYTE TestLoops:4;	/* CR3[4:7] */
649 
650 				} bitreg;
651 			} cr3;
652 
653 			union	/* SOP - CR4 Register */
654 			 {
655 				BYTE reg;
656 				struct _CR4_REGS {
657 					BYTE Fsc_en:1;	/* CR4[0:0] */
658 
659 					BYTE Int_en:1;	/* CR4[1:1] */
660 
661 					BYTE AGX:2;	/* CR4[2:3] */
662 
663 					BYTE AGR_R:2;	/* CR4[4:5] */
664 
665 					BYTE AGR_Z:2;	/* CR4[6:7] */
666 
667 				} bitreg;
668 			} cr4;
669 
670 			union	/* SOP - CR5 Register */
671 			 {
672 				BYTE reg;
673 				struct _CR5_REGS {
674 					BYTE V_0:1;	/* CR5[0:0] */
675 
676 					BYTE V_1:1;	/* CR5[1:1] */
677 
678 					BYTE V_2:1;	/* CR5[2:2] */
679 
680 					BYTE V_3:1;	/* CR5[3:3] */
681 
682 					BYTE V_4:1;	/* CR5[4:4] */
683 
684 					BYTE V_5:1;	/* CR5[5:5] */
685 
686 					BYTE V_6:1;	/* CR5[6:6] */
687 
688 					BYTE V_7:1;	/* CR5[7:7] */
689 
690 				} bitreg;
691 			} cr5;
692 
693 			union	/* SOP - CR6 Register */
694 			 {
695 				BYTE reg;
696 				struct _CR6_REGS {
697 					BYTE reserved:8;	/* CR6[0:7] */
698 
699 				} bitreg;
700 			} cr6;
701 
702 			union	/* SOP - CR7 Register */
703 			 {
704 				BYTE reg;
705 				struct _CR7_REGS {
706 					BYTE reserved:8;	/* CR7[0:7] */
707 
708 				} bitreg;
709 			} cr7;
710 		} SOP;
711 
712 		BYTE ByteRegs[sizeof(struct _SOP)];
713 
714 	} SOP_REGS;
715 
716 	/* DAA_REGS.SOP_REGS.SOP.CR5.reg */
717 	/* DAA_REGS.SOP_REGS.SOP.CR5.bitreg */
718 	/* DAA_REGS.SOP_REGS.SOP.CR5.bitreg.V_2 */
719 	/* DAA_REGS.SOP_REGS.ByteRegs[5] */
720 
721 	/*----------------------------------------------- */
722 	/* XOP Registers */
723 	/* */
724 	BYTE byXOP;
725 
726 	union _XOP_REGS {
727 		struct _XOP {
728 			union	XOPXR0/* XOP - XR0 Register - Read values */
729 			 {
730 				BYTE reg;
731 				struct _XR0_BITREGS {
732 					BYTE SI_0:1;	/* XR0[0:0] - Read */
733 
734 					BYTE SI_1:1;	/* XR0[1:1] - Read */
735 
736 					BYTE VDD_OK:1;	/* XR0[2:2] - Read */
737 
738 					BYTE Caller_ID:1;	/* XR0[3:3] - Read */
739 
740 					BYTE RING:1;	/* XR0[4:4] - Read */
741 
742 					BYTE Cadence:1;		/* XR0[5:5] - Read */
743 
744 					BYTE Wake_up:1;		/* XR0[6:6] - Read */
745 
746 					BYTE RMR:1;	/* XR0[7:7] - Read */
747 
748 				} bitreg;
749 			} xr0;
750 
751 			union	/* XOP - XR1 Register */
752 			 {
753 				BYTE reg;
754 				struct _XR1_BITREGS {
755 					BYTE M_SI_0:1;	/* XR1[0:0] */
756 
757 					BYTE M_SI_1:1;	/* XR1[1:1] */
758 
759 					BYTE M_VDD_OK:1;	/* XR1[2:2] */
760 
761 					BYTE M_Caller_ID:1;	/* XR1[3:3] */
762 
763 					BYTE M_RING:1;	/* XR1[4:4] */
764 
765 					BYTE M_Cadence:1;	/* XR1[5:5] */
766 
767 					BYTE M_Wake_up:1;	/* XR1[6:6] */
768 
769 					BYTE unused:1;	/* XR1[7:7] */
770 
771 				} bitreg;
772 			} xr1;
773 
774 			union	/* XOP - XR2 Register */
775 			 {
776 				BYTE reg;
777 				struct _XR2_BITREGS {
778 					BYTE CTO0:1;	/* XR2[0:0] */
779 
780 					BYTE CTO1:1;	/* XR2[1:1] */
781 
782 					BYTE CTO2:1;	/* XR2[2:2] */
783 
784 					BYTE CTO3:1;	/* XR2[3:3] */
785 
786 					BYTE CTO4:1;	/* XR2[4:4] */
787 
788 					BYTE CTO5:1;	/* XR2[5:5] */
789 
790 					BYTE CTO6:1;	/* XR2[6:6] */
791 
792 					BYTE CTO7:1;	/* XR2[7:7] */
793 
794 				} bitreg;
795 			} xr2;
796 
797 			union	/* XOP - XR3 Register */
798 			 {
799 				BYTE reg;
800 				struct _XR3_BITREGS {
801 					BYTE DCR0:1;	/* XR3[0:0] */
802 
803 					BYTE DCR1:1;	/* XR3[1:1] */
804 
805 					BYTE DCI:1;	/* XR3[2:2] */
806 
807 					BYTE DCU0:1;	/* XR3[3:3] */
808 
809 					BYTE DCU1:1;	/* XR3[4:4] */
810 
811 					BYTE B_off:1;	/* XR3[5:5] */
812 
813 					BYTE AGB0:1;	/* XR3[6:6] */
814 
815 					BYTE AGB1:1;	/* XR3[7:7] */
816 
817 				} bitreg;
818 			} xr3;
819 
820 			union	/* XOP - XR4 Register */
821 			 {
822 				BYTE reg;
823 				struct _XR4_BITREGS {
824 					BYTE C_0:1;	/* XR4[0:0] */
825 
826 					BYTE C_1:1;	/* XR4[1:1] */
827 
828 					BYTE C_2:1;	/* XR4[2:2] */
829 
830 					BYTE C_3:1;	/* XR4[3:3] */
831 
832 					BYTE C_4:1;	/* XR4[4:4] */
833 
834 					BYTE C_5:1;	/* XR4[5:5] */
835 
836 					BYTE C_6:1;	/* XR4[6:6] */
837 
838 					BYTE C_7:1;	/* XR4[7:7] */
839 
840 				} bitreg;
841 			} xr4;
842 
843 			union	/* XOP - XR5 Register */
844 			 {
845 				BYTE reg;
846 				struct _XR5_BITREGS {
847 					BYTE T_0:1;	/* XR5[0:0] */
848 
849 					BYTE T_1:1;	/* XR5[1:1] */
850 
851 					BYTE T_2:1;	/* XR5[2:2] */
852 
853 					BYTE T_3:1;	/* XR5[3:3] */
854 
855 					BYTE T_4:1;	/* XR5[4:4] */
856 
857 					BYTE T_5:1;	/* XR5[5:5] */
858 
859 					BYTE T_6:1;	/* XR5[6:6] */
860 
861 					BYTE T_7:1;	/* XR5[7:7] */
862 
863 				} bitreg;
864 			} xr5;
865 
866 			union	/* XOP - XR6 Register - Read Values */
867 			 {
868 				BYTE reg;
869 				struct _XR6_BITREGS {
870 					BYTE CPS0:1;	/* XR6[0:0] */
871 
872 					BYTE CPS1:1;	/* XR6[1:1] */
873 
874 					BYTE unused1:2;		/* XR6[2:3] */
875 
876 					BYTE CLK_OFF:1;		/* XR6[4:4] */
877 
878 					BYTE unused2:3;		/* XR6[5:7] */
879 
880 				} bitreg;
881 			} xr6;
882 
883 			union	/* XOP - XR7 Register */
884 			 {
885 				BYTE reg;
886 				struct _XR7_BITREGS {
887 					BYTE unused1:1;		/* XR7[0:0] */
888 
889 					BYTE Vdd0:1;	/* XR7[1:1] */
890 
891 					BYTE Vdd1:1;	/* XR7[2:2] */
892 
893 					BYTE unused2:5;		/* XR7[3:7] */
894 
895 				} bitreg;
896 			} xr7;
897 		} XOP;
898 
899 		BYTE ByteRegs[sizeof(struct _XOP)];
900 
901 	} XOP_REGS;
902 
903 	/* DAA_REGS.XOP_REGS.XOP.XR7.reg */
904 	/* DAA_REGS.XOP_REGS.XOP.XR7.bitreg */
905 	/* DAA_REGS.XOP_REGS.XOP.XR7.bitreg.Vdd0 */
906 	/* DAA_REGS.XOP_REGS.ByteRegs[7] */
907 
908 	/*----------------------------------------------- */
909 	/* COP Registers */
910 	/* */
911 	BYTE byCOP;
912 
913 	union _COP_REGS {
914 		struct _COP {
915 			BYTE THFilterCoeff_1[8];	/* COP - TH Filter Coefficients,      CODE=0, Part 1 */
916 
917 			BYTE THFilterCoeff_2[8];	/* COP - TH Filter Coefficients,      CODE=1, Part 2 */
918 
919 			BYTE THFilterCoeff_3[8];	/* COP - TH Filter Coefficients,      CODE=2, Part 3 */
920 
921 			BYTE RingerImpendance_1[8];	/* COP - Ringer Impendance Coefficients,  CODE=3, Part 1 */
922 
923 			BYTE IMFilterCoeff_1[8];	/* COP - IM Filter Coefficients,      CODE=4, Part 1 */
924 
925 			BYTE IMFilterCoeff_2[8];	/* COP - IM Filter Coefficients,      CODE=5, Part 2 */
926 
927 			BYTE RingerImpendance_2[8];	/* COP - Ringer Impendance Coefficients,  CODE=6, Part 2 */
928 
929 			BYTE FRRFilterCoeff[8];		/* COP - FRR Filter Coefficients,      CODE=7 */
930 
931 			BYTE FRXFilterCoeff[8];		/* COP - FRX Filter Coefficients,      CODE=8 */
932 
933 			BYTE ARFilterCoeff[4];	/* COP - AR Filter Coefficients,      CODE=9 */
934 
935 			BYTE AXFilterCoeff[4];	/* COP - AX Filter Coefficients,      CODE=10  */
936 
937 			BYTE Tone1Coeff[4];	/* COP - Tone1 Coefficients,        CODE=11 */
938 
939 			BYTE Tone2Coeff[4];	/* COP - Tone2 Coefficients,        CODE=12 */
940 
941 			BYTE LevelmeteringRinging[4];	/* COP - Levelmetering Ringing,        CODE=13 */
942 
943 			BYTE CallerID1stTone[8];	/* COP - Caller ID 1st Tone,        CODE=14 */
944 
945 			BYTE CallerID2ndTone[8];	/* COP - Caller ID 2nd Tone,        CODE=15 */
946 
947 		} COP;
948 
949 		BYTE ByteRegs[sizeof(struct _COP)];
950 
951 	} COP_REGS;
952 
953 	/* DAA_REGS.COP_REGS.COP.XR7.Tone1Coeff[3] */
954 	/* DAA_REGS.COP_REGS.COP.XR7.bitreg */
955 	/* DAA_REGS.COP_REGS.COP.XR7.bitreg.Vdd0 */
956 	/* DAA_REGS.COP_REGS.ByteRegs[57] */
957 
958 	/*----------------------------------------------- */
959 	/* CAO Registers */
960 	/* */
961 	BYTE byCAO;
962 
963 	union _CAO_REGS {
964 		struct _CAO {
965 			BYTE CallerID[512];	/* CAO - Caller ID Bytes */
966 
967 		} CAO;
968 
969 		BYTE ByteRegs[sizeof(struct _CAO)];
970 	} CAO_REGS;
971 
972 	union			/* XOP - XR0 Register - Write values */
973 	 {
974 		BYTE reg;
975 		struct _XR0_BITREGSW {
976 			BYTE SO_0:1;	/* XR1[0:0] - Write */
977 
978 			BYTE SO_1:1;	/* XR1[1:1] - Write */
979 
980 			BYTE SO_2:1;	/* XR1[2:2] - Write */
981 
982 			BYTE unused:5;	/* XR1[3:7] - Write */
983 
984 		} bitreg;
985 	} XOP_xr0_W;
986 
987 	union			/* XOP - XR6 Register - Write values */
988 	 {
989 		BYTE reg;
990 		struct _XR6_BITREGSW {
991 			BYTE unused1:4;		/* XR6[0:3] */
992 
993 			BYTE CLK_OFF:1;		/* XR6[4:4] */
994 
995 			BYTE unused2:3;		/* XR6[5:7] */
996 
997 		} bitreg;
998 	} XOP_xr6_W;
999 
1000 } DAA_REGS;
1001 
1002 #define ALISDAA_ID_BYTE      0x81
1003 #define ALISDAA_CALLERID_SIZE  512
1004 
1005 /*------------------------------ */
1006 /* */
1007 /*  Misc definitions */
1008 /* */
1009 
1010 /* Power Up Operation */
1011 #define SOP_PU_SLEEP    0
1012 #define SOP_PU_RINGING    1
1013 #define SOP_PU_CONVERSATION  2
1014 #define SOP_PU_PULSEDIALING  3
1015 #define SOP_PU_RESET    4
1016 
1017 #define ALISDAA_CALLERID_SIZE 512
1018 
1019 #define PLAYBACK_MODE_COMPRESSED	0	/*        Selects: Compressed modes, TrueSpeech 8.5-4.1, G.723.1, G.722, G.728, G.729 */
1020 #define PLAYBACK_MODE_TRUESPEECH_V40	0	/*        Selects: TrueSpeech 8.5, 6.3, 5.3, 4.8 or 4.1 Kbps */
1021 #define PLAYBACK_MODE_TRUESPEECH	8	/*        Selects: TrueSpeech 8.5, 6.3, 5.3, 4.8 or 4.1 Kbps Version 5.1 */
1022 #define PLAYBACK_MODE_ULAW		2	/*        Selects: 64 Kbit/sec MuA-law PCM */
1023 #define PLAYBACK_MODE_ALAW		10	/*        Selects: 64 Kbit/sec A-law PCM */
1024 #define PLAYBACK_MODE_16LINEAR		6	/*        Selects: 128 Kbit/sec 16-bit linear */
1025 #define PLAYBACK_MODE_8LINEAR		4	/*        Selects: 64 Kbit/sec 8-bit signed linear */
1026 #define PLAYBACK_MODE_8LINEAR_WSS	5	/*        Selects: 64 Kbit/sec WSS 8-bit unsigned linear */
1027 
1028 #define RECORD_MODE_COMPRESSED		0	/*        Selects: Compressed modes, TrueSpeech 8.5-4.1, G.723.1, G.722, G.728, G.729 */
1029 #define RECORD_MODE_TRUESPEECH		0	/*        Selects: TrueSpeech 8.5, 6.3, 5.3, 4.8 or 4.1 Kbps */
1030 #define RECORD_MODE_ULAW		4	/*        Selects: 64 Kbit/sec Mu-law PCM */
1031 #define RECORD_MODE_ALAW		12	/*        Selects: 64 Kbit/sec A-law PCM */
1032 #define RECORD_MODE_16LINEAR		5	/*        Selects: 128 Kbit/sec 16-bit linear */
1033 #define RECORD_MODE_8LINEAR		6	/*        Selects: 64 Kbit/sec 8-bit signed linear */
1034 #define RECORD_MODE_8LINEAR_WSS		7	/*        Selects: 64 Kbit/sec WSS 8-bit unsigned linear */
1035 
1036 enum SLIC_STATES {
1037 	PLD_SLIC_STATE_OC = 0,
1038 	PLD_SLIC_STATE_RINGING,
1039 	PLD_SLIC_STATE_ACTIVE,
1040 	PLD_SLIC_STATE_OHT,
1041 	PLD_SLIC_STATE_TIPOPEN,
1042 	PLD_SLIC_STATE_STANDBY,
1043 	PLD_SLIC_STATE_APR,
1044 	PLD_SLIC_STATE_OHTPR
1045 };
1046 
1047 enum SCI_CONTROL {
1048 	SCI_End = 0,
1049 	SCI_Enable_DAA,
1050 	SCI_Enable_Mixer,
1051 	SCI_Enable_EEPROM
1052 };
1053 
1054 enum Mode {
1055 	T63, T53, T48, T40
1056 };
1057 enum Dir {
1058 	V3_TO_V4, V4_TO_V3, V4_TO_V5, V5_TO_V4
1059 };
1060 
1061 typedef struct Proc_Info_Tag {
1062 	enum Mode convert_mode;
1063 	enum Dir convert_dir;
1064 	int Prev_Frame_Type;
1065 	int Current_Frame_Type;
1066 } Proc_Info_Type;
1067 
1068 enum PREVAL {
1069 	NORMAL = 0,
1070 	NOPOST,
1071 	POSTONLY,
1072 	PREERROR
1073 };
1074 
1075 enum IXJ_EXTENSIONS {
1076 	G729LOADER = 0,
1077 	TS85LOADER,
1078 	PRE_READ,
1079 	POST_READ,
1080 	PRE_WRITE,
1081 	POST_WRITE,
1082 	PRE_IOCTL,
1083 	POST_IOCTL
1084 };
1085 
1086 typedef struct {
1087 	char enable;
1088 	char en_filter;
1089 	unsigned int filter;
1090 	unsigned int state;	/* State 0 when cadence has not started. */
1091 
1092 	unsigned int on1;	/* State 1 */
1093 
1094 	unsigned long on1min;	/* State 1 - 10% + jiffies */
1095  	unsigned long on1dot;	/* State 1 + jiffies */
1096 
1097 	unsigned long on1max;	/* State 1 + 10% + jiffies */
1098 
1099 	unsigned int off1;	/* State 2 */
1100 
1101 	unsigned long off1min;
1102  	unsigned long off1dot;	/* State 2 + jiffies */
1103 	unsigned long off1max;
1104 	unsigned int on2;	/* State 3 */
1105 
1106 	unsigned long on2min;
1107 	unsigned long on2dot;
1108 	unsigned long on2max;
1109 	unsigned int off2;	/* State 4 */
1110 
1111 	unsigned long off2min;
1112  	unsigned long off2dot;	/* State 4 + jiffies */
1113 	unsigned long off2max;
1114 	unsigned int on3;	/* State 5 */
1115 
1116 	unsigned long on3min;
1117 	unsigned long on3dot;
1118 	unsigned long on3max;
1119 	unsigned int off3;	/* State 6 */
1120 
1121 	unsigned long off3min;
1122  	unsigned long off3dot;	/* State 6 + jiffies */
1123 	unsigned long off3max;
1124 } IXJ_CADENCE_F;
1125 
1126 typedef struct {
1127 	unsigned int busytone:1;
1128 	unsigned int dialtone:1;
1129 	unsigned int ringback:1;
1130 	unsigned int ringing:1;
1131 	unsigned int playing:1;
1132 	unsigned int recording:1;
1133 	unsigned int cringing:1;
1134 	unsigned int play_first_frame:1;
1135 	unsigned int pstn_present:1;
1136 	unsigned int pstn_ringing:1;
1137 	unsigned int pots_correct:1;
1138 	unsigned int pots_pstn:1;
1139 	unsigned int g729_loaded:1;
1140 	unsigned int ts85_loaded:1;
1141 	unsigned int dtmf_oob:1;	/* DTMF Out-Of-Band */
1142 
1143 	unsigned int pcmciascp:1;	/* SmartCABLE Present */
1144 
1145 	unsigned int pcmciasct:2;	/* SmartCABLE Type */
1146 
1147 	unsigned int pcmciastate:3;	/* SmartCABLE Init State */
1148 
1149 	unsigned int inwrite:1;	/* Currently writing */
1150 
1151 	unsigned int inread:1;	/* Currently reading */
1152 
1153 	unsigned int incheck:1;	/* Currently checking the SmartCABLE */
1154 
1155 	unsigned int cidplay:1; /* Currently playing Caller ID */
1156 
1157 	unsigned int cidring:1; /* This is the ring for Caller ID */
1158 
1159 	unsigned int cidsent:1; /* Caller ID has been sent */
1160 
1161 	unsigned int cidcw_ack:1; /* Caller ID CW ACK (from CPE) */
1162 	unsigned int firstring:1; /* First ring cadence is complete */
1163 	unsigned int pstncheck:1;	/* Currently checking the PSTN Line */
1164 	unsigned int pstn_rmr:1;
1165 	unsigned int x:3;	/* unsed bits */
1166 
1167 } IXJ_FLAGS;
1168 
1169 /******************************************************************************
1170 *
1171 *  This structure holds the state of all of the Quicknet cards
1172 *
1173 ******************************************************************************/
1174 
1175 typedef struct {
1176 	struct phone_device p;
1177 	struct timer_list timer;
1178 	unsigned int board;
1179 	unsigned int DSPbase;
1180 	unsigned int XILINXbase;
1181 	unsigned int serial;
1182 	atomic_t DSPWrite;
1183 	struct phone_capability caplist[30];
1184 	unsigned int caps;
1185 #if LINUX_VERSION_CODE < 0x020400
1186 	struct pnp_dev *dev;
1187 #else
1188 	struct pci_dev *dev;
1189 #endif
1190 	unsigned int cardtype;
1191 	unsigned int rec_codec;
1192 	unsigned int cid_rec_codec;
1193 	unsigned int cid_rec_volume;
1194 	unsigned char cid_rec_flag;
1195 	char rec_mode;
1196 	unsigned int play_codec;
1197 	unsigned int cid_play_codec;
1198 	unsigned int cid_play_volume;
1199 	unsigned char cid_play_flag;
1200 	char play_mode;
1201 	IXJ_FLAGS flags;
1202 	unsigned int busyflags;
1203 	unsigned int rec_frame_size;
1204 	unsigned int play_frame_size;
1205 	unsigned int cid_play_frame_size;
1206 	unsigned int cid_base_frame_size;
1207 	unsigned long cidcw_wait;
1208 	int aec_level;
1209 	int cid_play_aec_level;
1210 	int readers, writers;
1211 #if LINUX_VERSION_CODE < 0x020400
1212 	struct wait_queue *poll_q;
1213 	struct wait_queue *read_q;
1214 #else
1215         wait_queue_head_t poll_q;
1216         wait_queue_head_t read_q;
1217 #endif
1218 	char *read_buffer, *read_buffer_end;
1219 	char *read_convert_buffer;
1220 	unsigned int read_buffer_size;
1221 	unsigned int read_buffer_ready;
1222 #if LINUX_VERSION_CODE < 0x020400
1223 	struct wait_queue *write_q;
1224 #else
1225         wait_queue_head_t write_q;
1226 #endif
1227 	char *write_buffer, *write_buffer_end;
1228 	char *write_convert_buffer;
1229 	unsigned int write_buffer_size;
1230 	unsigned int write_buffers_empty;
1231 	unsigned long drybuffer;
1232 	char *write_buffer_rp, *write_buffer_wp;
1233 	char dtmfbuffer[80];
1234 	char dtmf_current;
1235 	int dtmf_wp, dtmf_rp, dtmf_state, dtmf_proc;
1236 	int tone_off_time, tone_on_time;
1237 	struct fasync_struct *async_queue;
1238 	unsigned long tone_start_jif;
1239 	char tone_index;
1240 	char tone_state;
1241 	char maxrings;
1242 	IXJ_CADENCE *cadence_t;
1243 	IXJ_CADENCE *cadence_r;
1244 	int tone_cadence_state;
1245 	IXJ_CADENCE_F cadence_f[6];
1246 	DTMF dtmf;
1247 	CPTF cptf;
1248 	BYTES dsp;
1249 	BYTES ver;
1250 	BYTES scr;
1251 	BYTES ssr;
1252 	BYTES baseframe;
1253 	HSR hsr;
1254 	GPIO gpio;
1255 	PLD_SCRR pld_scrr;
1256 	PLD_SCRW pld_scrw;
1257 	PLD_SLICW pld_slicw;
1258 	PLD_SLICR pld_slicr;
1259 	PLD_CLOCK pld_clock;
1260 	PCMCIA_CR1 pccr1;
1261 	PCMCIA_CR2 pccr2;
1262 	PCMCIA_SCCR psccr;
1263 	PCMCIA_SLIC pslic;
1264 	char pscdd;
1265 	Si3C1 sic1;
1266 	Si3C2 sic2;
1267 	Si3RXG sirxg;
1268 	Si3ADC siadc;
1269 	Si3DAC sidac;
1270 	Si3STAT sistat;
1271 	Si3AATT siaatt;
1272 	MIX mix;
1273 	unsigned short ring_cadence;
1274 	int ring_cadence_t;
1275 	unsigned long ring_cadence_jif;
1276 	unsigned long checkwait;
1277 	int intercom;
1278 	int m_hook;
1279 	int r_hook;
1280 	int p_hook;
1281 	char pstn_envelope;
1282 	char pstn_cid_intr;
1283 	unsigned char fskz;
1284 	unsigned char fskphase;
1285 	unsigned char fskcnt;
1286         unsigned int cidsize;
1287 	unsigned int cidcnt;
1288 	unsigned pstn_cid_received;
1289 	PHONE_CID cid;
1290 	PHONE_CID cid_send;
1291 	unsigned long pstn_ring_int;
1292 	unsigned long pstn_ring_start;
1293 	unsigned long pstn_ring_stop;
1294 	unsigned long pstn_winkstart;
1295 	unsigned long pstn_last_rmr;
1296 	unsigned long pstn_prev_rmr;
1297 	unsigned long pots_winkstart;
1298 	unsigned int winktime;
1299 	unsigned long flash_end;
1300 	char port;
1301 	char hookstate;
1302 	union telephony_exception ex;
1303 	union telephony_exception ex_sig;
1304 	int ixj_signals[35];
1305 	IXJ_SIGDEF sigdef;
1306 	char daa_mode;
1307 	char daa_country;
1308 	unsigned long pstn_sleeptil;
1309 	DAA_REGS m_DAAShadowRegs;
1310 	Proc_Info_Type Info_read;
1311 	Proc_Info_Type Info_write;
1312 	unsigned short frame_count;
1313 	unsigned int filter_hist[4];
1314 	unsigned char filter_en[4];
1315 	unsigned short proc_load;
1316 	unsigned long framesread;
1317 	unsigned long frameswritten;
1318 	unsigned long read_wait;
1319 	unsigned long write_wait;
1320 	unsigned long timerchecks;
1321 	unsigned long txreadycheck;
1322 	unsigned long rxreadycheck;
1323 	unsigned long statuswait;
1324 	unsigned long statuswaitfail;
1325 	unsigned long pcontrolwait;
1326 	unsigned long pcontrolwaitfail;
1327 	unsigned long iscontrolready;
1328 	unsigned long iscontrolreadyfail;
1329 	unsigned long pstnstatecheck;
1330 #ifdef IXJ_DYN_ALLOC
1331 	short *fskdata;
1332 #else
1333 	short fskdata[8000];
1334 #endif
1335 	int fsksize;
1336 	int fskdcnt;
1337 } IXJ;
1338 
1339 typedef int (*IXJ_REGFUNC) (IXJ * j, unsigned long arg);
1340 
1341 extern IXJ *ixj_pcmcia_probe(unsigned long, unsigned long);
1342 
1343