vserver 1.9.5.x5
[linux-2.6.git] / drivers / telephony / ixj.c
1 /****************************************************************************
2  *    ixj.c
3  *
4  * Device Driver for Quicknet Technologies, Inc.'s Telephony cards
5  * including the Internet PhoneJACK, Internet PhoneJACK Lite,
6  * Internet PhoneJACK PCI, Internet LineJACK, Internet PhoneCARD and
7  * SmartCABLE
8  *
9  *    (c) Copyright 1999-2001  Quicknet Technologies, Inc.
10  *
11  *    This program is free software; you can redistribute it and/or
12  *    modify it under the terms of the GNU General Public License
13  *    as published by the Free Software Foundation; either version
14  *    2 of the License, or (at your option) any later version.
15  *
16  * Author:          Ed Okerson, <eokerson@quicknet.net>
17  *
18  * Contributors:    Greg Herlein, <gherlein@quicknet.net>
19  *                  David W. Erhart, <derhart@quicknet.net>
20  *                  John Sellers, <jsellers@quicknet.net>
21  *                  Mike Preston, <mpreston@quicknet.net>
22  *    
23  * Fixes:           David Huggins-Daines, <dhd@cepstral.com>
24  *                  Fabio Ferrari, <fabio.ferrari@digitro.com.br>
25  *                  Artis Kugevics, <artis@mt.lv>
26  *                  Daniele Bellucci, <bellucda@tiscali.it>
27  *
28  * More information about the hardware related to this driver can be found  
29  * at our website:    http://www.quicknet.net
30  *
31  * IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR
32  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
33  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET
34  * TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *    
36  * QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES,
37  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
38  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
39  * ON AN "AS IS" BASIS, AND QUICKNET TECHNOLOGIES, INC. HAS NO OBLIGATION
40  * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
41  *
42  ***************************************************************************/
43
44 static char ixj_c_rcsid[] = "$Id: ixj.c,v 4.7 2001/08/13 06:19:33 craigs Exp $";
45 static char ixj_c_revision[] = "$Revision: 4.7 $";
46
47 /*
48  * $Log: ixj.c,v $
49  *
50  * Revision 4.8  2003/07/09 19:39:00  Daniele Bellucci
51  * Audit some copy_*_user and minor cleanup.
52  *
53  * Revision 4.7  2001/08/13 06:19:33  craigs
54  * Added additional changes from Alan Cox and John Anderson for
55  * 2.2 to 2.4 cleanup and bounds checking
56  *
57  * Revision 4.6  2001/08/13 01:05:05  craigs
58  * Really fixed PHONE_QUERY_CODEC problem this time
59  *
60  * Revision 4.5  2001/08/13 00:11:03  craigs
61  * Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson
62  *
63  * Revision 4.4  2001/08/07 07:58:12  craigs
64  * Changed back to three digit version numbers
65  * Added tagbuild target to allow automatic and easy tagging of versions
66  *
67  * Revision 4.3  2001/08/07 07:24:47  craigs
68  * Added ixj-ver.h to allow easy configuration management of driver
69  * Added display of version number in /prox/ixj
70  *
71  * Revision 4.2  2001/08/06 07:07:19  craigs
72  * Reverted IXJCTL_DSP_TYPE and IXJCTL_DSP_VERSION files to original
73  * behaviour of returning int rather than short *
74  *
75  * Revision 4.1  2001/08/05 00:17:37  craigs
76  * More changes for correct PCMCIA installation
77  * Start of changes for backward Linux compatibility
78  *
79  * Revision 4.0  2001/08/04 12:33:12  craigs
80  * New version using GNU autoconf
81  *
82  * Revision 3.105  2001/07/20 23:14:32  eokerson
83  * More work on CallerID generation when using ring cadences.
84  *
85  * Revision 3.104  2001/07/06 01:33:55  eokerson
86  * Some bugfixes from Robert Vojta <vojta@ipex.cz> and a few mods to the Makefile.
87  *
88  * Revision 3.103  2001/07/05 19:20:16  eokerson
89  * Updated HOWTO
90  * Changed mic gain to 30dB on Internet LineJACK mic/speaker port.
91  *
92  * Revision 3.102  2001/07/03 23:51:21  eokerson
93  * Un-mute mic on Internet LineJACK when in speakerphone mode.
94  *
95  * Revision 3.101  2001/07/02 19:26:56  eokerson
96  * Removed initialiazation of ixjdebug and ixj_convert_loaded so they will go in the .bss instead of the .data
97  *
98  * Revision 3.100  2001/07/02 19:18:27  eokerson
99  * Changed driver to make dynamic allocation possible.  We now pass IXJ * between functions instead of array indexes.
100  * Fixed the way the POTS and PSTN ports interact during a PSTN call to allow local answering.
101  * Fixed speaker mode on Internet LineJACK.
102  *
103  * Revision 3.99  2001/05/09 14:11:16  eokerson
104  * Fixed kmalloc error in ixj_build_filter_cadence.  Thanks David Chan <cat@waulogy.stanford.edu>.
105  *
106  * Revision 3.98  2001/05/08 19:55:33  eokerson
107  * Fixed POTS hookstate detection while it is connected to PSTN port.
108  *
109  * Revision 3.97  2001/05/08 00:01:04  eokerson
110  * Fixed kernel oops when sending caller ID data.
111  *
112  * Revision 3.96  2001/05/04 23:09:30  eokerson
113  * Now uses one kernel timer for each card, instead of one for the entire driver.
114  *
115  * Revision 3.95  2001/04/25 22:06:47  eokerson
116  * Fixed squawking at beginning of some G.723.1 calls.
117  *
118  * Revision 3.94  2001/04/03 23:42:00  eokerson
119  * Added linear volume ioctls
120  * Added raw filter load ioctl
121  *
122  * Revision 3.93  2001/02/27 01:00:06  eokerson
123  * Fixed blocking in CallerID.
124  * Reduced size of ixj structure for smaller driver footprint.
125  *
126  * Revision 3.92  2001/02/20 22:02:59  eokerson
127  * Fixed isapnp and pcmcia module compatibility for 2.4.x kernels.
128  * Improved PSTN ring detection.
129  * Fixed wink generation on POTS ports.
130  *
131  * Revision 3.91  2001/02/13 00:55:44  eokerson
132  * Turn AEC back on after changing frame sizes.
133  *
134  * Revision 3.90  2001/02/12 16:42:00  eokerson
135  * Added ALAW codec, thanks to Fabio Ferrari for the table based converters to make ALAW from ULAW.
136  *
137  * Revision 3.89  2001/02/12 15:41:16  eokerson
138  * Fix from Artis Kugevics - Tone gains were not being set correctly.
139  *
140  * Revision 3.88  2001/02/05 23:25:42  eokerson
141  * Fixed lockup bugs with deregister.
142  *
143  * Revision 3.87  2001/01/29 21:00:39  eokerson
144  * Fix from Fabio Ferrari <fabio.ferrari@digitro.com.br> to properly handle EAGAIN and EINTR during non-blocking write.
145  * Updated copyright date.
146  *
147  * Revision 3.86  2001/01/23 23:53:46  eokerson
148  * Fixes to G.729 compatibility.
149  *
150  * Revision 3.85  2001/01/23 21:30:36  eokerson
151  * Added verbage about cards supported.
152  * Removed commands that put the card in low power mode at some times that it should not be in low power mode.
153  *
154  * Revision 3.84  2001/01/22 23:32:10  eokerson
155  * Some bugfixes from David Huggins-Daines, <dhd@cepstral.com> and other cleanups.
156  *
157  * Revision 3.83  2001/01/19 14:51:41  eokerson
158  * Fixed ixj_WriteDSPCommand to decrement usage counter when command fails.
159  *
160  * Revision 3.82  2001/01/19 00:34:49  eokerson
161  * Added verbosity to write overlap errors.
162  *
163  * Revision 3.81  2001/01/18 23:56:54  eokerson
164  * Fixed PSTN line test functions.
165  *
166  * Revision 3.80  2001/01/18 22:29:27  eokerson
167  * Updated AEC/AGC values for different cards.
168  *
169  * Revision 3.79  2001/01/17 02:58:54  eokerson
170  * Fixed AEC reset after Caller ID.
171  * Fixed Codec lockup after Caller ID on Call Waiting when not using 30ms frames.
172  *
173  * Revision 3.78  2001/01/16 19:43:09  eokerson
174  * Added support for Linux 2.4.x kernels.
175  *
176  * Revision 3.77  2001/01/09 04:00:52  eokerson
177  * Linetest will now test the line, even if it has previously succeded.
178  *
179  * Revision 3.76  2001/01/08 19:27:00  eokerson
180  * Fixed problem with standard cable on Internet PhoneCARD.
181  *
182  * Revision 3.75  2000/12/22 16:52:14  eokerson
183  * Modified to allow hookstate detection on the POTS port when the PSTN port is selected.
184  *
185  * Revision 3.74  2000/12/08 22:41:50  eokerson
186  * Added capability for G729B.
187  *
188  * Revision 3.73  2000/12/07 23:35:16  eokerson
189  * Added capability to have different ring pattern before CallerID data.
190  * Added hookstate checks in CallerID routines to stop FSK.
191  *
192  * Revision 3.72  2000/12/06 19:31:31  eokerson
193  * Modified signal behavior to only send one signal per event.
194  *
195  * Revision 3.71  2000/12/06 03:23:08  eokerson
196  * Fixed CallerID on Call Waiting.
197  *
198  * Revision 3.70  2000/12/04 21:29:37  eokerson
199  * Added checking to Smart Cable gain functions.
200  *
201  * Revision 3.69  2000/12/04 21:05:20  eokerson
202  * Changed ixjdebug levels.
203  * Added ioctls to change gains in Internet Phone CARD Smart Cable.
204  *
205  * Revision 3.68  2000/12/04 00:17:21  craigs
206  * Changed mixer voice gain to +6dB rather than 0dB
207  *
208  * Revision 3.67  2000/11/30 21:25:51  eokerson
209  * Fixed write signal errors.
210  *
211  * Revision 3.66  2000/11/29 22:42:44  eokerson
212  * Fixed PSTN ring detect problems.
213  *
214  * Revision 3.65  2000/11/29 07:31:55  craigs
215  * Added new 425Hz filter co-efficients
216  * Added card-specific DTMF prescaler initialisation
217  *
218  * Revision 3.64  2000/11/28 14:03:32  craigs
219  * Changed certain mixer initialisations to be 0dB rather than 12dB
220  * Added additional information to /proc/ixj
221  *
222  * Revision 3.63  2000/11/28 11:38:41  craigs
223  * Added display of AEC modes in AUTO and AGC mode
224  *
225  * Revision 3.62  2000/11/28 04:05:44  eokerson
226  * Improved PSTN ring detection routine.
227  *
228  * Revision 3.61  2000/11/27 21:53:12  eokerson
229  * Fixed flash detection.
230  *
231  * Revision 3.60  2000/11/27 15:57:29  eokerson
232  * More work on G.729 load routines.
233  *
234  * Revision 3.59  2000/11/25 21:55:12  eokerson
235  * Fixed errors in G.729 load routine.
236  *
237  * Revision 3.58  2000/11/25 04:08:29  eokerson
238  * Added board locks around G.729 and TS85 load routines.
239  *
240  * Revision 3.57  2000/11/24 05:35:17  craigs
241  * Added ability to retrieve mixer values on LineJACK
242  * Added complete initialisation of all mixer values at startup
243  * Fixed spelling mistake
244  *
245  * Revision 3.56  2000/11/23 02:52:11  robertj
246  * Added cvs change log keyword.
247  * Fixed bug in capabilities list when using G.729 module.
248  *
249  */
250
251 #include "ixj-ver.h"
252
253 #define PERFMON_STATS
254 #define IXJDEBUG 0
255 #define MAXRINGS 5
256
257 #include <linux/module.h>
258
259 #include <linux/init.h>
260 #include <linux/sched.h>
261 #include <linux/kernel.h>       /* printk() */
262 #include <linux/fs.h>           /* everything... */
263 #include <linux/errno.h>        /* error codes */
264 #include <linux/slab.h>
265 #include <linux/mm.h>
266 #include <linux/ioport.h>
267 #include <linux/interrupt.h>
268 #include <linux/proc_fs.h>
269 #include <linux/poll.h>
270 #include <linux/timer.h>
271 #include <linux/delay.h>
272 #include <linux/pci.h>
273
274 #include <asm/io.h>
275 #include <asm/uaccess.h>
276
277 #include <linux/isapnp.h>
278
279 #include "ixj.h"
280
281 #define TYPE(inode) (iminor(inode) >> 4)
282 #define NUM(inode) (iminor(inode) & 0xf)
283
284 static int ixjdebug;
285 static int hertz = HZ;
286 static int samplerate = 100;
287
288 module_param(ixjdebug, int, 0);
289
290 /************************************************************************
291 *
292 * ixjdebug meanings are now bit mapped instead of level based
293 * Values can be or'ed together to turn on multiple messages
294 *
295 * bit  0 (0x0001) = any failure
296 * bit  1 (0x0002) = general messages
297 * bit  2 (0x0004) = POTS ringing related
298 * bit  3 (0x0008) = PSTN events
299 * bit  4 (0x0010) = PSTN Cadence state details
300 * bit  5 (0x0020) = Tone detection triggers
301 * bit  6 (0x0040) = Tone detection cadence details
302 * bit  7 (0x0080) = ioctl tracking
303 * bit  8 (0x0100) = signal tracking
304 * bit  9 (0x0200) = CallerID generation details
305 *
306 ************************************************************************/
307
308 #ifdef IXJ_DYN_ALLOC
309
310 static IXJ *ixj[IXJMAX];
311 #define get_ixj(b)      ixj[(b)]
312
313 /*
314  *      Allocate a free IXJ device
315  */
316  
317 static IXJ *ixj_alloc()
318 {
319         for(cnt=0; cnt<IXJMAX; cnt++)
320         {
321                 if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
322                 {
323                         j = kmalloc(sizeof(IXJ), GFP_KERNEL);
324                         if (j == NULL)
325                                 return NULL;
326                         ixj[cnt] = j;
327                         return j;
328                 }
329         }
330         return NULL;
331 }
332
333 static void ixj_fsk_free(IXJ *j)
334 {
335         if(j->fskdata != NULL) {
336                 kfree(j->fskdata);
337                 j->fskdata = NULL;
338         }
339 }
340
341 static void ixj_fsk_alloc(IXJ *j)
342 {
343         if(!j->fskdata) {
344                 j->fskdata = kmalloc(8000, GFP_KERNEL);
345                 if (!j->fskdata) {
346                         if(ixjdebug & 0x0200) {
347                                 printk("IXJ phone%d - allocate failed\n", j->board);
348                         }
349                         return;
350                 } else {
351                         j->fsksize = 8000;
352                         if(ixjdebug & 0x0200) {
353                                 printk("IXJ phone%d - allocate succeded\n", j->board);
354                         }
355                 }
356         }
357 }
358
359 #else
360
361 static IXJ ixj[IXJMAX];
362 #define get_ixj(b)      (&ixj[(b)])
363
364 /*
365  *      Allocate a free IXJ device
366  */
367  
368 static IXJ *ixj_alloc(void)
369 {
370         int cnt;
371         for(cnt=0; cnt<IXJMAX; cnt++) {
372                 if(!ixj[cnt].DSPbase)
373                         return &ixj[cnt];
374         }
375         return NULL;
376 }
377
378 static inline void ixj_fsk_free(IXJ *j) {;}
379
380 static inline void ixj_fsk_alloc(IXJ *j)
381 {
382         j->fsksize = 8000;
383 }
384
385 #endif
386
387 #ifdef PERFMON_STATS
388 #define ixj_perfmon(x)  ((x)++)
389 #else
390 #define ixj_perfmon(x)  do { } while(0)
391 #endif
392
393 static int ixj_convert_loaded;
394
395 static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
396
397 /************************************************************************
398 *
399 * These are function definitions to allow external modules to register
400 * enhanced functionality call backs.
401 *
402 ************************************************************************/
403
404 static int Stub(IXJ * J, unsigned long arg)
405 {
406         return 0;
407 }
408
409 static IXJ_REGFUNC ixj_PreRead = &Stub;
410 static IXJ_REGFUNC ixj_PostRead = &Stub;
411 static IXJ_REGFUNC ixj_PreWrite = &Stub;
412 static IXJ_REGFUNC ixj_PostWrite = &Stub;
413
414 static void ixj_read_frame(IXJ *j);
415 static void ixj_write_frame(IXJ *j);
416 static void ixj_init_timer(IXJ *j);
417 static void ixj_add_timer(IXJ * j);
418 static void ixj_timeout(unsigned long ptr);
419 static int read_filters(IXJ *j);
420 static int LineMonitor(IXJ *j);
421 static int ixj_fasync(int fd, struct file *, int mode);
422 static int ixj_set_port(IXJ *j, int arg);
423 static int ixj_set_pots(IXJ *j, int arg);
424 static int ixj_hookstate(IXJ *j);
425 static int ixj_record_start(IXJ *j);
426 static void ixj_record_stop(IXJ *j);
427 static void set_rec_volume(IXJ *j, int volume);
428 static int get_rec_volume(IXJ *j);
429 static int set_rec_codec(IXJ *j, int rate);
430 static void ixj_vad(IXJ *j, int arg);
431 static int ixj_play_start(IXJ *j);
432 static void ixj_play_stop(IXJ *j);
433 static int ixj_set_tone_on(unsigned short arg, IXJ *j);
434 static int ixj_set_tone_off(unsigned short, IXJ *j);
435 static int ixj_play_tone(IXJ *j, char tone);
436 static void ixj_aec_start(IXJ *j, int level);
437 static int idle(IXJ *j);
438 static void ixj_ring_on(IXJ *j);
439 static void ixj_ring_off(IXJ *j);
440 static void aec_stop(IXJ *j);
441 static void ixj_ringback(IXJ *j);
442 static void ixj_busytone(IXJ *j);
443 static void ixj_dialtone(IXJ *j);
444 static void ixj_cpt_stop(IXJ *j);
445 static char daa_int_read(IXJ *j);
446 static char daa_CR_read(IXJ *j, int cr);
447 static int daa_set_mode(IXJ *j, int mode);
448 static int ixj_linetest(IXJ *j);
449 static int ixj_daa_write(IXJ *j);
450 static int ixj_daa_cid_read(IXJ *j);
451 static void DAA_Coeff_US(IXJ *j);
452 static void DAA_Coeff_UK(IXJ *j);
453 static void DAA_Coeff_France(IXJ *j);
454 static void DAA_Coeff_Germany(IXJ *j);
455 static void DAA_Coeff_Australia(IXJ *j);
456 static void DAA_Coeff_Japan(IXJ *j);
457 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
458 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
459 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
460 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
461 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
462 /* Serial Control Interface funtions */
463 static int SCI_Control(IXJ *j, int control);
464 static int SCI_Prepare(IXJ *j);
465 static int SCI_WaitHighSCI(IXJ *j);
466 static int SCI_WaitLowSCI(IXJ *j);
467 static DWORD PCIEE_GetSerialNumber(WORD wAddress);
468 static int ixj_PCcontrol_wait(IXJ *j);
469 static void ixj_pre_cid(IXJ *j);
470 static void ixj_write_cid(IXJ *j);
471 static void ixj_write_cid_bit(IXJ *j, int bit);
472 static int set_base_frame(IXJ *j, int size);
473 static int set_play_codec(IXJ *j, int rate);
474 static void set_rec_depth(IXJ *j, int depth);
475 static int ixj_mixer(long val, IXJ *j);
476
477 /************************************************************************
478 CT8020/CT8021 Host Programmers Model
479 Host address    Function                                        Access
480 DSPbase +
481 0-1             Aux Software Status Register (reserved)         Read Only
482 2-3             Software Status Register                        Read Only
483 4-5             Aux Software Control Register (reserved)        Read Write
484 6-7             Software Control Register                       Read Write
485 8-9             Hardware Status Register                        Read Only
486 A-B             Hardware Control Register                       Read Write
487 C-D Host Transmit (Write) Data Buffer Access Port (buffer input)Write Only
488 E-F Host Recieve (Read) Data Buffer Access Port (buffer input)  Read Only
489 ************************************************************************/
490
491 static inline void ixj_read_HSR(IXJ *j)
492 {
493         j->hsr.bytes.low = inb_p(j->DSPbase + 8);
494         j->hsr.bytes.high = inb_p(j->DSPbase + 9);
495 }
496
497 static inline int IsControlReady(IXJ *j)
498 {
499         ixj_read_HSR(j);
500         return j->hsr.bits.controlrdy ? 1 : 0;
501 }
502
503 static inline int IsPCControlReady(IXJ *j)
504 {
505         j->pccr1.byte = inb_p(j->XILINXbase + 3);
506         return j->pccr1.bits.crr ? 1 : 0;
507 }
508
509 static inline int IsStatusReady(IXJ *j)
510 {
511         ixj_read_HSR(j);
512         return j->hsr.bits.statusrdy ? 1 : 0;
513 }
514
515 static inline int IsRxReady(IXJ *j)
516 {
517         ixj_read_HSR(j);
518         ixj_perfmon(j->rxreadycheck);
519         return j->hsr.bits.rxrdy ? 1 : 0;
520 }
521
522 static inline int IsTxReady(IXJ *j)
523 {
524         ixj_read_HSR(j);
525         ixj_perfmon(j->txreadycheck);
526         return j->hsr.bits.txrdy ? 1 : 0;
527 }
528
529 static inline void set_play_volume(IXJ *j, int volume)
530 {
531         if (ixjdebug & 0x0002)
532                 printk(KERN_INFO "IXJ: /dev/phone%d Setting Play Volume to 0x%4.4x\n", j->board, volume);
533         ixj_WriteDSPCommand(0xCF02, j);
534         ixj_WriteDSPCommand(volume, j);
535 }
536
537 static int set_play_volume_linear(IXJ *j, int volume)
538 {
539         int newvolume, dspplaymax;
540
541         if (ixjdebug & 0x0002)
542                 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Play Volume to 0x%4.4x\n", j->board, volume);
543         if(volume > 100 || volume < 0) {
544                 return -1;
545         }
546
547         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
548         switch (j->cardtype) {
549         case QTI_PHONEJACK:
550                 dspplaymax = 0x380;
551                 break;
552         case QTI_LINEJACK:
553                 if(j->port == PORT_PSTN) {
554                         dspplaymax = 0x48;
555                 } else {
556                         dspplaymax = 0x100;
557                 }
558                 break;
559         case QTI_PHONEJACK_LITE:
560                 dspplaymax = 0x380;
561                 break;
562         case QTI_PHONEJACK_PCI:
563                 dspplaymax = 0x6C;
564                 break;
565         case QTI_PHONECARD:
566                 dspplaymax = 0x50;
567                 break;
568         default:
569                 return -1;
570         }
571         newvolume = (dspplaymax * volume) / 100;
572         set_play_volume(j, newvolume);
573         return 0;
574 }
575
576 static inline void set_play_depth(IXJ *j, int depth)
577 {
578         if (depth > 60)
579                 depth = 60;
580         if (depth < 0)
581                 depth = 0;
582         ixj_WriteDSPCommand(0x5280 + depth, j);
583 }
584
585 static inline int get_play_volume(IXJ *j)
586 {
587         ixj_WriteDSPCommand(0xCF00, j);
588         return j->ssr.high << 8 | j->ssr.low;
589 }
590
591 static int get_play_volume_linear(IXJ *j)
592 {
593         int volume, newvolume, dspplaymax;
594
595         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
596         switch (j->cardtype) {
597         case QTI_PHONEJACK:
598                 dspplaymax = 0x380;
599                 break;
600         case QTI_LINEJACK:
601                 if(j->port == PORT_PSTN) {
602                         dspplaymax = 0x48;
603                 } else {
604                         dspplaymax = 0x100;
605                 }
606                 break;
607         case QTI_PHONEJACK_LITE:
608                 dspplaymax = 0x380;
609                 break;
610         case QTI_PHONEJACK_PCI:
611                 dspplaymax = 0x6C;
612                 break;
613         case QTI_PHONECARD:
614                 dspplaymax = 100;
615                 break;
616         default:
617                 return -1;
618         }
619         volume = get_play_volume(j);
620         newvolume = (volume * 100) / dspplaymax;
621         if(newvolume > 100)
622                 newvolume = 100;
623         return newvolume;
624 }
625
626 static inline BYTE SLIC_GetState(IXJ *j)
627 {
628         if (j->cardtype == QTI_PHONECARD) {
629                 j->pccr1.byte = 0;
630                 j->psccr.bits.dev = 3;
631                 j->psccr.bits.rw = 1;
632                 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
633                 ixj_PCcontrol_wait(j);
634                 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
635                 ixj_PCcontrol_wait(j);
636                 if (j->pslic.bits.powerdown)
637                         return PLD_SLIC_STATE_OC;
638                 else if (!j->pslic.bits.ring0 && !j->pslic.bits.ring1)
639                         return PLD_SLIC_STATE_ACTIVE;
640                 else
641                         return PLD_SLIC_STATE_RINGING;
642         } else {
643                 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
644         }
645         return j->pld_slicr.bits.state;
646 }
647
648 static BOOL SLIC_SetState(BYTE byState, IXJ *j)
649 {
650         BOOL fRetVal = FALSE;
651
652         if (j->cardtype == QTI_PHONECARD) {
653                 if (j->flags.pcmciasct) {
654                         switch (byState) {
655                         case PLD_SLIC_STATE_TIPOPEN:
656                         case PLD_SLIC_STATE_OC:
657                                 j->pslic.bits.powerdown = 1;
658                                 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
659                                 fRetVal = TRUE;
660                                 break;
661                         case PLD_SLIC_STATE_RINGING:
662                                 if (j->readers || j->writers) {
663                                         j->pslic.bits.powerdown = 0;
664                                         j->pslic.bits.ring0 = 1;
665                                         j->pslic.bits.ring1 = 0;
666                                         fRetVal = TRUE;
667                                 }
668                                 break;
669                         case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
670
671                         case PLD_SLIC_STATE_STANDBY:
672                         case PLD_SLIC_STATE_ACTIVE:
673                                 if (j->readers || j->writers) {
674                                         j->pslic.bits.powerdown = 0;
675                                 } else {
676                                         j->pslic.bits.powerdown = 1;
677                                 }
678                                 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
679                                 fRetVal = TRUE;
680                                 break;
681                         case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
682
683                         case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
684
685                         default:
686                                 fRetVal = FALSE;
687                                 break;
688                         }
689                         j->psccr.bits.dev = 3;
690                         j->psccr.bits.rw = 0;
691                         outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
692                         ixj_PCcontrol_wait(j);
693                 }
694         } else {
695                 /* Set the C1, C2, C3 & B2EN signals. */
696                 switch (byState) {
697                 case PLD_SLIC_STATE_OC:
698                         j->pld_slicw.bits.c1 = 0;
699                         j->pld_slicw.bits.c2 = 0;
700                         j->pld_slicw.bits.c3 = 0;
701                         j->pld_slicw.bits.b2en = 0;
702                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
703                         fRetVal = TRUE;
704                         break;
705                 case PLD_SLIC_STATE_RINGING:
706                         j->pld_slicw.bits.c1 = 1;
707                         j->pld_slicw.bits.c2 = 0;
708                         j->pld_slicw.bits.c3 = 0;
709                         j->pld_slicw.bits.b2en = 1;
710                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
711                         fRetVal = TRUE;
712                         break;
713                 case PLD_SLIC_STATE_ACTIVE:
714                         j->pld_slicw.bits.c1 = 0;
715                         j->pld_slicw.bits.c2 = 1;
716                         j->pld_slicw.bits.c3 = 0;
717                         j->pld_slicw.bits.b2en = 0;
718                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
719                         fRetVal = TRUE;
720                         break;
721                 case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
722
723                         j->pld_slicw.bits.c1 = 1;
724                         j->pld_slicw.bits.c2 = 1;
725                         j->pld_slicw.bits.c3 = 0;
726                         j->pld_slicw.bits.b2en = 0;
727                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
728                         fRetVal = TRUE;
729                         break;
730                 case PLD_SLIC_STATE_TIPOPEN:
731                         j->pld_slicw.bits.c1 = 0;
732                         j->pld_slicw.bits.c2 = 0;
733                         j->pld_slicw.bits.c3 = 1;
734                         j->pld_slicw.bits.b2en = 0;
735                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
736                         fRetVal = TRUE;
737                         break;
738                 case PLD_SLIC_STATE_STANDBY:
739                         j->pld_slicw.bits.c1 = 1;
740                         j->pld_slicw.bits.c2 = 0;
741                         j->pld_slicw.bits.c3 = 1;
742                         j->pld_slicw.bits.b2en = 1;
743                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
744                         fRetVal = TRUE;
745                         break;
746                 case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
747
748                         j->pld_slicw.bits.c1 = 0;
749                         j->pld_slicw.bits.c2 = 1;
750                         j->pld_slicw.bits.c3 = 1;
751                         j->pld_slicw.bits.b2en = 0;
752                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
753                         fRetVal = TRUE;
754                         break;
755                 case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
756
757                         j->pld_slicw.bits.c1 = 1;
758                         j->pld_slicw.bits.c2 = 1;
759                         j->pld_slicw.bits.c3 = 1;
760                         j->pld_slicw.bits.b2en = 0;
761                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
762                         fRetVal = TRUE;
763                         break;
764                 default:
765                         fRetVal = FALSE;
766                         break;
767                 }
768         }
769
770         return fRetVal;
771 }
772
773 static int ixj_wink(IXJ *j)
774 {
775         BYTE slicnow;
776
777         slicnow = SLIC_GetState(j);
778
779         j->pots_winkstart = jiffies;
780         SLIC_SetState(PLD_SLIC_STATE_OC, j);
781
782         while (time_before(jiffies, j->pots_winkstart + j->winktime)) {
783                 set_current_state(TASK_INTERRUPTIBLE);
784                 schedule_timeout(1);
785         }
786
787         SLIC_SetState(slicnow, j);
788         return 0;
789 }
790
791 static void ixj_init_timer(IXJ *j)
792 {
793         init_timer(&j->timer);
794         j->timer.function = ixj_timeout;
795         j->timer.data = (unsigned long)j;
796 }
797
798 static void ixj_add_timer(IXJ *j)
799 {
800         j->timer.expires = jiffies + (hertz / samplerate);
801         add_timer(&j->timer);
802 }
803
804 static void ixj_tone_timeout(IXJ *j)
805 {
806         IXJ_TONE ti;
807
808         j->tone_state++;
809         if (j->tone_state == 3) {
810                 j->tone_state = 0;
811                 if (j->cadence_t) {
812                         j->tone_cadence_state++;
813                         if (j->tone_cadence_state >= j->cadence_t->elements_used) {
814                                 switch (j->cadence_t->termination) {
815                                 case PLAY_ONCE:
816                                         ixj_cpt_stop(j);
817                                         break;
818                                 case REPEAT_LAST_ELEMENT:
819                                         j->tone_cadence_state--;
820                                         ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
821                                         break;
822                                 case REPEAT_ALL:
823                                         j->tone_cadence_state = 0;
824                                         if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
825                                                 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
826                                                 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
827                                                 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
828                                                 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
829                                                 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
830                                                 ixj_init_tone(j, &ti);
831                                         }
832                                         ixj_set_tone_on(j->cadence_t->ce[0].tone_on_time, j);
833                                         ixj_set_tone_off(j->cadence_t->ce[0].tone_off_time, j);
834                                         ixj_play_tone(j, j->cadence_t->ce[0].index);
835                                         break;
836                                 }
837                         } else {
838                                 if (j->cadence_t->ce[j->tone_cadence_state].gain0) {
839                                         ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
840                                         ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
841                                         ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
842                                         ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
843                                         ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
844                                         ixj_init_tone(j, &ti);
845                                 }
846                                 ixj_set_tone_on(j->cadence_t->ce[j->tone_cadence_state].tone_on_time, j);
847                                 ixj_set_tone_off(j->cadence_t->ce[j->tone_cadence_state].tone_off_time, j);
848                                 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
849                         }
850                 }
851         }
852 }
853
854 static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
855 {
856         if(j->ixj_signals[event]) {
857                 if(ixjdebug & 0x0100)
858                         printk("Sending signal for event %d\n", event);
859                         /* Send apps notice of change */
860                 /* see config.h for macro definition */
861                 kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
862         }
863 }
864
865 static void ixj_pstn_state(IXJ *j)
866 {
867         int var;
868         union XOPXR0 XR0, daaint;
869
870         var = 10;
871
872         XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
873         daaint.reg = 0;
874         XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
875
876         j->pld_scrr.byte = inb_p(j->XILINXbase);
877         if (j->pld_scrr.bits.daaflag) {
878                 daa_int_read(j);
879                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.RING) {
880                         if(time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
881                                 daaint.bitreg.RING = 1;
882                                 if(ixjdebug & 0x0008) {
883                                         printk(KERN_INFO "IXJ DAA Ring Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
884                                 }
885                         } else {
886                                 daa_set_mode(j, SOP_PU_RESET);
887                         }
888                 }
889                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Caller_ID) {
890                         daaint.bitreg.Caller_ID = 1;
891                         j->pstn_cid_intr = 1;
892                         j->pstn_cid_received = jiffies;
893                         if(ixjdebug & 0x0008) {
894                                 printk(KERN_INFO "IXJ DAA Caller_ID Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
895                         }
896                 }
897                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Cadence) {
898                         daaint.bitreg.Cadence = 1;
899                         if(ixjdebug & 0x0008) {
900                                 printk(KERN_INFO "IXJ DAA Cadence Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
901                         }
902                 }
903                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK != XR0.bitreg.VDD_OK) {
904                         daaint.bitreg.VDD_OK = 1;
905                         daaint.bitreg.SI_0 = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK;
906                 }
907         }
908         daa_CR_read(j, 1);
909         if(j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR != XR0.bitreg.RMR && time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
910                 daaint.bitreg.RMR = 1;
911                 daaint.bitreg.SI_1 = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
912                 if(ixjdebug & 0x0008) {
913                         printk(KERN_INFO "IXJ DAA RMR /dev/phone%d was %s for %ld\n", j->board, XR0.bitreg.RMR?"on":"off", jiffies - j->pstn_last_rmr);
914                 }
915                 j->pstn_prev_rmr = j->pstn_last_rmr;
916                 j->pstn_last_rmr = jiffies;
917         }
918         switch(j->daa_mode) {
919                 case SOP_PU_SLEEP:
920                         if (daaint.bitreg.RING) {
921                                 if (!j->flags.pstn_ringing) {
922                                         if (j->daa_mode != SOP_PU_RINGING) {
923                                                 j->pstn_ring_int = jiffies;
924                                                 daa_set_mode(j, SOP_PU_RINGING);
925                                         }
926                                 }
927                         }
928                         break;
929                 case SOP_PU_RINGING:
930                         if (daaint.bitreg.RMR) {
931                                 if (ixjdebug & 0x0008) {
932                                         printk(KERN_INFO "IXJ Ring Cadence a state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
933                                 }
934                                 if (daaint.bitreg.SI_1) {                /* Rising edge of RMR */
935                                         j->flags.pstn_rmr = 1;
936                                         j->pstn_ring_start = jiffies;
937                                         j->pstn_ring_stop = 0;
938                                         j->ex.bits.pstn_ring = 0;
939                                         if (j->cadence_f[4].state == 0) {
940                                                 j->cadence_f[4].state = 1;
941                                                 j->cadence_f[4].on1min = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 - var)) / 10000);
942                                                 j->cadence_f[4].on1dot = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100)) / 10000);
943                                                 j->cadence_f[4].on1max = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 + var)) / 10000);
944                                         } else if (j->cadence_f[4].state == 2) {
945                                                 if((time_after(jiffies, j->cadence_f[4].off1min) &&
946                                                     time_before(jiffies, j->cadence_f[4].off1max))) {
947                                                         if (j->cadence_f[4].on2) {
948                                                                 j->cadence_f[4].state = 3;
949                                                                 j->cadence_f[4].on2min = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 - var)) / 10000));
950                                                                 j->cadence_f[4].on2dot = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100)) / 10000));
951                                                                 j->cadence_f[4].on2max = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 + var)) / 10000));
952                                                         } else {
953                                                                 j->cadence_f[4].state = 7;
954                                                         }
955                                                 } else {
956                                                         if (ixjdebug & 0x0008) {
957                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
958                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
959                                                                                 j->cadence_f[4].off1);
960                                                         }
961                                                         j->cadence_f[4].state = 0;
962                                                 }
963                                         } else if (j->cadence_f[4].state == 4) {
964                                                 if((time_after(jiffies, j->cadence_f[4].off2min) &&
965                                                     time_before(jiffies, j->cadence_f[4].off2max))) {
966                                                         if (j->cadence_f[4].on3) {
967                                                                 j->cadence_f[4].state = 5;
968                                                                 j->cadence_f[4].on3min = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 - var)) / 10000));
969                                                                 j->cadence_f[4].on3dot = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100)) / 10000));
970                                                                 j->cadence_f[4].on3max = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 + var)) / 10000));
971                                                         } else {
972                                                                 j->cadence_f[4].state = 7;
973                                                         }
974                                                 } else {
975                                                         if (ixjdebug & 0x0008) {
976                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
977                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
978                                                                                 j->cadence_f[4].off2);
979                                                         }
980                                                         j->cadence_f[4].state = 0;
981                                                 }
982                                         } else if (j->cadence_f[4].state == 6) {
983                                                 if((time_after(jiffies, j->cadence_f[4].off3min) &&
984                                                     time_before(jiffies, j->cadence_f[4].off3max))) {
985                                                         j->cadence_f[4].state = 7;
986                                                 } else {
987                                                         if (ixjdebug & 0x0008) {
988                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
989                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
990                                                                                 j->cadence_f[4].off3);
991                                                         }
992                                                         j->cadence_f[4].state = 0;
993                                                 }
994                                         } else {
995                                                 j->cadence_f[4].state = 0;
996                                         }
997                                 } else {                                /* Falling edge of RMR */
998                                         j->pstn_ring_start = 0;
999                                         j->pstn_ring_stop = jiffies;
1000                                         if (j->cadence_f[4].state == 1) {
1001                                                 if(!j->cadence_f[4].on1) {
1002                                                         j->cadence_f[4].state = 7;
1003                                                 } else if((time_after(jiffies, j->cadence_f[4].on1min) &&
1004                                                   time_before(jiffies, j->cadence_f[4].on1max))) {
1005                                                         if (j->cadence_f[4].off1) {
1006                                                                 j->cadence_f[4].state = 2;
1007                                                                 j->cadence_f[4].off1min = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 - var)) / 10000));
1008                                                                 j->cadence_f[4].off1dot = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100)) / 10000));
1009                                                                 j->cadence_f[4].off1max = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 + var)) / 10000));
1010                                                         } else {
1011                                                                 j->cadence_f[4].state = 7;
1012                                                         }
1013                                                 } else {
1014                                                         if (ixjdebug & 0x0008) {
1015                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1016                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1017                                                                                 j->cadence_f[4].on1);
1018                                                         }
1019                                                         j->cadence_f[4].state = 0;
1020                                                 }
1021                                         } else if (j->cadence_f[4].state == 3) {
1022                                                 if((time_after(jiffies, j->cadence_f[4].on2min) &&
1023                                                     time_before(jiffies, j->cadence_f[4].on2max))) {
1024                                                         if (j->cadence_f[4].off2) {
1025                                                                 j->cadence_f[4].state = 4;
1026                                                                 j->cadence_f[4].off2min = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 - var)) / 10000));
1027                                                                 j->cadence_f[4].off2dot = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100)) / 10000));
1028                                                                 j->cadence_f[4].off2max = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 + var)) / 10000));
1029                                                         } else {
1030                                                                 j->cadence_f[4].state = 7;
1031                                                         }
1032                                                 } else {
1033                                                         if (ixjdebug & 0x0008) {
1034                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1035                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1036                                                                                 j->cadence_f[4].on2);
1037                                                         }
1038                                                         j->cadence_f[4].state = 0;
1039                                                 }
1040                                         } else if (j->cadence_f[4].state == 5) {
1041                                                 if((time_after(jiffies, j->cadence_f[4].on3min) &&
1042                                                     time_before(jiffies, j->cadence_f[4].on3max))) {
1043                                                         if (j->cadence_f[4].off3) {
1044                                                                 j->cadence_f[4].state = 6;
1045                                                                 j->cadence_f[4].off3min = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 - var)) / 10000));
1046                                                                 j->cadence_f[4].off3dot = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100)) / 10000));
1047                                                                 j->cadence_f[4].off3max = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 + var)) / 10000));
1048                                                         } else {
1049                                                                 j->cadence_f[4].state = 7;
1050                                                         }
1051                                                 } else {
1052                                                         j->cadence_f[4].state = 0;
1053                                                 }
1054                                         } else {
1055                                                 if (ixjdebug & 0x0008) {
1056                                                         printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1057                                                                         j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1058                                                                         j->cadence_f[4].on3);
1059                                                 }
1060                                                 j->cadence_f[4].state = 0;
1061                                         }
1062                                 }
1063                                 if (ixjdebug & 0x0010) {
1064                                         printk(KERN_INFO "IXJ Ring Cadence b state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
1065                                 }
1066                                 if (ixjdebug & 0x0010) {
1067                                         switch(j->cadence_f[4].state) {
1068                                                 case 1:
1069                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1070                                                 j->cadence_f[4].on1, j->cadence_f[4].on1min, j->cadence_f[4].on1dot, j->cadence_f[4].on1max);
1071                                                         break;
1072                                                 case 2:
1073                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1074                                                 j->cadence_f[4].off1, j->cadence_f[4].off1min, j->cadence_f[4].off1dot, j->cadence_f[4].off1max);
1075                                                         break;
1076                                                 case 3:
1077                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1078                                                 j->cadence_f[4].on2, j->cadence_f[4].on2min, j->cadence_f[4].on2dot, j->cadence_f[4].on2max);
1079                                                         break;
1080                                                 case 4:
1081                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1082                                                 j->cadence_f[4].off2, j->cadence_f[4].off2min, j->cadence_f[4].off2dot, j->cadence_f[4].off2max);
1083                                                         break;
1084                                                 case 5:
1085                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1086                                                 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max);
1087                                                         break;
1088                                                 case 6: 
1089                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1090                                                 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max);
1091                                                         break;
1092                                         }
1093                                 }
1094                         }
1095                         if (j->cadence_f[4].state == 7) {
1096                                 j->cadence_f[4].state = 0;
1097                                 j->pstn_ring_stop = jiffies;
1098                                 j->ex.bits.pstn_ring = 1;
1099                                 ixj_kill_fasync(j, SIG_PSTN_RING, POLL_IN);
1100                                 if(ixjdebug & 0x0008) {
1101                                         printk(KERN_INFO "IXJ Ring int set /dev/phone%d at %ld\n", j->board, jiffies);
1102                                 }
1103                         }
1104                         if((j->pstn_ring_int != 0 && time_after(jiffies, j->pstn_ring_int + (hertz * 5)) && !j->flags.pstn_rmr) ||
1105                            (j->pstn_ring_stop != 0 && time_after(jiffies, j->pstn_ring_stop + (hertz * 5)))) {
1106                                 if(ixjdebug & 0x0008) {
1107                                         printk("IXJ DAA no ring in 5 seconds /dev/phone%d at %ld\n", j->board, jiffies);
1108                                         printk("IXJ DAA pstn ring int /dev/phone%d at %ld\n", j->board, j->pstn_ring_int);
1109                                         printk("IXJ DAA pstn ring stop /dev/phone%d at %ld\n", j->board, j->pstn_ring_stop);
1110                                 }
1111                                 j->pstn_ring_stop = j->pstn_ring_int = 0;
1112                                 daa_set_mode(j, SOP_PU_SLEEP);
1113                         } 
1114                         outb_p(j->pld_scrw.byte, j->XILINXbase);
1115                         if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) {
1116                                 ixj_daa_cid_read(j);
1117                                 j->ex.bits.caller_id = 1;
1118                                 ixj_kill_fasync(j, SIG_CALLER_ID, POLL_IN);
1119                                 j->pstn_cid_intr = 0;
1120                         }
1121                         if (daaint.bitreg.Cadence) {
1122                                 if(ixjdebug & 0x0008) {
1123                                         printk("IXJ DAA Cadence interrupt going to sleep /dev/phone%d\n", j->board);
1124                                 }
1125                                 daa_set_mode(j, SOP_PU_SLEEP);
1126                                 j->ex.bits.pstn_ring = 0;
1127                         }
1128                         break;
1129                 case SOP_PU_CONVERSATION:
1130                         if (daaint.bitreg.VDD_OK) {
1131                                 if(!daaint.bitreg.SI_0) {
1132                                         if (!j->pstn_winkstart) {
1133                                                 if(ixjdebug & 0x0008) {
1134                                                         printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies);
1135                                                 }
1136                                                 j->pstn_winkstart = jiffies;
1137                                         } 
1138                                 } else {
1139                                         if (j->pstn_winkstart) {
1140                                                 if(ixjdebug & 0x0008) {
1141                                                         printk("IXJ DAA possible wink end /dev/phone%d %ld\n", j->board, jiffies);
1142                                                 }
1143                                                 j->pstn_winkstart = 0;
1144                                         }
1145                                 }
1146                         }
1147                         if (j->pstn_winkstart && time_after(jiffies, j->pstn_winkstart + ((hertz * j->winktime) / 1000))) {
1148                                 if(ixjdebug & 0x0008) {
1149                                         printk("IXJ DAA wink detected going to sleep /dev/phone%d %ld\n", j->board, jiffies);
1150                                 }
1151                                 daa_set_mode(j, SOP_PU_SLEEP);
1152                                 j->pstn_winkstart = 0;
1153                                 j->ex.bits.pstn_wink = 1;
1154                                 ixj_kill_fasync(j, SIG_PSTN_WINK, POLL_IN);
1155                         }
1156                         break;
1157         }
1158 }
1159
1160 static void ixj_timeout(unsigned long ptr)
1161 {
1162         int board;
1163         unsigned long jifon;
1164         IXJ *j = (IXJ *)ptr;
1165         board = j->board;
1166
1167         if (j->DSPbase && atomic_read(&j->DSPWrite) == 0 && test_and_set_bit(board, (void *)&j->busyflags) == 0) {
1168                 ixj_perfmon(j->timerchecks);
1169                 j->hookstate = ixj_hookstate(j);
1170                 if (j->tone_state) {
1171                         if (!(j->hookstate)) {
1172                                 ixj_cpt_stop(j);
1173                                 if (j->m_hook) {
1174                                         j->m_hook = 0;
1175                                         j->ex.bits.hookstate = 1;
1176                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1177                                 }
1178                                 clear_bit(board, &j->busyflags);
1179                                 ixj_add_timer(j);
1180                                 return;
1181                         }
1182                         if (j->tone_state == 1)
1183                                 jifon = ((hertz * j->tone_on_time) * 25 / 100000);
1184                         else
1185                                 jifon = ((hertz * j->tone_on_time) * 25 / 100000) + ((hertz * j->tone_off_time) * 25 / 100000);
1186                         if (time_before(jiffies, j->tone_start_jif + jifon)) {
1187                                 if (j->tone_state == 1) {
1188                                         ixj_play_tone(j, j->tone_index);
1189                                         if (j->dsp.low == 0x20) {
1190                                                 clear_bit(board, &j->busyflags);
1191                                                 ixj_add_timer(j);
1192                                                 return;
1193                                         }
1194                                 } else {
1195                                         ixj_play_tone(j, 0);
1196                                         if (j->dsp.low == 0x20) {
1197                                                 clear_bit(board, &j->busyflags);
1198                                                 ixj_add_timer(j);
1199                                                 return;
1200                                         }
1201                                 }
1202                         } else {
1203                                 ixj_tone_timeout(j);
1204                                 if (j->flags.dialtone) {
1205                                         ixj_dialtone(j);
1206                                 }
1207                                 if (j->flags.busytone) {
1208                                         ixj_busytone(j);
1209                                         if (j->dsp.low == 0x20) {
1210                                                 clear_bit(board, &j->busyflags);
1211                                                 ixj_add_timer(j);
1212                                                 return;
1213                                         }
1214                                 }
1215                                 if (j->flags.ringback) {
1216                                         ixj_ringback(j);
1217                                         if (j->dsp.low == 0x20) {
1218                                                 clear_bit(board, &j->busyflags);
1219                                                 ixj_add_timer(j);
1220                                                 return;
1221                                         }
1222                                 }
1223                                 if (!j->tone_state) {
1224                                         ixj_cpt_stop(j);
1225                                 }
1226                         }
1227                 }
1228                 if (!(j->tone_state && j->dsp.low == 0x20)) {
1229                         if (IsRxReady(j)) {
1230                                 ixj_read_frame(j);
1231                         }
1232                         if (IsTxReady(j)) {
1233                                 ixj_write_frame(j);
1234                         }
1235                 }
1236                 if (j->flags.cringing) {
1237                         if (j->hookstate & 1) {
1238                                 j->flags.cringing = 0;
1239                                 ixj_ring_off(j);
1240                         } else if(j->cadence_f[5].enable && ((!j->cadence_f[5].en_filter) || (j->cadence_f[5].en_filter && j->flags.firstring))) {
1241                                 switch(j->cadence_f[5].state) {
1242                                         case 0:
1243                                                 j->cadence_f[5].on1dot = jiffies + (long)((j->cadence_f[5].on1 * (hertz * 100) / 10000));
1244                                                 if (time_before(jiffies, j->cadence_f[5].on1dot)) {
1245                                                         if(ixjdebug & 0x0004) {
1246                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1247                                                         }
1248                                                         ixj_ring_on(j);
1249                                                 }
1250                                                 j->cadence_f[5].state = 1;
1251                                                 break;
1252                                         case 1:
1253                                                 if (time_after(jiffies, j->cadence_f[5].on1dot)) {
1254                                                         j->cadence_f[5].off1dot = jiffies + (long)((j->cadence_f[5].off1 * (hertz * 100) / 10000));
1255                                                         if(ixjdebug & 0x0004) {
1256                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1257                                                         }
1258                                                         ixj_ring_off(j);
1259                                                         j->cadence_f[5].state = 2;
1260                                                 }
1261                                                 break;
1262                                         case 2:
1263                                                 if (time_after(jiffies, j->cadence_f[5].off1dot)) {
1264                                                         if(ixjdebug & 0x0004) {
1265                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1266                                                         }
1267                                                         ixj_ring_on(j);
1268                                                         if (j->cadence_f[5].on2) {
1269                                                                 j->cadence_f[5].on2dot = jiffies + (long)((j->cadence_f[5].on2 * (hertz * 100) / 10000));
1270                                                                 j->cadence_f[5].state = 3;
1271                                                         } else {
1272                                                                 j->cadence_f[5].state = 7;
1273                                                         }
1274                                                 }
1275                                                 break;
1276                                         case 3:
1277                                                 if (time_after(jiffies, j->cadence_f[5].on2dot)) {
1278                                                         if(ixjdebug & 0x0004) {
1279                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1280                                                         }
1281                                                         ixj_ring_off(j);
1282                                                         if (j->cadence_f[5].off2) {
1283                                                                 j->cadence_f[5].off2dot = jiffies + (long)((j->cadence_f[5].off2 * (hertz * 100) / 10000));
1284                                                                 j->cadence_f[5].state = 4;
1285                                                         } else {
1286                                                                 j->cadence_f[5].state = 7;
1287                                                         }
1288                                                 }
1289                                                 break;
1290                                         case 4:
1291                                                 if (time_after(jiffies, j->cadence_f[5].off2dot)) {
1292                                                         if(ixjdebug & 0x0004) {
1293                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1294                                                         }
1295                                                         ixj_ring_on(j);
1296                                                         if (j->cadence_f[5].on3) {
1297                                                                 j->cadence_f[5].on3dot = jiffies + (long)((j->cadence_f[5].on3 * (hertz * 100) / 10000));
1298                                                                 j->cadence_f[5].state = 5;
1299                                                         } else {
1300                                                                 j->cadence_f[5].state = 7;
1301                                                         }
1302                                                 }
1303                                                 break;
1304                                         case 5:
1305                                                 if (time_after(jiffies, j->cadence_f[5].on3dot)) {
1306                                                         if(ixjdebug & 0x0004) {
1307                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1308                                                         }
1309                                                         ixj_ring_off(j);
1310                                                         if (j->cadence_f[5].off3) {
1311                                                                 j->cadence_f[5].off3dot = jiffies + (long)((j->cadence_f[5].off3 * (hertz * 100) / 10000));
1312                                                                 j->cadence_f[5].state = 6;
1313                                                         } else {
1314                                                                 j->cadence_f[5].state = 7;
1315                                                         }
1316                                                 }
1317                                                 break;
1318                                         case 6:
1319                                                 if (time_after(jiffies, j->cadence_f[5].off3dot)) {
1320                                                         if(ixjdebug & 0x0004) {
1321                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1322                                                         }
1323                                                         j->cadence_f[5].state = 7;
1324                                                 }
1325                                                 break;
1326                                         case 7:
1327                                                 if(ixjdebug & 0x0004) {
1328                                                         printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1329                                                 }
1330                                                 j->flags.cidring = 1;
1331                                                 j->cadence_f[5].state = 0;
1332                                                 break;
1333                                 }
1334                                 if (j->flags.cidring && !j->flags.cidsent) {
1335                                         j->flags.cidsent = 1;
1336                                         if(j->fskdcnt) {
1337                                                 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1338                                                 ixj_pre_cid(j);
1339                                         }
1340                                         j->flags.cidring = 0;
1341                                 }
1342                                 clear_bit(board, &j->busyflags);
1343                                 ixj_add_timer(j);
1344                                 return;
1345                         } else {
1346                                 if (time_after(jiffies, j->ring_cadence_jif + (hertz / 2))) {
1347                                         if (j->flags.cidring && !j->flags.cidsent) {
1348                                                 j->flags.cidsent = 1;
1349                                                 if(j->fskdcnt) {
1350                                                         SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1351                                                         ixj_pre_cid(j);
1352                                                 }
1353                                                 j->flags.cidring = 0;
1354                                         }
1355                                         j->ring_cadence_t--;
1356                                         if (j->ring_cadence_t == -1)
1357                                                 j->ring_cadence_t = 15;
1358                                         j->ring_cadence_jif = jiffies;
1359
1360                                         if (j->ring_cadence & 1 << j->ring_cadence_t) {
1361                                                 if(j->flags.cidsent && j->cadence_f[5].en_filter)
1362                                                         j->flags.firstring = 1;
1363                                                 else
1364                                                         ixj_ring_on(j);
1365                                         } else {
1366                                                 ixj_ring_off(j);
1367                                                 if(!j->flags.cidsent)
1368                                                         j->flags.cidring = 1;
1369                                         }
1370                                 }
1371                                 clear_bit(board, &j->busyflags);
1372                                 ixj_add_timer(j);
1373                                 return;
1374                         }
1375                 }
1376                 if (!j->flags.ringing) {
1377                         if (j->hookstate) { /* & 1) { */
1378                                 if (j->dsp.low != 0x20 &&
1379                                     SLIC_GetState(j) != PLD_SLIC_STATE_ACTIVE) {
1380                                         SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1381                                 }
1382                                 LineMonitor(j);
1383                                 read_filters(j);
1384                                 ixj_WriteDSPCommand(0x511B, j);
1385                                 j->proc_load = j->ssr.high << 8 | j->ssr.low;
1386                                 if (!j->m_hook && (j->hookstate & 1)) {
1387                                         j->m_hook = j->ex.bits.hookstate = 1;
1388                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1389                                 }
1390                         } else {
1391                                 if (j->ex.bits.dtmf_ready) {
1392                                         j->dtmf_wp = j->dtmf_rp = j->ex.bits.dtmf_ready = 0;
1393                                 }
1394                                 if (j->m_hook) {
1395                                         j->m_hook = 0;
1396                                         j->ex.bits.hookstate = 1;
1397                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1398                                 }
1399                         }
1400                 }
1401                 if (j->cardtype == QTI_LINEJACK && !j->flags.pstncheck && j->flags.pstn_present) {
1402                         ixj_pstn_state(j);
1403                 }
1404                 if (j->ex.bytes) {
1405                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
1406                 }
1407                 clear_bit(board, &j->busyflags);
1408         }
1409         ixj_add_timer(j);
1410 }
1411
1412 static int ixj_status_wait(IXJ *j)
1413 {
1414         unsigned long jif;
1415
1416         jif = jiffies + ((60 * hertz) / 100);
1417         while (!IsStatusReady(j)) {
1418                 ixj_perfmon(j->statuswait);
1419                 if (time_after(jiffies, jif)) {
1420                         ixj_perfmon(j->statuswaitfail);
1421                         return -1;
1422                 }
1423         }
1424         return 0;
1425 }
1426
1427 static int ixj_PCcontrol_wait(IXJ *j)
1428 {
1429         unsigned long jif;
1430
1431         jif = jiffies + ((60 * hertz) / 100);
1432         while (!IsPCControlReady(j)) {
1433                 ixj_perfmon(j->pcontrolwait);
1434                 if (time_after(jiffies, jif)) {
1435                         ixj_perfmon(j->pcontrolwaitfail);
1436                         return -1;
1437                 }
1438         }
1439         return 0;
1440 }
1441
1442 static int ixj_WriteDSPCommand(unsigned short cmd, IXJ *j)
1443 {
1444         BYTES bytes;
1445         unsigned long jif;
1446
1447         atomic_inc(&j->DSPWrite);
1448         if(atomic_read(&j->DSPWrite) > 1) {
1449                 printk("IXJ %d DSP write overlap attempting command 0x%4.4x\n", j->board, cmd);
1450                 return -1;
1451         }
1452         bytes.high = (cmd & 0xFF00) >> 8;
1453         bytes.low = cmd & 0x00FF;
1454         jif = jiffies + ((60 * hertz) / 100);
1455         while (!IsControlReady(j)) {
1456                 ixj_perfmon(j->iscontrolready);
1457                 if (time_after(jiffies, jif)) {
1458                         ixj_perfmon(j->iscontrolreadyfail);
1459                         atomic_dec(&j->DSPWrite);
1460                         if(atomic_read(&j->DSPWrite) > 0) {
1461                                 printk("IXJ %d DSP overlaped command 0x%4.4x during control ready failure.\n", j->board, cmd);
1462                                 while(atomic_read(&j->DSPWrite) > 0) {
1463                                         atomic_dec(&j->DSPWrite);
1464                                 }
1465                         }
1466                         return -1;
1467                 }
1468         }
1469         outb(bytes.low, j->DSPbase + 6);
1470         outb(bytes.high, j->DSPbase + 7);
1471
1472         if (ixj_status_wait(j)) {
1473                 j->ssr.low = 0xFF;
1474                 j->ssr.high = 0xFF;
1475                 atomic_dec(&j->DSPWrite);
1476                 if(atomic_read(&j->DSPWrite) > 0) {
1477                         printk("IXJ %d DSP overlaped command 0x%4.4x during status wait failure.\n", j->board, cmd);
1478                         while(atomic_read(&j->DSPWrite) > 0) {
1479                                 atomic_dec(&j->DSPWrite);
1480                         }
1481                 }
1482                 return -1;
1483         }
1484 /* Read Software Status Register */
1485         j->ssr.low = inb_p(j->DSPbase + 2);
1486         j->ssr.high = inb_p(j->DSPbase + 3);
1487         atomic_dec(&j->DSPWrite);
1488         if(atomic_read(&j->DSPWrite) > 0) {
1489                 printk("IXJ %d DSP overlaped command 0x%4.4x\n", j->board, cmd);
1490                 while(atomic_read(&j->DSPWrite) > 0) {
1491                         atomic_dec(&j->DSPWrite);
1492                 }
1493         }
1494         return 0;
1495 }
1496
1497 /***************************************************************************
1498 *
1499 *  General Purpose IO Register read routine
1500 *
1501 ***************************************************************************/
1502 static inline int ixj_gpio_read(IXJ *j)
1503 {
1504         if (ixj_WriteDSPCommand(0x5143, j))
1505                 return -1;
1506
1507         j->gpio.bytes.low = j->ssr.low;
1508         j->gpio.bytes.high = j->ssr.high;
1509
1510         return 0;
1511 }
1512
1513 static inline void LED_SetState(int state, IXJ *j)
1514 {
1515         if (j->cardtype == QTI_LINEJACK) {
1516                 j->pld_scrw.bits.led1 = state & 0x1 ? 1 : 0;
1517                 j->pld_scrw.bits.led2 = state & 0x2 ? 1 : 0;
1518                 j->pld_scrw.bits.led3 = state & 0x4 ? 1 : 0;
1519                 j->pld_scrw.bits.led4 = state & 0x8 ? 1 : 0;
1520
1521                 outb(j->pld_scrw.byte, j->XILINXbase);
1522         }
1523 }
1524
1525 /*********************************************************************
1526 *  GPIO Pins are configured as follows on the Quicknet Internet
1527 *  PhoneJACK Telephony Cards
1528
1529 * POTS Select        GPIO_6=0 GPIO_7=0
1530 * Mic/Speaker Select GPIO_6=0 GPIO_7=1
1531 * Handset Select     GPIO_6=1 GPIO_7=0
1532 *
1533 * SLIC Active        GPIO_1=0 GPIO_2=1 GPIO_5=0
1534 * SLIC Ringing       GPIO_1=1 GPIO_2=1 GPIO_5=0
1535 * SLIC Open Circuit  GPIO_1=0 GPIO_2=0 GPIO_5=0
1536 *
1537 * Hook Switch changes reported on GPIO_3
1538 *********************************************************************/
1539 static int ixj_set_port(IXJ *j, int arg)
1540 {
1541         if (j->cardtype == QTI_PHONEJACK_LITE) {
1542                 if (arg != PORT_POTS)
1543                         return 10;
1544                 else
1545                         return 0;
1546         }
1547         switch (arg) {
1548         case PORT_POTS:
1549                 j->port = PORT_POTS;
1550                 switch (j->cardtype) {
1551                 case QTI_PHONECARD:
1552                         if (j->flags.pcmciasct == 1)
1553                                 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1554                         else
1555                                 return 11;
1556                         break;
1557                 case QTI_PHONEJACK_PCI:
1558                         j->pld_slicw.pcib.mic = 0;
1559                         j->pld_slicw.pcib.spk = 0;
1560                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1561                         break;
1562                 case QTI_LINEJACK:
1563                         ixj_set_pots(j, 0);                     /* Disconnect POTS/PSTN relay */
1564                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to
1565                                                                            Software Control Register */
1566                                 return 2;
1567                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
1568
1569                         outb(j->pld_scrw.byte, j->XILINXbase);
1570                         j->pld_clock.byte = 0;
1571                         outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1572                         j->pld_slicw.bits.rly1 = 1;
1573                         j->pld_slicw.bits.spken = 0;
1574                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1575                         ixj_mixer(0x1200, j);   /* Turn Off MIC switch on mixer left */
1576                         ixj_mixer(0x1401, j);   /* Turn On Mono1 switch on mixer left */
1577                         ixj_mixer(0x1300, j);       /* Turn Off MIC switch on mixer right */
1578                         ixj_mixer(0x1501, j);       /* Turn On Mono1 switch on mixer right */
1579                         ixj_mixer(0x0E80, j);   /*Mic mute */
1580                         ixj_mixer(0x0F00, j);   /* Set mono out (SLIC) to 0dB */
1581                         ixj_mixer(0x0080, j);   /* Mute Master Left volume */
1582                         ixj_mixer(0x0180, j);   /* Mute Master Right volume */
1583                         SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
1584 /*                      SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
1585                         break;
1586                 case QTI_PHONEJACK:
1587                         j->gpio.bytes.high = 0x0B;
1588                         j->gpio.bits.gpio6 = 0;
1589                         j->gpio.bits.gpio7 = 0;
1590                         ixj_WriteDSPCommand(j->gpio.word, j);
1591                         break;
1592                 }
1593                 break;
1594         case PORT_PSTN:
1595                 if (j->cardtype == QTI_LINEJACK) {
1596                         ixj_WriteDSPCommand(0xC534, j); /* Write CODEC config to Software Control Register */
1597
1598                         j->pld_slicw.bits.rly3 = 0;
1599                         j->pld_slicw.bits.rly1 = 1;
1600                         j->pld_slicw.bits.spken = 0;
1601                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1602                         j->port = PORT_PSTN;
1603                 } else {
1604                         return 4;
1605                 }
1606                 break;
1607         case PORT_SPEAKER:
1608                 j->port = PORT_SPEAKER;
1609                 switch (j->cardtype) {
1610                 case QTI_PHONECARD:
1611                         if (j->flags.pcmciasct) {
1612                                 SLIC_SetState(PLD_SLIC_STATE_OC, j);
1613                         }
1614                         break;
1615                 case QTI_PHONEJACK_PCI:
1616                         j->pld_slicw.pcib.mic = 1;
1617                         j->pld_slicw.pcib.spk = 1;
1618                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1619                         break;
1620                 case QTI_LINEJACK:
1621                         ixj_set_pots(j, 0);                     /* Disconnect POTS/PSTN relay */
1622                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to
1623                                                                            Software Control Register */
1624                                 return 2;
1625                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
1626
1627                         outb(j->pld_scrw.byte, j->XILINXbase);
1628                         j->pld_clock.byte = 0;
1629                         outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1630                         j->pld_slicw.bits.rly1 = 1;
1631                         j->pld_slicw.bits.spken = 1;
1632                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1633                         ixj_mixer(0x1201, j);   /* Turn On MIC switch on mixer left */
1634                         ixj_mixer(0x1400, j);   /* Turn Off Mono1 switch on mixer left */
1635                         ixj_mixer(0x1301, j);       /* Turn On MIC switch on mixer right */
1636                         ixj_mixer(0x1500, j);       /* Turn Off Mono1 switch on mixer right */
1637                         ixj_mixer(0x0E06, j);   /*Mic un-mute 0dB */
1638                         ixj_mixer(0x0F80, j);   /* Mute mono out (SLIC) */
1639                         ixj_mixer(0x0000, j);   /* Set Master Left volume to 0dB */
1640                         ixj_mixer(0x0100, j);   /* Set Master Right volume to 0dB */
1641                         break;
1642                 case QTI_PHONEJACK:
1643                         j->gpio.bytes.high = 0x0B;
1644                         j->gpio.bits.gpio6 = 0;
1645                         j->gpio.bits.gpio7 = 1;
1646                         ixj_WriteDSPCommand(j->gpio.word, j);
1647                         break;
1648                 }
1649                 break;
1650         case PORT_HANDSET:
1651                 if (j->cardtype != QTI_PHONEJACK) {
1652                         return 5;
1653                 } else {
1654                         j->gpio.bytes.high = 0x0B;
1655                         j->gpio.bits.gpio6 = 1;
1656                         j->gpio.bits.gpio7 = 0;
1657                         ixj_WriteDSPCommand(j->gpio.word, j);
1658                         j->port = PORT_HANDSET;
1659                 }
1660                 break;
1661         default:
1662                 return 6;
1663                 break;
1664         }
1665         return 0;
1666 }
1667
1668 static int ixj_set_pots(IXJ *j, int arg)
1669 {
1670         if (j->cardtype == QTI_LINEJACK) {
1671                 if (arg) {
1672                         if (j->port == PORT_PSTN) {
1673                                 j->pld_slicw.bits.rly1 = 0;
1674                                 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1675                                 j->flags.pots_pstn = 1;
1676                                 return 1;
1677                         } else {
1678                                 j->flags.pots_pstn = 0;
1679                                 return 0;
1680                         }
1681                 } else {
1682                         j->pld_slicw.bits.rly1 = 1;
1683                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1684                         j->flags.pots_pstn = 0;
1685                         return 1;
1686                 }
1687         } else {
1688                 return 0;
1689         }
1690 }
1691
1692 static void ixj_ring_on(IXJ *j)
1693 {
1694         if (j->dsp.low == 0x20) /* Internet PhoneJACK */
1695          {
1696                 if (ixjdebug & 0x0004)
1697                         printk(KERN_INFO "IXJ Ring On /dev/phone%d\n",  j->board);
1698
1699                 j->gpio.bytes.high = 0x0B;
1700                 j->gpio.bytes.low = 0x00;
1701                 j->gpio.bits.gpio1 = 1;
1702                 j->gpio.bits.gpio2 = 1;
1703                 j->gpio.bits.gpio5 = 0;
1704                 ixj_WriteDSPCommand(j->gpio.word, j);   /* send the ring signal */
1705         } else                  /* Internet LineJACK, Internet PhoneJACK Lite or Internet PhoneJACK PCI */
1706         {
1707                 if (ixjdebug & 0x0004)
1708                         printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1709
1710                 SLIC_SetState(PLD_SLIC_STATE_RINGING, j);
1711         }
1712 }
1713
1714 static int ixj_siadc(IXJ *j, int val)
1715 {
1716         if(j->cardtype == QTI_PHONECARD){
1717                 if(j->flags.pcmciascp){
1718                         if(val == -1)
1719                                 return j->siadc.bits.rxg;
1720
1721                         if(val < 0 || val > 0x1F)
1722                                 return -1;
1723
1724                         j->siadc.bits.hom = 0;                          /* Handset Out Mute */
1725                         j->siadc.bits.lom = 0;                          /* Line Out Mute */
1726                         j->siadc.bits.rxg = val;                        /*(0xC000 - 0x41C8) / 0x4EF;    RX PGA Gain */
1727                         j->psccr.bits.addr = 6;                         /* R/W Smart Cable Register Address */
1728                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1729                         j->psccr.bits.dev = 0;
1730                         outb(j->siadc.byte, j->XILINXbase + 0x00);
1731                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1732                         ixj_PCcontrol_wait(j);
1733                         return j->siadc.bits.rxg;
1734                 }
1735         }
1736         return -1;
1737 }
1738
1739 static int ixj_sidac(IXJ *j, int val)
1740 {
1741         if(j->cardtype == QTI_PHONECARD){
1742                 if(j->flags.pcmciascp){
1743                         if(val == -1)
1744                                 return j->sidac.bits.txg;
1745
1746                         if(val < 0 || val > 0x1F)
1747                                 return -1;
1748
1749                         j->sidac.bits.srm = 1;                          /* Speaker Right Mute */
1750                         j->sidac.bits.slm = 1;                          /* Speaker Left Mute */
1751                         j->sidac.bits.txg = val;                        /* (0xC000 - 0x45E4) / 0x5D3;    TX PGA Gain */
1752                         j->psccr.bits.addr = 7;                         /* R/W Smart Cable Register Address */
1753                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1754                         j->psccr.bits.dev = 0;
1755                         outb(j->sidac.byte, j->XILINXbase + 0x00);
1756                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1757                         ixj_PCcontrol_wait(j);
1758                         return j->sidac.bits.txg;
1759                 }
1760         }
1761         return -1;
1762 }
1763
1764 static int ixj_pcmcia_cable_check(IXJ *j)
1765 {
1766         j->pccr1.byte = inb_p(j->XILINXbase + 0x03);
1767         if (!j->flags.pcmciastate) {
1768                 j->pccr2.byte = inb_p(j->XILINXbase + 0x02);
1769                 if (j->pccr1.bits.drf || j->pccr2.bits.rstc) {
1770                         j->flags.pcmciastate = 4;
1771                         return 0;
1772                 }
1773                 if (j->pccr1.bits.ed) {
1774                         j->pccr1.bits.ed = 0;
1775                         j->psccr.bits.dev = 3;
1776                         j->psccr.bits.rw = 1;
1777                         outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
1778                         ixj_PCcontrol_wait(j);
1779                         j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
1780                         j->pslic.bits.led2 = j->pslic.bits.det ? 1 : 0;
1781                         j->psccr.bits.dev = 3;
1782                         j->psccr.bits.rw = 0;
1783                         outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1784                         ixj_PCcontrol_wait(j);
1785                         return j->pslic.bits.led2 ? 1 : 0;
1786                 } else if (j->flags.pcmciasct) {
1787                         return j->r_hook;
1788                 } else {
1789                         return 1;
1790                 }
1791         } else if (j->flags.pcmciastate == 4) {
1792                 if (!j->pccr1.bits.drf) {
1793                         j->flags.pcmciastate = 3;
1794                 }
1795                 return 0;
1796         } else if (j->flags.pcmciastate == 3) {
1797                 j->pccr2.bits.pwr = 0;
1798                 j->pccr2.bits.rstc = 1;
1799                 outb(j->pccr2.byte, j->XILINXbase + 0x02);
1800                 j->checkwait = jiffies + (hertz * 2);
1801                 j->flags.incheck = 1;
1802                 j->flags.pcmciastate = 2;
1803                 return 0;
1804         } else if (j->flags.pcmciastate == 2) {
1805                 if (j->flags.incheck) {
1806                         if (time_before(jiffies, j->checkwait)) {
1807                                 return 0;
1808                         } else {
1809                                 j->flags.incheck = 0;
1810                         }
1811                 }
1812                 j->pccr2.bits.pwr = 0;
1813                 j->pccr2.bits.rstc = 0;
1814                 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1815                 j->flags.pcmciastate = 1;
1816                 return 0;
1817         } else if (j->flags.pcmciastate == 1) {
1818                 j->flags.pcmciastate = 0;
1819                 if (!j->pccr1.bits.drf) {
1820                         j->psccr.bits.dev = 3;
1821                         j->psccr.bits.rw = 1;
1822                         outb_p(j->psccr.byte, j->XILINXbase + 0x01);
1823                         ixj_PCcontrol_wait(j);
1824                         j->flags.pcmciascp = 1;         /* Set Cable Present Flag */
1825
1826                         j->flags.pcmciasct = (inw_p(j->XILINXbase + 0x00) >> 8) & 0x03;         /* Get Cable Type */
1827
1828                         if (j->flags.pcmciasct == 3) {
1829                                 j->flags.pcmciastate = 4;
1830                                 return 0;
1831                         } else if (j->flags.pcmciasct == 0) {
1832                                 j->pccr2.bits.pwr = 1;
1833                                 j->pccr2.bits.rstc = 0;
1834                                 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1835                                 j->port = PORT_SPEAKER;
1836                         } else {
1837                                 j->port = PORT_POTS;
1838                         }
1839                         j->sic1.bits.cpd = 0;                           /* Chip Power Down */
1840                         j->sic1.bits.mpd = 0;                           /* MIC Bias Power Down */
1841                         j->sic1.bits.hpd = 0;                           /* Handset Bias Power Down */
1842                         j->sic1.bits.lpd = 0;                           /* Line Bias Power Down */
1843                         j->sic1.bits.spd = 1;                           /* Speaker Drive Power Down */
1844                         j->psccr.bits.addr = 1;                         /* R/W Smart Cable Register Address */
1845                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1846                         j->psccr.bits.dev = 0;
1847                         outb(j->sic1.byte, j->XILINXbase + 0x00);
1848                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1849                         ixj_PCcontrol_wait(j);
1850
1851                         j->sic2.bits.al = 0;                            /* Analog Loopback DAC analog -> ADC analog */
1852                         j->sic2.bits.dl2 = 0;                           /* Digital Loopback DAC -> ADC one bit */
1853                         j->sic2.bits.dl1 = 0;                           /* Digital Loopback ADC -> DAC one bit */
1854                         j->sic2.bits.pll = 0;                           /* 1 = div 10, 0 = div 5 */
1855                         j->sic2.bits.hpd = 0;                           /* HPF disable */
1856                         j->psccr.bits.addr = 2;                         /* R/W Smart Cable Register Address */
1857                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1858                         j->psccr.bits.dev = 0;
1859                         outb(j->sic2.byte, j->XILINXbase + 0x00);
1860                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1861                         ixj_PCcontrol_wait(j);
1862
1863                         j->psccr.bits.addr = 3;                         /* R/W Smart Cable Register Address */
1864                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1865                         j->psccr.bits.dev = 0;
1866                         outb(0x00, j->XILINXbase + 0x00);               /* PLL Divide N1 */
1867                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1868                         ixj_PCcontrol_wait(j);
1869
1870                         j->psccr.bits.addr = 4;                         /* R/W Smart Cable Register Address */
1871                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1872                         j->psccr.bits.dev = 0;
1873                         outb(0x09, j->XILINXbase + 0x00);               /* PLL Multiply M1 */
1874                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1875                         ixj_PCcontrol_wait(j);
1876
1877                         j->sirxg.bits.lig = 1;                          /* Line In Gain */
1878                         j->sirxg.bits.lim = 1;                          /* Line In Mute */
1879                         j->sirxg.bits.mcg = 0;                          /* MIC In Gain was 3 */
1880                         j->sirxg.bits.mcm = 0;                          /* MIC In Mute */
1881                         j->sirxg.bits.him = 0;                          /* Handset In Mute */
1882                         j->sirxg.bits.iir = 1;                          /* IIR */
1883                         j->psccr.bits.addr = 5;                         /* R/W Smart Cable Register Address */
1884                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1885                         j->psccr.bits.dev = 0;
1886                         outb(j->sirxg.byte, j->XILINXbase + 0x00);
1887                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1888                         ixj_PCcontrol_wait(j);
1889
1890                         ixj_siadc(j, 0x17);
1891                         ixj_sidac(j, 0x1D);
1892
1893                         j->siaatt.bits.sot = 0;
1894                         j->psccr.bits.addr = 9;                         /* R/W Smart Cable Register Address */
1895                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1896                         j->psccr.bits.dev = 0;
1897                         outb(j->siaatt.byte, j->XILINXbase + 0x00);
1898                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1899                         ixj_PCcontrol_wait(j);
1900
1901                         if (j->flags.pcmciasct == 1 && !j->readers && !j->writers) {
1902                                 j->psccr.byte = j->pslic.byte = 0;
1903                                 j->pslic.bits.powerdown = 1;
1904                                 j->psccr.bits.dev = 3;
1905                                 j->psccr.bits.rw = 0;
1906                                 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1907                                 ixj_PCcontrol_wait(j);
1908                         }
1909                 }
1910                 return 0;
1911         } else {
1912                 j->flags.pcmciascp = 0;
1913                 return 0;
1914         }
1915         return 0;
1916 }
1917
1918 static int ixj_hookstate(IXJ *j)
1919 {
1920         unsigned long det;
1921         int fOffHook = 0;
1922
1923         switch (j->cardtype) {
1924         case QTI_PHONEJACK:
1925                 ixj_gpio_read(j);
1926                 fOffHook = j->gpio.bits.gpio3read ? 1 : 0;
1927                 break;
1928         case QTI_LINEJACK:
1929         case QTI_PHONEJACK_LITE:
1930         case QTI_PHONEJACK_PCI:
1931                 SLIC_GetState(j);
1932                 if(j->cardtype == QTI_LINEJACK && j->flags.pots_pstn == 1 && (j->readers || j->writers)) {
1933                         fOffHook = j->pld_slicr.bits.potspstn ? 1 : 0;
1934                         if(fOffHook != j->p_hook) {
1935                                 if(!j->checkwait) {
1936                                         j->checkwait = jiffies;
1937                                 } 
1938                                 if(time_before(jiffies, j->checkwait + 2)) {
1939                                         fOffHook ^= 1;
1940                                 } else {
1941                                         j->checkwait = 0;
1942                                 }
1943                                 j->p_hook = fOffHook;
1944                                 printk("IXJ : /dev/phone%d pots-pstn hookstate check %d at %ld\n", j->board, fOffHook, jiffies);
1945                         }
1946                 } else {
1947                         if (j->pld_slicr.bits.state == PLD_SLIC_STATE_ACTIVE ||
1948                             j->pld_slicr.bits.state == PLD_SLIC_STATE_STANDBY) {
1949                                 if (j->flags.ringing || j->flags.cringing) {
1950                                         if (!in_interrupt()) {
1951                                                 det = jiffies + (hertz / 50);
1952                                                 while (time_before(jiffies, det)) {
1953                                                         set_current_state(TASK_INTERRUPTIBLE);
1954                                                         schedule_timeout(1);
1955                                                 }
1956                                         }
1957                                         SLIC_GetState(j);
1958                                         if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
1959                                                 ixj_ring_on(j);
1960                                         }
1961                                 }
1962                                 if (j->cardtype == QTI_PHONEJACK_PCI) {
1963                                         j->pld_scrr.byte = inb_p(j->XILINXbase);
1964                                         fOffHook = j->pld_scrr.pcib.det ? 1 : 0;
1965                                 } else
1966                                         fOffHook = j->pld_slicr.bits.det ? 1 : 0;
1967                         }
1968                 }
1969                 break;
1970         case QTI_PHONECARD:
1971                 fOffHook = ixj_pcmcia_cable_check(j);
1972                 break;
1973         }
1974         if (j->r_hook != fOffHook) {
1975                 j->r_hook = fOffHook;
1976                 if (j->port == PORT_SPEAKER || j->port == PORT_HANDSET) { // || (j->port == PORT_PSTN && j->flags.pots_pstn == 0)) {
1977                         j->ex.bits.hookstate = 1;
1978                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1979                 } else if (!fOffHook) {
1980                         j->flash_end = jiffies + ((60 * hertz) / 100);
1981                 }
1982         }
1983         if (fOffHook) {
1984                 if(time_before(jiffies, j->flash_end)) {
1985                         j->ex.bits.flash = 1;
1986                         j->flash_end = 0;
1987                         ixj_kill_fasync(j, SIG_FLASH, POLL_IN);
1988                 }
1989         } else {
1990                 if(time_before(jiffies, j->flash_end)) {
1991                         fOffHook = 1;
1992                 }
1993         }
1994
1995         if (j->port == PORT_PSTN && j->daa_mode == SOP_PU_CONVERSATION)
1996                 fOffHook |= 2;
1997
1998         if (j->port == PORT_SPEAKER) {
1999                 if(j->cardtype == QTI_PHONECARD) {
2000                         if(j->flags.pcmciascp && j->flags.pcmciasct) {
2001                                 fOffHook |= 2;
2002                         }
2003                 } else {
2004                         fOffHook |= 2;
2005                 }
2006         }
2007
2008         if (j->port == PORT_HANDSET)
2009                 fOffHook |= 2;
2010
2011         return fOffHook;
2012 }
2013
2014 static void ixj_ring_off(IXJ *j)
2015 {
2016         if (j->dsp.low == 0x20) /* Internet PhoneJACK */
2017          {
2018                 if (ixjdebug & 0x0004)
2019                         printk(KERN_INFO "IXJ Ring Off\n");
2020                 j->gpio.bytes.high = 0x0B;
2021                 j->gpio.bytes.low = 0x00;
2022                 j->gpio.bits.gpio1 = 0;
2023                 j->gpio.bits.gpio2 = 1;
2024                 j->gpio.bits.gpio5 = 0;
2025                 ixj_WriteDSPCommand(j->gpio.word, j);
2026         } else                  /* Internet LineJACK */
2027         {
2028                 if (ixjdebug & 0x0004)
2029                         printk(KERN_INFO "IXJ Ring Off\n");
2030
2031                 if(!j->flags.cidplay)
2032                         SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
2033
2034                 SLIC_GetState(j);
2035         }
2036 }
2037
2038 static void ixj_ring_start(IXJ *j)
2039 {
2040         j->flags.cringing = 1;
2041         if (ixjdebug & 0x0004)
2042                 printk(KERN_INFO "IXJ Cadence Ringing Start /dev/phone%d\n", j->board);
2043         if (ixj_hookstate(j) & 1) {
2044                 if (j->port == PORT_POTS)
2045                         ixj_ring_off(j);
2046                 j->flags.cringing = 0;
2047                 if (ixjdebug & 0x0004)
2048                         printk(KERN_INFO "IXJ Cadence Ringing Stopped /dev/phone%d off hook\n", j->board);
2049         } else if(j->cadence_f[5].enable && (!j->cadence_f[5].en_filter)) {
2050                 j->ring_cadence_jif = jiffies;
2051                 j->flags.cidsent = j->flags.cidring = 0;
2052                 j->cadence_f[5].state = 0;
2053                 if(j->cadence_f[5].on1)
2054                         ixj_ring_on(j);
2055         } else {
2056                 j->ring_cadence_jif = jiffies;
2057                 j->ring_cadence_t = 15;
2058                 if (j->ring_cadence & 1 << j->ring_cadence_t) {
2059                         ixj_ring_on(j);
2060                 } else {
2061                         ixj_ring_off(j);
2062                 }
2063                 j->flags.cidsent = j->flags.cidring = j->flags.firstring = 0;
2064         }
2065 }
2066
2067 static int ixj_ring(IXJ *j)
2068 {
2069         char cntr;
2070         unsigned long jif, det;
2071
2072         j->flags.ringing = 1;
2073         if (ixj_hookstate(j) & 1) {
2074                 ixj_ring_off(j);
2075                 j->flags.ringing = 0;
2076                 return 1;
2077         }
2078         det = 0;
2079         for (cntr = 0; cntr < j->maxrings; cntr++) {
2080                 jif = jiffies + (1 * hertz);
2081                 ixj_ring_on(j);
2082                 while (time_before(jiffies, jif)) {
2083                         if (ixj_hookstate(j) & 1) {
2084                                 ixj_ring_off(j);
2085                                 j->flags.ringing = 0;
2086                                 return 1;
2087                         }
2088                         set_current_state(TASK_INTERRUPTIBLE);
2089                         schedule_timeout(1);
2090                         if (signal_pending(current))
2091                                 break;
2092                 }
2093                 jif = jiffies + (3 * hertz);
2094                 ixj_ring_off(j);
2095                 while (time_before(jiffies, jif)) {
2096                         if (ixj_hookstate(j) & 1) {
2097                                 det = jiffies + (hertz / 100);
2098                                 while (time_before(jiffies, det)) {
2099                                         set_current_state(TASK_INTERRUPTIBLE);
2100                                         schedule_timeout(1);
2101                                         if (signal_pending(current))
2102                                                 break;
2103                                 }
2104                                 if (ixj_hookstate(j) & 1) {
2105                                         j->flags.ringing = 0;
2106                                         return 1;
2107                                 }
2108                         }
2109                         set_current_state(TASK_INTERRUPTIBLE);
2110                         schedule_timeout(1);
2111                         if (signal_pending(current))
2112                                 break;
2113                 }
2114         }
2115         ixj_ring_off(j);
2116         j->flags.ringing = 0;
2117         return 0;
2118 }
2119
2120 static int ixj_open(struct phone_device *p, struct file *file_p)
2121 {
2122         IXJ *j = get_ixj(p->board);
2123         file_p->private_data = j;
2124
2125         if (!j->DSPbase)
2126                 return -ENODEV;
2127
2128         if (file_p->f_mode & FMODE_READ) {
2129                 if(!j->readers) {
2130                         j->readers++;
2131                 } else {
2132                         return -EBUSY;
2133                 }
2134         }
2135
2136         if (file_p->f_mode & FMODE_WRITE) {
2137                 if(!j->writers) {
2138                         j->writers++;
2139                 } else {
2140                         if (file_p->f_mode & FMODE_READ){
2141                                 j->readers--;
2142                         }
2143                         return -EBUSY;
2144                 }
2145         }
2146
2147         if (j->cardtype == QTI_PHONECARD) {
2148                 j->pslic.bits.powerdown = 0;
2149                 j->psccr.bits.dev = 3;
2150                 j->psccr.bits.rw = 0;
2151                 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
2152                 ixj_PCcontrol_wait(j);
2153         }
2154
2155         j->flags.cidplay = 0;
2156         j->flags.cidcw_ack = 0;
2157
2158         if (ixjdebug & 0x0002)
2159                 printk(KERN_INFO "Opening board %d\n", p->board);
2160
2161         j->framesread = j->frameswritten = 0;
2162         return 0;
2163 }
2164
2165 static int ixj_release(struct inode *inode, struct file *file_p)
2166 {
2167         IXJ_TONE ti;
2168         int cnt;
2169         IXJ *j = file_p->private_data;
2170         int board = j->p.board;
2171
2172         /*
2173          *    Set up locks to ensure that only one process is talking to the DSP at a time.
2174          *    This is necessary to keep the DSP from locking up.
2175          */
2176         while(test_and_set_bit(board, (void *)&j->busyflags) != 0) {
2177                 set_current_state(TASK_INTERRUPTIBLE);
2178                 schedule_timeout(1);
2179         }
2180         if (ixjdebug & 0x0002)
2181                 printk(KERN_INFO "Closing board %d\n", NUM(inode));
2182
2183         if (j->cardtype == QTI_PHONECARD)
2184                 ixj_set_port(j, PORT_SPEAKER);
2185         else
2186                 ixj_set_port(j, PORT_POTS);
2187
2188         aec_stop(j);
2189         ixj_play_stop(j);
2190         ixj_record_stop(j);
2191         set_play_volume(j, 0x100);
2192         set_rec_volume(j, 0x100);
2193         ixj_ring_off(j);
2194
2195         /* Restore the tone table to default settings. */
2196         ti.tone_index = 10;
2197         ti.gain0 = 1;
2198         ti.freq0 = hz941;
2199         ti.gain1 = 0;
2200         ti.freq1 = hz1209;
2201         ixj_init_tone(j, &ti);
2202         ti.tone_index = 11;
2203         ti.gain0 = 1;
2204         ti.freq0 = hz941;
2205         ti.gain1 = 0;
2206         ti.freq1 = hz1336;
2207         ixj_init_tone(j, &ti);
2208         ti.tone_index = 12;
2209         ti.gain0 = 1;
2210         ti.freq0 = hz941;
2211         ti.gain1 = 0;
2212         ti.freq1 = hz1477;
2213         ixj_init_tone(j, &ti);
2214         ti.tone_index = 13;
2215         ti.gain0 = 1;
2216         ti.freq0 = hz800;
2217         ti.gain1 = 0;
2218         ti.freq1 = 0;
2219         ixj_init_tone(j, &ti);
2220         ti.tone_index = 14;
2221         ti.gain0 = 1;
2222         ti.freq0 = hz1000;
2223         ti.gain1 = 0;
2224         ti.freq1 = 0;
2225         ixj_init_tone(j, &ti);
2226         ti.tone_index = 15;
2227         ti.gain0 = 1;
2228         ti.freq0 = hz1250;
2229         ti.gain1 = 0;
2230         ti.freq1 = 0;
2231         ixj_init_tone(j, &ti);
2232         ti.tone_index = 16;
2233         ti.gain0 = 1;
2234         ti.freq0 = hz950;
2235         ti.gain1 = 0;
2236         ti.freq1 = 0;
2237         ixj_init_tone(j, &ti);
2238         ti.tone_index = 17;
2239         ti.gain0 = 1;
2240         ti.freq0 = hz1100;
2241         ti.gain1 = 0;
2242         ti.freq1 = 0;
2243         ixj_init_tone(j, &ti);
2244         ti.tone_index = 18;
2245         ti.gain0 = 1;
2246         ti.freq0 = hz1400;
2247         ti.gain1 = 0;
2248         ti.freq1 = 0;
2249         ixj_init_tone(j, &ti);
2250         ti.tone_index = 19;
2251         ti.gain0 = 1;
2252         ti.freq0 = hz1500;
2253         ti.gain1 = 0;
2254         ti.freq1 = 0;
2255         ixj_init_tone(j, &ti);
2256         ti.tone_index = 20;
2257         ti.gain0 = 1;
2258         ti.freq0 = hz1600;
2259         ti.gain1 = 0;
2260         ti.freq1 = 0;
2261         ixj_init_tone(j, &ti);
2262         ti.tone_index = 21;
2263         ti.gain0 = 1;
2264         ti.freq0 = hz1800;
2265         ti.gain1 = 0;
2266         ti.freq1 = 0;
2267         ixj_init_tone(j, &ti);
2268         ti.tone_index = 22;
2269         ti.gain0 = 1;
2270         ti.freq0 = hz2100;
2271         ti.gain1 = 0;
2272         ti.freq1 = 0;
2273         ixj_init_tone(j, &ti);
2274         ti.tone_index = 23;
2275         ti.gain0 = 1;
2276         ti.freq0 = hz1300;
2277         ti.gain1 = 0;
2278         ti.freq1 = 0;
2279         ixj_init_tone(j, &ti);
2280         ti.tone_index = 24;
2281         ti.gain0 = 1;
2282         ti.freq0 = hz2450;
2283         ti.gain1 = 0;
2284         ti.freq1 = 0;
2285         ixj_init_tone(j, &ti);
2286         ti.tone_index = 25;
2287         ti.gain0 = 1;
2288         ti.freq0 = hz350;
2289         ti.gain1 = 0;
2290         ti.freq1 = hz440;
2291         ixj_init_tone(j, &ti);
2292         ti.tone_index = 26;
2293         ti.gain0 = 1;
2294         ti.freq0 = hz440;
2295         ti.gain1 = 0;
2296         ti.freq1 = hz480;
2297         ixj_init_tone(j, &ti);
2298         ti.tone_index = 27;
2299         ti.gain0 = 1;
2300         ti.freq0 = hz480;
2301         ti.gain1 = 0;
2302         ti.freq1 = hz620;
2303         ixj_init_tone(j, &ti);
2304
2305         set_rec_depth(j, 2);    /* Set Record Channel Limit to 2 frames */
2306
2307         set_play_depth(j, 2);   /* Set Playback Channel Limit to 2 frames */
2308
2309         j->ex.bits.dtmf_ready = 0;
2310         j->dtmf_state = 0;
2311         j->dtmf_wp = j->dtmf_rp = 0;
2312         j->rec_mode = j->play_mode = -1;
2313         j->flags.ringing = 0;
2314         j->maxrings = MAXRINGS;
2315         j->ring_cadence = USA_RING_CADENCE;
2316         if(j->cadence_f[5].enable) {
2317                 j->cadence_f[5].enable = j->cadence_f[5].en_filter = j->cadence_f[5].state = 0;
2318         }
2319         j->drybuffer = 0;
2320         j->winktime = 320;
2321         j->flags.dtmf_oob = 0;
2322         for (cnt = 0; cnt < 4; cnt++)
2323                 j->cadence_f[cnt].enable = 0;
2324
2325         idle(j);
2326
2327         if(j->cardtype == QTI_PHONECARD) {
2328                 SLIC_SetState(PLD_SLIC_STATE_OC, j);
2329         }
2330
2331         if (file_p->f_mode & FMODE_READ)
2332                 j->readers--;
2333         if (file_p->f_mode & FMODE_WRITE)
2334                 j->writers--;
2335
2336         if (j->read_buffer && !j->readers) {
2337                 kfree(j->read_buffer);
2338                 j->read_buffer = NULL;
2339                 j->read_buffer_size = 0;
2340         }
2341         if (j->write_buffer && !j->writers) {
2342                 kfree(j->write_buffer);
2343                 j->write_buffer = NULL;
2344                 j->write_buffer_size = 0;
2345         }
2346         j->rec_codec = j->play_codec = 0;
2347         j->rec_frame_size = j->play_frame_size = 0;
2348         j->flags.cidsent = j->flags.cidring = 0;
2349         ixj_fasync(-1, file_p, 0);      /* remove from list of async notification */
2350
2351         if(j->cardtype == QTI_LINEJACK && !j->readers && !j->writers) {
2352                 ixj_set_port(j, PORT_PSTN);
2353                 daa_set_mode(j, SOP_PU_SLEEP);
2354                 ixj_set_pots(j, 1);
2355         }
2356         ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
2357
2358         /* Set up the default signals for events */
2359         for (cnt = 0; cnt < 35; cnt++)
2360                 j->ixj_signals[cnt] = SIGIO;
2361
2362         /* Set the excetion signal enable flags */
2363         j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 
2364         j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 = 
2365         j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1;
2366
2367         file_p->private_data = NULL;
2368         clear_bit(board, &j->busyflags);
2369         return 0;
2370 }
2371
2372 static int read_filters(IXJ *j)
2373 {
2374         unsigned short fc, cnt, trg;
2375         int var;
2376
2377         trg = 0;
2378         if (ixj_WriteDSPCommand(0x5144, j)) {
2379                 if(ixjdebug & 0x0001) {
2380                         printk(KERN_INFO "Read Frame Counter failed!\n");
2381                 }
2382                 return -1;
2383         }
2384         fc = j->ssr.high << 8 | j->ssr.low;
2385         if (fc == j->frame_count)
2386                 return 1;
2387
2388         j->frame_count = fc;
2389
2390         if (j->dtmf_proc)
2391                 return 1;
2392
2393         var = 10;
2394
2395         for (cnt = 0; cnt < 4; cnt++) {
2396                 if (ixj_WriteDSPCommand(0x5154 + cnt, j)) {
2397                         if(ixjdebug & 0x0001) {
2398                                 printk(KERN_INFO "Select Filter %d failed!\n", cnt);
2399                         }
2400                         return -1;
2401                 }
2402                 if (ixj_WriteDSPCommand(0x515C, j)) {
2403                         if(ixjdebug & 0x0001) {
2404                                 printk(KERN_INFO "Read Filter History %d failed!\n", cnt);
2405                         }
2406                         return -1;
2407                 }
2408                 j->filter_hist[cnt] = j->ssr.high << 8 | j->ssr.low;
2409
2410                 if (j->cadence_f[cnt].enable) {
2411                         if (j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) {
2412                                 if (j->cadence_f[cnt].state == 0) {
2413                                         j->cadence_f[cnt].state = 1;
2414                                         j->cadence_f[cnt].on1min = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 - var)) / 10000));
2415                                         j->cadence_f[cnt].on1dot = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100)) / 10000));
2416                                         j->cadence_f[cnt].on1max = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 + var)) / 10000));
2417                                 } else if (j->cadence_f[cnt].state == 2 &&
2418                                            (time_after(jiffies, j->cadence_f[cnt].off1min) &&
2419                                             time_before(jiffies, j->cadence_f[cnt].off1max))) {
2420                                         if (j->cadence_f[cnt].on2) {
2421                                                 j->cadence_f[cnt].state = 3;
2422                                                 j->cadence_f[cnt].on2min = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 - var)) / 10000));
2423                                                 j->cadence_f[cnt].on2dot = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100)) / 10000));
2424                                                 j->cadence_f[cnt].on2max = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 + var)) / 10000));
2425                                         } else {
2426                                                 j->cadence_f[cnt].state = 7;
2427                                         }
2428                                 } else if (j->cadence_f[cnt].state == 4 &&
2429                                            (time_after(jiffies, j->cadence_f[cnt].off2min) &&
2430                                             time_before(jiffies, j->cadence_f[cnt].off2max))) {
2431                                         if (j->cadence_f[cnt].on3) {
2432                                                 j->cadence_f[cnt].state = 5;
2433                                                 j->cadence_f[cnt].on3min = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 - var)) / 10000));
2434                                                 j->cadence_f[cnt].on3dot = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100)) / 10000));
2435                                                 j->cadence_f[cnt].on3max = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 + var)) / 10000));
2436                                         } else {
2437                                                 j->cadence_f[cnt].state = 7;
2438                                         }
2439                                 } else {
2440                                         j->cadence_f[cnt].state = 0;
2441                                 }
2442                         } else if (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)) {
2443                                 if (j->cadence_f[cnt].state == 1) {
2444                                         if(!j->cadence_f[cnt].on1) {
2445                                                 j->cadence_f[cnt].state = 7;
2446                                         } else if((time_after(jiffies, j->cadence_f[cnt].on1min) &&
2447                                           time_before(jiffies, j->cadence_f[cnt].on1max))) {
2448                                                 if(j->cadence_f[cnt].off1) {
2449                                                         j->cadence_f[cnt].state = 2;
2450                                                         j->cadence_f[cnt].off1min = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 - var)) / 10000));
2451                                                         j->cadence_f[cnt].off1dot = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100)) / 10000));
2452                                                         j->cadence_f[cnt].off1max = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 + var)) / 10000));
2453                                                 } else {
2454                                                         j->cadence_f[cnt].state = 7;
2455                                                 }
2456                                         } else {
2457                                                 j->cadence_f[cnt].state = 0;
2458                                         }
2459                                 } else if (j->cadence_f[cnt].state == 3) {
2460                                         if((time_after(jiffies, j->cadence_f[cnt].on2min) &&
2461                                             time_before(jiffies, j->cadence_f[cnt].on2max))) {
2462                                                 if(j->cadence_f[cnt].off2) {
2463                                                         j->cadence_f[cnt].state = 4;
2464                                                         j->cadence_f[cnt].off2min = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 - var)) / 10000));
2465                                                         j->cadence_f[cnt].off2dot = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100)) / 10000));
2466                                                         j->cadence_f[cnt].off2max = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 + var)) / 10000));
2467                                                 } else {
2468                                                         j->cadence_f[cnt].state = 7;
2469                                                 }
2470                                         } else {
2471                                                 j->cadence_f[cnt].state = 0;
2472                                         }
2473                                 } else if (j->cadence_f[cnt].state == 5) {
2474                                         if ((time_after(jiffies, j->cadence_f[cnt].on3min) &&
2475                                             time_before(jiffies, j->cadence_f[cnt].on3max))) {
2476                                                 if(j->cadence_f[cnt].off3) {
2477                                                         j->cadence_f[cnt].state = 6;
2478                                                         j->cadence_f[cnt].off3min = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 - var)) / 10000));
2479                                                         j->cadence_f[cnt].off3dot = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100)) / 10000));
2480                                                         j->cadence_f[cnt].off3max = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 + var)) / 10000));
2481                                                 } else {
2482                                                         j->cadence_f[cnt].state = 7;
2483                                                 }
2484                                         } else {
2485                                                 j->cadence_f[cnt].state = 0;
2486                                         }
2487                                 } else {
2488                                         j->cadence_f[cnt].state = 0;
2489                                 }
2490                         } else {
2491                                 switch(j->cadence_f[cnt].state) {
2492                                         case 1:
2493                                                 if(time_after(jiffies, j->cadence_f[cnt].on1dot) &&
2494                                                    !j->cadence_f[cnt].off1 &&
2495                                                    !j->cadence_f[cnt].on2 && !j->cadence_f[cnt].off2 &&
2496                                                    !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2497                                                         j->cadence_f[cnt].state = 7;
2498                                                 }
2499                                                 break;
2500                                         case 3:
2501                                                 if(time_after(jiffies, j->cadence_f[cnt].on2dot) &&
2502                                                    !j->cadence_f[cnt].off2 &&
2503                                                    !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2504                                                         j->cadence_f[cnt].state = 7;
2505                                                 }
2506                                                 break;
2507                                         case 5:
2508                                                 if(time_after(jiffies, j->cadence_f[cnt].on3dot) &&
2509                                                    !j->cadence_f[cnt].off3) {
2510                                                         j->cadence_f[cnt].state = 7;
2511                                                 }
2512                                                 break;
2513                                 }
2514                         }
2515
2516                         if (ixjdebug & 0x0040) {
2517                                 printk(KERN_INFO "IXJ Tone Cadence state = %d /dev/phone%d at %ld\n", j->cadence_f[cnt].state, j->board, jiffies);
2518                                 switch(j->cadence_f[cnt].state) {
2519                                         case 0:
2520                                                 printk(KERN_INFO "IXJ /dev/phone%d No Tone detected\n", j->board);
2521                                                 break;
2522                                         case 1:
2523                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %u %ld - %ld - %ld\n", j->board,
2524                                         j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max);
2525                                                 break;
2526                                         case 2:
2527                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min, 
2528                                                                                                                         j->cadence_f[cnt].off1max);
2529                                                 break;
2530                                         case 3:
2531                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on2min,
2532                                                                                                                         j->cadence_f[cnt].on2max);
2533                                                 break;
2534                                         case 4:
2535                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off2min,
2536                                                                                                                         j->cadence_f[cnt].off2max);
2537                                                 break;
2538                                         case 5:
2539                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min,
2540                                                                                                                         j->cadence_f[cnt].on3max);
2541                                                 break;
2542                                         case 6: 
2543                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min,
2544                                                                                                                         j->cadence_f[cnt].off3max);
2545                                                 break;
2546                                 }
2547                         } 
2548                 }
2549                 if (j->cadence_f[cnt].state == 7) {
2550                         j->cadence_f[cnt].state = 0;
2551                         if (j->cadence_f[cnt].enable == 1)
2552                                 j->cadence_f[cnt].enable = 0;
2553                         switch (cnt) {
2554                         case 0:
2555                                 if(ixjdebug & 0x0020) {
2556                                         printk(KERN_INFO "Filter Cadence 0 triggered %ld\n", jiffies);
2557                                 }
2558                                 j->ex.bits.fc0 = 1;
2559                                 ixj_kill_fasync(j, SIG_FC0, POLL_IN);
2560                                 break;
2561                         case 1:
2562                                 if(ixjdebug & 0x0020) {
2563                                         printk(KERN_INFO "Filter Cadence 1 triggered %ld\n", jiffies);
2564                                 }
2565                                 j->ex.bits.fc1 = 1;
2566                                 ixj_kill_fasync(j, SIG_FC1, POLL_IN);
2567                                 break;
2568                         case 2:
2569                                 if(ixjdebug & 0x0020) {
2570                                         printk(KERN_INFO "Filter Cadence 2 triggered %ld\n", jiffies);
2571                                 }
2572                                 j->ex.bits.fc2 = 1;
2573                                 ixj_kill_fasync(j, SIG_FC2, POLL_IN);
2574                                 break;
2575                         case 3:
2576                                 if(ixjdebug & 0x0020) {
2577                                         printk(KERN_INFO "Filter Cadence 3 triggered %ld\n", jiffies);
2578                                 }
2579                                 j->ex.bits.fc3 = 1;
2580                                 ixj_kill_fasync(j, SIG_FC3, POLL_IN);
2581                                 break;
2582                         }
2583                 }
2584                 if (j->filter_en[cnt] && ((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) ||
2585                                           (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)))) {
2586                         if((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12))) {
2587                                 trg = 1;
2588                         } else if((j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3))) {
2589                                 trg = 0;
2590                         }
2591                         switch (cnt) {
2592                         case 0:
2593                                 if(ixjdebug & 0x0020) {
2594                                         printk(KERN_INFO "Filter 0 triggered %d at %ld\n", trg, jiffies);
2595                                 }
2596                                 j->ex.bits.f0 = 1;
2597                                 ixj_kill_fasync(j, SIG_F0, POLL_IN);
2598                                 break;
2599                         case 1:
2600                                 if(ixjdebug & 0x0020) {
2601                                         printk(KERN_INFO "Filter 1 triggered %d at %ld\n", trg, jiffies);
2602                                 }
2603                                 j->ex.bits.f1 = 1;
2604                                 ixj_kill_fasync(j, SIG_F1, POLL_IN);
2605                                 break;
2606                         case 2:
2607                                 if(ixjdebug & 0x0020) {
2608                                         printk(KERN_INFO "Filter 2 triggered %d at %ld\n", trg, jiffies);
2609                                 }
2610                                 j->ex.bits.f2 = 1;
2611                                 ixj_kill_fasync(j, SIG_F2, POLL_IN);
2612                                 break;
2613                         case 3:
2614                                 if(ixjdebug & 0x0020) {
2615                                         printk(KERN_INFO "Filter 3 triggered %d at %ld\n", trg, jiffies);
2616                                 }
2617                                 j->ex.bits.f3 = 1;
2618                                 ixj_kill_fasync(j, SIG_F3, POLL_IN);
2619                                 break;
2620                         }
2621                 }
2622         }
2623         return 0;
2624 }
2625
2626 static int LineMonitor(IXJ *j)
2627 {
2628         if (j->dtmf_proc) {
2629                 return -1;
2630         }
2631         j->dtmf_proc = 1;
2632
2633         if (ixj_WriteDSPCommand(0x7000, j))             /* Line Monitor */
2634                 return -1;
2635
2636         j->dtmf.bytes.high = j->ssr.high;
2637         j->dtmf.bytes.low = j->ssr.low;
2638         if (!j->dtmf_state && j->dtmf.bits.dtmf_valid) {
2639                 j->dtmf_state = 1;
2640                 j->dtmf_current = j->dtmf.bits.digit;
2641         }
2642         if (j->dtmf_state && !j->dtmf.bits.dtmf_valid)  /* && j->dtmf_wp != j->dtmf_rp) */
2643          {
2644                 if(!j->cidcw_wait) {
2645                         j->dtmfbuffer[j->dtmf_wp] = j->dtmf_current;
2646                         j->dtmf_wp++;
2647                         if (j->dtmf_wp == 79)
2648                                 j->dtmf_wp = 0;
2649                         j->ex.bits.dtmf_ready = 1;
2650                         if(j->ex_sig.bits.dtmf_ready) {
2651                                 ixj_kill_fasync(j, SIG_DTMF_READY, POLL_IN);
2652                         }
2653                 }
2654                 else if(j->dtmf_current == 0x00 || j->dtmf_current == 0x0D) {
2655                         if(ixjdebug & 0x0020) {
2656                                 printk("IXJ phone%d saw CIDCW Ack DTMF %d from display at %ld\n", j->board, j->dtmf_current, jiffies);
2657                         }
2658                         j->flags.cidcw_ack = 1;
2659                 }
2660                 j->dtmf_state = 0;
2661         }
2662         j->dtmf_proc = 0;
2663
2664         return 0;
2665 }
2666
2667 /************************************************************************
2668 *
2669 * Functions to allow alaw <-> ulaw conversions.
2670 *
2671 ************************************************************************/
2672
2673 static void ulaw2alaw(unsigned char *buff, unsigned long len)
2674 {
2675         static unsigned char table_ulaw2alaw[] =
2676         {
2677                 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D, 
2678                 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, 
2679                 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D, 
2680                 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, 
2681                 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02, 
2682                 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A, 
2683                 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12, 
2684                 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B, 
2685                 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63, 
2686                 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79, 
2687                 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71, 
2688                 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D, 
2689                 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45, 
2690                 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D, 
2691                 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51, 
2692                 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5, 
2693                 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD, 
2694                 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5, 
2695                 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD, 
2696                 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5, 
2697                 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82, 
2698                 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A, 
2699                 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92, 
2700                 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB, 
2701                 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3, 
2702                 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9, 
2703                 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1, 
2704                 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD, 
2705                 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5, 
2706                 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD, 
2707                 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1, 
2708                 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5
2709         };
2710
2711         while (len--)
2712         {
2713                 *buff = table_ulaw2alaw[*(unsigned char *)buff];
2714                 buff++;
2715         }
2716 }
2717
2718 static void alaw2ulaw(unsigned char *buff, unsigned long len)
2719 {
2720         static unsigned char table_alaw2ulaw[] =
2721         {
2722                 0x29, 0x2A, 0x27, 0x28, 0x2D, 0x2E, 0x2B, 0x2C, 
2723                 0x21, 0x22, 0x1F, 0x20, 0x25, 0x26, 0x23, 0x24, 
2724                 0x39, 0x3A, 0x37, 0x38, 0x3D, 0x3E, 0x3B, 0x3C, 
2725                 0x31, 0x32, 0x2F, 0x30, 0x35, 0x36, 0x33, 0x34, 
2726                 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 
2727                 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 
2728                 0x1A, 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 
2729                 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 
2730                 0x62, 0x63, 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 
2731                 0x5D, 0x5D, 0x5C, 0x5C, 0x5F, 0x5F, 0x5E, 0x5E, 
2732                 0x74, 0x76, 0x70, 0x72, 0x7C, 0x7E, 0x78, 0x7A, 
2733                 0x6A, 0x6B, 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 
2734                 0x48, 0x49, 0x46, 0x47, 0x4C, 0x4D, 0x4A, 0x4B, 
2735                 0x40, 0x41, 0x3F, 0x3F, 0x44, 0x45, 0x42, 0x43, 
2736                 0x56, 0x57, 0x54, 0x55, 0x5A, 0x5B, 0x58, 0x59, 
2737                 0x4F, 0x4F, 0x4E, 0x4E, 0x52, 0x53, 0x50, 0x51, 
2738                 0xA9, 0xAA, 0xA7, 0xA8, 0xAD, 0xAE, 0xAB, 0xAC, 
2739                 0xA1, 0xA2, 0x9F, 0xA0, 0xA5, 0xA6, 0xA3, 0xA4, 
2740                 0xB9, 0xBA, 0xB7, 0xB8, 0xBD, 0xBE, 0xBB, 0xBC, 
2741                 0xB1, 0xB2, 0xAF, 0xB0, 0xB5, 0xB6, 0xB3, 0xB4, 
2742                 0x8A, 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 
2743                 0x82, 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 
2744                 0x9A, 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 
2745                 0x92, 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 
2746                 0xE2, 0xE3, 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 
2747                 0xDD, 0xDD, 0xDC, 0xDC, 0xDF, 0xDF, 0xDE, 0xDE, 
2748                 0xF4, 0xF6, 0xF0, 0xF2, 0xFC, 0xFE, 0xF8, 0xFA, 
2749                 0xEA, 0xEB, 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 
2750                 0xC8, 0xC9, 0xC6, 0xC7, 0xCC, 0xCD, 0xCA, 0xCB, 
2751                 0xC0, 0xC1, 0xBF, 0xBF, 0xC4, 0xC5, 0xC2, 0xC3, 
2752                 0xD6, 0xD7, 0xD4, 0xD5, 0xDA, 0xDB, 0xD8, 0xD9, 
2753                 0xCF, 0xCF, 0xCE, 0xCE, 0xD2, 0xD3, 0xD0, 0xD1
2754         };
2755
2756         while (len--)
2757         {
2758                 *buff = table_alaw2ulaw[*(unsigned char *)buff];
2759                 buff++;
2760         }
2761 }
2762
2763 static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos)
2764 {
2765         unsigned long i = *ppos;
2766         IXJ * j = get_ixj(NUM(file_p->f_dentry->d_inode));
2767
2768         DECLARE_WAITQUEUE(wait, current);
2769
2770         if (j->flags.inread)
2771                 return -EALREADY;
2772
2773         j->flags.inread = 1;
2774
2775         add_wait_queue(&j->read_q, &wait);
2776         set_current_state(TASK_INTERRUPTIBLE);
2777         mb();
2778
2779         while (!j->read_buffer_ready || (j->dtmf_state && j->flags.dtmf_oob)) {
2780                 ++j->read_wait;
2781                 if (file_p->f_flags & O_NONBLOCK) {
2782                         set_current_state(TASK_RUNNING);
2783                         remove_wait_queue(&j->read_q, &wait);
2784                         j->flags.inread = 0;
2785                         return -EAGAIN;
2786                 }
2787                 if (!ixj_hookstate(j)) {
2788                         set_current_state(TASK_RUNNING);
2789                         remove_wait_queue(&j->read_q, &wait);
2790                         j->flags.inread = 0;
2791                         return 0;
2792                 }
2793                 interruptible_sleep_on(&j->read_q);
2794                 if (signal_pending(current)) {
2795                         set_current_state(TASK_RUNNING);
2796                         remove_wait_queue(&j->read_q, &wait);
2797                         j->flags.inread = 0;
2798                         return -EINTR;
2799                 }
2800         }
2801
2802         remove_wait_queue(&j->read_q, &wait);
2803         set_current_state(TASK_RUNNING);
2804         /* Don't ever copy more than the user asks */
2805         if(j->rec_codec == ALAW)
2806                 ulaw2alaw(j->read_buffer, min(length, j->read_buffer_size));
2807         i = copy_to_user(buf, j->read_buffer, min(length, j->read_buffer_size));
2808         j->read_buffer_ready = 0;
2809         if (i) {
2810                 j->flags.inread = 0;
2811                 return -EFAULT;
2812         } else {
2813                 j->flags.inread = 0;
2814                 return min(length, j->read_buffer_size);
2815         }
2816 }
2817
2818 static ssize_t ixj_enhanced_read(struct file * file_p, char __user *buf, size_t length,
2819                           loff_t * ppos)
2820 {
2821         int pre_retval;
2822         ssize_t read_retval = 0;
2823         IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode));
2824
2825         pre_retval = ixj_PreRead(j, 0L);
2826         switch (pre_retval) {
2827         case NORMAL:
2828                 read_retval = ixj_read(file_p, buf, length, ppos);
2829                 ixj_PostRead(j, 0L);
2830                 break;
2831         case NOPOST:
2832                 read_retval = ixj_read(file_p, buf, length, ppos);
2833                 break;
2834         case POSTONLY:
2835                 ixj_PostRead(j, 0L);
2836                 break;
2837         default:
2838                 read_retval = pre_retval;
2839         }
2840         return read_retval;
2841 }
2842
2843 static ssize_t ixj_write(struct file *file_p, const char __user *buf, size_t count, loff_t * ppos)
2844 {
2845         unsigned long i = *ppos;
2846         IXJ *j = file_p->private_data;
2847
2848         DECLARE_WAITQUEUE(wait, current);
2849
2850         if (j->flags.inwrite)
2851                 return -EALREADY;
2852
2853         j->flags.inwrite = 1;
2854
2855         add_wait_queue(&j->write_q, &wait);
2856         set_current_state(TASK_INTERRUPTIBLE);
2857         mb();
2858
2859
2860         while (!j->write_buffers_empty) {
2861                 ++j->write_wait;
2862                 if (file_p->f_flags & O_NONBLOCK) {
2863                         set_current_state(TASK_RUNNING);
2864                         remove_wait_queue(&j->write_q, &wait);
2865                         j->flags.inwrite = 0;
2866                         return -EAGAIN;
2867                 }
2868                 if (!ixj_hookstate(j)) {
2869                         set_current_state(TASK_RUNNING);
2870                         remove_wait_queue(&j->write_q, &wait);
2871                         j->flags.inwrite = 0;
2872                         return 0;
2873                 }
2874                 interruptible_sleep_on(&j->write_q);
2875                 if (signal_pending(current)) {
2876                         set_current_state(TASK_RUNNING);
2877                         remove_wait_queue(&j->write_q, &wait);
2878                         j->flags.inwrite = 0;
2879                         return -EINTR;
2880                 }
2881         }
2882         set_current_state(TASK_RUNNING);
2883         remove_wait_queue(&j->write_q, &wait);
2884         if (j->write_buffer_wp + count >= j->write_buffer_end)
2885                 j->write_buffer_wp = j->write_buffer;
2886         i = copy_from_user(j->write_buffer_wp, buf, min(count, j->write_buffer_size));
2887         if (i) {
2888                 j->flags.inwrite = 0;
2889                 return -EFAULT;
2890         }
2891        if(j->play_codec == ALAW)
2892                alaw2ulaw(j->write_buffer_wp, min(count, j->write_buffer_size));
2893         j->flags.inwrite = 0;
2894         return min(count, j->write_buffer_size);
2895 }
2896
2897 static ssize_t ixj_enhanced_write(struct file * file_p, const char __user *buf, size_t count, loff_t * ppos)
2898 {
2899         int pre_retval;
2900         ssize_t write_retval = 0;
2901
2902         IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode));
2903
2904         pre_retval = ixj_PreWrite(j, 0L);
2905         switch (pre_retval) {
2906         case NORMAL:
2907                 write_retval = ixj_write(file_p, buf, count, ppos);
2908                 if (write_retval > 0) {
2909                         ixj_PostWrite(j, 0L);
2910                         j->write_buffer_wp += write_retval;
2911                         j->write_buffers_empty--;
2912                 }
2913                 break;
2914         case NOPOST:
2915                 write_retval = ixj_write(file_p, buf, count, ppos);
2916                 if (write_retval > 0) {
2917                         j->write_buffer_wp += write_retval;
2918                         j->write_buffers_empty--;
2919                 }
2920                 break;
2921         case POSTONLY:
2922                 ixj_PostWrite(j, 0L);
2923                 break;
2924         default:
2925                 write_retval = pre_retval;
2926         }
2927         return write_retval;
2928 }
2929
2930 static void ixj_read_frame(IXJ *j)
2931 {
2932         int cnt, dly;
2933
2934         if (j->read_buffer) {
2935                 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2936                         if (!(cnt % 16) && !IsRxReady(j)) {
2937                                 dly = 0;
2938                                 while (!IsRxReady(j)) {
2939                                         if (dly++ > 5) {
2940                                                 dly = 0;
2941                                                 break;
2942                                         }
2943                                         udelay(10);
2944                                 }
2945                         }
2946                         /* Throw away word 0 of the 8021 compressed format to get standard G.729. */
2947                         if (j->rec_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
2948                                 inb_p(j->DSPbase + 0x0E);
2949                                 inb_p(j->DSPbase + 0x0F);
2950                         }
2951                         *(j->read_buffer + cnt) = inb_p(j->DSPbase + 0x0E);
2952                         *(j->read_buffer + cnt + 1) = inb_p(j->DSPbase + 0x0F);
2953                 }
2954                 ++j->framesread;
2955                 if (j->intercom != -1) {
2956                         if (IsTxReady(get_ixj(j->intercom))) {
2957                                 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2958                                         if (!(cnt % 16) && !IsTxReady(j)) {
2959                                                 dly = 0;
2960                                                 while (!IsTxReady(j)) {
2961                                                         if (dly++ > 5) {
2962                                                                 dly = 0;
2963                                                                 break;
2964                                                         }
2965                                                         udelay(10);
2966                                                 }
2967                                         }
2968                                         outb_p(*(j->read_buffer + cnt), get_ixj(j->intercom)->DSPbase + 0x0C);
2969                                         outb_p(*(j->read_buffer + cnt + 1), get_ixj(j->intercom)->DSPbase + 0x0D);
2970                                 }
2971                                 get_ixj(j->intercom)->frameswritten++;
2972                         }
2973                 } else {
2974                         j->read_buffer_ready = 1;
2975                         wake_up_interruptible(&j->read_q);      /* Wake any blocked readers */
2976
2977                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
2978
2979                         if(j->ixj_signals[SIG_READ_READY])
2980                                 ixj_kill_fasync(j, SIG_READ_READY, POLL_OUT);
2981                 }
2982         }
2983 }
2984
2985 static short fsk[][6][20] =
2986 {
2987         {
2988                 {
2989                         0, 17846, 29934, 32364, 24351, 8481, -10126, -25465, -32587, -29196,
2990                         -16384, 1715, 19260, 30591, 32051, 23170, 6813, -11743, -26509, -32722
2991                 },
2992                 {
2993                         -28377, -14876, 3425, 20621, 31163, 31650, 21925, 5126, -13328, -27481,
2994                         -32767, -27481, -13328, 5126, 21925, 31650, 31163, 20621, 3425, -14876
2995                 },
2996                 {
2997                         -28377, -32722, -26509, -11743, 6813, 23170, 32051, 30591, 19260, 1715,
2998                         -16384, -29196, -32587, -25465, -10126, 8481, 24351, 32364, 29934, 17846
2999                 },
3000                 {
3001                         0, -17846, -29934, -32364, -24351, -8481, 10126, 25465, 32587, 29196,
3002                         16384, -1715, -19260, -30591, -32051, -23170, -6813, 11743, 26509, 32722
3003                 },
3004                 {
3005                         28377, 14876, -3425, -20621, -31163, -31650, -21925, -5126, 13328, 27481,
3006                         32767, 27481, 13328, -5126, -21925, -31650, -31163, -20621, -3425, 14876
3007                 },
3008                 {
3009                         28377, 32722, 26509, 11743, -6813, -23170, -32051, -30591, -19260, -1715,
3010                         16384, 29196, 32587, 25465, 10126, -8481, -24351, -32364, -29934, -17846
3011                 }
3012         },
3013         {
3014                 {
3015                         0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126,
3016                         0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126
3017                 },
3018                 {
3019                         -28377, -21925, -13328, -3425, 6813, 16384, 24351, 29934, 32587, 32051,
3020                         28377, 21925, 13328, 3425, -6813, -16384, -24351, -29934, -32587, -32051
3021                 },
3022                 {
3023                         -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925,
3024                         28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925
3025                 },
3026                 {
3027                         0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126,
3028                         0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126
3029                 },
3030                 {
3031                         28377, 21925, 13328, 3425, -6813, -16383, -24351, -29934, -32587, -32051,
3032                         -28377, -21925, -13328, -3425, 6813, 16383, 24351, 29934, 32587, 32051
3033                 },
3034                 {
3035                         28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925,
3036                         -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925
3037                 }
3038         }
3039 };
3040
3041
3042 static void ixj_write_cid_bit(IXJ *j, int bit)
3043 {
3044         while (j->fskcnt < 20) {
3045                 if(j->fskdcnt < (j->fsksize - 1))
3046                         j->fskdata[j->fskdcnt++] = fsk[bit][j->fskz][j->fskcnt];
3047
3048                 j->fskcnt += 3;
3049         }
3050         j->fskcnt %= 20;
3051
3052         if (!bit)
3053                 j->fskz++;
3054         if (j->fskz >= 6)
3055                 j->fskz = 0;
3056
3057 }
3058
3059 static void ixj_write_cid_byte(IXJ *j, char byte)
3060 {
3061         IXJ_CBYTE cb;
3062
3063                 cb.cbyte = byte;
3064                 ixj_write_cid_bit(j, 0);
3065                 ixj_write_cid_bit(j, cb.cbits.b0 ? 1 : 0);
3066                 ixj_write_cid_bit(j, cb.cbits.b1 ? 1 : 0);
3067                 ixj_write_cid_bit(j, cb.cbits.b2 ? 1 : 0);
3068                 ixj_write_cid_bit(j, cb.cbits.b3 ? 1 : 0);
3069                 ixj_write_cid_bit(j, cb.cbits.b4 ? 1 : 0);
3070                 ixj_write_cid_bit(j, cb.cbits.b5 ? 1 : 0);
3071                 ixj_write_cid_bit(j, cb.cbits.b6 ? 1 : 0);
3072                 ixj_write_cid_bit(j, cb.cbits.b7 ? 1 : 0);
3073                 ixj_write_cid_bit(j, 1);
3074 }
3075
3076 static void ixj_write_cid_seize(IXJ *j)
3077 {
3078         int cnt;
3079
3080         for (cnt = 0; cnt < 150; cnt++) {
3081                 ixj_write_cid_bit(j, 0);
3082                 ixj_write_cid_bit(j, 1);
3083         }
3084         for (cnt = 0; cnt < 180; cnt++) {
3085                 ixj_write_cid_bit(j, 1);
3086         }
3087 }
3088
3089 static void ixj_write_cidcw_seize(IXJ *j)
3090 {
3091         int cnt;
3092
3093         for (cnt = 0; cnt < 80; cnt++) {
3094                 ixj_write_cid_bit(j, 1);
3095         }
3096 }
3097
3098 static int ixj_write_cid_string(IXJ *j, char *s, int checksum)
3099 {
3100         int cnt;
3101
3102         for (cnt = 0; cnt < strlen(s); cnt++) {
3103                 ixj_write_cid_byte(j, s[cnt]);
3104                 checksum = (checksum + s[cnt]);
3105         }
3106         return checksum;
3107 }
3108
3109 static void ixj_pad_fsk(IXJ *j, int pad)
3110 {
3111         int cnt; 
3112
3113         for (cnt = 0; cnt < pad; cnt++) {
3114                 if(j->fskdcnt < (j->fsksize - 1))
3115                         j->fskdata[j->fskdcnt++] = 0x0000;
3116         }
3117         for (cnt = 0; cnt < 720; cnt++) {
3118                 if(j->fskdcnt < (j->fsksize - 1))
3119                         j->fskdata[j->fskdcnt++] = 0x0000;
3120         }
3121 }
3122
3123 static void ixj_pre_cid(IXJ *j)
3124 {
3125         j->cid_play_codec = j->play_codec;
3126         j->cid_play_frame_size = j->play_frame_size;
3127         j->cid_play_volume = get_play_volume(j);
3128         j->cid_play_flag = j->flags.playing;
3129
3130         j->cid_rec_codec = j->rec_codec;
3131         j->cid_rec_volume = get_rec_volume(j);
3132         j->cid_rec_flag = j->flags.recording;
3133
3134         j->cid_play_aec_level = j->aec_level;
3135
3136         switch(j->baseframe.low) {
3137                 case 0xA0:
3138                         j->cid_base_frame_size = 20;
3139                         break;
3140                 case 0x50:
3141                         j->cid_base_frame_size = 10;
3142                         break;
3143                 case 0xF0:
3144                         j->cid_base_frame_size = 30;
3145                         break;
3146         }
3147
3148         ixj_play_stop(j);
3149         ixj_cpt_stop(j);
3150
3151         j->flags.cidplay = 1;
3152
3153         set_base_frame(j, 30);
3154         set_play_codec(j, LINEAR16);
3155         set_play_volume(j, 0x1B);
3156         ixj_play_start(j);
3157 }
3158
3159 static void ixj_post_cid(IXJ *j)
3160 {
3161         ixj_play_stop(j);
3162
3163         if(j->cidsize > 5000) {
3164                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
3165         }
3166         j->flags.cidplay = 0;
3167         if(ixjdebug & 0x0200) {
3168                 printk("IXJ phone%d Finished Playing CallerID data %ld\n", j->board, jiffies);
3169         }
3170
3171         ixj_fsk_free(j);
3172
3173         j->fskdcnt = 0;
3174         set_base_frame(j, j->cid_base_frame_size);
3175         set_play_codec(j, j->cid_play_codec);
3176         ixj_aec_start(j, j->cid_play_aec_level);
3177         set_play_volume(j, j->cid_play_volume);
3178
3179         set_rec_codec(j, j->cid_rec_codec);
3180         set_rec_volume(j, j->cid_rec_volume);
3181
3182         if(j->cid_rec_flag)
3183                 ixj_record_start(j);
3184
3185         if(j->cid_play_flag)
3186                 ixj_play_start(j);
3187
3188         if(j->cid_play_flag) {
3189                 wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3190         }
3191 }
3192
3193 static void ixj_write_cid(IXJ *j)
3194 {
3195         char sdmf1[50];
3196         char sdmf2[50];
3197         char sdmf3[80];
3198         char mdmflen, len1, len2, len3;
3199         int pad;
3200
3201         int checksum = 0;
3202
3203         if (j->dsp.low == 0x20 || j->flags.cidplay)
3204                 return;
3205
3206         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3207         j->cidsize = j->cidcnt = 0;
3208
3209         ixj_fsk_alloc(j);
3210
3211         strcpy(sdmf1, j->cid_send.month);
3212         strcat(sdmf1, j->cid_send.day);
3213         strcat(sdmf1, j->cid_send.hour);
3214         strcat(sdmf1, j->cid_send.min);
3215         strcpy(sdmf2, j->cid_send.number);
3216         strcpy(sdmf3, j->cid_send.name);
3217
3218         len1 = strlen(sdmf1);
3219         len2 = strlen(sdmf2);
3220         len3 = strlen(sdmf3);
3221         mdmflen = len1 + len2 + len3 + 6;
3222
3223         while(1){
3224                 ixj_write_cid_seize(j);
3225
3226                 ixj_write_cid_byte(j, 0x80);
3227                 checksum = 0x80;
3228                 ixj_write_cid_byte(j, mdmflen);
3229                 checksum = checksum + mdmflen;
3230
3231                 ixj_write_cid_byte(j, 0x01);
3232                 checksum = checksum + 0x01;
3233                 ixj_write_cid_byte(j, len1);
3234                 checksum = checksum + len1;
3235                 checksum = ixj_write_cid_string(j, sdmf1, checksum);
3236                 if(ixj_hookstate(j) & 1)
3237                         break;
3238
3239                 ixj_write_cid_byte(j, 0x02);
3240                 checksum = checksum + 0x02;
3241                 ixj_write_cid_byte(j, len2);
3242                 checksum = checksum + len2;
3243                 checksum = ixj_write_cid_string(j, sdmf2, checksum);
3244                 if(ixj_hookstate(j) & 1)
3245                         break;
3246
3247                 ixj_write_cid_byte(j, 0x07);
3248                 checksum = checksum + 0x07;
3249                 ixj_write_cid_byte(j, len3);
3250                 checksum = checksum + len3;
3251                 checksum = ixj_write_cid_string(j, sdmf3, checksum);
3252                 if(ixj_hookstate(j) & 1)
3253                         break;
3254
3255                 checksum %= 256;
3256                 checksum ^= 0xFF;
3257                 checksum += 1;
3258
3259                 ixj_write_cid_byte(j, (char) checksum);
3260
3261                 pad = j->fskdcnt % 240;
3262                 if (pad) {
3263                         pad = 240 - pad;
3264                 }
3265                 ixj_pad_fsk(j, pad);
3266                 break;
3267         }
3268
3269         ixj_write_frame(j);
3270 }
3271
3272 static void ixj_write_cidcw(IXJ *j)
3273 {
3274         IXJ_TONE ti;
3275
3276         char sdmf1[50];
3277         char sdmf2[50];
3278         char sdmf3[80];
3279         char mdmflen, len1, len2, len3;
3280         int pad;
3281
3282         int checksum = 0;
3283
3284         if (j->dsp.low == 0x20 || j->flags.cidplay)
3285                 return;
3286
3287         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3288         j->cidsize = j->cidcnt = 0;
3289
3290         ixj_fsk_alloc(j);
3291
3292         j->flags.cidcw_ack = 0;
3293
3294         ti.tone_index = 23;
3295         ti.gain0 = 1;
3296         ti.freq0 = hz440;
3297         ti.gain1 = 0;
3298         ti.freq1 = 0;
3299         ixj_init_tone(j, &ti);
3300
3301         ixj_set_tone_on(1500, j);
3302         ixj_set_tone_off(32, j);
3303         if(ixjdebug & 0x0200) {
3304                 printk("IXJ cidcw phone%d first tone start at %ld\n", j->board, jiffies);
3305         }
3306         ixj_play_tone(j, 23);
3307
3308         clear_bit(j->board, &j->busyflags);
3309         while(j->tone_state) {
3310                 set_current_state(TASK_INTERRUPTIBLE);
3311                 schedule_timeout(1);
3312         }
3313         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3314                 set_current_state(TASK_INTERRUPTIBLE);
3315                 schedule_timeout(1);
3316         }
3317         if(ixjdebug & 0x0200) {
3318                 printk("IXJ cidcw phone%d first tone end at %ld\n", j->board, jiffies);
3319         }
3320
3321         ti.tone_index = 24;
3322         ti.gain0 = 1;
3323         ti.freq0 = hz2130;
3324         ti.gain1 = 0;
3325         ti.freq1 = hz2750;
3326         ixj_init_tone(j, &ti);
3327
3328         ixj_set_tone_off(10, j);
3329         ixj_set_tone_on(600, j);
3330         if(ixjdebug & 0x0200) {
3331                 printk("IXJ cidcw phone%d second tone start at %ld\n", j->board, jiffies);
3332         }
3333         ixj_play_tone(j, 24);
3334
3335         clear_bit(j->board, &j->busyflags);
3336         while(j->tone_state) {
3337                 set_current_state(TASK_INTERRUPTIBLE);
3338                 schedule_timeout(1);
3339         }
3340         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3341                 set_current_state(TASK_INTERRUPTIBLE);
3342                 schedule_timeout(1);
3343         }
3344         if(ixjdebug & 0x0200) {
3345                 printk("IXJ cidcw phone%d sent second tone at %ld\n", j->board, jiffies);
3346         }
3347
3348         j->cidcw_wait = jiffies + ((50 * hertz) / 100);
3349
3350         clear_bit(j->board, &j->busyflags);
3351         while(!j->flags.cidcw_ack && time_before(jiffies, j->cidcw_wait)) {
3352                 set_current_state(TASK_INTERRUPTIBLE);
3353                 schedule_timeout(1);
3354         }
3355         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3356                 set_current_state(TASK_INTERRUPTIBLE);
3357                 schedule_timeout(1);
3358         }
3359         j->cidcw_wait = 0;
3360         if(!j->flags.cidcw_ack) {
3361                 if(ixjdebug & 0x0200) {
3362                         printk("IXJ cidcw phone%d did not receive ACK from display %ld\n", j->board, jiffies);
3363                 }
3364                 ixj_post_cid(j);
3365                 if(j->cid_play_flag) {
3366                         wake_up_interruptible(&j->write_q);     /* Wake any blocked readers */
3367                 }
3368                 return;
3369         } else {
3370                 ixj_pre_cid(j);
3371         }
3372         j->flags.cidcw_ack = 0;
3373         strcpy(sdmf1, j->cid_send.month);
3374         strcat(sdmf1, j->cid_send.day);
3375         strcat(sdmf1, j->cid_send.hour);
3376         strcat(sdmf1, j->cid_send.min);
3377         strcpy(sdmf2, j->cid_send.number);
3378         strcpy(sdmf3, j->cid_send.name);
3379
3380         len1 = strlen(sdmf1);
3381         len2 = strlen(sdmf2);
3382         len3 = strlen(sdmf3);
3383         mdmflen = len1 + len2 + len3 + 6;
3384
3385         ixj_write_cidcw_seize(j);
3386
3387         ixj_write_cid_byte(j, 0x80);
3388         checksum = 0x80;
3389         ixj_write_cid_byte(j, mdmflen);
3390         checksum = checksum + mdmflen;
3391
3392         ixj_write_cid_byte(j, 0x01);
3393         checksum = checksum + 0x01;
3394         ixj_write_cid_byte(j, len1);
3395         checksum = checksum + len1;
3396         checksum = ixj_write_cid_string(j, sdmf1, checksum);
3397
3398         ixj_write_cid_byte(j, 0x02);
3399         checksum = checksum + 0x02;
3400         ixj_write_cid_byte(j, len2);
3401         checksum = checksum + len2;
3402         checksum = ixj_write_cid_string(j, sdmf2, checksum);
3403
3404         ixj_write_cid_byte(j, 0x07);
3405         checksum = checksum + 0x07;
3406         ixj_write_cid_byte(j, len3);
3407         checksum = checksum + len3;
3408         checksum = ixj_write_cid_string(j, sdmf3, checksum);
3409
3410         checksum %= 256;
3411         checksum ^= 0xFF;
3412         checksum += 1;
3413
3414         ixj_write_cid_byte(j, (char) checksum);
3415
3416         pad = j->fskdcnt % 240;
3417         if (pad) {
3418                 pad = 240 - pad;
3419         }
3420         ixj_pad_fsk(j, pad);
3421         if(ixjdebug & 0x0200) {
3422                 printk("IXJ cidcw phone%d sent FSK data at %ld\n", j->board, jiffies);
3423         }
3424 }
3425
3426 static void ixj_write_vmwi(IXJ *j, int msg)
3427 {
3428         char mdmflen;
3429         int pad;
3430
3431         int checksum = 0;
3432
3433         if (j->dsp.low == 0x20 || j->flags.cidplay)
3434                 return;
3435
3436         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3437         j->cidsize = j->cidcnt = 0;
3438
3439         ixj_fsk_alloc(j);
3440
3441         mdmflen = 3;
3442
3443         if (j->port == PORT_POTS)
3444                 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
3445
3446         ixj_write_cid_seize(j);
3447
3448         ixj_write_cid_byte(j, 0x82);
3449         checksum = 0x82;
3450         ixj_write_cid_byte(j, mdmflen);
3451         checksum = checksum + mdmflen;
3452
3453         ixj_write_cid_byte(j, 0x0B);
3454         checksum = checksum + 0x0B;
3455         ixj_write_cid_byte(j, 1);
3456         checksum = checksum + 1;
3457
3458         if(msg) {
3459                 ixj_write_cid_byte(j, 0xFF);
3460                 checksum = checksum + 0xFF;
3461         }
3462         else {
3463                 ixj_write_cid_byte(j, 0x00);
3464                 checksum = checksum + 0x00;
3465         }
3466
3467         checksum %= 256;
3468         checksum ^= 0xFF;
3469         checksum += 1;
3470
3471         ixj_write_cid_byte(j, (char) checksum);
3472
3473         pad = j->fskdcnt % 240;
3474         if (pad) {
3475                 pad = 240 - pad;
3476         }
3477         ixj_pad_fsk(j, pad);
3478 }
3479
3480 static void ixj_write_frame(IXJ *j)
3481 {
3482         int cnt, frame_count, dly;
3483         IXJ_WORD dat;
3484         BYTES blankword;
3485
3486         frame_count = 0;
3487         if(j->flags.cidplay) {
3488                 for(cnt = 0; cnt < 480; cnt++) {
3489                         if (!(cnt % 16) && !IsTxReady(j)) {
3490                                 dly = 0;
3491                                 while (!IsTxReady(j)) {
3492                                         if (dly++ > 5) {
3493                                                 dly = 0;
3494                                                 break;
3495                                         }
3496                                         udelay(10);
3497                                 }
3498                         }
3499                         dat.word = j->fskdata[j->cidcnt++];
3500                         outb_p(dat.bytes.low, j->DSPbase + 0x0C);
3501                         outb_p(dat.bytes.high, j->DSPbase + 0x0D);
3502                         cnt++;
3503                 }
3504                 if(j->cidcnt >= j->fskdcnt) {
3505                         ixj_post_cid(j);
3506                 }
3507                 /* This may seem rude, but if we just played one frame of FSK data for CallerID
3508                    and there is real audio data in the buffer, we need to throw it away because 
3509                    we just used it's time slot */
3510                 if (j->write_buffer_rp > j->write_buffer_wp) {
3511                         j->write_buffer_rp += j->cid_play_frame_size * 2;
3512                         if (j->write_buffer_rp >= j->write_buffer_end) {
3513                                 j->write_buffer_rp = j->write_buffer;
3514                         }
3515                         j->write_buffers_empty++;
3516                         wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3517
3518                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
3519                 }
3520         } else if (j->write_buffer && j->write_buffers_empty < 1) { 
3521                 if (j->write_buffer_wp > j->write_buffer_rp) {
3522                         frame_count =
3523                             (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2);
3524                 }
3525                 if (j->write_buffer_rp > j->write_buffer_wp) {
3526                         frame_count =
3527                             (j->write_buffer_wp - j->write_buffer) / (j->play_frame_size * 2) +
3528                             (j->write_buffer_end - j->write_buffer_rp) / (j->play_frame_size * 2);
3529                 }
3530                 if (frame_count >= 1) {
3531                         if (j->ver.low == 0x12 && j->play_mode && j->flags.play_first_frame) {
3532                                 switch (j->play_mode) {
3533                                 case PLAYBACK_MODE_ULAW:
3534                                 case PLAYBACK_MODE_ALAW:
3535                                         blankword.low = blankword.high = 0xFF;
3536                                         break;
3537                                 case PLAYBACK_MODE_8LINEAR:
3538                                 case PLAYBACK_MODE_16LINEAR:
3539                                         blankword.low = blankword.high = 0x00;
3540                                         break;
3541                                 case PLAYBACK_MODE_8LINEAR_WSS:
3542                                         blankword.low = blankword.high = 0x80;
3543                                         break;
3544                                 }
3545                                 for (cnt = 0; cnt < 16; cnt++) {
3546                                         if (!(cnt % 16) && !IsTxReady(j)) {
3547                                                 dly = 0;
3548                                                 while (!IsTxReady(j)) {
3549                                                         if (dly++ > 5) {
3550                                                                 dly = 0;
3551                                                                 break;
3552                                                         }
3553                                                         udelay(10);
3554                                                 }
3555                                         }
3556                                         outb_p((blankword.low), j->DSPbase + 0x0C);
3557                                         outb_p((blankword.high), j->DSPbase + 0x0D);
3558                                 }
3559                                 j->flags.play_first_frame = 0;
3560                         } else  if (j->play_codec == G723_63 && j->flags.play_first_frame) {
3561                                 for (cnt = 0; cnt < 24; cnt++) {
3562                                         if(cnt == 12) {
3563                                                 blankword.low = 0x02;
3564                                                 blankword.high = 0x00;
3565                                         }
3566                                         else {
3567                                                 blankword.low = blankword.high = 0x00;
3568                                         }
3569                                         if (!(cnt % 16) && !IsTxReady(j)) {
3570                                                 dly = 0;
3571                                                 while (!IsTxReady(j)) {
3572                                                         if (dly++ > 5) {
3573                                                                 dly = 0;
3574                                                                 break;
3575                                                         }
3576                                                         udelay(10);
3577                                                 }
3578                                         }
3579                                         outb_p((blankword.low), j->DSPbase + 0x0C);
3580                                         outb_p((blankword.high), j->DSPbase + 0x0D);
3581                                 }
3582                                 j->flags.play_first_frame = 0;
3583                         }
3584                         for (cnt = 0; cnt < j->play_frame_size * 2; cnt += 2) {
3585                                 if (!(cnt % 16) && !IsTxReady(j)) {
3586                                         dly = 0;
3587                                         while (!IsTxReady(j)) {
3588                                                 if (dly++ > 5) {
3589                                                         dly = 0;
3590                                                         break;
3591                                                 }
3592                                                 udelay(10);
3593                                         }
3594                                 }
3595                         /* Add word 0 to G.729 frames for the 8021.  Right now we don't do VAD/CNG  */
3596                                 if (j->play_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
3597                                         if(j->write_buffer_rp + cnt == 0 && j->write_buffer_rp + cnt + 1 == 0 && j->write_buffer_rp + cnt + 2 == 0 &&
3598                                            j->write_buffer_rp + cnt + 3 == 0 && j->write_buffer_rp + cnt + 4 == 0 && j->write_buffer_rp + cnt + 5 == 0 &&
3599                                            j->write_buffer_rp + cnt + 6 == 0 && j->write_buffer_rp + cnt + 7 == 0 && j->write_buffer_rp + cnt + 8 == 0 &&
3600                                            j->write_buffer_rp + cnt + 9 == 0) {
3601                                         /* someone is trying to write silence lets make this a type 0 frame. */
3602                                                 outb_p(0x00, j->DSPbase + 0x0C);
3603                                                 outb_p(0x00, j->DSPbase + 0x0D);
3604                                         } else {
3605                                         /* so all other frames are type 1. */
3606                                                 outb_p(0x01, j->DSPbase + 0x0C);
3607                                                 outb_p(0x00, j->DSPbase + 0x0D);
3608                                         }
3609                                 }
3610                                 outb_p(*(j->write_buffer_rp + cnt), j->DSPbase + 0x0C);
3611                                 outb_p(*(j->write_buffer_rp + cnt + 1), j->DSPbase + 0x0D);
3612                                 *(j->write_buffer_rp + cnt) = 0;
3613                                 *(j->write_buffer_rp + cnt + 1) = 0;
3614                         }
3615                         j->write_buffer_rp += j->play_frame_size * 2;
3616                         if (j->write_buffer_rp >= j->write_buffer_end) {
3617                                 j->write_buffer_rp = j->write_buffer;
3618                         }
3619                         j->write_buffers_empty++;
3620                         wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3621
3622                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
3623
3624                         ++j->frameswritten;
3625                 }
3626         } else {
3627                 j->drybuffer++;
3628         }
3629         if(j->ixj_signals[SIG_WRITE_READY]) {
3630                 ixj_kill_fasync(j, SIG_WRITE_READY, POLL_OUT);
3631         }
3632 }
3633
3634 static int idle(IXJ *j)
3635 {
3636         if (ixj_WriteDSPCommand(0x0000, j))             /* DSP Idle */
3637
3638                 return 0;
3639
3640         if (j->ssr.high || j->ssr.low) {
3641                 return 0;
3642         } else {
3643                 j->play_mode = -1;
3644                 j->flags.playing = 0;
3645                 j->rec_mode = -1;
3646                 j->flags.recording = 0;
3647                 return 1;
3648         }
3649 }
3650
3651 static int set_base_frame(IXJ *j, int size)
3652 {
3653         unsigned short cmd;
3654         int cnt;
3655
3656         idle(j);
3657         j->cid_play_aec_level = j->aec_level;
3658         aec_stop(j);
3659         for (cnt = 0; cnt < 10; cnt++) {
3660                 if (idle(j))
3661                         break;
3662         }
3663         if (j->ssr.high || j->ssr.low)
3664                 return -1;
3665         if (j->dsp.low != 0x20) {
3666                 switch (size) {
3667                 case 30:
3668                         cmd = 0x07F0;
3669                         /* Set Base Frame Size to 240 pg9-10 8021 */
3670                         break;
3671                 case 20:
3672                         cmd = 0x07A0;
3673                         /* Set Base Frame Size to 160 pg9-10 8021 */
3674                         break;
3675                 case 10:
3676                         cmd = 0x0750;
3677                         /* Set Base Frame Size to 80 pg9-10 8021 */
3678                         break;
3679                 default:
3680                         return -1;
3681                 }
3682         } else {
3683                 if (size == 30)
3684                         return size;
3685                 else
3686                         return -1;
3687         }
3688         if (ixj_WriteDSPCommand(cmd, j)) {
3689                 j->baseframe.high = j->baseframe.low = 0xFF;
3690                 return -1;
3691         } else {
3692                 j->baseframe.high = j->ssr.high;
3693                 j->baseframe.low = j->ssr.low;
3694                 /* If the status returned is 0x0000 (pg9-9 8021) the call failed */
3695                 if(j->baseframe.high == 0x00 && j->baseframe.low == 0x00) {
3696                         return -1;
3697                 }
3698         }
3699         ixj_aec_start(j, j->cid_play_aec_level);
3700         return size;
3701 }
3702
3703 static int set_rec_codec(IXJ *j, int rate)
3704 {
3705         int retval = 0;
3706
3707         j->rec_codec = rate;
3708
3709         switch (rate) {
3710         case G723_63:
3711                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3712                         j->rec_frame_size = 12;
3713                         j->rec_mode = 0;
3714                 } else {
3715                         retval = 1;
3716                 }
3717                 break;
3718         case G723_53:
3719                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3720                         j->rec_frame_size = 10;
3721                         j->rec_mode = 0;
3722                 } else {
3723                         retval = 1;
3724                 }
3725                 break;
3726         case TS85:
3727                 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
3728                         j->rec_frame_size = 16;
3729                         j->rec_mode = 0;
3730                 } else {
3731                         retval = 1;
3732                 }
3733                 break;
3734         case TS48:
3735                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3736                         j->rec_frame_size = 9;
3737                         j->rec_mode = 0;
3738                 } else {
3739                         retval = 1;
3740                 }
3741                 break;
3742         case TS41:
3743                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3744                         j->rec_frame_size = 8;
3745                         j->rec_mode = 0;
3746                 } else {
3747                         retval = 1;
3748                 }
3749                 break;
3750         case G728:
3751                 if (j->dsp.low != 0x20) {
3752                         j->rec_frame_size = 48;
3753                         j->rec_mode = 0;
3754                 } else {
3755                         retval = 1;
3756                 }
3757                 break;
3758         case G729:
3759                 if (j->dsp.low != 0x20) {
3760                         if (!j->flags.g729_loaded) {
3761                                 retval = 1;
3762                                 break;
3763                         }
3764                         switch (j->baseframe.low) {
3765                         case 0xA0:
3766                                 j->rec_frame_size = 10;
3767                                 break;
3768                         case 0x50:
3769                                 j->rec_frame_size = 5;
3770                                 break;
3771                         default:
3772                                 j->rec_frame_size = 15;
3773                                 break;
3774                         }
3775                         j->rec_mode = 0;
3776                 } else {
3777                         retval = 1;
3778                 }
3779                 break;
3780         case G729B:
3781                 if (j->dsp.low != 0x20) {
3782                         if (!j->flags.g729_loaded) {
3783                                 retval = 1;
3784                                 break;
3785                         }
3786                         switch (j->baseframe.low) {
3787                         case 0xA0:
3788                                 j->rec_frame_size = 12;
3789                                 break;
3790                         case 0x50:
3791                                 j->rec_frame_size = 6;
3792                                 break;
3793                         default:
3794                                 j->rec_frame_size = 18;
3795                                 break;
3796                         }
3797                         j->rec_mode = 0;
3798                 } else {
3799                         retval = 1;
3800                 }
3801                 break;
3802         case ULAW:
3803                 switch (j->baseframe.low) {
3804                 case 0xA0:
3805                         j->rec_frame_size = 80;
3806                         break;
3807                 case 0x50:
3808                         j->rec_frame_size = 40;
3809                         break;
3810                 default:
3811                         j->rec_frame_size = 120;
3812                         break;
3813                 }
3814                 j->rec_mode = 4;
3815                 break;
3816         case ALAW:
3817                 switch (j->baseframe.low) {
3818                 case 0xA0:
3819                         j->rec_frame_size = 80;
3820                         break;
3821                 case 0x50:
3822                         j->rec_frame_size = 40;
3823                         break;
3824                 default:
3825                         j->rec_frame_size = 120;
3826                         break;
3827                 }
3828                 j->rec_mode = 4;
3829                 break;
3830         case LINEAR16:
3831                 switch (j->baseframe.low) {
3832                 case 0xA0:
3833                         j->rec_frame_size = 160;
3834                         break;
3835                 case 0x50:
3836                         j->rec_frame_size = 80;
3837                         break;
3838                 default:
3839                         j->rec_frame_size = 240;
3840                         break;
3841                 }
3842                 j->rec_mode = 5;
3843                 break;
3844         case LINEAR8:
3845                 switch (j->baseframe.low) {
3846                 case 0xA0:
3847                         j->rec_frame_size = 80;
3848                         break;
3849                 case 0x50:
3850                         j->rec_frame_size = 40;
3851                         break;
3852                 default:
3853                         j->rec_frame_size = 120;
3854                         break;
3855                 }
3856                 j->rec_mode = 6;
3857                 break;
3858         case WSS:
3859                 switch (j->baseframe.low) {
3860                 case 0xA0:
3861                         j->rec_frame_size = 80;
3862                         break;
3863                 case 0x50:
3864                         j->rec_frame_size = 40;
3865                         break;
3866                 default:
3867                         j->rec_frame_size = 120;
3868                         break;
3869                 }
3870                 j->rec_mode = 7;
3871                 break;
3872         default:
3873                 j->rec_frame_size = 0;
3874                 j->rec_mode = -1;
3875                 if (j->read_buffer) {
3876                         kfree(j->read_buffer);
3877                         j->read_buffer = NULL;
3878                         j->read_buffer_size = 0;
3879                 }
3880                 retval = 1;
3881                 break;
3882         }
3883         return retval;
3884 }
3885
3886 static int ixj_record_start(IXJ *j)
3887 {
3888         unsigned short cmd = 0x0000;
3889
3890         if (j->read_buffer) {
3891                 ixj_record_stop(j);
3892         }
3893         j->flags.recording = 1;
3894         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
3895
3896         if(ixjdebug & 0x0002)
3897                 printk("IXJ %d Starting Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3898
3899         if (!j->rec_mode) {
3900                 switch (j->rec_codec) {
3901                 case G723_63:
3902                         cmd = 0x5131;
3903                         break;
3904                 case G723_53:
3905                         cmd = 0x5132;
3906                         break;
3907                 case TS85:
3908                         cmd = 0x5130;   /* TrueSpeech 8.5 */
3909
3910                         break;
3911                 case TS48:
3912                         cmd = 0x5133;   /* TrueSpeech 4.8 */
3913
3914                         break;
3915                 case TS41:
3916                         cmd = 0x5134;   /* TrueSpeech 4.1 */
3917
3918                         break;
3919                 case G728:
3920                         cmd = 0x5135;
3921                         break;
3922                 case G729:
3923                 case G729B:
3924                         cmd = 0x5136;
3925                         break;
3926                 default:
3927                         return 1;
3928                 }
3929                 if (ixj_WriteDSPCommand(cmd, j))
3930                         return -1;
3931         }
3932         if (!j->read_buffer) {
3933                 if (!j->read_buffer)
3934                         j->read_buffer = kmalloc(j->rec_frame_size * 2, GFP_ATOMIC);
3935                 if (!j->read_buffer) {
3936                         printk("Read buffer allocation for ixj board %d failed!\n", j->board);
3937                         return -ENOMEM;
3938                 }
3939         }
3940         j->read_buffer_size = j->rec_frame_size * 2;
3941
3942         if (ixj_WriteDSPCommand(0x5102, j))             /* Set Poll sync mode */
3943
3944                 return -1;
3945
3946         switch (j->rec_mode) {
3947         case 0:
3948                 cmd = 0x1C03;   /* Record C1 */
3949
3950                 break;
3951         case 4:
3952                 if (j->ver.low == 0x12) {
3953                         cmd = 0x1E03;   /* Record C1 */
3954
3955                 } else {
3956                         cmd = 0x1E01;   /* Record C1 */
3957
3958                 }
3959                 break;
3960         case 5:
3961                 if (j->ver.low == 0x12) {
3962                         cmd = 0x1E83;   /* Record C1 */
3963
3964                 } else {
3965                         cmd = 0x1E81;   /* Record C1 */
3966
3967                 }
3968                 break;
3969         case 6:
3970                 if (j->ver.low == 0x12) {
3971                         cmd = 0x1F03;   /* Record C1 */
3972
3973                 } else {
3974                         cmd = 0x1F01;   /* Record C1 */
3975
3976                 }
3977                 break;
3978         case 7:
3979                 if (j->ver.low == 0x12) {
3980                         cmd = 0x1F83;   /* Record C1 */
3981                 } else {
3982                         cmd = 0x1F81;   /* Record C1 */
3983                 }
3984                 break;
3985         }
3986         if (ixj_WriteDSPCommand(cmd, j))
3987                 return -1;
3988
3989         if (j->flags.playing) {
3990                 ixj_aec_start(j, j->aec_level);
3991         }
3992         return 0;
3993 }
3994
3995 static void ixj_record_stop(IXJ *j)
3996 {
3997         if(ixjdebug & 0x0002)
3998                 printk("IXJ %d Stopping Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3999
4000         if (j->read_buffer) {
4001                 kfree(j->read_buffer);
4002                 j->read_buffer = NULL;
4003                 j->read_buffer_size = 0;
4004         }
4005         if (j->rec_mode > -1) {
4006                 ixj_WriteDSPCommand(0x5120, j);
4007                 j->rec_mode = -1;
4008         }
4009         j->flags.recording = 0;
4010 }
4011 static void ixj_vad(IXJ *j, int arg)
4012 {
4013         if (arg)
4014                 ixj_WriteDSPCommand(0x513F, j);
4015         else
4016                 ixj_WriteDSPCommand(0x513E, j);
4017 }
4018
4019 static void set_rec_depth(IXJ *j, int depth)
4020 {
4021         if (depth > 60)
4022                 depth = 60;
4023         if (depth < 0)
4024                 depth = 0;
4025         ixj_WriteDSPCommand(0x5180 + depth, j);
4026 }
4027
4028 static void set_dtmf_prescale(IXJ *j, int volume)
4029 {
4030         ixj_WriteDSPCommand(0xCF07, j);
4031         ixj_WriteDSPCommand(volume, j);
4032 }
4033
4034 static int get_dtmf_prescale(IXJ *j)
4035 {
4036         ixj_WriteDSPCommand(0xCF05, j);
4037         return j->ssr.high << 8 | j->ssr.low;
4038 }
4039
4040 static void set_rec_volume(IXJ *j, int volume)
4041 {
4042         if(j->aec_level == AEC_AGC) {
4043                 if (ixjdebug & 0x0002)
4044                         printk(KERN_INFO "IXJ: /dev/phone%d Setting AGC Threshold to 0x%4.4x\n", j->board, volume);
4045                 ixj_WriteDSPCommand(0xCF96, j);
4046                 ixj_WriteDSPCommand(volume, j);
4047         } else {
4048                 if (ixjdebug & 0x0002)
4049                         printk(KERN_INFO "IXJ: /dev/phone %d Setting Record Volume to 0x%4.4x\n", j->board, volume);
4050                 ixj_WriteDSPCommand(0xCF03, j);
4051                 ixj_WriteDSPCommand(volume, j);
4052         }
4053 }
4054
4055 static int set_rec_volume_linear(IXJ *j, int volume)
4056 {
4057         int newvolume, dsprecmax;
4058
4059         if (ixjdebug & 0x0002)
4060                 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Record Volume to 0x%4.4x\n", j->board, volume);
4061         if(volume > 100 || volume < 0) {
4062           return -1;
4063         }
4064
4065         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
4066         switch (j->cardtype) {
4067         case QTI_PHONEJACK:
4068                 dsprecmax = 0x440;
4069                 break;
4070         case QTI_LINEJACK:
4071                 dsprecmax = 0x180;
4072                 ixj_mixer(0x0203, j);   /*Voice Left Volume unmute 6db */
4073                 ixj_mixer(0x0303, j);   /*Voice Right Volume unmute 6db */
4074                 ixj_mixer(0x0C00, j);   /*Mono1 unmute 12db */
4075                 break;
4076         case QTI_PHONEJACK_LITE:
4077                 dsprecmax = 0x4C0;
4078                 break;
4079         case QTI_PHONEJACK_PCI:
4080                 dsprecmax = 0x100;
4081                 break;
4082         case QTI_PHONECARD:
4083                 dsprecmax = 0x400;
4084                 break;
4085         default:
4086                 return -1;
4087         }
4088         newvolume = (dsprecmax * volume) / 100;
4089         set_rec_volume(j, newvolume);
4090         return 0;
4091 }
4092
4093 static int get_rec_volume(IXJ *j)
4094 {
4095         if(j->aec_level == AEC_AGC) {
4096                 if (ixjdebug & 0x0002)
4097                         printk(KERN_INFO "Getting AGC Threshold\n");
4098                 ixj_WriteDSPCommand(0xCF86, j);
4099                 if (ixjdebug & 0x0002)
4100                         printk(KERN_INFO "AGC Threshold is 0x%2.2x%2.2x\n", j->ssr.high, j->ssr.low);
4101                 return j->ssr.high << 8 | j->ssr.low;
4102         } else {
4103                 if (ixjdebug & 0x0002)
4104                         printk(KERN_INFO "Getting Record Volume\n");
4105                 ixj_WriteDSPCommand(0xCF01, j);
4106                 return j->ssr.high << 8 | j->ssr.low;
4107         }
4108 }
4109
4110 static int get_rec_volume_linear(IXJ *j)
4111 {
4112         int volume, newvolume, dsprecmax;
4113
4114         switch (j->cardtype) {
4115         case QTI_PHONEJACK:
4116                 dsprecmax = 0x440;
4117                 break;
4118         case QTI_LINEJACK:
4119                 dsprecmax = 0x180;
4120                 break;
4121         case QTI_PHONEJACK_LITE:
4122                 dsprecmax = 0x4C0;
4123                 break;
4124         case QTI_PHONEJACK_PCI:
4125                 dsprecmax = 0x100;
4126                 break;
4127         case QTI_PHONECARD:
4128                 dsprecmax = 0x400;
4129                 break;
4130         default:
4131                 return -1;
4132         }
4133         volume = get_rec_volume(j);
4134         newvolume = (volume * 100) / dsprecmax;
4135         if(newvolume > 100)
4136                 newvolume = 100;
4137         return newvolume;
4138 }
4139
4140 static int get_rec_level(IXJ *j)
4141 {
4142         int retval;
4143
4144         ixj_WriteDSPCommand(0xCF88, j);
4145
4146         retval = j->ssr.high << 8 | j->ssr.low;
4147         retval = (retval * 256) / 240;
4148         return retval;
4149 }
4150
4151 static void ixj_aec_start(IXJ *j, int level)
4152 {
4153         j->aec_level = level;
4154         if (ixjdebug & 0x0002)
4155                 printk(KERN_INFO "AGC set = 0x%2.2x\n", j->aec_level);
4156         if (!level) {
4157                 aec_stop(j);
4158         } else {
4159                 if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4160                         ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer */
4161
4162                         ixj_WriteDSPCommand(0x0300, j);
4163                 }
4164                 ixj_WriteDSPCommand(0xB001, j); /* AEC On */
4165
4166                 ixj_WriteDSPCommand(0xE013, j); /* Advanced AEC C1 */
4167
4168                 switch (level) {
4169                 case AEC_LOW:
4170                         ixj_WriteDSPCommand(0x0000, j); /* Advanced AEC C2 = off */
4171
4172                         ixj_WriteDSPCommand(0xE011, j);
4173                         ixj_WriteDSPCommand(0xFFFF, j);
4174
4175                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4176                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4177                         
4178                         break;
4179
4180                 case AEC_MED:
4181                         ixj_WriteDSPCommand(0x0600, j); /* Advanced AEC C2 = on medium */
4182
4183                         ixj_WriteDSPCommand(0xE011, j);
4184                         ixj_WriteDSPCommand(0x0080, j);
4185
4186                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4187                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4188                         
4189                         break;
4190
4191                 case AEC_HIGH:
4192                         ixj_WriteDSPCommand(0x0C00, j); /* Advanced AEC C2 = on high */
4193
4194                         ixj_WriteDSPCommand(0xE011, j);
4195                         ixj_WriteDSPCommand(0x0080, j);
4196
4197                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4198                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4199                         
4200                         break;
4201
4202                 case AEC_AGC:
4203                         /* First we have to put the AEC into advance auto mode so that AGC will not conflict with it */
4204                         ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
4205
4206                         ixj_WriteDSPCommand(0xE011, j);
4207                         ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
4208
4209                         ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
4210
4211                         if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4212                                 ixj_WriteDSPCommand(0x0224, j);
4213                         else
4214                                 ixj_WriteDSPCommand(0x1224, j);
4215
4216                         ixj_WriteDSPCommand(0xE014, j);
4217                         ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
4218
4219                         ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
4220
4221                         /* Now we can set the AGC initial parameters and turn it on */
4222                         ixj_WriteDSPCommand(0xCF90, j); /* Set AGC Minumum gain */
4223                         ixj_WriteDSPCommand(0x0020, j); /* to 0.125 (-18dB) */
4224         
4225                         ixj_WriteDSPCommand(0xCF91, j); /* Set AGC Maximum gain */
4226                         ixj_WriteDSPCommand(0x1000, j); /* to 16 (24dB) */
4227                         
4228                         ixj_WriteDSPCommand(0xCF92, j); /* Set AGC start gain */
4229                         ixj_WriteDSPCommand(0x0800, j); /* to 8 (+18dB) */
4230                 
4231                         ixj_WriteDSPCommand(0xCF93, j); /* Set AGC hold time */
4232                         ixj_WriteDSPCommand(0x1F40, j); /* to 2 seconds (units are 250us) */
4233                         
4234                         ixj_WriteDSPCommand(0xCF94, j); /* Set AGC Attack Time Constant */
4235                         ixj_WriteDSPCommand(0x0005, j); /* to 8ms */
4236                         
4237                         ixj_WriteDSPCommand(0xCF95, j); /* Set AGC Decay Time Constant */
4238                         ixj_WriteDSPCommand(0x000D, j); /* to 4096ms */
4239                         
4240                         ixj_WriteDSPCommand(0xCF96, j); /* Set AGC Attack Threshold */
4241                         ixj_WriteDSPCommand(0x1200, j); /* to 25% */
4242                         
4243                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4244                         ixj_WriteDSPCommand(0x0001, j); /* to on */
4245                         
4246                         break;
4247
4248                 case AEC_AUTO:
4249                         ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
4250
4251                         ixj_WriteDSPCommand(0xE011, j);
4252                         ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
4253
4254                         ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
4255
4256                         if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4257                                 ixj_WriteDSPCommand(0x0224, j);
4258                         else
4259                                 ixj_WriteDSPCommand(0x1224, j);
4260
4261                         ixj_WriteDSPCommand(0xE014, j);
4262                         ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
4263
4264                         ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
4265
4266                         break;
4267                 }
4268         }
4269 }
4270
4271 static void aec_stop(IXJ *j)
4272 {
4273         j->aec_level = AEC_OFF;
4274         if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4275                 ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer back */
4276
4277                 ixj_WriteDSPCommand(0x0700, j);
4278         }
4279         if (j->play_mode != -1 && j->rec_mode != -1)
4280         {
4281                 ixj_WriteDSPCommand(0xB002, j); /* AEC Stop */
4282         }
4283 }
4284
4285 static int set_play_codec(IXJ *j, int rate)
4286 {
4287         int retval = 0;
4288
4289         j->play_codec = rate;
4290
4291         switch (rate) {
4292         case G723_63:
4293                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4294                         j->play_frame_size = 12;
4295                         j->play_mode = 0;
4296                 } else {
4297                         retval = 1;
4298                 }
4299                 break;
4300         case G723_53:
4301                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4302                         j->play_frame_size = 10;
4303                         j->play_mode = 0;
4304                 } else {
4305                         retval = 1;
4306                 }
4307                 break;
4308         case TS85:
4309                 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
4310                         j->play_frame_size = 16;
4311                         j->play_mode = 0;
4312                 } else {
4313                         retval = 1;
4314                 }
4315                 break;
4316         case TS48:
4317                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4318                         j->play_frame_size = 9;
4319                         j->play_mode = 0;
4320                 } else {
4321                         retval = 1;
4322                 }
4323                 break;
4324         case TS41:
4325                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4326                         j->play_frame_size = 8;
4327                         j->play_mode = 0;
4328                 } else {
4329                         retval = 1;
4330                 }
4331                 break;
4332         case G728:
4333                 if (j->dsp.low != 0x20) {
4334                         j->play_frame_size = 48;
4335                         j->play_mode = 0;
4336                 } else {
4337                         retval = 1;
4338                 }
4339                 break;
4340         case G729:
4341                 if (j->dsp.low != 0x20) {
4342                         if (!j->flags.g729_loaded) {
4343                                 retval = 1;
4344                                 break;
4345                         }
4346                         switch (j->baseframe.low) {
4347                         case 0xA0:
4348                                 j->play_frame_size = 10;
4349                                 break;
4350                         case 0x50:
4351                                 j->play_frame_size = 5;
4352                                 break;
4353                         default:
4354                                 j->play_frame_size = 15;
4355                                 break;
4356                         }
4357                         j->play_mode = 0;
4358                 } else {
4359                         retval = 1;
4360                 }
4361                 break;
4362         case G729B:
4363                 if (j->dsp.low != 0x20) {
4364                         if (!j->flags.g729_loaded) {
4365                                 retval = 1;
4366                                 break;
4367                         }
4368                         switch (j->baseframe.low) {
4369                         case 0xA0:
4370                                 j->play_frame_size = 12;
4371                                 break;
4372                         case 0x50:
4373                                 j->play_frame_size = 6;
4374                                 break;
4375                         default:
4376                                 j->play_frame_size = 18;
4377                                 break;
4378                         }
4379                         j->play_mode = 0;
4380                 } else {
4381                         retval = 1;
4382                 }
4383                 break;
4384         case ULAW:
4385                 switch (j->baseframe.low) {
4386                 case 0xA0:
4387                         j->play_frame_size = 80;
4388                         break;
4389                 case 0x50:
4390                         j->play_frame_size = 40;
4391                         break;
4392                 default:
4393                         j->play_frame_size = 120;
4394                         break;
4395                 }
4396                 j->play_mode = 2;
4397                 break;
4398         case ALAW:
4399                 switch (j->baseframe.low) {
4400                 case 0xA0:
4401                         j->play_frame_size = 80;
4402                         break;
4403                 case 0x50:
4404                         j->play_frame_size = 40;
4405                         break;
4406                 default:
4407                         j->play_frame_size = 120;
4408                         break;
4409                 }
4410                 j->play_mode = 2;
4411                 break;
4412         case LINEAR16:
4413                 switch (j->baseframe.low) {
4414                 case 0xA0:
4415                         j->play_frame_size = 160;
4416                         break;
4417                 case 0x50:
4418                         j->play_frame_size = 80;
4419                         break;
4420                 default:
4421                         j->play_frame_size = 240;
4422                         break;
4423                 }
4424                 j->play_mode = 6;
4425                 break;
4426         case LINEAR8:
4427                 switch (j->baseframe.low) {
4428                 case 0xA0:
4429                         j->play_frame_size = 80;
4430                         break;
4431                 case 0x50:
4432                         j->play_frame_size = 40;
4433                         break;
4434                 default:
4435                         j->play_frame_size = 120;
4436                         break;
4437                 }
4438                 j->play_mode = 4;
4439                 break;
4440         case WSS:
4441                 switch (j->baseframe.low) {
4442                 case 0xA0:
4443                         j->play_frame_size = 80;
4444                         break;
4445                 case 0x50:
4446                         j->play_frame_size = 40;
4447                         break;
4448                 default:
4449                         j->play_frame_size = 120;
4450                         break;
4451                 }
4452                 j->play_mode = 5;
4453                 break;
4454         default:
4455                 j->play_frame_size = 0;
4456                 j->play_mode = -1;
4457                 if (j->write_buffer) {
4458                         kfree(j->write_buffer);
4459                         j->write_buffer = NULL;
4460                         j->write_buffer_size = 0;
4461                 }
4462                 retval = 1;
4463                 break;
4464         }
4465         return retval;
4466 }
4467
4468 static int ixj_play_start(IXJ *j)
4469 {
4470         unsigned short cmd = 0x0000;
4471
4472         if (j->write_buffer) {
4473                 ixj_play_stop(j);
4474         }
4475
4476         if(ixjdebug & 0x0002)
4477                 printk("IXJ %d Starting Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4478
4479         j->flags.playing = 1;
4480         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
4481
4482         j->flags.play_first_frame = 1;
4483         j->drybuffer = 0;
4484
4485         if (!j->play_mode) {
4486                 switch (j->play_codec) {
4487                 case G723_63:
4488                         cmd = 0x5231;
4489                         break;
4490                 case G723_53:
4491                         cmd = 0x5232;
4492                         break;
4493                 case TS85:
4494                         cmd = 0x5230;   /* TrueSpeech 8.5 */
4495
4496                         break;
4497                 case TS48:
4498                         cmd = 0x5233;   /* TrueSpeech 4.8 */
4499
4500                         break;
4501                 case TS41:
4502                         cmd = 0x5234;   /* TrueSpeech 4.1 */
4503
4504                         break;
4505                 case G728:
4506                         cmd = 0x5235;
4507                         break;
4508                 case G729:
4509                 case G729B:
4510                         cmd = 0x5236;
4511                         break;
4512                 default:
4513                         return 1;
4514                 }
4515                 if (ixj_WriteDSPCommand(cmd, j))
4516                         return -1;
4517         }
4518         j->write_buffer = kmalloc(j->play_frame_size * 2, GFP_ATOMIC);
4519         if (!j->write_buffer) {
4520                 printk("Write buffer allocation for ixj board %d failed!\n", j->board);
4521                 return -ENOMEM;
4522         }
4523 /*      j->write_buffers_empty = 2; */
4524         j->write_buffers_empty = 1; 
4525         j->write_buffer_size = j->play_frame_size * 2;
4526         j->write_buffer_end = j->write_buffer + j->play_frame_size * 2;
4527         j->write_buffer_rp = j->write_buffer_wp = j->write_buffer;
4528
4529         if (ixj_WriteDSPCommand(0x5202, j))             /* Set Poll sync mode */
4530
4531                 return -1;
4532
4533         switch (j->play_mode) {
4534         case 0:
4535                 cmd = 0x2C03;
4536                 break;
4537         case 2:
4538                 if (j->ver.low == 0x12) {
4539                         cmd = 0x2C23;
4540                 } else {
4541                         cmd = 0x2C21;
4542                 }
4543                 break;
4544         case 4:
4545                 if (j->ver.low == 0x12) {
4546                         cmd = 0x2C43;
4547                 } else {
4548                         cmd = 0x2C41;
4549                 }
4550                 break;
4551         case 5:
4552                 if (j->ver.low == 0x12) {
4553                         cmd = 0x2C53;
4554                 } else {
4555                         cmd = 0x2C51;
4556                 }
4557                 break;
4558         case 6:
4559                 if (j->ver.low == 0x12) {
4560                         cmd = 0x2C63;
4561                 } else {
4562                         cmd = 0x2C61;
4563                 }
4564                 break;
4565         }
4566         if (ixj_WriteDSPCommand(cmd, j))
4567                 return -1;
4568
4569         if (ixj_WriteDSPCommand(0x2000, j))             /* Playback C2 */
4570                 return -1;
4571
4572         if (ixj_WriteDSPCommand(0x2000 + j->play_frame_size, j))        /* Playback C3 */
4573                 return -1;
4574
4575         if (j->flags.recording) {
4576                 ixj_aec_start(j, j->aec_level);
4577         }
4578
4579         return 0;
4580 }
4581
4582 static void ixj_play_stop(IXJ *j)
4583 {
4584         if(ixjdebug & 0x0002)
4585                 printk("IXJ %d Stopping Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4586
4587         if (j->write_buffer) {
4588                 kfree(j->write_buffer);
4589                 j->write_buffer = NULL;
4590                 j->write_buffer_size = 0;
4591         }
4592         if (j->play_mode > -1) {
4593                 ixj_WriteDSPCommand(0x5221, j); /* Stop playback and flush buffers.  8022 reference page 9-40 */
4594
4595                 j->play_mode = -1;
4596         }
4597         j->flags.playing = 0;
4598 }
4599
4600 static inline int get_play_level(IXJ *j)
4601 {
4602         int retval;
4603
4604         ixj_WriteDSPCommand(0xCF8F, j); /* 8022 Reference page 9-38 */
4605         return j->ssr.high << 8 | j->ssr.low;
4606         retval = j->ssr.high << 8 | j->ssr.low;
4607         retval = (retval * 256) / 240;
4608         return retval;
4609 }
4610
4611 static unsigned int ixj_poll(struct file *file_p, poll_table * wait)
4612 {
4613         unsigned int mask = 0;
4614
4615         IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode));
4616
4617         poll_wait(file_p, &(j->poll_q), wait);
4618         if (j->read_buffer_ready > 0)
4619                 mask |= POLLIN | POLLRDNORM;    /* readable */
4620         if (j->write_buffers_empty > 0)
4621                 mask |= POLLOUT | POLLWRNORM;   /* writable */
4622         if (j->ex.bytes)
4623                 mask |= POLLPRI;
4624         return mask;
4625 }
4626
4627 static int ixj_play_tone(IXJ *j, char tone)
4628 {
4629         if (!j->tone_state) {
4630                 if(ixjdebug & 0x0002) {
4631                         printk("IXJ %d starting tone %d at %ld\n", j->board, tone, jiffies);
4632                 }
4633                 if (j->dsp.low == 0x20) {
4634                         idle(j);
4635                 }
4636                 j->tone_start_jif = jiffies;
4637
4638                 j->tone_state = 1;
4639         }
4640
4641         j->tone_index = tone;
4642         if (ixj_WriteDSPCommand(0x6000 + j->tone_index, j))
4643                 return -1;
4644
4645         return 0;
4646 }
4647
4648 static int ixj_set_tone_on(unsigned short arg, IXJ *j)
4649 {
4650         j->tone_on_time = arg;
4651
4652         if (ixj_WriteDSPCommand(0x6E04, j))             /* Set Tone On Period */
4653
4654                 return -1;
4655
4656         if (ixj_WriteDSPCommand(arg, j))
4657                 return -1;
4658
4659         return 0;
4660 }
4661
4662 static int SCI_WaitHighSCI(IXJ *j)
4663 {
4664         int cnt;
4665
4666         j->pld_scrr.byte = inb_p(j->XILINXbase);
4667         if (!j->pld_scrr.bits.sci) {
4668                 for (cnt = 0; cnt < 10; cnt++) {
4669                         udelay(32);
4670                         j->pld_scrr.byte = inb_p(j->XILINXbase);
4671
4672                         if ((j->pld_scrr.bits.sci))
4673                                 return 1;
4674                 }
4675                 if (ixjdebug & 0x0001)
4676                         printk(KERN_INFO "SCI Wait High failed %x\n", j->pld_scrr.byte);
4677                 return 0;
4678         } else
4679                 return 1;
4680 }
4681
4682 static int SCI_WaitLowSCI(IXJ *j)
4683 {
4684         int cnt;
4685
4686         j->pld_scrr.byte = inb_p(j->XILINXbase);
4687         if (j->pld_scrr.bits.sci) {
4688                 for (cnt = 0; cnt < 10; cnt++) {
4689                         udelay(32);
4690                         j->pld_scrr.byte = inb_p(j->XILINXbase);
4691
4692                         if (!(j->pld_scrr.bits.sci))
4693                                 return 1;
4694                 }
4695                 if (ixjdebug & 0x0001)
4696                         printk(KERN_INFO "SCI Wait Low failed %x\n", j->pld_scrr.byte);
4697                 return 0;
4698         } else
4699                 return 1;
4700 }
4701
4702 static int SCI_Control(IXJ *j, int control)
4703 {
4704         switch (control) {
4705         case SCI_End:
4706                 j->pld_scrw.bits.c0 = 0;        /* Set PLD Serial control interface */
4707
4708                 j->pld_scrw.bits.c1 = 0;        /* to no selection */
4709
4710                 break;
4711         case SCI_Enable_DAA:
4712                 j->pld_scrw.bits.c0 = 1;        /* Set PLD Serial control interface */
4713
4714                 j->pld_scrw.bits.c1 = 0;        /* to write to DAA */
4715
4716                 break;
4717         case SCI_Enable_Mixer:
4718                 j->pld_scrw.bits.c0 = 0;        /* Set PLD Serial control interface */
4719
4720                 j->pld_scrw.bits.c1 = 1;        /* to write to mixer */
4721
4722                 break;
4723         case SCI_Enable_EEPROM:
4724                 j->pld_scrw.bits.c0 = 1;        /* Set PLD Serial control interface */
4725
4726                 j->pld_scrw.bits.c1 = 1;        /* to write to EEPROM */
4727
4728                 break;
4729         default:
4730                 return 0;
4731                 break;
4732         }
4733         outb_p(j->pld_scrw.byte, j->XILINXbase);
4734
4735         switch (control) {
4736         case SCI_End:
4737                 return 1;
4738                 break;
4739         case SCI_Enable_DAA:
4740         case SCI_Enable_Mixer:
4741         case SCI_Enable_EEPROM:
4742                 if (!SCI_WaitHighSCI(j))
4743                         return 0;
4744                 break;
4745         default:
4746                 return 0;
4747                 break;
4748         }
4749         return 1;
4750 }
4751
4752 static int SCI_Prepare(IXJ *j)
4753 {
4754         if (!SCI_Control(j, SCI_End))
4755                 return 0;
4756
4757         if (!SCI_WaitLowSCI(j))
4758                 return 0;
4759
4760         return 1;
4761 }
4762
4763 static int ixj_get_mixer(long val, IXJ *j)
4764 {
4765         int reg = (val & 0x1F00) >> 8;
4766         return j->mix.vol[reg];
4767 }
4768
4769 static int ixj_mixer(long val, IXJ *j)
4770 {
4771         BYTES bytes;
4772
4773         bytes.high = (val & 0x1F00) >> 8;
4774         bytes.low = val & 0x00FF;
4775
4776         /* save mixer value so we can get back later on */
4777         j->mix.vol[bytes.high] = bytes.low;
4778
4779         outb_p(bytes.high & 0x1F, j->XILINXbase + 0x03);        /* Load Mixer Address */
4780
4781         outb_p(bytes.low, j->XILINXbase + 0x02);        /* Load Mixer Data */
4782
4783         SCI_Control(j, SCI_Enable_Mixer);
4784
4785         SCI_Control(j, SCI_End);
4786
4787         return 0;
4788 }
4789
4790 static int daa_load(BYTES * p_bytes, IXJ *j)
4791 {
4792         outb_p(p_bytes->high, j->XILINXbase + 0x03);
4793         outb_p(p_bytes->low, j->XILINXbase + 0x02);
4794         if (!SCI_Control(j, SCI_Enable_DAA))
4795                 return 0;
4796         else
4797                 return 1;
4798 }
4799
4800 static int ixj_daa_cr4(IXJ *j, char reg)
4801 {
4802         BYTES bytes;
4803
4804         switch (j->daa_mode) {
4805         case SOP_PU_SLEEP:
4806                 bytes.high = 0x14;
4807                 break;
4808         case SOP_PU_RINGING:
4809                 bytes.high = 0x54;
4810                 break;
4811         case SOP_PU_CONVERSATION:
4812                 bytes.high = 0x94;
4813                 break;
4814         case SOP_PU_PULSEDIALING:
4815                 bytes.high = 0xD4;
4816                 break;
4817         }
4818
4819         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = reg;
4820
4821         switch (j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGX) {
4822         case 0:
4823                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 0;
4824                 break;
4825         case 1:
4826                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 2;
4827                 break;
4828         case 2:
4829                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 1;
4830                 break;
4831         case 3:
4832                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 3;
4833                 break;
4834         }
4835
4836         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
4837
4838         if (!daa_load(&bytes, j))
4839                 return 0;
4840
4841         if (!SCI_Prepare(j))
4842                 return 0;
4843
4844         return 1;
4845 }
4846
4847 static char daa_int_read(IXJ *j)
4848 {
4849         BYTES bytes;
4850
4851         if (!SCI_Prepare(j))
4852                 return 0;
4853
4854         bytes.high = 0x38;
4855         bytes.low = 0x00;
4856         outb_p(bytes.high, j->XILINXbase + 0x03);
4857         outb_p(bytes.low, j->XILINXbase + 0x02);
4858
4859         if (!SCI_Control(j, SCI_Enable_DAA))
4860                 return 0;
4861
4862         bytes.high = inb_p(j->XILINXbase + 0x03);
4863         bytes.low = inb_p(j->XILINXbase + 0x02);
4864         if (bytes.low != ALISDAA_ID_BYTE) {
4865                 if (ixjdebug & 0x0001)
4866                         printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4867                 return 0;
4868         }
4869         if (!SCI_Control(j, SCI_Enable_DAA))
4870                 return 0;
4871         if (!SCI_Control(j, SCI_End))
4872                 return 0;
4873
4874         bytes.high = inb_p(j->XILINXbase + 0x03);
4875         bytes.low = inb_p(j->XILINXbase + 0x02);
4876
4877         j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg = bytes.high;
4878
4879         return 1;
4880 }
4881
4882 static char daa_CR_read(IXJ *j, int cr)
4883 {
4884         IXJ_WORD wdata;
4885         BYTES bytes;
4886
4887         if (!SCI_Prepare(j))
4888                 return 0;
4889
4890         switch (j->daa_mode) {
4891         case SOP_PU_SLEEP:
4892                 bytes.high = 0x30 + cr;
4893                 break;
4894         case SOP_PU_RINGING:
4895                 bytes.high = 0x70 + cr;
4896                 break;
4897         case SOP_PU_CONVERSATION:
4898                 bytes.high = 0xB0 + cr;
4899                 break;
4900         case SOP_PU_PULSEDIALING:
4901                 bytes.high = 0xF0 + cr;
4902                 break;
4903         }
4904
4905         bytes.low = 0x00;
4906
4907         outb_p(bytes.high, j->XILINXbase + 0x03);
4908         outb_p(bytes.low, j->XILINXbase + 0x02);
4909
4910         if (!SCI_Control(j, SCI_Enable_DAA))
4911                 return 0;
4912
4913         bytes.high = inb_p(j->XILINXbase + 0x03);
4914         bytes.low = inb_p(j->XILINXbase + 0x02);
4915         if (bytes.low != ALISDAA_ID_BYTE) {
4916                 if (ixjdebug & 0x0001)
4917                         printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4918                 return 0;
4919         }
4920         if (!SCI_Control(j, SCI_Enable_DAA))
4921                 return 0;
4922         if (!SCI_Control(j, SCI_End))
4923                 return 0;
4924
4925         wdata.word = inw_p(j->XILINXbase + 0x02);
4926
4927         switch(cr){
4928                 case 5:
4929                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = wdata.bytes.high;
4930                         break;
4931                 case 4:
4932                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = wdata.bytes.high;
4933                         break;
4934                 case 3:
4935                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = wdata.bytes.high;
4936                         break;
4937                 case 2:
4938                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = wdata.bytes.high;
4939                         break;
4940                 case 1:
4941                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = wdata.bytes.high;
4942                         break;
4943                 case 0:
4944                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = wdata.bytes.high;
4945                         break;
4946                 default:
4947                         return 0;
4948         }
4949         return 1;
4950 }
4951
4952 static int ixj_daa_cid_reset(IXJ *j)
4953 {
4954         int i;
4955         BYTES bytes;
4956
4957         if (ixjdebug & 0x0002)
4958                 printk("DAA Clearing CID ram\n");
4959
4960         if (!SCI_Prepare(j))
4961                 return 0;
4962
4963         bytes.high = 0x58;
4964         bytes.low = 0x00;
4965         outb_p(bytes.high, j->XILINXbase + 0x03);
4966         outb_p(bytes.low, j->XILINXbase + 0x02);
4967
4968         if (!SCI_Control(j, SCI_Enable_DAA))
4969                 return 0;
4970
4971         if (!SCI_WaitHighSCI(j))
4972                 return 0;
4973
4974         for (i = 0; i < ALISDAA_CALLERID_SIZE - 1; i += 2) {
4975                 bytes.high = bytes.low = 0x00;
4976                 outb_p(bytes.high, j->XILINXbase + 0x03);
4977
4978                 if (i < ALISDAA_CALLERID_SIZE - 1)
4979                         outb_p(bytes.low, j->XILINXbase + 0x02);
4980
4981                 if (!SCI_Control(j, SCI_Enable_DAA))
4982                         return 0;
4983
4984                 if (!SCI_WaitHighSCI(j))
4985                         return 0;
4986
4987         }
4988
4989         if (!SCI_Control(j, SCI_End))
4990                 return 0;
4991
4992         if (ixjdebug & 0x0002)
4993                 printk("DAA CID ram cleared\n");
4994
4995         return 1;
4996 }
4997
4998 static int ixj_daa_cid_read(IXJ *j)
4999 {
5000         int i;
5001         BYTES bytes;
5002         char CID[ALISDAA_CALLERID_SIZE], mContinue;
5003         char *pIn, *pOut;
5004
5005         if (!SCI_Prepare(j))
5006                 return 0;
5007
5008         bytes.high = 0x78;
5009         bytes.low = 0x00;
5010         outb_p(bytes.high, j->XILINXbase + 0x03);
5011         outb_p(bytes.low, j->XILINXbase + 0x02);
5012
5013         if (!SCI_Control(j, SCI_Enable_DAA))
5014                 return 0;
5015
5016         if (!SCI_WaitHighSCI(j))
5017                 return 0;
5018
5019         bytes.high = inb_p(j->XILINXbase + 0x03);
5020         bytes.low = inb_p(j->XILINXbase + 0x02);
5021         if (bytes.low != ALISDAA_ID_BYTE) {
5022                 if (ixjdebug & 0x0001)
5023                         printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
5024                 return 0;
5025         }
5026         for (i = 0; i < ALISDAA_CALLERID_SIZE; i += 2) {
5027                 bytes.high = bytes.low = 0x00;
5028                 outb_p(bytes.high, j->XILINXbase + 0x03);
5029                 outb_p(bytes.low, j->XILINXbase + 0x02);
5030
5031                 if (!SCI_Control(j, SCI_Enable_DAA))
5032                         return 0;
5033
5034                 if (!SCI_WaitHighSCI(j))
5035                         return 0;
5036
5037                 CID[i + 0] = inb_p(j->XILINXbase + 0x03);
5038                 CID[i + 1] = inb_p(j->XILINXbase + 0x02);
5039         }
5040
5041         if (!SCI_Control(j, SCI_End))
5042                 return 0;
5043
5044         pIn = CID;
5045         pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5046         mContinue = 1;
5047         while (mContinue) {
5048                 if ((pIn[1] & 0x03) == 0x01) {
5049                         pOut[0] = pIn[0];
5050                 }
5051                 if ((pIn[2] & 0x0c) == 0x04) {
5052                         pOut[1] = ((pIn[2] & 0x03) << 6) | ((pIn[1] & 0xfc) >> 2);
5053                 }
5054                 if ((pIn[3] & 0x30) == 0x10) {
5055                         pOut[2] = ((pIn[3] & 0x0f) << 4) | ((pIn[2] & 0xf0) >> 4);
5056                 }
5057                 if ((pIn[4] & 0xc0) == 0x40) {
5058                         pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6);
5059                 } else {
5060                         mContinue = FALSE;
5061                 }
5062                 pIn += 5, pOut += 4;
5063         }
5064         memset(&j->cid, 0, sizeof(PHONE_CID));
5065         pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5066         pOut += 4;
5067         strncpy(j->cid.month, pOut, 2);
5068         pOut += 2;
5069         strncpy(j->cid.day, pOut, 2);
5070         pOut += 2;
5071         strncpy(j->cid.hour, pOut, 2);
5072         pOut += 2;
5073         strncpy(j->cid.min, pOut, 2);
5074         pOut += 3;
5075         j->cid.numlen = *pOut;
5076         pOut += 1;
5077         strncpy(j->cid.number, pOut, j->cid.numlen);
5078         pOut += j->cid.numlen + 1;
5079         j->cid.namelen = *pOut;
5080         pOut += 1;
5081         strncpy(j->cid.name, pOut, j->cid.namelen);
5082
5083         ixj_daa_cid_reset(j);
5084         return 1;
5085 }
5086
5087 static char daa_get_version(IXJ *j)
5088 {
5089         BYTES bytes;
5090
5091         if (!SCI_Prepare(j))
5092                 return 0;
5093
5094         bytes.high = 0x35;
5095         bytes.low = 0x00;
5096         outb_p(bytes.high, j->XILINXbase + 0x03);
5097         outb_p(bytes.low, j->XILINXbase + 0x02);
5098
5099         if (!SCI_Control(j, SCI_Enable_DAA))
5100                 return 0;
5101
5102         bytes.high = inb_p(j->XILINXbase + 0x03);
5103         bytes.low = inb_p(j->XILINXbase + 0x02);
5104         if (bytes.low != ALISDAA_ID_BYTE) {
5105                 if (ixjdebug & 0x0001)
5106                         printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
5107                 return 0;
5108         }
5109         if (!SCI_Control(j, SCI_Enable_DAA))
5110                 return 0;
5111
5112         if (!SCI_Control(j, SCI_End))
5113                 return 0;
5114
5115         bytes.high = inb_p(j->XILINXbase + 0x03);
5116         bytes.low = inb_p(j->XILINXbase + 0x02);
5117         if (ixjdebug & 0x0002)
5118                 printk("DAA CR5 Byte high = 0x%x low = 0x%x\n", bytes.high, bytes.low);
5119         j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = bytes.high;
5120         return bytes.high;
5121 }
5122
5123 static int daa_set_mode(IXJ *j, int mode)
5124 {
5125         /* NOTE:
5126               The DAA *MUST* be in the conversation mode if the
5127               PSTN line is to be seized (PSTN line off-hook).
5128               Taking the PSTN line off-hook while the DAA is in
5129               a mode other than conversation mode will cause a
5130               hardware failure of the ALIS-A part.
5131
5132            NOTE:
5133               The DAA can only go to SLEEP, RINGING or PULSEDIALING modes
5134               if the PSTN line is on-hook.  Failure to have the PSTN line
5135               in the on-hook state WILL CAUSE A HARDWARE FAILURE OF THE
5136               ALIS-A part.
5137         */
5138
5139         BYTES bytes;
5140
5141         j->flags.pstn_rmr = 0;
5142
5143         if (!SCI_Prepare(j))
5144                 return 0;
5145
5146         switch (mode) {
5147         case SOP_PU_RESET:
5148                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5149
5150                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5151                 j->pld_slicw.bits.rly2 = 0;
5152                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5153                 bytes.high = 0x10;
5154                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5155                 daa_load(&bytes, j);
5156                 if (!SCI_Prepare(j))
5157                         return 0;
5158
5159                 j->daa_mode = SOP_PU_SLEEP;
5160                 break;
5161         case SOP_PU_SLEEP:
5162                 if(j->daa_mode == SOP_PU_SLEEP)
5163                 {
5164                         break;
5165                 }
5166                 if (ixjdebug & 0x0008)
5167                         printk(KERN_INFO "phone DAA: SOP_PU_SLEEP at %ld\n", jiffies);
5168 /*              if(j->daa_mode == SOP_PU_CONVERSATION) */
5169                 {
5170                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5171
5172                         outb_p(j->pld_scrw.byte, j->XILINXbase);
5173                         j->pld_slicw.bits.rly2 = 0;
5174                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5175                         bytes.high = 0x10;
5176                         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5177                         daa_load(&bytes, j);
5178                         if (!SCI_Prepare(j))
5179                                 return 0;
5180                 }
5181                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5182
5183                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5184                 j->pld_slicw.bits.rly2 = 0;
5185                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5186                 bytes.high = 0x10;
5187                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5188                 daa_load(&bytes, j);
5189                 if (!SCI_Prepare(j))
5190                         return 0;
5191
5192                 j->daa_mode = SOP_PU_SLEEP;
5193                 j->flags.pstn_ringing = 0;
5194                 j->ex.bits.pstn_ring = 0;
5195                 j->pstn_sleeptil = jiffies + (hertz / 4);
5196                 wake_up_interruptible(&j->read_q);      /* Wake any blocked readers */
5197                 wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
5198                 wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
5199                 break;
5200         case SOP_PU_RINGING:
5201                 if (ixjdebug & 0x0008)
5202                         printk(KERN_INFO "phone DAA: SOP_PU_RINGING at %ld\n", jiffies);
5203                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5204
5205                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5206                 j->pld_slicw.bits.rly2 = 0;
5207                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5208                 bytes.high = 0x50;
5209                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5210                 daa_load(&bytes, j);
5211                 if (!SCI_Prepare(j))
5212                         return 0;
5213                 j->daa_mode = SOP_PU_RINGING;
5214                 break;
5215         case SOP_PU_CONVERSATION:
5216                 if (ixjdebug & 0x0008)
5217                         printk(KERN_INFO "phone DAA: SOP_PU_CONVERSATION at %ld\n", jiffies);
5218                 bytes.high = 0x90;
5219                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5220                 daa_load(&bytes, j);
5221                 if (!SCI_Prepare(j))
5222                         return 0;
5223                 j->pld_slicw.bits.rly2 = 1;
5224                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5225                 j->pld_scrw.bits.daafsyncen = 1;        /* Turn on DAA Frame Sync */
5226
5227                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5228                 j->daa_mode = SOP_PU_CONVERSATION;
5229                 j->flags.pstn_ringing = 0;
5230                 j->ex.bits.pstn_ring = 0;
5231                 j->pstn_sleeptil = jiffies;
5232                 j->pstn_ring_start = j->pstn_ring_stop = j->pstn_ring_int = 0;
5233                 break;
5234         case SOP_PU_PULSEDIALING:
5235                 if (ixjdebug & 0x0008)
5236                         printk(KERN_INFO "phone DAA: SOP_PU_PULSEDIALING at %ld\n", jiffies);
5237                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5238
5239                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5240                 j->pld_slicw.bits.rly2 = 0;
5241                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5242                 bytes.high = 0xD0;
5243                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5244                 daa_load(&bytes, j);
5245                 if (!SCI_Prepare(j))
5246                         return 0;
5247                 j->daa_mode = SOP_PU_PULSEDIALING;
5248                 break;
5249         default:
5250                 break;
5251         }
5252         return 1;
5253 }
5254
5255 static int ixj_daa_write(IXJ *j)
5256 {
5257         BYTES bytes;
5258
5259         j->flags.pstncheck = 1;
5260
5261         daa_set_mode(j, SOP_PU_SLEEP);
5262
5263         if (!SCI_Prepare(j))
5264                 return 0;
5265
5266         outb_p(j->pld_scrw.byte, j->XILINXbase);
5267
5268         bytes.high = 0x14;
5269         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
5270         if (!daa_load(&bytes, j))
5271                 return 0;
5272
5273         bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg;
5274         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg;
5275         if (!daa_load(&bytes, j))
5276                 return 0;
5277
5278         bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg;
5279         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5280         if (!daa_load(&bytes, j))
5281                 return 0;
5282
5283         if (!SCI_Prepare(j))
5284                 return 0;
5285
5286         bytes.high = 0x1F;
5287         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg;
5288         if (!daa_load(&bytes, j))
5289                 return 0;
5290
5291         bytes.high = j->m_DAAShadowRegs.XOP_xr6_W.reg;
5292         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg;
5293         if (!daa_load(&bytes, j))
5294                 return 0;
5295
5296         bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg;
5297         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg;
5298         if (!daa_load(&bytes, j))
5299                 return 0;
5300
5301         bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg;
5302         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg;
5303         if (!daa_load(&bytes, j))
5304                 return 0;
5305
5306         bytes.high = j->m_DAAShadowRegs.XOP_xr0_W.reg;
5307         bytes.low = 0x00;
5308         if (!daa_load(&bytes, j))
5309                 return 0;
5310
5311         if (!SCI_Prepare(j))
5312                 return 0;
5313
5314         bytes.high = 0x00;
5315         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7];
5316         if (!daa_load(&bytes, j))
5317                 return 0;
5318
5319         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6];
5320         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5];
5321         if (!daa_load(&bytes, j))
5322                 return 0;
5323
5324         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4];
5325         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3];
5326         if (!daa_load(&bytes, j))
5327                 return 0;
5328
5329         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2];
5330         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1];
5331         if (!daa_load(&bytes, j))
5332                 return 0;
5333
5334         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0];
5335         bytes.low = 0x00;
5336         if (!daa_load(&bytes, j))
5337                 return 0;
5338
5339         if (!SCI_Control(j, SCI_End))
5340                 return 0;
5341         if (!SCI_WaitLowSCI(j))
5342                 return 0;
5343
5344         bytes.high = 0x01;
5345         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7];
5346         if (!daa_load(&bytes, j))
5347                 return 0;
5348
5349         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6];
5350         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5];
5351         if (!daa_load(&bytes, j))
5352                 return 0;
5353
5354         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4];
5355         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3];
5356         if (!daa_load(&bytes, j))
5357                 return 0;
5358
5359         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2];
5360         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1];
5361         if (!daa_load(&bytes, j))
5362                 return 0;
5363
5364         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0];
5365         bytes.low = 0x00;
5366         if (!daa_load(&bytes, j))
5367                 return 0;
5368
5369         if (!SCI_Control(j, SCI_End))
5370                 return 0;
5371         if (!SCI_WaitLowSCI(j))
5372                 return 0;
5373
5374         bytes.high = 0x02;
5375         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7];
5376         if (!daa_load(&bytes, j))
5377                 return 0;
5378
5379         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6];
5380         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5];
5381         if (!daa_load(&bytes, j))
5382                 return 0;
5383
5384         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4];
5385         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3];
5386         if (!daa_load(&bytes, j))
5387                 return 0;
5388
5389         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2];
5390         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1];
5391         if (!daa_load(&bytes, j))
5392                 return 0;
5393
5394         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0];
5395         bytes.low = 0x00;
5396         if (!daa_load(&bytes, j))
5397                 return 0;
5398
5399         if (!SCI_Control(j, SCI_End))
5400                 return 0;
5401         if (!SCI_WaitLowSCI(j))
5402                 return 0;
5403
5404         bytes.high = 0x03;
5405         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7];
5406         if (!daa_load(&bytes, j))
5407                 return 0;
5408
5409         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6];
5410         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5];
5411         if (!daa_load(&bytes, j))
5412                 return 0;
5413
5414         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4];
5415         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3];
5416         if (!daa_load(&bytes, j))
5417                 return 0;
5418
5419         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2];
5420         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1];
5421         if (!daa_load(&bytes, j))
5422                 return 0;
5423
5424         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0];
5425         bytes.low = 0x00;
5426         if (!daa_load(&bytes, j))
5427                 return 0;
5428
5429         if (!SCI_Control(j, SCI_End))
5430                 return 0;
5431         if (!SCI_WaitLowSCI(j))
5432                 return 0;
5433
5434         bytes.high = 0x04;
5435         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7];
5436         if (!daa_load(&bytes, j))
5437                 return 0;
5438
5439         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6];
5440         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5];
5441         if (!daa_load(&bytes, j))
5442                 return 0;
5443
5444         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4];
5445         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3];
5446         if (!daa_load(&bytes, j))
5447                 return 0;
5448
5449         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2];
5450         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1];
5451         if (!daa_load(&bytes, j))
5452                 return 0;
5453
5454         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0];
5455         bytes.low = 0x00;
5456         if (!daa_load(&bytes, j))
5457                 return 0;
5458
5459         if (!SCI_Control(j, SCI_End))
5460                 return 0;
5461         if (!SCI_WaitLowSCI(j))
5462                 return 0;
5463
5464         bytes.high = 0x05;
5465         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7];
5466         if (!daa_load(&bytes, j))
5467                 return 0;
5468
5469         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6];
5470         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5];
5471         if (!daa_load(&bytes, j))
5472                 return 0;
5473
5474         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4];
5475         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3];
5476         if (!daa_load(&bytes, j))
5477                 return 0;
5478
5479         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2];
5480         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1];
5481         if (!daa_load(&bytes, j))
5482                 return 0;
5483
5484         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0];
5485         bytes.low = 0x00;
5486         if (!daa_load(&bytes, j))
5487                 return 0;
5488
5489         if (!SCI_Control(j, SCI_End))
5490                 return 0;
5491         if (!SCI_WaitLowSCI(j))
5492                 return 0;
5493
5494         bytes.high = 0x06;
5495         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7];
5496         if (!daa_load(&bytes, j))
5497                 return 0;
5498
5499         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6];
5500         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5];
5501         if (!daa_load(&bytes, j))
5502                 return 0;
5503
5504         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4];
5505         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3];
5506         if (!daa_load(&bytes, j))
5507                 return 0;
5508
5509         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2];
5510         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1];
5511         if (!daa_load(&bytes, j))
5512                 return 0;
5513
5514         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0];
5515         bytes.low = 0x00;
5516         if (!daa_load(&bytes, j))
5517                 return 0;
5518
5519         if (!SCI_Control(j, SCI_End))
5520                 return 0;
5521         if (!SCI_WaitLowSCI(j))
5522                 return 0;
5523
5524         bytes.high = 0x07;
5525         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7];
5526         if (!daa_load(&bytes, j))
5527                 return 0;
5528
5529         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6];
5530         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5];
5531         if (!daa_load(&bytes, j))
5532                 return 0;
5533
5534         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4];
5535         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3];
5536         if (!daa_load(&bytes, j))
5537                 return 0;
5538
5539         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2];
5540         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1];
5541         if (!daa_load(&bytes, j))
5542                 return 0;
5543
5544         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0];
5545         bytes.low = 0x00;
5546         if (!daa_load(&bytes, j))
5547                 return 0;
5548
5549         if (!SCI_Control(j, SCI_End))
5550                 return 0;
5551         if (!SCI_WaitLowSCI(j))
5552                 return 0;
5553
5554         bytes.high = 0x08;
5555         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7];
5556         if (!daa_load(&bytes, j))
5557                 return 0;
5558
5559         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6];
5560         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5];
5561         if (!daa_load(&bytes, j))
5562                 return 0;
5563
5564         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4];
5565         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3];
5566         if (!daa_load(&bytes, j))
5567                 return 0;
5568
5569         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2];
5570         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1];
5571         if (!daa_load(&bytes, j))
5572                 return 0;
5573
5574         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0];
5575         bytes.low = 0x00;
5576         if (!daa_load(&bytes, j))
5577                 return 0;
5578
5579         if (!SCI_Control(j, SCI_End))
5580                 return 0;
5581         if (!SCI_WaitLowSCI(j))
5582                 return 0;
5583
5584         bytes.high = 0x09;
5585         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3];
5586         if (!daa_load(&bytes, j))
5587                 return 0;
5588
5589         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2];
5590         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1];
5591         if (!daa_load(&bytes, j))
5592                 return 0;
5593
5594         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0];
5595         bytes.low = 0x00;
5596         if (!daa_load(&bytes, j))
5597                 return 0;
5598
5599         if (!SCI_Control(j, SCI_End))
5600                 return 0;
5601         if (!SCI_WaitLowSCI(j))
5602                 return 0;
5603
5604         bytes.high = 0x0A;
5605         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3];
5606         if (!daa_load(&bytes, j))
5607                 return 0;
5608
5609         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2];
5610         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1];
5611         if (!daa_load(&bytes, j))
5612                 return 0;
5613
5614         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0];
5615         bytes.low = 0x00;
5616         if (!daa_load(&bytes, j))
5617                 return 0;
5618
5619         if (!SCI_Control(j, SCI_End))
5620                 return 0;
5621         if (!SCI_WaitLowSCI(j))
5622                 return 0;
5623
5624         bytes.high = 0x0B;
5625         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3];
5626         if (!daa_load(&bytes, j))
5627                 return 0;
5628
5629         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2];
5630         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1];
5631         if (!daa_load(&bytes, j))
5632                 return 0;
5633
5634         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0];
5635         bytes.low = 0x00;
5636         if (!daa_load(&bytes, j))
5637                 return 0;
5638
5639         if (!SCI_Control(j, SCI_End))
5640                 return 0;
5641         if (!SCI_WaitLowSCI(j))
5642                 return 0;
5643
5644         bytes.high = 0x0C;
5645         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3];
5646         if (!daa_load(&bytes, j))
5647                 return 0;
5648
5649         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2];
5650         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1];
5651         if (!daa_load(&bytes, j))
5652                 return 0;
5653
5654         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0];
5655         bytes.low = 0x00;
5656         if (!daa_load(&bytes, j))
5657                 return 0;
5658
5659         if (!SCI_Control(j, SCI_End))
5660                 return 0;
5661         if (!SCI_WaitLowSCI(j))
5662                 return 0;
5663
5664         bytes.high = 0x0D;
5665         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3];
5666         if (!daa_load(&bytes, j))
5667                 return 0;
5668
5669         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2];
5670         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1];
5671         if (!daa_load(&bytes, j))
5672                 return 0;
5673
5674         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0];
5675         bytes.low = 0x00;
5676         if (!daa_load(&bytes, j))
5677                 return 0;
5678
5679         if (!SCI_Control(j, SCI_End))
5680                 return 0;
5681         if (!SCI_WaitLowSCI(j))
5682                 return 0;
5683
5684         bytes.high = 0x0E;
5685         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7];
5686         if (!daa_load(&bytes, j))
5687                 return 0;
5688
5689         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6];
5690         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5];
5691         if (!daa_load(&bytes, j))
5692                 return 0;
5693
5694         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4];
5695         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3];
5696         if (!daa_load(&bytes, j))
5697                 return 0;
5698
5699         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2];
5700         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1];
5701         if (!daa_load(&bytes, j))
5702                 return 0;
5703
5704         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0];
5705         bytes.low = 0x00;
5706         if (!daa_load(&bytes, j))
5707                 return 0;
5708
5709         if (!SCI_Control(j, SCI_End))
5710                 return 0;
5711         if (!SCI_WaitLowSCI(j))
5712                 return 0;
5713
5714         bytes.high = 0x0F;
5715         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7];
5716         if (!daa_load(&bytes, j))
5717                 return 0;
5718
5719         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6];
5720         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5];
5721         if (!daa_load(&bytes, j))
5722                 return 0;
5723
5724         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4];
5725         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3];
5726         if (!daa_load(&bytes, j))
5727                 return 0;
5728
5729         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2];
5730         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1];
5731         if (!daa_load(&bytes, j))
5732                 return 0;
5733
5734         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0];
5735         bytes.low = 0x00;
5736         if (!daa_load(&bytes, j))
5737                 return 0;
5738
5739         udelay(32);
5740         j->pld_scrr.byte = inb_p(j->XILINXbase);
5741         if (!SCI_Control(j, SCI_End))
5742                 return 0;
5743
5744         outb_p(j->pld_scrw.byte, j->XILINXbase);
5745
5746         if (ixjdebug & 0x0002)
5747                 printk("DAA Coefficients Loaded\n");
5748
5749         j->flags.pstncheck = 0;
5750         return 1;
5751 }
5752
5753 int ixj_set_tone_off(unsigned short arg, IXJ *j)
5754 {
5755         j->tone_off_time = arg;
5756         if (ixj_WriteDSPCommand(0x6E05, j))             /* Set Tone Off Period */
5757
5758                 return -1;
5759         if (ixj_WriteDSPCommand(arg, j))
5760                 return -1;
5761         return 0;
5762 }
5763
5764 static int ixj_get_tone_on(IXJ *j)
5765 {
5766         if (ixj_WriteDSPCommand(0x6E06, j))             /* Get Tone On Period */
5767
5768                 return -1;
5769         return 0;
5770 }
5771
5772 static int ixj_get_tone_off(IXJ *j)
5773 {
5774         if (ixj_WriteDSPCommand(0x6E07, j))             /* Get Tone Off Period */
5775
5776                 return -1;
5777         return 0;
5778 }
5779
5780 static void ixj_busytone(IXJ *j)
5781 {
5782         j->flags.ringback = 0;
5783         j->flags.dialtone = 0;
5784         j->flags.busytone = 1;
5785         ixj_set_tone_on(0x07D0, j);
5786         ixj_set_tone_off(0x07D0, j);
5787         ixj_play_tone(j, 27);
5788 }
5789
5790 static void ixj_dialtone(IXJ *j)
5791 {
5792         j->flags.ringback = 0;
5793         j->flags.dialtone = 1;
5794         j->flags.busytone = 0;
5795         if (j->dsp.low == 0x20) {
5796                 return;
5797         } else {
5798                 ixj_set_tone_on(0xFFFF, j);
5799                 ixj_set_tone_off(0x0000, j);
5800                 ixj_play_tone(j, 25);
5801         }
5802 }
5803
5804 static void ixj_cpt_stop(IXJ *j)
5805 {
5806         if(j->tone_state || j->tone_cadence_state)
5807         {
5808                 j->flags.dialtone = 0;
5809                 j->flags.busytone = 0;
5810                 j->flags.ringback = 0;
5811                 ixj_set_tone_on(0x0001, j);
5812                 ixj_set_tone_off(0x0000, j);
5813                 ixj_play_tone(j, 0);
5814                 j->tone_state = j->tone_cadence_state = 0;
5815                 if (j->cadence_t) {
5816                         if (j->cadence_t->ce) {
5817                                 kfree(j->cadence_t->ce);
5818                         }
5819                         kfree(j->cadence_t);
5820                         j->cadence_t = NULL;
5821                 }
5822         }
5823         if (j->play_mode == -1 && j->rec_mode == -1)
5824                 idle(j);
5825         if (j->play_mode != -1 && j->dsp.low == 0x20)
5826                 ixj_play_start(j);
5827         if (j->rec_mode != -1 && j->dsp.low == 0x20)
5828                 ixj_record_start(j);
5829 }
5830
5831 static void ixj_ringback(IXJ *j)
5832 {
5833         j->flags.busytone = 0;
5834         j->flags.dialtone = 0;
5835         j->flags.ringback = 1;
5836         ixj_set_tone_on(0x0FA0, j);
5837         ixj_set_tone_off(0x2EE0, j);
5838         ixj_play_tone(j, 26);
5839 }
5840
5841 static void ixj_testram(IXJ *j)
5842 {
5843         ixj_WriteDSPCommand(0x3001, j); /* Test External SRAM */
5844 }
5845
5846 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp)
5847 {
5848         ixj_cadence *lcp;
5849         IXJ_CADENCE_ELEMENT __user *cep;
5850         IXJ_CADENCE_ELEMENT *lcep;
5851         IXJ_TONE ti;
5852         int err;
5853
5854         lcp = kmalloc(sizeof(ixj_cadence), GFP_KERNEL);
5855         if (lcp == NULL)
5856                 return -ENOMEM;
5857
5858         err = -EFAULT;
5859         if (copy_from_user(&lcp->elements_used,
5860                            &cp->elements_used, sizeof(int)))
5861                 goto out;
5862         if (copy_from_user(&lcp->termination,
5863                            &cp->termination, sizeof(IXJ_CADENCE_TERM)))
5864                 goto out;
5865         if (get_user(cep, &cp->ce))
5866                 goto out;
5867
5868         err = -EINVAL;
5869         if ((unsigned)lcp->elements_used >= ~0U/sizeof(IXJ_CADENCE_ELEMENT))
5870                 goto out;
5871
5872         err = -ENOMEM;
5873         lcep = kmalloc(sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used, GFP_KERNEL);
5874         if (!lcep)
5875                 goto out;
5876
5877         err = -EFAULT;
5878         if (copy_from_user(lcep, cep, sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used))
5879                 goto out1;
5880
5881         if (j->cadence_t) {
5882                 kfree(j->cadence_t->ce);
5883                 kfree(j->cadence_t);
5884         }
5885         lcp->ce = (void *) lcep;
5886         j->cadence_t = lcp;
5887         j->tone_cadence_state = 0;
5888         ixj_set_tone_on(lcp->ce[0].tone_on_time, j);
5889         ixj_set_tone_off(lcp->ce[0].tone_off_time, j);
5890         if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
5891                 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
5892                 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
5893                 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
5894                 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
5895                 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
5896                 ixj_init_tone(j, &ti);
5897         }
5898         ixj_play_tone(j, lcp->ce[0].index);
5899         return 1;
5900 out1:
5901         kfree(lcep);
5902 out:
5903         kfree(lcp);
5904         return err;
5905 }
5906
5907 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp)
5908 {
5909         IXJ_FILTER_CADENCE *lcp;
5910         lcp = kmalloc(sizeof(IXJ_FILTER_CADENCE), GFP_KERNEL);
5911         if (lcp == NULL) {
5912                 if(ixjdebug & 0x0001) {
5913                         printk(KERN_INFO "Could not allocate memory for cadence\n");
5914                 }
5915                 return -ENOMEM;
5916         }
5917         if (copy_from_user(lcp, cp, sizeof(IXJ_FILTER_CADENCE))) {
5918                 if(ixjdebug & 0x0001) {
5919                         printk(KERN_INFO "Could not copy cadence to kernel\n");
5920                 }
5921                 kfree(lcp);
5922                 return -EFAULT;
5923         }
5924         if (lcp->filter > 5) {
5925                 if(ixjdebug & 0x0001) {
5926                         printk(KERN_INFO "Cadence out of range\n");
5927                 }
5928                 kfree(lcp);
5929                 return -1;
5930         }
5931         j->cadence_f[lcp->filter].state = 0;
5932         j->cadence_f[lcp->filter].enable = lcp->enable;
5933         j->filter_en[lcp->filter] = j->cadence_f[lcp->filter].en_filter = lcp->en_filter;
5934         j->cadence_f[lcp->filter].on1 = lcp->on1;
5935         j->cadence_f[lcp->filter].on1min = 0;
5936         j->cadence_f[lcp->filter].on1max = 0;
5937         j->cadence_f[lcp->filter].off1 = lcp->off1;
5938         j->cadence_f[lcp->filter].off1min = 0;
5939         j->cadence_f[lcp->filter].off1max = 0;
5940         j->cadence_f[lcp->filter].on2 = lcp->on2;
5941         j->cadence_f[lcp->filter].on2min = 0;
5942         j->cadence_f[lcp->filter].on2max = 0;
5943         j->cadence_f[lcp->filter].off2 = lcp->off2;
5944         j->cadence_f[lcp->filter].off2min = 0;
5945         j->cadence_f[lcp->filter].off2max = 0;
5946         j->cadence_f[lcp->filter].on3 = lcp->on3;
5947         j->cadence_f[lcp->filter].on3min = 0;
5948         j->cadence_f[lcp->filter].on3max = 0;
5949         j->cadence_f[lcp->filter].off3 = lcp->off3;
5950         j->cadence_f[lcp->filter].off3min = 0;
5951         j->cadence_f[lcp->filter].off3max = 0;
5952         kfree(lcp);
5953         if(ixjdebug & 0x0002) {
5954                 printk(KERN_INFO "Cadence %d loaded\n", lcp->filter);
5955         }
5956         return 0;
5957 }
5958
5959 static void add_caps(IXJ *j)
5960 {
5961         j->caps = 0;
5962         j->caplist[j->caps].cap = PHONE_VENDOR_QUICKNET;
5963         strcpy(j->caplist[j->caps].desc, "Quicknet Technologies, Inc. (www.quicknet.net)");
5964         j->caplist[j->caps].captype = vendor;
5965         j->caplist[j->caps].handle = j->caps++;
5966         j->caplist[j->caps].captype = device;
5967         switch (j->cardtype) {
5968         case QTI_PHONEJACK:
5969                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK");
5970                 break;
5971         case QTI_LINEJACK:
5972                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet LineJACK");
5973                 break;
5974         case QTI_PHONEJACK_LITE:
5975                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK Lite");
5976                 break;
5977         case QTI_PHONEJACK_PCI:
5978                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK PCI");
5979                 break;
5980         case QTI_PHONECARD:
5981                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneCARD");
5982                 break;
5983         }
5984         j->caplist[j->caps].cap = j->cardtype;
5985         j->caplist[j->caps].handle = j->caps++;
5986         strcpy(j->caplist[j->caps].desc, "POTS");
5987         j->caplist[j->caps].captype = port;
5988         j->caplist[j->caps].cap = pots;
5989         j->caplist[j->caps].handle = j->caps++;
5990
5991         /* add devices that can do speaker/mic */
5992         switch (j->cardtype) {
5993         case QTI_PHONEJACK:
5994         case QTI_LINEJACK:
5995         case QTI_PHONEJACK_PCI:
5996         case QTI_PHONECARD:
5997                 strcpy(j->caplist[j->caps].desc, "SPEAKER");
5998                 j->caplist[j->caps].captype = port;
5999                 j->caplist[j->caps].cap = speaker;
6000                 j->caplist[j->caps].handle = j->caps++;
6001         default:
6002                 break;
6003         }
6004
6005         /* add devices that can do handset */
6006         switch (j->cardtype) {
6007         case QTI_PHONEJACK:
6008                 strcpy(j->caplist[j->caps].desc, "HANDSET");
6009                 j->caplist[j->caps].captype = port;
6010                 j->caplist[j->caps].cap = handset;
6011                 j->caplist[j->caps].handle = j->caps++;
6012                 break;
6013         default:
6014                 break;
6015         }
6016
6017         /* add devices that can do PSTN */
6018         switch (j->cardtype) {
6019         case QTI_LINEJACK:
6020                 strcpy(j->caplist[j->caps].desc, "PSTN");
6021                 j->caplist[j->caps].captype = port;
6022                 j->caplist[j->caps].cap = pstn;
6023                 j->caplist[j->caps].handle = j->caps++;
6024                 break;
6025         default:
6026                 break;
6027         }
6028
6029         /* add codecs - all cards can do uLaw, linear 8/16, and Windows sound system */
6030         strcpy(j->caplist[j->caps].desc, "ULAW");
6031         j->caplist[j->caps].captype = codec;
6032         j->caplist[j->caps].cap = ULAW;
6033         j->caplist[j->caps].handle = j->caps++;
6034
6035         strcpy(j->caplist[j->caps].desc, "LINEAR 16 bit");
6036         j->caplist[j->caps].captype = codec;
6037         j->caplist[j->caps].cap = LINEAR16;
6038         j->caplist[j->caps].handle = j->caps++;
6039
6040         strcpy(j->caplist[j->caps].desc, "LINEAR 8 bit");
6041         j->caplist[j->caps].captype = codec;
6042         j->caplist[j->caps].cap = LINEAR8;
6043         j->caplist[j->caps].handle = j->caps++;
6044
6045         strcpy(j->caplist[j->caps].desc, "Windows Sound System");
6046         j->caplist[j->caps].captype = codec;
6047         j->caplist[j->caps].cap = WSS;
6048         j->caplist[j->caps].handle = j->caps++;
6049
6050         /* software ALAW codec, made from ULAW */
6051         strcpy(j->caplist[j->caps].desc, "ALAW");
6052         j->caplist[j->caps].captype = codec;
6053         j->caplist[j->caps].cap = ALAW;
6054         j->caplist[j->caps].handle = j->caps++;
6055
6056         /* version 12 of the 8020 does the following codecs in a broken way */
6057         if (j->dsp.low != 0x20 || j->ver.low != 0x12) {
6058                 strcpy(j->caplist[j->caps].desc, "G.723.1 6.3kbps");
6059                 j->caplist[j->caps].captype = codec;
6060                 j->caplist[j->caps].cap = G723_63;
6061                 j->caplist[j->caps].handle = j->caps++;
6062
6063                 strcpy(j->caplist[j->caps].desc, "G.723.1 5.3kbps");
6064                 j->caplist[j->caps].captype = codec;
6065                 j->caplist[j->caps].cap = G723_53;
6066                 j->caplist[j->caps].handle = j->caps++;
6067
6068                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.8kbps");
6069                 j->caplist[j->caps].captype = codec;
6070                 j->caplist[j->caps].cap = TS48;
6071                 j->caplist[j->caps].handle = j->caps++;
6072
6073                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.1kbps");
6074                 j->caplist[j->caps].captype = codec;
6075                 j->caplist[j->caps].cap = TS41;
6076                 j->caplist[j->caps].handle = j->caps++;
6077         }
6078
6079         /* 8020 chips can do TS8.5 native, and 8021/8022 can load it */
6080         if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
6081                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 8.5kbps");
6082                 j->caplist[j->caps].captype = codec;
6083                 j->caplist[j->caps].cap = TS85;
6084                 j->caplist[j->caps].handle = j->caps++;
6085         }
6086
6087         /* 8021 chips can do G728 */
6088         if (j->dsp.low == 0x21) {
6089                 strcpy(j->caplist[j->caps].desc, "G.728 16kbps");
6090                 j->caplist[j->caps].captype = codec;
6091                 j->caplist[j->caps].cap = G728;
6092                 j->caplist[j->caps].handle = j->caps++;
6093         }
6094
6095         /* 8021/8022 chips can do G729 if loaded */
6096         if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6097                 strcpy(j->caplist[j->caps].desc, "G.729A 8kbps");
6098                 j->caplist[j->caps].captype = codec;
6099                 j->caplist[j->caps].cap = G729;
6100                 j->caplist[j->caps].handle = j->caps++;
6101         }
6102         if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6103                 strcpy(j->caplist[j->caps].desc, "G.729B 8kbps");
6104                 j->caplist[j->caps].captype = codec;
6105                 j->caplist[j->caps].cap = G729B;
6106                 j->caplist[j->caps].handle = j->caps++;
6107         }
6108 }
6109
6110 static int capabilities_check(IXJ *j, struct phone_capability *pcreq)
6111 {
6112         int cnt;
6113         int retval = 0;
6114         for (cnt = 0; cnt < j->caps; cnt++) {
6115                 if (pcreq->captype == j->caplist[cnt].captype
6116                     && pcreq->cap == j->caplist[cnt].cap) {
6117                         retval = 1;
6118                         break;
6119                 }
6120         }
6121         return retval;
6122 }
6123
6124 static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd, unsigned long arg)
6125 {
6126         IXJ_TONE ti;
6127         IXJ_FILTER jf;
6128         IXJ_FILTER_RAW jfr;
6129         void __user *argp = (void __user *)arg;
6130
6131         unsigned int raise, mant;
6132         unsigned int minor = iminor(inode);
6133         int board = NUM(inode);
6134
6135         IXJ *j = get_ixj(NUM(inode));
6136
6137         int retval = 0;
6138
6139         /*
6140          *    Set up locks to ensure that only one process is talking to the DSP at a time.
6141          *    This is necessary to keep the DSP from locking up.
6142          */
6143         while(test_and_set_bit(board, (void *)&j->busyflags) != 0) {
6144                 set_current_state(TASK_INTERRUPTIBLE);
6145                 schedule_timeout(1);
6146         }
6147         if (ixjdebug & 0x0040)
6148                 printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6149         if (minor >= IXJMAX) {
6150                 clear_bit(board, &j->busyflags);
6151                 return -ENODEV;
6152         }
6153         /*
6154          *    Check ioctls only root can use.
6155          */
6156         if (!capable(CAP_SYS_ADMIN)) {
6157                 switch (cmd) {
6158                 case IXJCTL_TESTRAM:
6159                 case IXJCTL_HZ:
6160                         retval = -EPERM;
6161                 }
6162         }
6163         switch (cmd) {
6164         case IXJCTL_TESTRAM:
6165                 ixj_testram(j);
6166                 retval = (j->ssr.high << 8) + j->ssr.low;
6167                 break;
6168         case IXJCTL_CARDTYPE:
6169                 retval = j->cardtype;
6170                 break;
6171         case IXJCTL_SERIAL:
6172                 retval = j->serial;
6173                 break;
6174         case IXJCTL_VERSION:
6175                 if (copy_to_user(argp, ixj_c_revision, strlen(ixj_c_revision))) 
6176                         retval = -EFAULT;
6177                 break;
6178         case PHONE_RING_CADENCE:
6179                 j->ring_cadence = arg;
6180                 break;
6181         case IXJCTL_CIDCW:
6182                 if(arg) {
6183                         if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6184                                 retval = -EFAULT;
6185                                 break;
6186                         }
6187                 } else {
6188                         memset(&j->cid_send, 0, sizeof(PHONE_CID));
6189                 }
6190                 ixj_write_cidcw(j);
6191                 break;
6192         /* Binary compatbility */
6193         case OLD_PHONE_RING_START:
6194                 arg = 0;
6195                 /* Fall through */
6196         case PHONE_RING_START:
6197                 if(arg) {
6198                         if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6199                                 retval = -EFAULT;
6200                                 break;
6201                         }
6202                         ixj_write_cid(j);
6203                 } else {
6204                         memset(&j->cid_send, 0, sizeof(PHONE_CID));
6205                 }
6206                 ixj_ring_start(j);
6207                 break;
6208         case PHONE_RING_STOP:
6209                 j->flags.cringing = 0;
6210                 if(j->cadence_f[5].enable) {
6211                         j->cadence_f[5].state = 0;
6212                 }
6213                 ixj_ring_off(j);
6214                 break;
6215         case PHONE_RING:
6216                 retval = ixj_ring(j);
6217                 break;
6218         case PHONE_EXCEPTION:
6219                 retval = j->ex.bytes;
6220                 if(j->ex.bits.flash) {
6221                         j->flash_end = 0;
6222                         j->ex.bits.flash = 0;
6223                 }
6224                 j->ex.bits.pstn_ring = 0;
6225                 j->ex.bits.caller_id = 0;
6226                 j->ex.bits.pstn_wink = 0;
6227                 j->ex.bits.f0 = 0;
6228                 j->ex.bits.f1 = 0;
6229                 j->ex.bits.f2 = 0;
6230                 j->ex.bits.f3 = 0;
6231                 j->ex.bits.fc0 = 0;
6232                 j->ex.bits.fc1 = 0;
6233                 j->ex.bits.fc2 = 0;
6234                 j->ex.bits.fc3 = 0;
6235                 j->ex.bits.reserved = 0;
6236                 break;
6237         case PHONE_HOOKSTATE:
6238                 j->ex.bits.hookstate = 0;
6239                 retval = j->hookstate;  //j->r_hook;
6240                 break;
6241         case IXJCTL_SET_LED:
6242                 LED_SetState(arg, j);
6243                 break;
6244         case PHONE_FRAME:
6245                 retval = set_base_frame(j, arg);
6246                 break;
6247         case PHONE_REC_CODEC:
6248                 retval = set_rec_codec(j, arg);
6249                 break;
6250         case PHONE_VAD:
6251                 ixj_vad(j, arg);
6252                 break;
6253         case PHONE_REC_START:
6254                 ixj_record_start(j);
6255                 break;
6256         case PHONE_REC_STOP:
6257                 ixj_record_stop(j);
6258                 break;
6259         case PHONE_REC_DEPTH:
6260                 set_rec_depth(j, arg);
6261                 break;
6262         case PHONE_REC_VOLUME:
6263                 if(arg == -1) {
6264                         retval = get_rec_volume(j);
6265                 }
6266                 else {
6267                         set_rec_volume(j, arg);
6268                         retval = arg;
6269                 }
6270                 break;
6271         case PHONE_REC_VOLUME_LINEAR:
6272                 if(arg == -1) {
6273                         retval = get_rec_volume_linear(j);
6274                 }
6275                 else {
6276                         set_rec_volume_linear(j, arg);
6277                         retval = arg;
6278                 }
6279                 break;
6280         case IXJCTL_DTMF_PRESCALE:
6281                 if(arg == -1) {
6282                         retval = get_dtmf_prescale(j);
6283                 }
6284                 else {
6285                         set_dtmf_prescale(j, arg);
6286                         retval = arg;
6287                 }
6288                 break;
6289         case PHONE_REC_LEVEL:
6290                 retval = get_rec_level(j);
6291                 break;
6292         case IXJCTL_SC_RXG:
6293                 retval = ixj_siadc(j, arg);
6294                 break;
6295         case IXJCTL_SC_TXG:
6296                 retval = ixj_sidac(j, arg);
6297                 break;
6298         case IXJCTL_AEC_START:
6299                 ixj_aec_start(j, arg);
6300                 break;
6301         case IXJCTL_AEC_STOP:
6302                 aec_stop(j);
6303                 break;
6304         case IXJCTL_AEC_GET_LEVEL:
6305                 retval = j->aec_level;
6306                 break;
6307         case PHONE_PLAY_CODEC:
6308                 retval = set_play_codec(j, arg);
6309                 break;
6310         case PHONE_PLAY_START:
6311                 retval = ixj_play_start(j);
6312                 break;
6313         case PHONE_PLAY_STOP:
6314                 ixj_play_stop(j);
6315                 break;
6316         case PHONE_PLAY_DEPTH:
6317                 set_play_depth(j, arg);
6318                 break;
6319         case PHONE_PLAY_VOLUME:
6320                 if(arg == -1) {
6321                         retval = get_play_volume(j);
6322                 }
6323                 else {
6324                         set_play_volume(j, arg);
6325                         retval = arg;
6326                 }
6327                 break;
6328         case PHONE_PLAY_VOLUME_LINEAR:
6329                 if(arg == -1) {
6330                         retval = get_play_volume_linear(j);
6331                 }
6332                 else {
6333                         set_play_volume_linear(j, arg);
6334                         retval = arg;
6335                 }
6336                 break;
6337         case PHONE_PLAY_LEVEL:
6338                 retval = get_play_level(j);
6339                 break;
6340         case IXJCTL_DSP_TYPE:
6341                 retval = (j->dsp.high << 8) + j->dsp.low;
6342                 break;
6343         case IXJCTL_DSP_VERSION:
6344                 retval = (j->ver.high << 8) + j->ver.low;
6345                 break;
6346         case IXJCTL_HZ:
6347                 hertz = arg;
6348                 break;
6349         case IXJCTL_RATE:
6350                 if (arg > hertz)
6351                         retval = -1;
6352                 else
6353                         samplerate = arg;
6354                 break;
6355         case IXJCTL_DRYBUFFER_READ:
6356                 put_user(j->drybuffer, (unsigned long __user *) argp);
6357                 break;
6358         case IXJCTL_DRYBUFFER_CLEAR:
6359                 j->drybuffer = 0;
6360                 break;
6361         case IXJCTL_FRAMES_READ:
6362                 put_user(j->framesread, (unsigned long __user *) argp);
6363                 break;
6364         case IXJCTL_FRAMES_WRITTEN:
6365                 put_user(j->frameswritten, (unsigned long __user *) argp);
6366                 break;
6367         case IXJCTL_READ_WAIT:
6368                 put_user(j->read_wait, (unsigned long __user *) argp);
6369                 break;
6370         case IXJCTL_WRITE_WAIT:
6371                 put_user(j->write_wait, (unsigned long __user *) argp);
6372                 break;
6373         case PHONE_MAXRINGS:
6374                 j->maxrings = arg;
6375                 break;
6376         case PHONE_SET_TONE_ON_TIME:
6377                 ixj_set_tone_on(arg, j);
6378                 break;
6379         case PHONE_SET_TONE_OFF_TIME:
6380                 ixj_set_tone_off(arg, j);
6381                 break;
6382         case PHONE_GET_TONE_ON_TIME:
6383                 if (ixj_get_tone_on(j)) {
6384                         retval = -1;
6385                 } else {
6386                         retval = (j->ssr.high << 8) + j->ssr.low;
6387                 }
6388                 break;
6389         case PHONE_GET_TONE_OFF_TIME:
6390                 if (ixj_get_tone_off(j)) {
6391                         retval = -1;
6392                 } else {
6393                         retval = (j->ssr.high << 8) + j->ssr.low;
6394                 }
6395                 break;
6396         case PHONE_PLAY_TONE:
6397                 if (!j->tone_state)
6398                         retval = ixj_play_tone(j, arg);
6399                 else
6400                         retval = -1;
6401                 break;
6402         case PHONE_GET_TONE_STATE:
6403                 retval = j->tone_state;
6404                 break;
6405         case PHONE_DTMF_READY:
6406                 retval = j->ex.bits.dtmf_ready;
6407                 break;
6408         case PHONE_GET_DTMF:
6409                 if (ixj_hookstate(j)) {
6410                         if (j->dtmf_rp != j->dtmf_wp) {
6411                                 retval = j->dtmfbuffer[j->dtmf_rp];
6412                                 j->dtmf_rp++;
6413                                 if (j->dtmf_rp == 79)
6414                                         j->dtmf_rp = 0;
6415                                 if (j->dtmf_rp == j->dtmf_wp) {
6416                                         j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6417                                 }
6418                         }
6419                 }
6420                 break;
6421         case PHONE_GET_DTMF_ASCII:
6422                 if (ixj_hookstate(j)) {
6423                         if (j->dtmf_rp != j->dtmf_wp) {
6424                                 switch (j->dtmfbuffer[j->dtmf_rp]) {
6425                                 case 10:
6426                                         retval = 42;    /* '*'; */
6427
6428                                         break;
6429                                 case 11:
6430                                         retval = 48;    /*'0'; */
6431
6432                                         break;
6433                                 case 12:
6434                                         retval = 35;    /*'#'; */
6435
6436                                         break;
6437                                 case 28:
6438                                         retval = 65;    /*'A'; */
6439
6440                                         break;
6441                                 case 29:
6442                                         retval = 66;    /*'B'; */
6443
6444                                         break;
6445                                 case 30:
6446                                         retval = 67;    /*'C'; */
6447
6448                                         break;
6449                                 case 31:
6450                                         retval = 68;    /*'D'; */
6451
6452                                         break;
6453                                 default:
6454                                         retval = 48 + j->dtmfbuffer[j->dtmf_rp];
6455                                         break;
6456                                 }
6457                                 j->dtmf_rp++;
6458                                 if (j->dtmf_rp == 79)
6459                                         j->dtmf_rp = 0;
6460                                 if(j->dtmf_rp == j->dtmf_wp)
6461                                 {
6462                                         j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6463                                 }
6464                         }
6465                 }
6466                 break;
6467         case PHONE_DTMF_OOB:
6468                 j->flags.dtmf_oob = arg;
6469                 break;
6470         case PHONE_DIALTONE:
6471                 ixj_dialtone(j);
6472                 break;
6473         case PHONE_BUSY:
6474                 ixj_busytone(j);
6475                 break;
6476         case PHONE_RINGBACK:
6477                 ixj_ringback(j);
6478                 break;
6479         case PHONE_WINK:
6480                 if(j->cardtype == QTI_PHONEJACK) 
6481                         retval = -1;
6482                 else 
6483                         retval = ixj_wink(j);
6484                 break;
6485         case PHONE_CPT_STOP:
6486                 ixj_cpt_stop(j);
6487                 break;
6488         case PHONE_QUERY_CODEC:
6489         {
6490                 struct phone_codec_data pd;
6491                 int val;
6492                 int proto_size[] = {
6493                         -1,
6494                         12, 10, 16, 9, 8, 48, 5,
6495                         40, 40, 80, 40, 40, 6
6496                 };
6497                 if(copy_from_user(&pd, argp, sizeof(pd))) {
6498                         retval = -EFAULT;
6499                         break;
6500                 }
6501                 if(pd.type<1 || pd.type>13) {
6502                         retval = -EPROTONOSUPPORT;
6503                         break;
6504                 }
6505                 if(pd.type<G729)
6506                         val=proto_size[pd.type];
6507                 else switch(j->baseframe.low)
6508                 {
6509                         case 0xA0:val=2*proto_size[pd.type];break;
6510                         case 0x50:val=proto_size[pd.type];break;
6511                         default:val=proto_size[pd.type]*3;break;
6512                 }
6513                 pd.buf_min=pd.buf_max=pd.buf_opt=val;
6514                 if(copy_to_user(argp, &pd, sizeof(pd)))
6515                         retval = -EFAULT;
6516                 break;
6517         }
6518         case IXJCTL_DSP_IDLE:
6519                 idle(j);
6520                 break;
6521         case IXJCTL_MIXER:
6522                 if ((arg & 0xff) == 0xff)
6523                         retval = ixj_get_mixer(arg, j);
6524                 else
6525                         ixj_mixer(arg, j);
6526                 break;
6527         case IXJCTL_DAA_COEFF_SET:
6528                 switch (arg) {
6529                 case DAA_US:
6530                         DAA_Coeff_US(j);
6531                         retval = ixj_daa_write(j);
6532                         break;
6533                 case DAA_UK:
6534                         DAA_Coeff_UK(j);
6535                         retval = ixj_daa_write(j);
6536                         break;
6537                 case DAA_FRANCE:
6538                         DAA_Coeff_France(j);
6539                         retval = ixj_daa_write(j);
6540                         break;
6541                 case DAA_GERMANY:
6542                         DAA_Coeff_Germany(j);
6543                         retval = ixj_daa_write(j);
6544                         break;
6545                 case DAA_AUSTRALIA:
6546                         DAA_Coeff_Australia(j);
6547                         retval = ixj_daa_write(j);
6548                         break;
6549                 case DAA_JAPAN:
6550                         DAA_Coeff_Japan(j);
6551                         retval = ixj_daa_write(j);
6552                         break;
6553                 default:
6554                         retval = 1;
6555                         break;
6556                 }
6557                 break;
6558         case IXJCTL_DAA_AGAIN:
6559                 ixj_daa_cr4(j, arg | 0x02);
6560                 break;
6561         case IXJCTL_PSTN_LINETEST:
6562                 retval = ixj_linetest(j);
6563                 break;
6564         case IXJCTL_VMWI:
6565                 ixj_write_vmwi(j, arg);
6566                 break;
6567         case IXJCTL_CID:
6568                 if (copy_to_user(argp, &j->cid, sizeof(PHONE_CID))) 
6569                         retval = -EFAULT;
6570                 j->ex.bits.caller_id = 0;
6571                 break;
6572         case IXJCTL_WINK_DURATION:
6573                 j->winktime = arg;
6574                 break;
6575         case IXJCTL_PORT:
6576                 if (arg)
6577                         retval = ixj_set_port(j, arg);
6578                 else
6579                         retval = j->port;
6580                 break;
6581         case IXJCTL_POTS_PSTN:
6582                 retval = ixj_set_pots(j, arg);
6583                 break;
6584         case PHONE_CAPABILITIES:
6585                 add_caps(j);
6586                 retval = j->caps;
6587                 break;
6588         case PHONE_CAPABILITIES_LIST:
6589                 add_caps(j);
6590                 if (copy_to_user(argp, j->caplist, sizeof(struct phone_capability) * j->caps)) 
6591                         retval = -EFAULT;
6592                 break;
6593         case PHONE_CAPABILITIES_CHECK:
6594                 {
6595                         struct phone_capability cap;
6596                         if (copy_from_user(&cap, argp, sizeof(cap))) 
6597                                 retval = -EFAULT;
6598                         else {
6599                                 add_caps(j);
6600                                 retval = capabilities_check(j, &cap);
6601                         }
6602                 }
6603                 break;
6604         case PHONE_PSTN_SET_STATE:
6605                 daa_set_mode(j, arg);
6606                 break;
6607         case PHONE_PSTN_GET_STATE:
6608                 retval = j->daa_mode;
6609                 j->ex.bits.pstn_ring = 0;
6610                 break;
6611         case IXJCTL_SET_FILTER:
6612                 if (copy_from_user(&jf, argp, sizeof(jf))) 
6613                         retval = -EFAULT;
6614                 retval = ixj_init_filter(j, &jf);
6615                 break;
6616         case IXJCTL_SET_FILTER_RAW:
6617                 if (copy_from_user(&jfr, argp, sizeof(jfr))) 
6618                         retval = -EFAULT;
6619                 else
6620                         retval = ixj_init_filter_raw(j, &jfr);
6621                 break;
6622         case IXJCTL_GET_FILTER_HIST:
6623                 if(arg<0||arg>3)
6624                         retval = -EINVAL;
6625                 else
6626                         retval = j->filter_hist[arg];
6627                 break;
6628         case IXJCTL_INIT_TONE:
6629                 if (copy_from_user(&ti, argp, sizeof(ti)))
6630                         retval = -EFAULT;
6631                 else
6632                         retval = ixj_init_tone(j, &ti);
6633                 break;
6634         case IXJCTL_TONE_CADENCE:
6635                 retval = ixj_build_cadence(j, argp);
6636                 break;
6637         case IXJCTL_FILTER_CADENCE:
6638                 retval = ixj_build_filter_cadence(j, argp);
6639                 break;
6640         case IXJCTL_SIGCTL:
6641                 if (copy_from_user(&j->sigdef, argp, sizeof(IXJ_SIGDEF))) {
6642                         retval = -EFAULT;
6643                         break;
6644                 }
6645                 j->ixj_signals[j->sigdef.event] = j->sigdef.signal;
6646                 if(j->sigdef.event < 33) {
6647                         raise = 1;
6648                         for(mant = 0; mant < j->sigdef.event; mant++){
6649                                 raise *= 2;
6650                         }
6651                         if(j->sigdef.signal)
6652                                 j->ex_sig.bytes |= raise; 
6653                         else
6654                                 j->ex_sig.bytes &= (raise^0xffff); 
6655                 }
6656                 break;
6657         case IXJCTL_INTERCOM_STOP:
6658                 if(arg < 0 || arg >= IXJMAX)
6659                         return -EINVAL;
6660                 j->intercom = -1;
6661                 ixj_record_stop(j);
6662                 ixj_play_stop(j);
6663                 idle(j);
6664                 get_ixj(arg)->intercom = -1;
6665                 ixj_record_stop(get_ixj(arg));
6666                 ixj_play_stop(get_ixj(arg));
6667                 idle(get_ixj(arg));
6668                 break;
6669         case IXJCTL_INTERCOM_START:
6670                 if(arg < 0 || arg >= IXJMAX)
6671                         return -EINVAL;
6672                 j->intercom = arg;
6673                 ixj_record_start(j);
6674                 ixj_play_start(j);
6675                 get_ixj(arg)->intercom = board;
6676                 ixj_play_start(get_ixj(arg));
6677                 ixj_record_start(get_ixj(arg));
6678                 break;
6679         }
6680         if (ixjdebug & 0x0040)
6681                 printk("phone%d ioctl end, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6682         clear_bit(board, &j->busyflags);
6683         return retval;
6684 }
6685
6686 static int ixj_fasync(int fd, struct file *file_p, int mode)
6687 {
6688         IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode));
6689
6690         return fasync_helper(fd, file_p, mode, &j->async_queue);
6691 }
6692
6693 static struct file_operations ixj_fops =
6694 {
6695         .owner          = THIS_MODULE,
6696         .read           = ixj_enhanced_read,
6697         .write          = ixj_enhanced_write,
6698         .poll           = ixj_poll,
6699         .ioctl          = ixj_ioctl,
6700         .release        = ixj_release,
6701         .fasync         = ixj_fasync
6702 };
6703
6704 static int ixj_linetest(IXJ *j)
6705 {
6706         unsigned long jifwait;
6707
6708         j->flags.pstncheck = 1; /* Testing */
6709         j->flags.pstn_present = 0; /* Assume the line is not there */
6710
6711         daa_int_read(j);        /*Clear DAA Interrupt flags */
6712         /* */
6713         /* Hold all relays in the normally de-energized position. */
6714         /* */
6715
6716         j->pld_slicw.bits.rly1 = 0;
6717         j->pld_slicw.bits.rly2 = 0;
6718         j->pld_slicw.bits.rly3 = 0;
6719         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6720         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6721
6722         outb_p(j->pld_scrw.byte, j->XILINXbase);
6723         j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
6724         if (j->pld_slicr.bits.potspstn) {
6725                 j->flags.pots_pstn = 1;
6726                 j->flags.pots_correct = 0;
6727                 LED_SetState(0x4, j);
6728         } else {
6729                 j->flags.pots_pstn = 0;
6730                 j->pld_slicw.bits.rly1 = 0;
6731                 j->pld_slicw.bits.rly2 = 0;
6732                 j->pld_slicw.bits.rly3 = 1;
6733                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6734                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6735
6736                 outb_p(j->pld_scrw.byte, j->XILINXbase);
6737                 daa_set_mode(j, SOP_PU_CONVERSATION);
6738                 jifwait = jiffies + hertz;
6739                 while (time_before(jiffies, jifwait)) {
6740                         set_current_state(TASK_INTERRUPTIBLE);
6741                         schedule_timeout(1);
6742                 }
6743                 daa_int_read(j);
6744                 daa_set_mode(j, SOP_PU_RESET);
6745                 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6746                         j->flags.pots_correct = 0;      /* Should not be line voltage on POTS port. */
6747                         LED_SetState(0x4, j);
6748                         j->pld_slicw.bits.rly3 = 0;
6749                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6750                 } else {
6751                         j->flags.pots_correct = 1;
6752                         LED_SetState(0x8, j);
6753                         j->pld_slicw.bits.rly1 = 1;
6754                         j->pld_slicw.bits.rly2 = 0;
6755                         j->pld_slicw.bits.rly3 = 0;
6756                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6757                 }
6758         }
6759         j->pld_slicw.bits.rly3 = 0;
6760         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6761         daa_set_mode(j, SOP_PU_CONVERSATION);
6762         jifwait = jiffies + hertz;
6763         while (time_before(jiffies, jifwait)) {
6764                 set_current_state(TASK_INTERRUPTIBLE);
6765                 schedule_timeout(1);
6766         }
6767         daa_int_read(j);
6768         daa_set_mode(j, SOP_PU_RESET);
6769         if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6770                 j->pstn_sleeptil = jiffies + (hertz / 4);
6771                 j->flags.pstn_present = 1;
6772         } else {
6773                 j->flags.pstn_present = 0;
6774         }
6775         if (j->flags.pstn_present) {
6776                 if (j->flags.pots_correct) {
6777                         LED_SetState(0xA, j);
6778                 } else {
6779                         LED_SetState(0x6, j);
6780                 }
6781         } else {
6782                 if (j->flags.pots_correct) {
6783                         LED_SetState(0x9, j);
6784                 } else {
6785                         LED_SetState(0x5, j);
6786                 }
6787         }
6788         j->flags.pstncheck = 0; /* Testing */
6789         return j->flags.pstn_present;
6790 }
6791
6792 static int ixj_selfprobe(IXJ *j)
6793 {
6794         unsigned short cmd;
6795         unsigned long jif;
6796         int cnt;
6797         BYTES bytes;
6798
6799         init_waitqueue_head(&j->poll_q);
6800         init_waitqueue_head(&j->read_q);
6801         init_waitqueue_head(&j->write_q);
6802
6803         while(atomic_read(&j->DSPWrite) > 0)
6804                 atomic_dec(&j->DSPWrite);
6805         if (ixjdebug & 0x0002)
6806                 printk(KERN_INFO "Write IDLE to Software Control Register\n");
6807         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
6808
6809         if (ixj_WriteDSPCommand(0x0000, j))             /* Write IDLE to Software Control Register */
6810                 return -1;
6811 /* The read values of the SSR should be 0x00 for the IDLE command */
6812         if (j->ssr.low || j->ssr.high)
6813                 return -1;
6814         if (ixjdebug & 0x0002)
6815                 printk(KERN_INFO "Get Device ID Code\n");
6816         if (ixj_WriteDSPCommand(0x3400, j))             /* Get Device ID Code */
6817                 return -1;
6818         j->dsp.low = j->ssr.low;
6819         j->dsp.high = j->ssr.high;
6820         if (ixjdebug & 0x0002)
6821                 printk(KERN_INFO "Get Device Version Code\n");
6822         if (ixj_WriteDSPCommand(0x3800, j))             /* Get Device Version Code */
6823                 return -1;
6824         j->ver.low = j->ssr.low;
6825         j->ver.high = j->ssr.high;
6826         if (!j->cardtype) {
6827                 if (j->dsp.low == 0x21) {
6828                         bytes.high = bytes.low = inb_p(j->XILINXbase + 0x02);
6829                         outb_p(bytes.low ^ 0xFF, j->XILINXbase + 0x02);
6830 /* Test for Internet LineJACK or Internet PhoneJACK Lite */
6831                         bytes.low = inb_p(j->XILINXbase + 0x02);
6832                         if (bytes.low == bytes.high)    /*  Register is read only on */
6833                                 /*  Internet PhoneJack Lite */
6834                          {
6835                                 j->cardtype = QTI_PHONEJACK_LITE;
6836                                 if (!request_region(j->XILINXbase, 4, "ixj control")) {
6837                                         printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6838                                         return -1;
6839                                 }
6840                                 j->pld_slicw.pcib.e1 = 1;
6841                                 outb_p(j->pld_slicw.byte, j->XILINXbase);
6842                         } else {
6843                                 j->cardtype = QTI_LINEJACK;
6844
6845                                 if (!request_region(j->XILINXbase, 8, "ixj control")) {
6846                                         printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6847                                         return -1;
6848                                 }
6849                         }
6850                 } else if (j->dsp.low == 0x22) {
6851                         j->cardtype = QTI_PHONEJACK_PCI;
6852                         request_region(j->XILINXbase, 4, "ixj control");
6853                         j->pld_slicw.pcib.e1 = 1;
6854                         outb_p(j->pld_slicw.byte, j->XILINXbase);
6855                 } else
6856                         j->cardtype = QTI_PHONEJACK;
6857         } else {
6858                 switch (j->cardtype) {
6859                 case QTI_PHONEJACK:
6860                         if (!j->dsp.low != 0x20) {
6861                                 j->dsp.high = 0x80;
6862                                 j->dsp.low = 0x20;
6863                                 ixj_WriteDSPCommand(0x3800, j);
6864                                 j->ver.low = j->ssr.low;
6865                                 j->ver.high = j->ssr.high;
6866                         }
6867                         break;
6868                 case QTI_LINEJACK:
6869                         if (!request_region(j->XILINXbase, 8, "ixj control")) {
6870                                 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6871                                 return -1;
6872                         }
6873                         break;
6874                 case QTI_PHONEJACK_LITE:
6875                 case QTI_PHONEJACK_PCI:
6876                         if (!request_region(j->XILINXbase, 4, "ixj control")) {
6877                                 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6878                                 return -1;
6879                         }
6880                         j->pld_slicw.pcib.e1 = 1;
6881                         outb_p(j->pld_slicw.byte, j->XILINXbase);
6882                         break;
6883                 case QTI_PHONECARD:
6884                         break;
6885                 }
6886         }
6887         if (j->dsp.low == 0x20 || j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
6888                 if (ixjdebug & 0x0002)
6889                         printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6890                 if (ixj_WriteDSPCommand(0xC462, j))             /* Write CODEC config to Software Control Register */
6891                         return -1;
6892                 if (ixjdebug & 0x0002)
6893                         printk(KERN_INFO "Write CODEC timing to Software Control Register\n");
6894                 if (j->cardtype == QTI_PHONEJACK) {
6895                         cmd = 0x9FF2;
6896                 } else {
6897                         cmd = 0x9FF5;
6898                 }
6899                 if (ixj_WriteDSPCommand(cmd, j))        /* Write CODEC timing to Software Control Register */
6900                         return -1;
6901         } else {
6902                 if (set_base_frame(j, 30) != 30)
6903                         return -1;
6904                 if (ixjdebug & 0x0002)
6905                         printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6906                 if (j->cardtype == QTI_PHONECARD) {
6907                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to Software Control Register */
6908                                 return -1;
6909                 }
6910                 if (j->cardtype == QTI_LINEJACK) {
6911                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to Software Control Register */
6912                                 return -1;
6913                         if (ixjdebug & 0x0002)
6914                                 printk(KERN_INFO "Turn on the PLD Clock at 8Khz\n");
6915                         j->pld_clock.byte = 0;
6916                         outb_p(j->pld_clock.byte, j->XILINXbase + 0x04);
6917                 }
6918         }
6919
6920         if (j->dsp.low == 0x20) {
6921                 if (ixjdebug & 0x0002)
6922                         printk(KERN_INFO "Configure GPIO pins\n");
6923                 j->gpio.bytes.high = 0x09;
6924 /*  bytes.low = 0xEF;  0xF7 */
6925                 j->gpio.bits.gpio1 = 1;
6926                 j->gpio.bits.gpio2 = 1;
6927                 j->gpio.bits.gpio3 = 0;
6928                 j->gpio.bits.gpio4 = 1;
6929                 j->gpio.bits.gpio5 = 1;
6930                 j->gpio.bits.gpio6 = 1;
6931                 j->gpio.bits.gpio7 = 1;
6932                 ixj_WriteDSPCommand(j->gpio.word, j);   /* Set GPIO pin directions */
6933                 if (ixjdebug & 0x0002)
6934                         printk(KERN_INFO "Enable SLIC\n");
6935                 j->gpio.bytes.high = 0x0B;
6936                 j->gpio.bytes.low = 0x00;
6937                 j->gpio.bits.gpio1 = 0;
6938                 j->gpio.bits.gpio2 = 1;
6939                 j->gpio.bits.gpio5 = 0;
6940                 ixj_WriteDSPCommand(j->gpio.word, j);   /* send the ring stop signal */
6941                 j->port = PORT_POTS;
6942         } else {
6943                 if (j->cardtype == QTI_LINEJACK) {
6944                         LED_SetState(0x1, j);
6945                         jif = jiffies + (hertz / 10);
6946                         while (time_before(jiffies, jif)) {
6947                                 set_current_state(TASK_INTERRUPTIBLE);
6948                                 schedule_timeout(1);
6949                         }
6950                         LED_SetState(0x2, j);
6951                         jif = jiffies + (hertz / 10);
6952                         while (time_before(jiffies, jif)) {
6953                                 set_current_state(TASK_INTERRUPTIBLE);
6954                                 schedule_timeout(1);
6955                         }
6956                         LED_SetState(0x4, j);
6957                         jif = jiffies + (hertz / 10);
6958                         while (time_before(jiffies, jif)) {
6959                                 set_current_state(TASK_INTERRUPTIBLE);
6960                                 schedule_timeout(1);
6961                         }
6962                         LED_SetState(0x8, j);
6963                         jif = jiffies + (hertz / 10);
6964                         while (time_before(jiffies, jif)) {
6965                                 set_current_state(TASK_INTERRUPTIBLE);
6966                                 schedule_timeout(1);
6967                         }
6968                         LED_SetState(0x0, j);
6969                         daa_get_version(j);
6970                         if (ixjdebug & 0x0002)
6971                                 printk("Loading DAA Coefficients\n");
6972                         DAA_Coeff_US(j);
6973                         if (!ixj_daa_write(j)) {
6974                                 printk("DAA write failed on board %d\n", j->board);
6975                                 return -1;
6976                         }
6977                         if(!ixj_daa_cid_reset(j)) {
6978                                 printk("DAA CID reset failed on board %d\n", j->board);
6979                                 return -1;
6980                         }
6981                         j->flags.pots_correct = 0;
6982                         j->flags.pstn_present = 0;
6983                         ixj_linetest(j);
6984                         if (j->flags.pots_correct) {
6985                                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6986
6987                                 outb_p(j->pld_scrw.byte, j->XILINXbase);
6988                                 j->pld_slicw.bits.rly1 = 1;
6989                                 j->pld_slicw.bits.spken = 1;
6990                                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6991                                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
6992 /*                              SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
6993                                 j->port = PORT_POTS;
6994                         }
6995                         ixj_set_port(j, PORT_PSTN);
6996                         ixj_set_pots(j, 1);
6997                         if (ixjdebug & 0x0002)
6998                                 printk(KERN_INFO "Enable Mixer\n");
6999                         ixj_mixer(0x0000, j);   /*Master Volume Left unmute 0db */
7000                         ixj_mixer(0x0100, j);   /*Master Volume Right unmute 0db */
7001
7002                         ixj_mixer(0x0203, j);   /*Voice Left Volume unmute 6db */
7003                         ixj_mixer(0x0303, j);   /*Voice Right Volume unmute 6db */
7004
7005                         ixj_mixer(0x0480, j);   /*FM Left mute */
7006                         ixj_mixer(0x0580, j);   /*FM Right mute */
7007
7008                         ixj_mixer(0x0680, j);   /*CD Left mute */
7009                         ixj_mixer(0x0780, j);   /*CD Right mute */
7010
7011                         ixj_mixer(0x0880, j);   /*Line Left mute */
7012                         ixj_mixer(0x0980, j);   /*Line Right mute */
7013
7014                         ixj_mixer(0x0A80, j);   /*Aux left mute  */
7015                         ixj_mixer(0x0B80, j);   /*Aux right mute */
7016
7017                         ixj_mixer(0x0C00, j);   /*Mono1 unmute 12db */
7018                         ixj_mixer(0x0D80, j);   /*Mono2 mute */
7019
7020                         ixj_mixer(0x0E80, j);   /*Mic mute */
7021
7022                         ixj_mixer(0x0F00, j);   /*Mono Out Volume unmute 0db */
7023
7024                         ixj_mixer(0x1000, j);   /*Voice Left and Right out only */
7025                         ixj_mixer(0x110C, j);
7026
7027
7028                         ixj_mixer(0x1200, j);   /*Mono1 switch on mixer left */
7029                         ixj_mixer(0x1401, j);
7030
7031                         ixj_mixer(0x1300, j);       /*Mono1 switch on mixer right */
7032                         ixj_mixer(0x1501, j);
7033
7034                         ixj_mixer(0x1700, j);   /*Clock select */
7035
7036                         ixj_mixer(0x1800, j);   /*ADC input from mixer */
7037
7038                         ixj_mixer(0x1901, j);   /*Mic gain 30db */
7039
7040                         if (ixjdebug & 0x0002)
7041                                 printk(KERN_INFO "Setting Default US Ring Cadence Detection\n");
7042                         j->cadence_f[4].state = 0;
7043                         j->cadence_f[4].on1 = 0;        /*Cadence Filter 4 is used for PSTN ring cadence */
7044                         j->cadence_f[4].off1 = 0;
7045                         j->cadence_f[4].on2 = 0;
7046                         j->cadence_f[4].off2 = 0;
7047                         j->cadence_f[4].on3 = 0;
7048                         j->cadence_f[4].off3 = 0;       /* These should represent standard US ring pulse. */
7049                         j->pstn_last_rmr = jiffies;
7050
7051                 } else {
7052                         if (j->cardtype == QTI_PHONECARD) {
7053                                 ixj_WriteDSPCommand(0xCF07, j);
7054                                 ixj_WriteDSPCommand(0x00B0, j);
7055                                 ixj_set_port(j, PORT_SPEAKER);
7056                         } else {
7057                                 ixj_set_port(j, PORT_POTS);
7058                                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
7059 /*                              SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
7060                         }
7061                 }
7062         }
7063
7064         j->intercom = -1;
7065         j->framesread = j->frameswritten = 0;
7066         j->read_wait = j->write_wait = 0;
7067         j->rxreadycheck = j->txreadycheck = 0;
7068
7069         /* initialise the DTMF prescale to a sensible value */
7070         if (j->cardtype == QTI_LINEJACK) {
7071                 set_dtmf_prescale(j, 0x10); 
7072         } else {
7073                 set_dtmf_prescale(j, 0x40); 
7074         }
7075         set_play_volume(j, 0x100);
7076         set_rec_volume(j, 0x100);
7077
7078         if (ixj_WriteDSPCommand(0x0000, j))             /* Write IDLE to Software Control Register */
7079                 return -1;
7080 /* The read values of the SSR should be 0x00 for the IDLE command */
7081         if (j->ssr.low || j->ssr.high)
7082                 return -1;
7083
7084         if (ixjdebug & 0x0002)
7085                 printk(KERN_INFO "Enable Line Monitor\n");
7086
7087         if (ixjdebug & 0x0002)
7088                 printk(KERN_INFO "Set Line Monitor to Asyncronous Mode\n");
7089
7090         if (ixj_WriteDSPCommand(0x7E01, j))             /* Asynchronous Line Monitor */
7091                 return -1;
7092
7093         if (ixjdebug & 0x002)
7094                 printk(KERN_INFO "Enable DTMF Detectors\n");
7095
7096         if (ixj_WriteDSPCommand(0x5151, j))             /* Enable DTMF detection */
7097                 return -1;
7098
7099         if (ixj_WriteDSPCommand(0x6E01, j))             /* Set Asyncronous Tone Generation */
7100                 return -1;
7101
7102         set_rec_depth(j, 2);    /* Set Record Channel Limit to 2 frames */
7103
7104         set_play_depth(j, 2);   /* Set Playback Channel Limit to 2 frames */
7105
7106         j->ex.bits.dtmf_ready = 0;
7107         j->dtmf_state = 0;
7108         j->dtmf_wp = j->dtmf_rp = 0;
7109         j->rec_mode = j->play_mode = -1;
7110         j->flags.ringing = 0;
7111         j->maxrings = MAXRINGS;
7112         j->ring_cadence = USA_RING_CADENCE;
7113         j->drybuffer = 0;
7114         j->winktime = 320;
7115         j->flags.dtmf_oob = 0;
7116         for (cnt = 0; cnt < 4; cnt++)
7117                 j->cadence_f[cnt].enable = 0;
7118         /* must be a device on the specified address */
7119         ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
7120
7121         /* Set up the default signals for events */
7122         for (cnt = 0; cnt < 35; cnt++)
7123                 j->ixj_signals[cnt] = SIGIO;
7124
7125         /* Set the excetion signal enable flags */
7126         j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 
7127         j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 = 
7128         j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1;
7129 #ifdef IXJ_DYN_ALLOC
7130         j->fskdata = NULL;
7131 #endif
7132         j->fskdcnt = 0;
7133         j->cidcw_wait = 0;
7134  
7135         /* Register with the Telephony for Linux subsystem */
7136         j->p.f_op = &ixj_fops;
7137         j->p.open = ixj_open;
7138         j->p.board = j->board;
7139         phone_register_device(&j->p, PHONE_UNIT_ANY);
7140
7141         ixj_init_timer(j);
7142         ixj_add_timer(j);
7143         return 0;
7144 }
7145
7146 /*
7147  *      Exported service for pcmcia card handling
7148  */
7149  
7150 IXJ *ixj_pcmcia_probe(unsigned long dsp, unsigned long xilinx)
7151 {
7152         IXJ *j = ixj_alloc();
7153
7154         j->board = 0;
7155
7156         j->DSPbase = dsp;
7157         j->XILINXbase = xilinx;
7158         j->cardtype = QTI_PHONECARD;
7159         ixj_selfprobe(j);
7160         return j;
7161 }
7162
7163 EXPORT_SYMBOL(ixj_pcmcia_probe);                /* Fpr PCMCIA */
7164
7165 static int ixj_get_status_proc(char *buf)
7166 {
7167         int len;
7168         int cnt;
7169         IXJ *j;
7170         len = 0;
7171         len += sprintf(buf + len, "%s", ixj_c_rcsid);
7172         len += sprintf(buf + len, "\n%s", ixj_h_rcsid);
7173         len += sprintf(buf + len, "\n%s", ixjuser_h_rcsid);
7174         len += sprintf(buf + len, "\nDriver version %i.%i.%i", IXJ_VER_MAJOR, IXJ_VER_MINOR, IXJ_BLD_VER);
7175         len += sprintf(buf + len, "\nsizeof IXJ struct %Zd bytes", sizeof(IXJ));
7176         len += sprintf(buf + len, "\nsizeof DAA struct %Zd bytes", sizeof(DAA_REGS));
7177         len += sprintf(buf + len, "\nUsing old telephony API");
7178         len += sprintf(buf + len, "\nDebug Level %d\n", ixjdebug);
7179
7180         for (cnt = 0; cnt < IXJMAX; cnt++) {
7181                 j = get_ixj(cnt);
7182                 if(j==NULL)
7183                         continue;
7184                 if (j->DSPbase) {
7185                         len += sprintf(buf + len, "\nCard Num %d", cnt);
7186                         len += sprintf(buf + len, "\nDSP Base Address 0x%4.4x", j->DSPbase);
7187                         if (j->cardtype != QTI_PHONEJACK)
7188                                 len += sprintf(buf + len, "\nXILINX Base Address 0x%4.4x", j->XILINXbase);
7189                         len += sprintf(buf + len, "\nDSP Type %2.2x%2.2x", j->dsp.high, j->dsp.low);
7190                         len += sprintf(buf + len, "\nDSP Version %2.2x.%2.2x", j->ver.high, j->ver.low);
7191                         len += sprintf(buf + len, "\nSerial Number %8.8x", j->serial);
7192                         switch (j->cardtype) {
7193                         case (QTI_PHONEJACK):
7194                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK");
7195                                 break;
7196                         case (QTI_LINEJACK):
7197                                 len += sprintf(buf + len, "\nCard Type = Internet LineJACK");
7198                                 if (j->flags.g729_loaded)
7199                                         len += sprintf(buf + len, " w/G.729 A/B");
7200                                 len += sprintf(buf + len, " Country = %d", j->daa_country);
7201                                 break;
7202                         case (QTI_PHONEJACK_LITE):
7203                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK Lite");
7204                                 if (j->flags.g729_loaded)
7205                                         len += sprintf(buf + len, " w/G.729 A/B");
7206                                 break;
7207                         case (QTI_PHONEJACK_PCI):
7208                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK PCI");
7209                                 if (j->flags.g729_loaded)
7210                                         len += sprintf(buf + len, " w/G.729 A/B");
7211                                 break;
7212                         case (QTI_PHONECARD):
7213                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneCARD");
7214                                 if (j->flags.g729_loaded)
7215                                         len += sprintf(buf + len, " w/G.729 A/B");
7216                                 len += sprintf(buf + len, "\nSmart Cable %spresent", j->pccr1.bits.drf ? "not " : "");
7217                                 if (!j->pccr1.bits.drf)
7218                                         len += sprintf(buf + len, "\nSmart Cable type %d", j->flags.pcmciasct);
7219                                 len += sprintf(buf + len, "\nSmart Cable state %d", j->flags.pcmciastate);
7220                                 break;
7221                         default:
7222                                 len += sprintf(buf + len, "\nCard Type = %d", j->cardtype);
7223                                 break;
7224                         }
7225                         len += sprintf(buf + len, "\nReaders %d", j->readers);
7226                         len += sprintf(buf + len, "\nWriters %d", j->writers);
7227                         add_caps(j);
7228                         len += sprintf(buf + len, "\nCapabilities %d", j->caps);
7229                         if (j->dsp.low != 0x20)
7230                                 len += sprintf(buf + len, "\nDSP Processor load %d", j->proc_load);
7231                         if (j->flags.cidsent)
7232                                 len += sprintf(buf + len, "\nCaller ID data sent");
7233                         else
7234                                 len += sprintf(buf + len, "\nCaller ID data not sent");
7235
7236                         len += sprintf(buf + len, "\nPlay CODEC ");
7237                         switch (j->play_codec) {
7238                         case G723_63:
7239                                 len += sprintf(buf + len, "G.723.1 6.3");
7240                                 break;
7241                         case G723_53:
7242                                 len += sprintf(buf + len, "G.723.1 5.3");
7243                                 break;
7244                         case TS85:
7245                                 len += sprintf(buf + len, "TrueSpeech 8.5");
7246                                 break;
7247                         case TS48:
7248                                 len += sprintf(buf + len, "TrueSpeech 4.8");
7249                                 break;
7250                         case TS41:
7251                                 len += sprintf(buf + len, "TrueSpeech 4.1");
7252                                 break;
7253                         case G728:
7254                                 len += sprintf(buf + len, "G.728");
7255                                 break;
7256                         case G729:
7257                                 len += sprintf(buf + len, "G.729");
7258                                 break;
7259                         case G729B:
7260                                 len += sprintf(buf + len, "G.729B");
7261                                 break;
7262                         case ULAW:
7263                                 len += sprintf(buf + len, "uLaw");
7264                                 break;
7265                         case ALAW:
7266                                 len += sprintf(buf + len, "aLaw");
7267                                 break;
7268                         case LINEAR16:
7269                                 len += sprintf(buf + len, "16 bit Linear");
7270                                 break;
7271                         case LINEAR8:
7272                                 len += sprintf(buf + len, "8 bit Linear");
7273                                 break;
7274                         case WSS:
7275                                 len += sprintf(buf + len, "Windows Sound System");
7276                                 break;
7277                         default:
7278                                 len += sprintf(buf + len, "NO CODEC CHOSEN");
7279                                 break;
7280                         }
7281                         len += sprintf(buf + len, "\nRecord CODEC ");
7282                         switch (j->rec_codec) {
7283                         case G723_63:
7284                                 len += sprintf(buf + len, "G.723.1 6.3");
7285                                 break;
7286                         case G723_53:
7287                                 len += sprintf(buf + len, "G.723.1 5.3");
7288                                 break;
7289                         case TS85:
7290                                 len += sprintf(buf + len, "TrueSpeech 8.5");
7291                                 break;
7292                         case TS48:
7293                                 len += sprintf(buf + len, "TrueSpeech 4.8");
7294                                 break;
7295                         case TS41:
7296                                 len += sprintf(buf + len, "TrueSpeech 4.1");
7297                                 break;
7298                         case G728:
7299                                 len += sprintf(buf + len, "G.728");
7300                                 break;
7301                         case G729:
7302                                 len += sprintf(buf + len, "G.729");
7303                                 break;
7304                         case G729B:
7305                                 len += sprintf(buf + len, "G.729B");
7306                                 break;
7307                         case ULAW:
7308                                 len += sprintf(buf + len, "uLaw");
7309                                 break;
7310                         case ALAW:
7311                                 len += sprintf(buf + len, "aLaw");
7312                                 break;
7313                         case LINEAR16:
7314                                 len += sprintf(buf + len, "16 bit Linear");
7315                                 break;
7316                         case LINEAR8:
7317                                 len += sprintf(buf + len, "8 bit Linear");
7318                                 break;
7319                         case WSS:
7320                                 len += sprintf(buf + len, "Windows Sound System");
7321                                 break;
7322                         default:
7323                                 len += sprintf(buf + len, "NO CODEC CHOSEN");
7324                                 break;
7325                         }
7326                         len += sprintf(buf + len, "\nAEC ");
7327                         switch (j->aec_level) {
7328                         case AEC_OFF:
7329                                 len += sprintf(buf + len, "Off");
7330                                 break;
7331                         case AEC_LOW:
7332                                 len += sprintf(buf + len, "Low");
7333                                 break;
7334                         case AEC_MED:
7335                                 len += sprintf(buf + len, "Med");
7336                                 break;
7337                         case AEC_HIGH:
7338                                 len += sprintf(buf + len, "High");
7339                                 break;
7340                         case AEC_AUTO:
7341                                 len += sprintf(buf + len, "Auto");
7342                                 break;
7343                         case AEC_AGC:
7344                                 len += sprintf(buf + len, "AEC/AGC");
7345                                 break;
7346                         default:
7347                                 len += sprintf(buf + len, "unknown(%i)", j->aec_level);
7348                                 break;
7349                         }
7350
7351                         len += sprintf(buf + len, "\nRec volume 0x%x", get_rec_volume(j));
7352                         len += sprintf(buf + len, "\nPlay volume 0x%x", get_play_volume(j));
7353                         len += sprintf(buf + len, "\nDTMF prescale 0x%x", get_dtmf_prescale(j));
7354                         
7355                         len += sprintf(buf + len, "\nHook state %d", j->hookstate); /* j->r_hook);      */
7356
7357                         if (j->cardtype == QTI_LINEJACK) {
7358                                 len += sprintf(buf + len, "\nPOTS Correct %d", j->flags.pots_correct);
7359                                 len += sprintf(buf + len, "\nPSTN Present %d", j->flags.pstn_present);
7360                                 len += sprintf(buf + len, "\nPSTN Check %d", j->flags.pstncheck);
7361                                 len += sprintf(buf + len, "\nPOTS to PSTN %d", j->flags.pots_pstn);
7362                                 switch (j->daa_mode) {
7363                                 case SOP_PU_SLEEP:
7364                                         len += sprintf(buf + len, "\nDAA PSTN On Hook");
7365                                         break;
7366                                 case SOP_PU_RINGING:
7367                                         len += sprintf(buf + len, "\nDAA PSTN Ringing");
7368                                         len += sprintf(buf + len, "\nRinging state = %d", j->cadence_f[4].state);
7369                                         break;
7370                                 case SOP_PU_CONVERSATION:
7371                                         len += sprintf(buf + len, "\nDAA PSTN Off Hook");
7372                                         break;
7373                                 case SOP_PU_PULSEDIALING:
7374                                         len += sprintf(buf + len, "\nDAA PSTN Pulse Dialing");
7375                                         break;
7376                                 }
7377                                 len += sprintf(buf + len, "\nDAA RMR = %d", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR);
7378                                 len += sprintf(buf + len, "\nDAA VDD OK = %d", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK);
7379                                 len += sprintf(buf + len, "\nDAA CR0 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg);
7380                                 len += sprintf(buf + len, "\nDAA CR1 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg);
7381                                 len += sprintf(buf + len, "\nDAA CR2 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg);
7382                                 len += sprintf(buf + len, "\nDAA CR3 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg);
7383                                 len += sprintf(buf + len, "\nDAA CR4 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg);
7384                                 len += sprintf(buf + len, "\nDAA CR5 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg);
7385                                 len += sprintf(buf + len, "\nDAA XR0 = 0x%02x", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg);
7386                                 len += sprintf(buf + len, "\nDAA ringstop %ld - jiffies %ld", j->pstn_ring_stop, jiffies);
7387                         }
7388                         switch (j->port) {
7389                         case PORT_POTS:
7390                                 len += sprintf(buf + len, "\nPort POTS");
7391                                 break;
7392                         case PORT_PSTN:
7393                                 len += sprintf(buf + len, "\nPort PSTN");
7394                                 break;
7395                         case PORT_SPEAKER:
7396                                 len += sprintf(buf + len, "\nPort SPEAKER/MIC");
7397                                 break;
7398                         case PORT_HANDSET:
7399                                 len += sprintf(buf + len, "\nPort HANDSET");
7400                                 break;
7401                         }
7402                         if (j->dsp.low == 0x21 || j->dsp.low == 0x22) {
7403                                 len += sprintf(buf + len, "\nSLIC state ");
7404                                 switch (SLIC_GetState(j)) {
7405                                 case PLD_SLIC_STATE_OC:
7406                                         len += sprintf(buf + len, "OC");
7407                                         break;
7408                                 case PLD_SLIC_STATE_RINGING:
7409                                         len += sprintf(buf + len, "RINGING");
7410                                         break;
7411                                 case PLD_SLIC_STATE_ACTIVE:
7412                                         len += sprintf(buf + len, "ACTIVE");
7413                                         break;
7414                                 case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
7415                                         len += sprintf(buf + len, "OHT");
7416                                         break;
7417                                 case PLD_SLIC_STATE_TIPOPEN:
7418                                         len += sprintf(buf + len, "TIPOPEN");
7419                                         break;
7420                                 case PLD_SLIC_STATE_STANDBY:
7421                                         len += sprintf(buf + len, "STANDBY");
7422                                         break;
7423                                 case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
7424                                         len += sprintf(buf + len, "APR");
7425                                         break;
7426                                 case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
7427                                         len += sprintf(buf + len, "OHTPR");
7428                                         break;
7429                                 default:
7430                                         len += sprintf(buf + len, "%d", SLIC_GetState(j));
7431                                         break;
7432                                 }
7433                         }
7434                         len += sprintf(buf + len, "\nBase Frame %2.2x.%2.2x", j->baseframe.high, j->baseframe.low);
7435                         len += sprintf(buf + len, "\nCID Base Frame %2d", j->cid_base_frame_size);
7436 #ifdef PERFMON_STATS
7437                         len += sprintf(buf + len, "\nTimer Checks %ld", j->timerchecks);
7438                         len += sprintf(buf + len, "\nRX Ready Checks %ld", j->rxreadycheck);
7439                         len += sprintf(buf + len, "\nTX Ready Checks %ld", j->txreadycheck);
7440                         len += sprintf(buf + len, "\nFrames Read %ld", j->framesread);
7441                         len += sprintf(buf + len, "\nFrames Written %ld", j->frameswritten);
7442                         len += sprintf(buf + len, "\nDry Buffer %ld", j->drybuffer);
7443                         len += sprintf(buf + len, "\nRead Waits %ld", j->read_wait);
7444                         len += sprintf(buf + len, "\nWrite Waits %ld", j->write_wait);
7445                         len += sprintf(buf + len, "\nStatus Waits %ld", j->statuswait);
7446                         len += sprintf(buf + len, "\nStatus Wait Fails %ld", j->statuswaitfail);
7447                         len += sprintf(buf + len, "\nPControl Waits %ld", j->pcontrolwait);
7448                         len += sprintf(buf + len, "\nPControl Wait Fails %ld", j->pcontrolwaitfail);
7449                         len += sprintf(buf + len, "\nIs Control Ready Checks %ld", j->iscontrolready);
7450                         len += sprintf(buf + len, "\nIs Control Ready Check failures %ld", j->iscontrolreadyfail);
7451  
7452 #endif
7453                         len += sprintf(buf + len, "\n");
7454                 }
7455         }
7456         return len;
7457 }
7458
7459 static int ixj_read_proc(char *page, char **start, off_t off,
7460                               int count, int *eof, void *data)
7461 {
7462         int len = ixj_get_status_proc(page);
7463         if (len <= off+count) *eof = 1;
7464         *start = page + off;
7465         len -= off;
7466         if (len>count) len = count;
7467         if (len<0) len = 0;
7468         return len;
7469 }
7470
7471
7472 static void cleanup(void)
7473 {
7474         int cnt;
7475         IXJ *j;
7476
7477         for (cnt = 0; cnt < IXJMAX; cnt++) {
7478                 j = get_ixj(cnt);
7479                 if(j != NULL && j->DSPbase) {
7480                         if (ixjdebug & 0x0002)
7481                                 printk(KERN_INFO "IXJ: Deleting timer for /dev/phone%d\n", cnt);
7482                         del_timer(&j->timer);
7483                         if (j->cardtype == QTI_LINEJACK) {
7484                                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
7485
7486                                 outb_p(j->pld_scrw.byte, j->XILINXbase);
7487                                 j->pld_slicw.bits.rly1 = 0;
7488                                 j->pld_slicw.bits.rly2 = 0;
7489                                 j->pld_slicw.bits.rly3 = 0;
7490                                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
7491                                 LED_SetState(0x0, j);
7492                                 if (ixjdebug & 0x0002)
7493                                         printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7494                                 release_region(j->XILINXbase, 8);
7495                         } else if (j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
7496                                 if (ixjdebug & 0x0002)
7497                                         printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7498                                 release_region(j->XILINXbase, 4);
7499                         }
7500                         if (j->read_buffer)
7501                                 kfree(j->read_buffer);
7502                         if (j->write_buffer)
7503                                 kfree(j->write_buffer);
7504                         if (j->dev)
7505                                 pnp_device_detach(j->dev);
7506                         if (ixjdebug & 0x0002)
7507                                 printk(KERN_INFO "IXJ: Unregistering /dev/phone%d from LTAPI\n", cnt);
7508                         phone_unregister_device(&j->p);
7509                         if (ixjdebug & 0x0002)
7510                                 printk(KERN_INFO "IXJ: Releasing DSP address for /dev/phone%d\n", cnt);
7511                         release_region(j->DSPbase, 16);
7512 #ifdef IXJ_DYN_ALLOC
7513                         if (ixjdebug & 0x0002)
7514                                 printk(KERN_INFO "IXJ: Freeing memory for /dev/phone%d\n", cnt);
7515                         kfree(j);
7516                         ixj[cnt] = NULL;
7517 #endif
7518                 }
7519         }
7520         if (ixjdebug & 0x0002)
7521                 printk(KERN_INFO "IXJ: Removing /proc/ixj\n");
7522         remove_proc_entry ("ixj", NULL);
7523 }
7524
7525 /* Typedefs */
7526 typedef struct {
7527         BYTE length;
7528         DWORD bits;
7529 } DATABLOCK;
7530
7531 static void PCIEE_WriteBit(WORD wEEPROMAddress, BYTE lastLCC, BYTE byData)
7532 {
7533         lastLCC = lastLCC & 0xfb;
7534         lastLCC = lastLCC | (byData ? 4 : 0);
7535         outb(lastLCC, wEEPROMAddress);  /*set data out bit as appropriate */
7536
7537         mdelay(1);
7538         lastLCC = lastLCC | 0x01;
7539         outb(lastLCC, wEEPROMAddress);  /*SK rising edge */
7540
7541         byData = byData << 1;
7542         lastLCC = lastLCC & 0xfe;
7543         mdelay(1);
7544         outb(lastLCC, wEEPROMAddress);  /*after delay, SK falling edge */
7545
7546 }
7547
7548 static BYTE PCIEE_ReadBit(WORD wEEPROMAddress, BYTE lastLCC)
7549 {
7550         mdelay(1);
7551         lastLCC = lastLCC | 0x01;
7552         outb(lastLCC, wEEPROMAddress);  /*SK rising edge */
7553
7554         lastLCC = lastLCC & 0xfe;
7555         mdelay(1);
7556         outb(lastLCC, wEEPROMAddress);  /*after delay, SK falling edge */
7557
7558         return ((inb(wEEPROMAddress) >> 3) & 1);
7559 }
7560
7561 static BOOL PCIEE_ReadWord(WORD wAddress, WORD wLoc, WORD * pwResult)
7562 {
7563         BYTE lastLCC;
7564         WORD wEEPROMAddress = wAddress + 3;
7565         DWORD i;
7566         BYTE byResult;
7567         *pwResult = 0;
7568         lastLCC = inb(wEEPROMAddress);
7569         lastLCC = lastLCC | 0x02;
7570         lastLCC = lastLCC & 0xfe;
7571         outb(lastLCC, wEEPROMAddress);  /* CS hi, SK lo */
7572
7573         mdelay(1);              /* delay */
7574
7575         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7576         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7577         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 0);
7578         for (i = 0; i < 8; i++) {
7579                 PCIEE_WriteBit(wEEPROMAddress, lastLCC, wLoc & 0x80 ? 1 : 0);
7580                 wLoc <<= 1;
7581         }
7582
7583         for (i = 0; i < 16; i++) {
7584                 byResult = PCIEE_ReadBit(wEEPROMAddress, lastLCC);
7585                 *pwResult = (*pwResult << 1) | byResult;
7586         }
7587
7588         mdelay(1);              /* another delay */
7589
7590         lastLCC = lastLCC & 0xfd;
7591         outb(lastLCC, wEEPROMAddress);  /* negate CS */
7592
7593         return 0;
7594 }
7595
7596 static DWORD PCIEE_GetSerialNumber(WORD wAddress)
7597 {
7598         WORD wLo, wHi;
7599         if (PCIEE_ReadWord(wAddress, 62, &wLo))
7600                 return 0;
7601         if (PCIEE_ReadWord(wAddress, 63, &wHi))
7602                 return 0;
7603         return (((DWORD) wHi << 16) | wLo);
7604 }
7605
7606 static int dspio[IXJMAX + 1] =
7607 {
7608         0,
7609 };
7610 static int xio[IXJMAX + 1] =
7611 {
7612         0,
7613 };
7614
7615 module_param_array(dspio, int, NULL, 0);
7616 module_param_array(xio, int, NULL, 0);
7617 MODULE_DESCRIPTION("Quicknet VoIP Telephony card module - www.quicknet.net");
7618 MODULE_AUTHOR("Ed Okerson <eokerson@quicknet.net>");
7619 MODULE_LICENSE("GPL");
7620
7621 static void __exit ixj_exit(void)
7622 {
7623         cleanup();
7624 }
7625
7626 static IXJ *new_ixj(unsigned long port)
7627 {
7628         IXJ *res;
7629         if (!request_region(port, 16, "ixj DSP")) {
7630                 printk(KERN_INFO "ixj: can't get I/O address 0x%lx\n", port);
7631                 return NULL;
7632         }
7633         res = ixj_alloc();
7634         if (!res) {
7635                 release_region(port, 16);
7636                 printk(KERN_INFO "ixj: out of memory\n");
7637                 return NULL;
7638         }
7639         res->DSPbase = port;
7640         return res;
7641 }
7642
7643 static int __init ixj_probe_isapnp(int *cnt)
7644 {               
7645         int probe = 0;
7646         int func = 0x110;
7647         struct pnp_dev *dev = NULL, *old_dev = NULL;
7648
7649         while (1) {
7650                 do {
7651                         IXJ *j;
7652                         int result;
7653
7654                         old_dev = dev;
7655                         dev = pnp_find_dev(NULL, ISAPNP_VENDOR('Q', 'T', 'I'),
7656                                          ISAPNP_FUNCTION(func), old_dev);
7657                         if (!dev || !dev->card)
7658                                 break;
7659                         result = pnp_device_attach(dev);
7660                         if (result < 0) {
7661                                 printk("pnp attach failed %d \n", result);
7662                                 break;
7663                         }
7664                         if (pnp_activate_dev(dev) < 0) {
7665                                 printk("pnp activate failed (out of resources?)\n");
7666                                 pnp_device_detach(dev);
7667                                 return -ENOMEM;
7668                         }
7669
7670                         if (!pnp_port_valid(dev, 0)) {
7671                                 pnp_device_detach(dev);
7672                                 return -ENODEV;
7673                         }
7674
7675                         j = new_ixj(pnp_port_start(dev, 0));
7676                         if (!j)
7677                                 break;
7678
7679                         if (func != 0x110)
7680                                 j->XILINXbase = pnp_port_start(dev, 1); /* get real port */
7681
7682                         switch (func) {
7683                         case (0x110):
7684                                 j->cardtype = QTI_PHONEJACK;
7685                                 break;
7686                         case (0x310):
7687                                 j->cardtype = QTI_LINEJACK;
7688                                 break;
7689                         case (0x410):
7690                                 j->cardtype = QTI_PHONEJACK_LITE;
7691                                 break;
7692                         }
7693                         j->board = *cnt;
7694                         probe = ixj_selfprobe(j);
7695                         if(!probe) {
7696                                 j->serial = dev->card->serial;
7697                                 j->dev = dev;
7698                                 switch (func) {
7699                                 case 0x110:
7700                                         printk(KERN_INFO "ixj: found Internet PhoneJACK at 0x%x\n", j->DSPbase);
7701                                         break;
7702                                 case 0x310:
7703                                         printk(KERN_INFO "ixj: found Internet LineJACK at 0x%x\n", j->DSPbase);
7704                                         break;
7705                                 case 0x410:
7706                                         printk(KERN_INFO "ixj: found Internet PhoneJACK Lite at 0x%x\n", j->DSPbase);
7707                                         break;
7708                                 }
7709                         }
7710                         ++*cnt;
7711                 } while (dev);
7712                 if (func == 0x410)
7713                         break;
7714                 if (func == 0x310)
7715                         func = 0x410;
7716                 if (func == 0x110)
7717                         func = 0x310;
7718                 dev = NULL;
7719         }
7720         return probe;
7721 }
7722                         
7723 static int __init ixj_probe_isa(int *cnt)
7724 {
7725         int i, probe;
7726
7727         /* Use passed parameters for older kernels without PnP */
7728         for (i = 0; i < IXJMAX; i++) {
7729                 if (dspio[i]) {
7730                         IXJ *j = new_ixj(dspio[i]);
7731
7732                         if (!j)
7733                                 break;
7734
7735                         j->XILINXbase = xio[i];
7736                         j->cardtype = 0;
7737
7738                         j->board = *cnt;
7739                         probe = ixj_selfprobe(j);
7740                         j->dev = NULL;
7741                         ++*cnt;
7742                 }
7743         }
7744         return 0;
7745 }
7746
7747 static int __init ixj_probe_pci(int *cnt)
7748 {
7749         struct pci_dev *pci = NULL;   
7750         int i, probe = 0;
7751         IXJ *j = NULL;
7752
7753         for (i = 0; i < IXJMAX - *cnt; i++) {
7754                 pci = pci_find_device(0x15E2, 0x0500, pci);
7755                 if (!pci)
7756                         break;
7757
7758                 if (pci_enable_device(pci))
7759                         break;
7760                 j = new_ixj(pci_resource_start(pci, 0));
7761                 if (!j)
7762                         break;
7763
7764                 j->serial = (PCIEE_GetSerialNumber)pci_resource_start(pci, 2);
7765                 j->XILINXbase = j->DSPbase + 0x10;
7766                 j->cardtype = QTI_PHONEJACK_PCI;
7767                 j->board = *cnt;
7768                 probe = ixj_selfprobe(j);
7769                 if (!probe)
7770                         printk(KERN_INFO "ixj: found Internet PhoneJACK PCI at 0x%x\n", j->DSPbase);
7771                 ++*cnt;
7772         }
7773         return probe;
7774 }
7775
7776 static int __init ixj_init(void)
7777 {
7778         int cnt = 0;
7779         int probe = 0;   
7780
7781         cnt = 0;
7782
7783         /* These might be no-ops, see above. */
7784         if ((probe = ixj_probe_isapnp(&cnt)) < 0) {
7785                 return probe;
7786         }
7787         if ((probe = ixj_probe_isa(&cnt)) < 0) {
7788                 return probe;
7789         }
7790         if ((probe = ixj_probe_pci(&cnt)) < 0) {
7791                 return probe;
7792         }
7793         printk("%s\n", ixj_c_rcsid);
7794         create_proc_read_entry ("ixj", 0, NULL, ixj_read_proc, NULL);
7795         return probe;
7796 }
7797
7798 module_init(ixj_init);
7799 module_exit(ixj_exit);
7800
7801 static void DAA_Coeff_US(IXJ *j)
7802 {
7803         int i;
7804
7805         j->daa_country = DAA_US;
7806         /*----------------------------------------------- */
7807         /* CAO */
7808         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
7809                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
7810         }
7811
7812 /* Bytes for IM-filter part 1 (04): 0E,32,E2,2F,C2,5A,C0,00 */
7813         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x03;
7814         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0x4B;
7815         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x5D;
7816         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xCD;
7817         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x24;
7818         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xC5;
7819         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
7820         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
7821 /* Bytes for IM-filter part 2 (05): 72,85,00,0E,2B,3A,D0,08 */
7822         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x71;
7823         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x1A;
7824         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
7825         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
7826         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xB5;
7827         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
7828         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
7829         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
7830 /* Bytes for FRX-filter       (08): 03,8F,48,F2,8F,48,70,08 */
7831         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x05;
7832         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xA3;
7833         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x72;
7834         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
7835         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x3F;
7836         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x3B;
7837         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
7838         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
7839 /* Bytes for FRR-filter       (07): 04,8F,38,7F,9B,EA,B0,08 */
7840         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x05;
7841         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
7842         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
7843         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x3E;
7844         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x32;
7845         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xDA;
7846         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
7847         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
7848 /* Bytes for AX-filter        (0A): 16,55,DD,CA */
7849         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x41;
7850         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
7851         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
7852         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
7853 /* Bytes for AR-filter        (09): 52,D3,11,42 */
7854         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
7855         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
7856         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
7857         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
7858 /* Bytes for TH-filter part 1 (00): 00,42,48,81,B3,80,00,98 */
7859         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
7860         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
7861         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
7862         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
7863         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA5;
7864         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
7865         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
7866         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
7867 /* Bytes for TH-filter part 2 (01): 02,F2,33,A0,68,AB,8A,AD */
7868         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
7869         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xA2;
7870         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2B;
7871         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
7872         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
7873         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAB;
7874         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
7875         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xCC;
7876 /* Bytes for TH-filter part 3 (02): 00,88,DA,54,A4,BA,2D,BB */
7877         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
7878         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
7879         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xD2;
7880         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x24;
7881         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBA;
7882         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xA9;
7883         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x3B;
7884         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xA6;
7885 /* ;  (10K, 0.68uF) */
7886         /*  */
7887         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
7888         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
7889         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
7890         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
7891         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
7892         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
7893         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
7894         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
7895         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
7896         /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */
7897         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
7898         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
7899         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
7900         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
7901         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
7902         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
7903         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
7904         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
7905
7906         /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
7907         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
7908         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
7909         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
7910         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
7911
7912         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
7913 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1C; */
7914 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0xB3; */
7915 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0xAB; */
7916 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0xAB; */
7917 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x54; */
7918 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x2D; */
7919 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0x62; */
7920 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x2D; */
7921         /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */ 
7922 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x2D; */
7923 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x62; */
7924 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6; */
7925 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBB; */
7926 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x2A; */
7927 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7D; */
7928 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A; */
7929 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD4; */
7930 /* */
7931         /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
7932 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA; */
7933 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x05; */
7934 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F; */
7935 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E; */
7936
7937         /* Caller ID 1st Tone           (0E):CA,0E,CA,09,99,99,99,99 */
7938         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
7939         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
7940         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
7941         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
7942         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
7943         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
7944         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
7945         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
7946 /* Caller ID 2nd Tone           (0F):FD,B5,BA,07,DA,00,00,00 */
7947         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
7948         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
7949         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
7950         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
7951         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
7952         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
7953         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
7954         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
7955 /*  */
7956         /* ;CR Registers */
7957         /* Config. Reg. 0 (filters)       (cr0):FE ; CLK gen. by crystal */
7958         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
7959 /* Config. Reg. 1 (dialing)       (cr1):05 */
7960         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
7961 /* Config. Reg. 2 (caller ID)     (cr2):04 */
7962         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
7963 /* Config. Reg. 3 (testloops)     (cr3):03 ; SEL Bit==0, HP-disabled */
7964         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
7965 /* Config. Reg. 4 (analog gain)   (cr4):02 */
7966         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
7967         /* Config. Reg. 5 (Version)       (cr5):02 */
7968         /* Config. Reg. 6 (Reserved)      (cr6):00 */
7969         /* Config. Reg. 7 (Reserved)      (cr7):00 */
7970         /*  */
7971         /* ;xr Registers */
7972         /* Ext. Reg. 0 (Interrupt Reg.)   (xr0):02 */
7973
7974         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
7975         /* Ext. Reg. 1 (Interrupt enable) (xr1):3C Cadence, RING, Caller ID, VDD_OK */
7976
7977         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x3C;
7978 /* Ext. Reg. 2 (Cadence Time Out) (xr2):7D */
7979         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
7980 /* Ext. Reg. 3 (DC Char)          (xr3):32 ; B-Filter Off == 1 */
7981         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x3B;         /*0x32; */
7982         /* Ext. Reg. 4 (Cadence)          (xr4):00 */
7983
7984         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
7985 /* Ext. Reg. 5 (Ring timer)       (xr5):22 */
7986         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
7987 /* Ext. Reg. 6 (Power State)      (xr6):00 */
7988         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
7989 /* Ext. Reg. 7 (Vdd)              (xr7):40 */
7990         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
7991         /*  */
7992         /* DTMF Tone 1                     (0B): 11,B3,5A,2C ;   697 Hz   */
7993         /*                                       12,33,5A,C3 ;  770 Hz   */
7994         /*                                       13,3C,5B,32 ;  852 Hz   */
7995         /*                                       1D,1B,5C,CC ;  941 Hz   */
7996
7997         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
7998         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
7999         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8000         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8001 /* DTMF Tone 2                     (0C): 32,32,52,B3 ;  1209 Hz   */
8002         /*                                       EC,1D,52,22 ;  1336 Hz   */
8003         /*                                       AA,AC,51,D2 ;  1477 Hz   */
8004         /*                                       9B,3B,51,25 ;  1633 Hz   */
8005         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8006         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8007         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8008         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8009 }
8010
8011 static void DAA_Coeff_UK(IXJ *j)
8012 {
8013         int i;
8014
8015         j->daa_country = DAA_UK;
8016         /*----------------------------------------------- */
8017         /* CAO */
8018         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8019                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8020         }
8021
8022 /*  Bytes for IM-filter part 1 (04): 00,C2,BB,A8,CB,81,A0,00 */
8023         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8024         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xC2;
8025         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
8026         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xA8;
8027         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xCB;
8028         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
8029         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8030         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8031 /* Bytes for IM-filter part 2 (05): 40,00,00,0A,A4,33,E0,08 */
8032         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x40;
8033         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x00;
8034         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8035         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
8036         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xA4;
8037         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8038         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8039         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8040 /* Bytes for FRX-filter       (08): 07,9B,ED,24,B2,A2,A0,08 */
8041         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8042         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9B;
8043         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xED;
8044         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x24;
8045         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0xB2;
8046         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0xA2;
8047         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xA0;
8048         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8049 /* Bytes for FRR-filter       (07): 0F,92,F2,B2,87,D2,30,08 */
8050         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8051         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x92;
8052         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF2;
8053         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0xB2;
8054         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8055         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xD2;
8056         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x30;
8057         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8058 /* Bytes for AX-filter        (0A): 1B,A5,DD,CA */
8059         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x1B;
8060         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xA5;
8061         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8062         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8063 /* Bytes for AR-filter        (09): E2,27,10,D6 */
8064         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8065         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x27;
8066         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8067         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8068 /* Bytes for TH-filter part 1 (00): 80,2D,38,8B,D0,00,00,98 */
8069         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8070         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x2D;
8071         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x38;
8072         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x8B;
8073         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xD0;
8074         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x00;
8075         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8076         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8077 /* Bytes for TH-filter part 2 (01): 02,5A,53,F0,0B,5F,84,D4 */
8078         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8079         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x5A;
8080         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x53;
8081         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xF0;
8082         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x0B;
8083         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5F;
8084         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x84;
8085         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xD4;
8086 /* Bytes for TH-filter part 3 (02): 00,88,6A,A4,8F,52,F5,32 */
8087         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8088         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8089         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x6A;
8090         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA4;
8091         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x8F;
8092         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x52;
8093         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xF5;
8094         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x32;
8095 /* ; idle */
8096         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8097         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8098         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8099         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8100         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8101         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8102         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8103         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8104         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8105 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8106         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8107         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8108         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8109         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8110         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8111         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8112         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8113         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8114 /* Levelmetering Ringing           (0D):AA,35,0F,8E     ; 25Hz 30V less possible? */
8115         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8116         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8117         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8118         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8119 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8120         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8121         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8122         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8123         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8124         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8125         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8126         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8127         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8128 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8129         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8130         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8131         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8132         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8133         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8134         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8135         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8136         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8137 /* ;CR Registers */
8138         /* Config. Reg. 0 (filters)        (cr0):FF */
8139         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8140 /* Config. Reg. 1 (dialing)        (cr1):05 */
8141         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8142 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8143         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8144 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8145         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8146 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8147         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8148         /* Config. Reg. 5 (Version)        (cr5):02 */
8149         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8150         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8151         /* ;xr Registers */
8152         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8153
8154         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8155         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8156
8157         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8158         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8159
8160         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8161 /* Ext. Reg. 3 (DC Char)           (xr3):36        ;  */
8162         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8163 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8164         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8165 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8166         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8167 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8168         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8169 /* Ext. Reg. 7 (Vdd)               (xr7):46 */
8170         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;         /* 0x46 ??? Should it be 0x00? */
8171         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8172         /*                                       12,33,5A,C3    ;  770 Hz   */
8173         /*                                       13,3C,5B,32    ;  852 Hz   */
8174         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8175
8176         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8177         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8178         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8179         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8180 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8181         /*                                       EC,1D,52,22    ;  1336 Hz   */
8182         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8183         /*                                       9B,3B,51,25    ;  1633 Hz   */
8184         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8185         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8186         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8187         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8188 }
8189
8190
8191 static void DAA_Coeff_France(IXJ *j)
8192 {
8193         int i;
8194
8195         j->daa_country = DAA_FRANCE;
8196         /*----------------------------------------------- */
8197         /* CAO */
8198         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8199                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8200         }
8201
8202 /* Bytes for IM-filter part 1 (04): 02,A2,43,2C,22,AF,A0,00 */
8203         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x02;
8204         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA2;
8205         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x43;
8206         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2C;
8207         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x22;
8208         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xAF;
8209         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8210         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8211 /* Bytes for IM-filter part 2 (05): 67,CE,00,0C,22,33,E0,08 */
8212         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x67;
8213         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xCE;
8214         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8215         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x2C;
8216         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x22;
8217         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8218         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8219         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8220 /* Bytes for FRX-filter       (08): 07,9A,28,F6,23,4A,B0,08 */
8221         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8222         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9A;
8223         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x28;
8224         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0xF6;
8225         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x23;
8226         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x4A;
8227         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xB0;
8228         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8229 /* Bytes for FRR-filter       (07): 03,8F,F9,2F,9E,FA,20,08 */
8230         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8231         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8232         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
8233         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8234         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9E;
8235         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xFA;
8236         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8237         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8238 /* Bytes for AX-filter        (0A): 16,B5,DD,CA */
8239         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x16;
8240         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
8241         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8242         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8243 /* Bytes for AR-filter        (09): 52,C7,10,D6 */
8244         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8245         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
8246         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8247         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8248 /* Bytes for TH-filter part 1 (00): 00,42,48,81,A6,80,00,98 */
8249         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8250         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8251         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8252         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8253         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA6;
8254         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8255         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8256         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8257 /* Bytes for TH-filter part 2 (01): 02,AC,2A,30,78,AC,8A,2C */
8258         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8259         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAC;
8260         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8261         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x30;
8262         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x78;
8263         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAC;
8264         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x8A;
8265         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x2C;
8266 /* Bytes for TH-filter part 3 (02): 00,88,DA,A5,22,BA,2C,45 */
8267         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8268         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8269         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8270         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA5;
8271         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x22;
8272         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xBA;
8273         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x2C;
8274         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x45;
8275 /* ; idle */
8276         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8277         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8278         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8279         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8280         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8281         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8282         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8283         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8284         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8285 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8286         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8287         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8288         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8289         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8290         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8291         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8292         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8293         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8294 /* Levelmetering Ringing           (0D):32,45,B5,84     ; 50Hz 20V */
8295         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8296         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8297         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8298         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8299 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8300         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8301         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8302         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8303         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8304         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8305         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8306         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8307         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8308 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8309         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8310         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8311         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8312         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8313         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8314         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8315         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8316         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8317 /* ;CR Registers */
8318         /* Config. Reg. 0 (filters)        (cr0):FF */
8319         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8320 /* Config. Reg. 1 (dialing)        (cr1):05 */
8321         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8322 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8323         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8324 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8325         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8326 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8327         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8328         /* Config. Reg. 5 (Version)        (cr5):02 */
8329         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8330         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8331         /* ;xr Registers */
8332         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8333
8334         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8335         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8336
8337         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8338         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8339
8340         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8341 /* Ext. Reg. 3 (DC Char)           (xr3):36        ;  */
8342         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8343 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8344         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8345 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8346         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8347 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8348         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8349 /* Ext. Reg. 7 (Vdd)               (xr7):46 */
8350         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;         /* 0x46 ??? Should it be 0x00? */
8351         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8352         /*                                       12,33,5A,C3    ;  770 Hz   */
8353         /*                                       13,3C,5B,32    ;  852 Hz   */
8354         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8355
8356         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8357         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8358         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8359         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8360 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8361         /*                                       EC,1D,52,22    ;  1336 Hz   */
8362         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8363         /*                                       9B,3B,51,25    ;  1633 Hz   */
8364         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8365         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8366         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8367         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8368 }
8369
8370
8371 static void DAA_Coeff_Germany(IXJ *j)
8372 {
8373         int i;
8374
8375         j->daa_country = DAA_GERMANY;
8376         /*----------------------------------------------- */
8377         /* CAO */
8378         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8379                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8380         }
8381
8382 /* Bytes for IM-filter part 1 (04): 00,CE,BB,B8,D2,81,B0,00 */
8383         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8384         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xCE;
8385         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
8386         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xB8;
8387         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xD2;
8388         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
8389         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xB0;
8390         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8391 /* Bytes for IM-filter part 2 (05): 45,8F,00,0C,D2,3A,D0,08 */
8392         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x45;
8393         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x8F;
8394         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8395         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0C;
8396         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xD2;
8397         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x3A;
8398         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xD0;
8399         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8400 /* Bytes for FRX-filter       (08): 07,AA,E2,34,24,89,20,08 */
8401         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8402         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xAA;
8403         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8404         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8405         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x24;
8406         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x89;
8407         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x20;
8408         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8409 /* Bytes for FRR-filter       (07): 02,87,FA,37,9A,CA,B0,08 */
8410         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x02;
8411         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
8412         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xFA;
8413         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x37;
8414         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9A;
8415         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCA;
8416         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
8417         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8418 /* Bytes for AX-filter        (0A): 72,D5,DD,CA */
8419         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x72;
8420         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xD5;
8421         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8422         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8423 /* Bytes for AR-filter        (09): 72,42,13,4B */
8424         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x72;
8425         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x42;
8426         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x13;
8427         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0x4B;
8428 /* Bytes for TH-filter part 1 (00): 80,52,48,81,AD,80,00,98 */
8429         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8430         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8431         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8432         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8433         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAD;
8434         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8435         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8436         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8437 /* Bytes for TH-filter part 2 (01): 02,42,5A,20,E8,1A,81,27 */
8438         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8439         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x42;
8440         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x5A;
8441         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8442         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
8443         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x1A;
8444         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
8445         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x27;
8446 /* Bytes for TH-filter part 3 (02): 00,88,63,26,BD,4B,A3,C2 */
8447         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8448         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8449         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x63;
8450         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x26;
8451         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBD;
8452         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x4B;
8453         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xA3;
8454         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xC2;
8455 /* ;  (10K, 0.68uF) */
8456         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
8457         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8458         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3B;
8459         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x9B;
8460         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0xBA;
8461         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0xD4;
8462         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x1C;
8463         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xB3;
8464         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8465 /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */
8466         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x13;
8467         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x42;
8468         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8469         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8470         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0xD4;
8471         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x73;
8472         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0xCA;
8473         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8474 /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
8475         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xB2;
8476         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8477         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8478         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8479 /* Caller ID 1st Tone           (0E):CA,0E,CA,09,99,99,99,99 */
8480         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8481         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8482         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8483         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8484         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8485         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8486         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8487         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8488 /* Caller ID 2nd Tone           (0F):FD,B5,BA,07,DA,00,00,00 */
8489         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8490         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8491         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8492         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8493         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8494         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8495         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8496         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8497 /* ;CR Registers */
8498         /* Config. Reg. 0 (filters)        (cr0):FF ; all Filters enabled, CLK from ext. source */
8499         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8500 /* Config. Reg. 1 (dialing)        (cr1):05 ; Manual Ring, Ring metering enabled */
8501         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8502 /* Config. Reg. 2 (caller ID)      (cr2):04 ; Analog Gain 0dB, FSC internal */
8503         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8504 /* Config. Reg. 3 (testloops)      (cr3):00 ; SEL Bit==0, HP-enabled */
8505         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8506 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8507         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8508         /* Config. Reg. 5 (Version)        (cr5):02 */
8509         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8510         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8511         /* ;xr Registers */
8512         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8513
8514         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8515         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C ; Ring, CID, VDDOK Interrupts enabled */
8516
8517         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8518         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8519
8520         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8521 /* Ext. Reg. 3 (DC Char)           (xr3):32 ; B-Filter Off==1, U0=3.5V, R=200Ohm */
8522         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x32;
8523 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8524         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8525 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8526         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8527 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8528         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8529 /* Ext. Reg. 7 (Vdd)               (xr7):40 ; VDD=4.25 V */
8530         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8531         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8532         /*                                       12,33,5A,C3    ;  770 Hz   */
8533         /*                                       13,3C,5B,32    ;  852 Hz   */
8534         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8535
8536         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8537         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8538         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8539         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8540 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8541         /*                                       EC,1D,52,22    ;  1336 Hz   */
8542         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8543         /*                                       9B,3B,51,25    ;  1633 Hz   */
8544         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8545         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8546         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8547         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8548 }
8549
8550
8551 static void DAA_Coeff_Australia(IXJ *j)
8552 {
8553         int i;
8554
8555         j->daa_country = DAA_AUSTRALIA;
8556         /*----------------------------------------------- */
8557         /* CAO */
8558         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8559                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8560         }
8561
8562 /* Bytes for IM-filter part 1 (04): 00,A3,AA,28,B3,82,D0,00 */
8563         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8564         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA3;
8565         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xAA;
8566         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x28;
8567         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xB3;
8568         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x82;
8569         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xD0;
8570         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8571 /* Bytes for IM-filter part 2 (05): 70,96,00,09,32,6B,C0,08 */
8572         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x70;
8573         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x96;
8574         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8575         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x09;
8576         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x32;
8577         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x6B;
8578         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xC0;
8579         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8580 /* Bytes for FRX-filter       (08): 07,96,E2,34,32,9B,30,08 */
8581         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8582         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x96;
8583         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8584         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8585         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x32;
8586         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x9B;
8587         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
8588         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8589 /* Bytes for FRR-filter       (07): 0F,9A,E9,2F,22,CC,A0,08 */
8590         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8591         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x9A;
8592         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xE9;
8593         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8594         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x22;
8595         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCC;
8596         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xA0;
8597         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8598 /* Bytes for AX-filter        (0A): CB,45,DD,CA */
8599         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0xCB;
8600         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0x45;
8601         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8602         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8603 /* Bytes for AR-filter        (09): 1B,67,10,D6 */
8604         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x1B;
8605         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x67;
8606         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8607         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8608 /* Bytes for TH-filter part 1 (00): 80,52,48,81,AF,80,00,98 */
8609         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8610         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8611         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8612         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8613         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAF;
8614         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8615         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8616         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8617 /* Bytes for TH-filter part 2 (01): 02,DB,52,B0,38,01,82,AC */
8618         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8619         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xDB;
8620         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x52;
8621         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
8622         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x38;
8623         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x01;
8624         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x82;
8625         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xAC;
8626 /* Bytes for TH-filter part 3 (02): 00,88,4A,3E,2C,3B,24,46 */
8627         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8628         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8629         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x4A;
8630         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x3E;
8631         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x2C;
8632         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x3B;
8633         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x24;
8634         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x46;
8635 /* ;  idle */
8636         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8637         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8638         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8639         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8640         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8641         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8642         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8643         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8644         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8645 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8646         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8647         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8648         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8649         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8650         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8651         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8652         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8653         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8654 /* Levelmetering Ringing           (0D):32,45,B5,84   ; 50Hz 20V */
8655         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8656         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8657         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8658         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8659 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8660         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8661         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8662         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8663         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8664         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8665         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8666         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8667         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8668 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8669         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8670         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8671         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8672         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8673         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8674         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8675         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8676         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8677 /* ;CR Registers */
8678         /* Config. Reg. 0 (filters)        (cr0):FF */
8679         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8680 /* Config. Reg. 1 (dialing)        (cr1):05 */
8681         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8682 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8683         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8684 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8685         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8686 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8687         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8688         /* Config. Reg. 5 (Version)        (cr5):02 */
8689         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8690         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8691         /* ;xr Registers */
8692         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8693
8694         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8695         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8696
8697         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8698         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8699
8700         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8701 /* Ext. Reg. 3 (DC Char)           (xr3):2B      ;  */
8702         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x2B;
8703 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8704         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8705 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8706         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8707 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8708         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8709 /* Ext. Reg. 7 (Vdd)               (xr7):40 */
8710         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8711
8712         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;  697 Hz   */
8713         /*                                       12,33,5A,C3    ;  770 Hz   */
8714         /*                                       13,3C,5B,32    ;  852 Hz   */
8715         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8716         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8717         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8718         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8719         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8720
8721         /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8722         /*                                       EC,1D,52,22    ;  1336 Hz   */
8723         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8724         /*                                       9B,3B,51,25    ;  1633 Hz   */
8725         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8726         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8727         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8728         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8729 }
8730
8731 static void DAA_Coeff_Japan(IXJ *j)
8732 {
8733         int i;
8734
8735         j->daa_country = DAA_JAPAN;
8736         /*----------------------------------------------- */
8737         /* CAO */
8738         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8739                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8740         }
8741
8742 /* Bytes for IM-filter part 1 (04): 06,BD,E2,2D,BA,F9,A0,00 */
8743         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x06;
8744         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xBD;
8745         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xE2;
8746         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2D;
8747         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xBA;
8748         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xF9;
8749         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8750         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8751 /* Bytes for IM-filter part 2 (05): 6F,F7,00,0E,34,33,E0,08 */
8752         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x6F;
8753         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xF7;
8754         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8755         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0E;
8756         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x34;
8757         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8758         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8759         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8760 /* Bytes for FRX-filter       (08): 02,8F,68,77,9C,58,F0,08 */
8761         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x02;
8762         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x8F;
8763         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x68;
8764         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x77;
8765         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x9C;
8766         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x58;
8767         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xF0;
8768         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8769 /* Bytes for FRR-filter       (07): 03,8F,38,73,87,EA,20,08 */
8770         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8771         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8772         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0x38;
8773         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x73;
8774         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8775         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xEA;
8776         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8777         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8778 /* Bytes for AX-filter        (0A): 51,C5,DD,CA */
8779         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x51;
8780         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xC5;
8781         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8782         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8783 /* Bytes for AR-filter        (09): 25,A7,10,D6 */
8784         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
8785         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xA7;
8786         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8787         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8788 /* Bytes for TH-filter part 1 (00): 00,42,48,81,AE,80,00,98 */
8789         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8790         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8791         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8792         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8793         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAE;
8794         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8795         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8796         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8797 /* Bytes for TH-filter part 2 (01): 02,AB,2A,20,99,5B,89,28 */
8798         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8799         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAB;
8800         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8801         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8802         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x99;
8803         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5B;
8804         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x89;
8805         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x28;
8806 /* Bytes for TH-filter part 3 (02): 00,88,DA,25,34,C5,4C,BA */
8807         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8808         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8809         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8810         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x25;
8811         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x34;
8812         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xC5;
8813         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x4C;
8814         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xBA;
8815 /* ;  idle */
8816         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8817         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8818         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8819         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8820         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8821         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8822         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8823         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8824         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8825 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8826         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8827         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8828         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8829         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8830         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8831         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8832         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8833         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8834 /* Levelmetering Ringing           (0D):AA,35,0F,8E    ; 25Hz 30V ????????? */
8835         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8836         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8837         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8838         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8839 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8840         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8841         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8842         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8843         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8844         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8845         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8846         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8847         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8848 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8849         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8850         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8851         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8852         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8853         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8854         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8855         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8856         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8857 /* ;CR Registers */
8858         /* Config. Reg. 0 (filters)        (cr0):FF */
8859         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8860 /* Config. Reg. 1 (dialing)        (cr1):05 */
8861         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8862 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8863         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8864 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8865         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8866 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8867         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8868         /* Config. Reg. 5 (Version)        (cr5):02 */
8869         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8870         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8871         /* ;xr Registers */
8872         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8873
8874         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8875         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8876
8877         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8878         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8879
8880         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8881 /* Ext. Reg. 3 (DC Char)           (xr3):22        ;  */
8882         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x22;
8883 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8884         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8885 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8886         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8887 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8888         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8889 /* Ext. Reg. 7 (Vdd)               (xr7):40 */
8890         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8891         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8892         /*                                       12,33,5A,C3    ;  770 Hz   */
8893         /*                                       13,3C,5B,32    ;  852 Hz   */
8894         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8895
8896         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8897         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8898         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8899         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8900 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8901         /*                                       EC,1D,52,22    ;  1336 Hz   */
8902         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8903         /*                                       9B,3B,51,25    ;  1633 Hz   */
8904         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8905         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8906         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8907         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8908 }
8909
8910 static s16 tone_table[][19] =
8911 {
8912         {                       /* f20_50[] 11 */
8913                 32538,          /* A1 = 1.985962 */
8914                  -32325,        /* A2 = -0.986511 */
8915                  -343,          /* B2 = -0.010493 */
8916                  0,             /* B1 = 0 */
8917                  343,           /* B0 = 0.010493 */
8918                  32619,         /* A1 = 1.990906 */
8919                  -32520,        /* A2 = -0.992462 */
8920                  19179,         /* B2 = 0.585327 */
8921                  -19178,        /* B1 = -1.170593 */
8922                  19179,         /* B0 = 0.585327 */
8923                  32723,         /* A1 = 1.997314 */
8924                  -32686,        /* A2 = -0.997528 */
8925                  9973,          /* B2 = 0.304352 */
8926                  -9955,         /* B1 = -0.607605 */
8927                  9973,          /* B0 = 0.304352 */
8928                  7,             /* Internal filter scaling */
8929                  159,           /* Minimum in-band energy threshold */
8930                  21,            /* 21/32 in-band to broad-band ratio */
8931                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8932         },
8933         {                       /* f133_200[] 12 */
8934                 32072,          /* A1 = 1.95752 */
8935                  -31896,        /* A2 = -0.973419 */
8936                  -435,          /* B2 = -0.013294 */
8937                  0,             /* B1 = 0 */
8938                  435,           /* B0 = 0.013294 */
8939                  32188,         /* A1 = 1.9646 */
8940                  -32400,        /* A2 = -0.98877 */
8941                  15139,         /* B2 = 0.462036 */
8942                  -14882,        /* B1 = -0.908356 */
8943                  15139,         /* B0 = 0.462036 */
8944                  32473,         /* A1 = 1.981995 */
8945                  -32524,        /* A2 = -0.992584 */
8946                  23200,         /* B2 = 0.708008 */
8947                  -23113,        /* B1 = -1.410706 */
8948                  23200,         /* B0 = 0.708008 */
8949                  7,             /* Internal filter scaling */
8950                  159,           /* Minimum in-band energy threshold */
8951                  21,            /* 21/32 in-band to broad-band ratio */
8952                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8953         },
8954         {                       /* f300 13 */
8955                 31769,          /* A1 = -1.939026 */
8956                  -32584,        /* A2 = 0.994385 */
8957                  -475,          /* B2 = -0.014522 */
8958                  0,             /* B1 = 0.000000 */
8959                  475,           /* B0 = 0.014522 */
8960                  31789,         /* A1 = -1.940247 */
8961                  -32679,        /* A2 = 0.997284 */
8962                  17280,         /* B2 = 0.527344 */
8963                  -16865,        /* B1 = -1.029358 */
8964                  17280,         /* B0 = 0.527344 */
8965                  31841,         /* A1 = -1.943481 */
8966                  -32681,        /* A2 = 0.997345 */
8967                  543,           /* B2 = 0.016579 */
8968                  -525,          /* B1 = -0.032097 */
8969                  543,           /* B0 = 0.016579 */
8970                  5,             /* Internal filter scaling */
8971                  159,           /* Minimum in-band energy threshold */
8972                  21,            /* 21/32 in-band to broad-band ratio */
8973                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8974         },
8975         {                       /* f300_420[] 14 */
8976                 30750,          /* A1 = 1.876892 */
8977                  -31212,        /* A2 = -0.952515 */
8978                  -804,          /* B2 = -0.024541 */
8979                  0,             /* B1 = 0 */
8980                  804,           /* B0 = 0.024541 */
8981                  30686,         /* A1 = 1.872925 */
8982                  -32145,        /* A2 = -0.980988 */
8983                  14747,         /* B2 = 0.450043 */
8984                  -13703,        /* B1 = -0.836395 */
8985                  14747,         /* B0 = 0.450043 */
8986                  31651,         /* A1 = 1.931824 */
8987                  -32321,        /* A2 = -0.986389 */
8988                  24425,         /* B2 = 0.745422 */
8989                  -23914,        /* B1 = -1.459595 */
8990                  24427,         /* B0 = 0.745483 */
8991                  7,             /* Internal filter scaling */
8992                  159,           /* Minimum in-band energy threshold */
8993                  21,            /* 21/32 in-band to broad-band ratio */
8994                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8995         },
8996         {                       /* f330 15 */
8997                 31613,          /* A1 = -1.929565 */
8998                  -32646,        /* A2 = 0.996277 */
8999                  -185,          /* B2 = -0.005657 */
9000                  0,             /* B1 = 0.000000 */
9001                  185,           /* B0 = 0.005657 */
9002                  31620,         /* A1 = -1.929932 */
9003                  -32713,        /* A2 = 0.998352 */
9004                  19253,         /* B2 = 0.587585 */
9005                  -18566,        /* B1 = -1.133179 */
9006                  19253,         /* B0 = 0.587585 */
9007                  31674,         /* A1 = -1.933228 */
9008                  -32715,        /* A2 = 0.998413 */
9009                  2575,          /* B2 = 0.078590 */
9010                  -2495,         /* B1 = -0.152283 */
9011                  2575,          /* B0 = 0.078590 */
9012                  5,             /* Internal filter scaling */
9013                  159,           /* Minimum in-band energy threshold */
9014                  21,            /* 21/32 in-band to broad-band ratio */
9015                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9016         },
9017         {                       /* f300_425[] 16 */
9018                 30741,          /* A1 = 1.876282 */
9019                  -31475,        /* A2 = -0.960541 */
9020                  -703,          /* B2 = -0.021484 */
9021                  0,             /* B1 = 0 */
9022                  703,           /* B0 = 0.021484 */
9023                  30688,         /* A1 = 1.873047 */
9024                  -32248,        /* A2 = -0.984161 */
9025                  14542,         /* B2 = 0.443787 */
9026                  -13523,        /* B1 = -0.825439 */
9027                  14542,         /* B0 = 0.443817 */
9028                  31494,         /* A1 = 1.922302 */
9029                  -32366,        /* A2 = -0.987762 */
9030                  21577,         /* B2 = 0.658508 */
9031                  -21013,        /* B1 = -1.282532 */
9032                  21577,         /* B0 = 0.658508 */
9033                  7,             /* Internal filter scaling */
9034                  159,           /* Minimum in-band energy threshold */
9035                  21,            /* 21/32 in-band to broad-band ratio */
9036                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9037         },
9038         {                       /* f330_440[] 17 */
9039                 30627,          /* A1 = 1.869324 */
9040                  -31338,        /* A2 = -0.95636 */
9041                  -843,          /* B2 = -0.025749 */
9042                  0,             /* B1 = 0 */
9043                  843,           /* B0 = 0.025749 */
9044                  30550,         /* A1 = 1.864685 */
9045                  -32221,        /* A2 = -0.983337 */
9046                  13594,         /* B2 = 0.414886 */
9047                  -12589,        /* B1 = -0.768402 */
9048                  13594,         /* B0 = 0.414886 */
9049                  31488,         /* A1 = 1.921936 */
9050                  -32358,        /* A2 = -0.987518 */
9051                  24684,         /* B2 = 0.753296 */
9052                  -24029,        /* B1 = -1.466614 */
9053                  24684,         /* B0 = 0.753296 */
9054                  7,             /* Internal filter scaling */
9055                  159,           /* Minimum in-band energy threshold */
9056                  21,            /* 21/32 in-band to broad-band ratio */
9057                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9058         },
9059         {                       /* f340 18 */
9060                 31546,          /* A1 = -1.925476 */
9061                  -32646,        /* A2 = 0.996277 */
9062                  -445,          /* B2 = -0.013588 */
9063                  0,             /* B1 = 0.000000 */
9064                  445,           /* B0 = 0.013588 */
9065                  31551,         /* A1 = -1.925781 */
9066                  -32713,        /* A2 = 0.998352 */
9067                  23884,         /* B2 = 0.728882 */
9068                  -22979,        /* B1 = -1.402527 */
9069                  23884,         /* B0 = 0.728882 */
9070                  31606,         /* A1 = -1.929138 */
9071                  -32715,        /* A2 = 0.998413 */
9072                  863,           /* B2 = 0.026367 */
9073                  -835,          /* B1 = -0.050985 */
9074                  863,           /* B0 = 0.026367 */
9075                  5,             /* Internal filter scaling */
9076                  159,           /* Minimum in-band energy threshold */
9077                  21,            /* 21/32 in-band to broad-band ratio */
9078                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9079         },
9080         {                       /* f350_400[] 19 */
9081                 31006,          /* A1 = 1.892517 */
9082                  -32029,        /* A2 = -0.977448 */
9083                  -461,          /* B2 = -0.014096 */
9084                  0,             /* B1 = 0 */
9085                  461,           /* B0 = 0.014096 */
9086                  30999,         /* A1 = 1.892029 */
9087                  -32487,        /* A2 = -0.991455 */
9088                  11325,         /* B2 = 0.345612 */
9089                  -10682,        /* B1 = -0.651978 */
9090                  11325,         /* B0 = 0.345612 */
9091                  31441,         /* A1 = 1.919067 */
9092                  -32526,        /* A2 = -0.992615 */
9093                  24324,         /* B2 = 0.74231 */
9094                  -23535,        /* B1 = -1.436523 */
9095                  24324,         /* B0 = 0.74231 */
9096                  7,             /* Internal filter scaling */
9097                  159,           /* Minimum in-band energy threshold */
9098                  21,            /* 21/32 in-band to broad-band ratio */
9099                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9100         },
9101         {                       /* f350_440[] */
9102                 30634,          /* A1 = 1.869751 */
9103                  -31533,        /* A2 = -0.962341 */
9104                  -680,          /* B2 = -0.020782 */
9105                  0,             /* B1 = 0 */
9106                  680,           /* B0 = 0.020782 */
9107                  30571,         /* A1 = 1.865906 */
9108                  -32277,        /* A2 = -0.985016 */
9109                  12894,         /* B2 = 0.393524 */
9110                  -11945,        /* B1 = -0.729065 */
9111                  12894,         /* B0 = 0.393524 */
9112                  31367,         /* A1 = 1.91449 */
9113                  -32379,        /* A2 = -0.988129 */
9114                  23820,         /* B2 = 0.726929 */
9115                  -23104,        /* B1 = -1.410217 */
9116                  23820,         /* B0 = 0.726929 */
9117                  7,             /* Internal filter scaling */
9118                  159,           /* Minimum in-band energy threshold */
9119                  21,            /* 21/32 in-band to broad-band ratio */
9120                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9121         },
9122         {                       /* f350_450[] */
9123                 30552,          /* A1 = 1.864807 */
9124                  -31434,        /* A2 = -0.95929 */
9125                  -690,          /* B2 = -0.021066 */
9126                  0,             /* B1 = 0 */
9127                  690,           /* B0 = 0.021066 */
9128                  30472,         /* A1 = 1.859924 */
9129                  -32248,        /* A2 = -0.984161 */
9130                  13385,         /* B2 = 0.408478 */
9131                  -12357,        /* B1 = -0.754242 */
9132                  13385,         /* B0 = 0.408478 */
9133                  31358,         /* A1 = 1.914001 */
9134                  -32366,        /* A2 = -0.987732 */
9135                  26488,         /* B2 = 0.80835 */
9136                  -25692,        /* B1 = -1.568176 */
9137                  26490,         /* B0 = 0.808411 */
9138                  7,             /* Internal filter scaling */
9139                  159,           /* Minimum in-band energy threshold */
9140                  21,            /* 21/32 in-band to broad-band ratio */
9141                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9142         },
9143         {                       /* f360 */
9144                 31397,          /* A1 = -1.916321 */
9145                  -32623,        /* A2 = 0.995605 */
9146                  -117,          /* B2 = -0.003598 */
9147                  0,             /* B1 = 0.000000 */
9148                  117,           /* B0 = 0.003598 */
9149                  31403,         /* A1 = -1.916687 */
9150                  -32700,        /* A2 = 0.997925 */
9151                  3388,          /* B2 = 0.103401 */
9152                  -3240,         /* B1 = -0.197784 */
9153                  3388,          /* B0 = 0.103401 */
9154                  31463,         /* A1 = -1.920410 */
9155                  -32702,        /* A2 = 0.997986 */
9156                  13346,         /* B2 = 0.407288 */
9157                  -12863,        /* B1 = -0.785126 */
9158                  13346,         /* B0 = 0.407288 */
9159                  5,             /* Internal filter scaling */
9160                  159,           /* Minimum in-band energy threshold */
9161                  21,            /* 21/32 in-band to broad-band ratio */
9162                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9163         },
9164         {                       /* f380_420[] */
9165                 30831,          /* A1 = 1.881775 */
9166                  -32064,        /* A2 = -0.978546 */
9167                  -367,          /* B2 = -0.01122 */
9168                  0,             /* B1 = 0 */
9169                  367,           /* B0 = 0.01122 */
9170                  30813,         /* A1 = 1.880737 */
9171                  -32456,        /* A2 = -0.990509 */
9172                  11068,         /* B2 = 0.337769 */
9173                  -10338,        /* B1 = -0.631042 */
9174                  11068,         /* B0 = 0.337769 */
9175                  31214,         /* A1 = 1.905212 */
9176                  -32491,        /* A2 = -0.991577 */
9177                  16374,         /* B2 = 0.499695 */
9178                  -15781,        /* B1 = -0.963196 */
9179                  16374,         /* B0 = 0.499695 */
9180                  7,             /* Internal filter scaling */
9181                  159,           /* Minimum in-band energy threshold */
9182                  21,            /* 21/32 in-band to broad-band ratio */
9183                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9184         },
9185         {                       /* f392 */
9186                 31152,          /* A1 = -1.901428 */
9187                  -32613,        /* A2 = 0.995300 */
9188                  -314,          /* B2 = -0.009605 */
9189                  0,             /* B1 = 0.000000 */
9190                  314,           /* B0 = 0.009605 */
9191                  31156,         /* A1 = -1.901672 */
9192                  -32694,        /* A2 = 0.997742 */
9193                  28847,         /* B2 = 0.880371 */
9194                  -2734,         /* B1 = -0.166901 */
9195                  28847,         /* B0 = 0.880371 */
9196                  31225,         /* A1 = -1.905823 */
9197                  -32696,        /* A2 = 0.997803 */
9198                  462,           /* B2 = 0.014108 */
9199                  -442,          /* B1 = -0.027019 */
9200                  462,           /* B0 = 0.014108 */
9201                  5,             /* Internal filter scaling */
9202                  159,           /* Minimum in-band energy threshold */
9203                  21,            /* 21/32 in-band to broad-band ratio */
9204                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9205         },
9206         {                       /* f400_425[] */
9207                 30836,          /* A1 = 1.882141 */
9208                  -32296,        /* A2 = -0.985596 */
9209                  -324,          /* B2 = -0.009903 */
9210                  0,             /* B1 = 0 */
9211                  324,           /* B0 = 0.009903 */
9212                  30825,         /* A1 = 1.881409 */
9213                  -32570,        /* A2 = -0.993958 */
9214                  16847,         /* B2 = 0.51416 */
9215                  -15792,        /* B1 = -0.963898 */
9216                  16847,         /* B0 = 0.51416 */
9217                  31106,         /* A1 = 1.89856 */
9218                  -32584,        /* A2 = -0.994415 */
9219                  9579,          /* B2 = 0.292328 */
9220                  -9164,         /* B1 = -0.559357 */
9221                  9579,          /* B0 = 0.292328 */
9222                  7,             /* Internal filter scaling */
9223                  159,           /* Minimum in-band energy threshold */
9224                  21,            /* 21/32 in-band to broad-band ratio */
9225                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9226         },
9227         {                       /* f400_440[] */
9228                 30702,          /* A1 = 1.873962 */
9229                  -32134,        /* A2 = -0.980682 */
9230                  -517,          /* B2 = -0.015793 */
9231                  0,             /* B1 = 0 */
9232                  517,           /* B0 = 0.015793 */
9233                  30676,         /* A1 = 1.872375 */
9234                  -32520,        /* A2 = -0.992462 */
9235                  8144,          /* B2 = 0.24855 */
9236                  -7596,         /* B1 = -0.463684 */
9237                  8144,          /* B0 = 0.24855 */
9238                  31084,         /* A1 = 1.897217 */
9239                  -32547,        /* A2 = -0.993256 */
9240                  22713,         /* B2 = 0.693176 */
9241                  -21734,        /* B1 = -1.326599 */
9242                  22713,         /* B0 = 0.693176 */
9243                  7,             /* Internal filter scaling */
9244                  159,           /* Minimum in-band energy threshold */
9245                  21,            /* 21/32 in-band to broad-band ratio */
9246                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9247         },
9248         {                       /* f400_450[] */
9249                 30613,          /* A1 = 1.86853 */
9250                  -32031,        /* A2 = -0.977509 */
9251                  -618,          /* B2 = -0.018866 */
9252                  0,             /* B1 = 0 */
9253                  618,           /* B0 = 0.018866 */
9254                  30577,         /* A1 = 1.866272 */
9255                  -32491,        /* A2 = -0.991577 */
9256                  9612,          /* B2 = 0.293335 */
9257                  -8935,         /* B1 = -0.54541 */
9258                  9612,          /* B0 = 0.293335 */
9259                  31071,         /* A1 = 1.896484 */
9260                  -32524,        /* A2 = -0.992584 */
9261                  21596,         /* B2 = 0.659058 */
9262                  -20667,        /* B1 = -1.261414 */
9263                  21596,         /* B0 = 0.659058 */
9264                  7,             /* Internal filter scaling */
9265                  159,           /* Minimum in-band energy threshold */
9266                  21,            /* 21/32 in-band to broad-band ratio */
9267                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9268         },
9269         {                       /* f420 */
9270                 30914,          /* A1 = -1.886841 */
9271                  -32584,        /* A2 = 0.994385 */
9272                  -426,          /* B2 = -0.013020 */
9273                  0,             /* B1 = 0.000000 */
9274                  426,           /* B0 = 0.013020 */
9275                  30914,         /* A1 = -1.886841 */
9276                  -32679,        /* A2 = 0.997314 */
9277                  17520,         /* B2 = 0.534668 */
9278                  -16471,        /* B1 = -1.005310 */
9279                  17520,         /* B0 = 0.534668 */
9280                  31004,         /* A1 = -1.892334 */
9281                  -32683,        /* A2 = 0.997406 */
9282                  819,           /* B2 = 0.025023 */
9283                  -780,          /* B1 = -0.047619 */
9284                  819,           /* B0 = 0.025023 */
9285                  5,             /* Internal filter scaling */
9286                  159,           /* Minimum in-band energy threshold */
9287                  21,            /* 21/32 in-band to broad-band ratio */
9288                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9289         },
9290 #if 0
9291         {                       /* f425 */
9292                 30881,          /* A1 = -1.884827 */
9293                  -32603,        /* A2 = 0.994965 */
9294                  -496,          /* B2 = -0.015144 */
9295                  0,             /* B1 = 0.000000 */
9296                  496,           /* B0 = 0.015144 */
9297                  30880,         /* A1 = -1.884766 */
9298                  -32692,        /* A2 = 0.997711 */
9299                  24767,         /* B2 = 0.755859 */
9300                  -23290,        /* B1 = -1.421509 */
9301                  24767,         /* B0 = 0.755859 */
9302                  30967,         /* A1 = -1.890076 */
9303                  -32694,        /* A2 = 0.997772 */
9304                  728,           /* B2 = 0.022232 */
9305                  -691,          /* B1 = -0.042194 */
9306                  728,           /* B0 = 0.022232 */
9307                  5,             /* Internal filter scaling */
9308                  159,           /* Minimum in-band energy threshold */
9309                  21,            /* 21/32 in-band to broad-band ratio */
9310                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9311         },
9312 #else
9313         {
9314                 30850,
9315                 -32534,
9316                 -504,
9317                 0,
9318                 504,
9319                 30831,
9320                 -32669,
9321                 24303,
9322                 -22080,
9323                 24303,
9324                 30994,
9325                 -32673,
9326                 1905,
9327                 -1811,
9328                 1905,
9329                 5,
9330                 129,
9331                 17,
9332                 0xff5
9333         },
9334 #endif
9335         {                       /* f425_450[] */
9336                 30646,          /* A1 = 1.870544 */
9337                  -32327,        /* A2 = -0.986572 */
9338                  -287,          /* B2 = -0.008769 */
9339                  0,             /* B1 = 0 */
9340                  287,           /* B0 = 0.008769 */
9341                  30627,         /* A1 = 1.869324 */
9342                  -32607,        /* A2 = -0.995087 */
9343                  13269,         /* B2 = 0.404968 */
9344                  -12376,        /* B1 = -0.755432 */
9345                  13269,         /* B0 = 0.404968 */
9346                  30924,         /* A1 = 1.887512 */
9347                  -32619,        /* A2 = -0.995453 */
9348                  19950,         /* B2 = 0.608826 */
9349                  -18940,        /* B1 = -1.156006 */
9350                  19950,         /* B0 = 0.608826 */
9351                  7,             /* Internal filter scaling */
9352                  159,           /* Minimum in-band energy threshold */
9353                  21,            /* 21/32 in-band to broad-band ratio */
9354                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9355         },
9356         {                       /* f425_475[] */
9357                 30396,          /* A1 = 1.855225 */
9358                  -32014,        /* A2 = -0.97699 */
9359                  -395,          /* B2 = -0.012055 */
9360                  0,             /* B1 = 0 */
9361                  395,           /* B0 = 0.012055 */
9362                  30343,         /* A1 = 1.85199 */
9363                  -32482,        /* A2 = -0.991302 */
9364                  17823,         /* B2 = 0.543945 */
9365                  -16431,        /* B1 = -1.002869 */
9366                  17823,         /* B0 = 0.543945 */
9367                  30872,         /* A1 = 1.884338 */
9368                  -32516,        /* A2 = -0.99231 */
9369                  18124,         /* B2 = 0.553101 */
9370                  -17246,        /* B1 = -1.052673 */
9371                  18124,         /* B0 = 0.553101 */
9372                  7,             /* Internal filter scaling */
9373                  159,           /* Minimum in-band energy threshold */
9374                  21,            /* 21/32 in-band to broad-band ratio */
9375                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9376         },
9377         {                       /* f435 */
9378                 30796,          /* A1 = -1.879639 */
9379                  -32603,        /* A2 = 0.994965 */
9380                  -254,          /* B2 = -0.007762 */
9381                  0,             /* B1 = 0.000000 */
9382                  254,           /* B0 = 0.007762 */
9383                  30793,         /* A1 = -1.879456 */
9384                  -32692,        /* A2 = 0.997711 */
9385                  18934,         /* B2 = 0.577820 */
9386                  -17751,        /* B1 = -1.083496 */
9387                  18934,         /* B0 = 0.577820 */
9388                  30882,         /* A1 = -1.884888 */
9389                  -32694,        /* A2 = 0.997772 */
9390                  1858,          /* B2 = 0.056713 */
9391                  -1758,         /* B1 = -0.107357 */
9392                  1858,          /* B0 = 0.056713 */
9393                  5,             /* Internal filter scaling */
9394                  159,           /* Minimum in-band energy threshold */
9395                  21,            /* 21/32 in-band to broad-band ratio */
9396                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9397         },
9398         {                       /* f440_450[] */
9399                 30641,          /* A1 = 1.870239 */
9400                  -32458,        /* A2 = -0.99057 */
9401                  -155,          /* B2 = -0.004735 */
9402                  0,             /* B1 = 0 */
9403                  155,           /* B0 = 0.004735 */
9404                  30631,         /* A1 = 1.869568 */
9405                  -32630,        /* A2 = -0.995789 */
9406                  11453,         /* B2 = 0.349548 */
9407                  -10666,        /* B1 = -0.651001 */
9408                  11453,         /* B0 = 0.349548 */
9409                  30810,         /* A1 = 1.880554 */
9410                  -32634,        /* A2 = -0.995941 */
9411                  12237,         /* B2 = 0.373474 */
9412                  -11588,        /* B1 = -0.707336 */
9413                  12237,         /* B0 = 0.373474 */
9414                  7,             /* Internal filter scaling */
9415                  159,           /* Minimum in-band energy threshold */
9416                  21,            /* 21/32 in-band to broad-band ratio */
9417                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9418         },
9419         {                       /* f440_480[] */
9420                 30367,          /* A1 = 1.853455 */
9421                  -32147,        /* A2 = -0.981079 */
9422                  -495,          /* B2 = -0.015113 */
9423                  0,             /* B1 = 0 */
9424                  495,           /* B0 = 0.015113 */
9425                  30322,         /* A1 = 1.850769 */
9426                  -32543,        /* A2 = -0.993134 */
9427                  10031,         /* B2 = 0.306152 */
9428                  -9252,         /* B1 = -0.564728 */
9429                  10031,         /* B0 = 0.306152 */
9430                  30770,         /* A1 = 1.878052 */
9431                  -32563,        /* A2 = -0.993774 */
9432                  22674,         /* B2 = 0.691956 */
9433                  -21465,        /* B1 = -1.31012 */
9434                  22674,         /* B0 = 0.691956 */
9435                  7,             /* Internal filter scaling */
9436                  159,           /* Minimum in-band energy threshold */
9437                  21,            /* 21/32 in-band to broad-band ratio */
9438                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9439         },
9440         {                       /* f445 */
9441                 30709,          /* A1 = -1.874329 */
9442                  -32603,        /* A2 = 0.994965 */
9443                  -83,           /* B2 = -0.002545 */
9444                  0,             /* B1 = 0.000000 */
9445                  83,            /* B0 = 0.002545 */
9446                  30704,         /* A1 = -1.874084 */
9447                  -32692,        /* A2 = 0.997711 */
9448                  10641,         /* B2 = 0.324738 */
9449                  -9947,         /* B1 = -0.607147 */
9450                  10641,         /* B0 = 0.324738 */
9451                  30796,         /* A1 = -1.879639 */
9452                  -32694,        /* A2 = 0.997772 */
9453                  10079,         /* B2 = 0.307587 */
9454                  9513,          /* B1 = 0.580688 */
9455                  10079,         /* B0 = 0.307587 */
9456                  5,             /* Internal filter scaling */
9457                  159,           /* Minimum in-band energy threshold */
9458                  21,            /* 21/32 in-band to broad-band ratio */
9459                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9460         },
9461         {                       /* f450 */
9462                 30664,          /* A1 = -1.871643 */
9463                  -32603,        /* A2 = 0.994965 */
9464                  -164,          /* B2 = -0.005029 */
9465                  0,             /* B1 = 0.000000 */
9466                  164,           /* B0 = 0.005029 */
9467                  30661,         /* A1 = -1.871399 */
9468                  -32692,        /* A2 = 0.997711 */
9469                  15294,         /* B2 = 0.466736 */
9470                  -14275,        /* B1 = -0.871307 */
9471                  15294,         /* B0 = 0.466736 */
9472                  30751,         /* A1 = -1.876953 */
9473                  -32694,        /* A2 = 0.997772 */
9474                  3548,          /* B2 = 0.108284 */
9475                  -3344,         /* B1 = -0.204155 */
9476                  3548,          /* B0 = 0.108284 */
9477                  5,             /* Internal filter scaling */
9478                  159,           /* Minimum in-band energy threshold */
9479                  21,            /* 21/32 in-band to broad-band ratio */
9480                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9481         },
9482         {                       /* f452 */
9483                 30653,          /* A1 = -1.870911 */
9484                  -32615,        /* A2 = 0.995361 */
9485                  -209,          /* B2 = -0.006382 */
9486                  0,             /* B1 = 0.000000 */
9487                  209,           /* B0 = 0.006382 */
9488                  30647,         /* A1 = -1.870605 */
9489                  -32702,        /* A2 = 0.997986 */
9490                  18971,         /* B2 = 0.578979 */
9491                  -17716,        /* B1 = -1.081299 */
9492                  18971,         /* B0 = 0.578979 */
9493                  30738,         /* A1 = -1.876099 */
9494                  -32702,        /* A2 = 0.998016 */
9495                  2967,          /* B2 = 0.090561 */
9496                  -2793,         /* B1 = -0.170502 */
9497                  2967,          /* B0 = 0.090561 */
9498                  5,             /* Internal filter scaling */
9499                  159,           /* Minimum in-band energy threshold */
9500                  21,            /* 21/32 in-band to broad-band ratio */
9501                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9502         },
9503         {                       /* f475 */
9504                 30437,          /* A1 = -1.857727 */
9505                  -32603,        /* A2 = 0.994965 */
9506                  -264,          /* B2 = -0.008062 */
9507                  0,             /* B1 = 0.000000 */
9508                  264,           /* B0 = 0.008062 */
9509                  30430,         /* A1 = -1.857300 */
9510                  -32692,        /* A2 = 0.997711 */
9511                  21681,         /* B2 = 0.661682 */
9512                  -20082,        /* B1 = -1.225708 */
9513                  21681,         /* B0 = 0.661682 */
9514                  30526,         /* A1 = -1.863220 */
9515                  -32694,        /* A2 = 0.997742 */
9516                  1559,          /* B2 = 0.047600 */
9517                  -1459,         /* B1 = -0.089096 */
9518                  1559,          /* B0 = 0.047600 */
9519                  5,             /* Internal filter scaling */
9520                  159,           /* Minimum in-band energy threshold */
9521                  21,            /* 21/32 in-band to broad-band ratio */
9522                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9523         },
9524         {                       /* f480_620[] */
9525                 28975,          /* A1 = 1.768494 */
9526                  -30955,        /* A2 = -0.944672 */
9527                  -1026,         /* B2 = -0.03133 */
9528                  0,             /* B1 = 0 */
9529                  1026,          /* B0 = 0.03133 */
9530                  28613,         /* A1 = 1.746399 */
9531                  -32089,        /* A2 = -0.979309 */
9532                  14214,         /* B2 = 0.433807 */
9533                  -12202,        /* B1 = -0.744812 */
9534                  14214,         /* B0 = 0.433807 */
9535                  30243,         /* A1 = 1.845947 */
9536                  -32238,        /* A2 = -0.983856 */
9537                  24825,         /* B2 = 0.757629 */
9538                  -23402,        /* B1 = -1.428345 */
9539                  24825,         /* B0 = 0.757629 */
9540                  7,             /* Internal filter scaling */
9541                  159,           /* Minimum in-band energy threshold */
9542                  21,            /* 21/32 in-band to broad-band ratio */
9543                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9544         },
9545         {                       /* f494 */
9546                 30257,          /* A1 = -1.846741 */
9547                  -32605,        /* A2 = 0.995056 */
9548                  -249,          /* B2 = -0.007625 */
9549                  0,             /* B1 = 0.000000 */
9550                  249,           /* B0 = 0.007625 */
9551                  30247,         /* A1 = -1.846191 */
9552                  -32694,        /* A2 = 0.997772 */
9553                  18088,         /* B2 = 0.552002 */
9554                  -16652,        /* B1 = -1.016418 */
9555                  18088,         /* B0 = 0.552002 */
9556                  30348,         /* A1 = -1.852295 */
9557                  -32696,        /* A2 = 0.997803 */
9558                  2099,          /* B2 = 0.064064 */
9559                  -1953,         /* B1 = -0.119202 */
9560                  2099,          /* B0 = 0.064064 */
9561                  5,             /* Internal filter scaling */
9562                  159,           /* Minimum in-band energy threshold */
9563                  21,            /* 21/32 in-band to broad-band ratio */
9564                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9565         },
9566         {                       /* f500 */
9567                 30202,          /* A1 = -1.843431 */
9568                  -32624,        /* A2 = 0.995622 */
9569                  -413,          /* B2 = -0.012622 */
9570                  0,             /* B1 = 0.000000 */
9571                  413,           /* B0 = 0.012622 */
9572                  30191,         /* A1 = -1.842721 */
9573                  -32714,        /* A2 = 0.998364 */
9574                  25954,         /* B2 = 0.792057 */
9575                  -23890,        /* B1 = -1.458131 */
9576                  25954,         /* B0 = 0.792057 */
9577                  30296,         /* A1 = -1.849172 */
9578                  -32715,        /* A2 = 0.998397 */
9579                  2007,          /* B2 = 0.061264 */
9580                  -1860,         /* B1 = -0.113568 */
9581                  2007,          /* B0 = 0.061264 */
9582                  5,             /* Internal filter scaling */
9583                  159,           /* Minimum in-band energy threshold */
9584                  21,            /* 21/32 in-band to broad-band ratio */
9585                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9586         },
9587         {                       /* f520 */
9588                 30001,          /* A1 = -1.831116 */
9589                  -32613,        /* A2 = 0.995270 */
9590                  -155,          /* B2 = -0.004750 */
9591                  0,             /* B1 = 0.000000 */
9592                  155,           /* B0 = 0.004750 */
9593                  29985,         /* A1 = -1.830200 */
9594                  -32710,        /* A2 = 0.998260 */
9595                  6584,          /* B2 = 0.200928 */
9596                  -6018,         /* B1 = -0.367355 */
9597                  6584,          /* B0 = 0.200928 */
9598                  30105,         /* A1 = -1.837524 */
9599                  -32712,        /* A2 = 0.998291 */
9600                  23812,         /* B2 = 0.726685 */
9601                  -21936,        /* B1 = -1.338928 */
9602                  23812,         /* B0 = 0.726685 */
9603                  5,             /* Internal filter scaling */
9604                  159,           /* Minimum in-band energy threshold */
9605                  21,            /* 21/32 in-band to broad-band ratio */
9606                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9607         },
9608         {                       /* f523 */
9609                 29964,          /* A1 = -1.828918 */
9610                  -32601,        /* A2 = 0.994904 */
9611                  -101,          /* B2 = -0.003110 */
9612                  0,             /* B1 = 0.000000 */
9613                  101,           /* B0 = 0.003110 */
9614                  29949,         /* A1 = -1.827942 */
9615                  -32700,        /* A2 = 0.997925 */
9616                  11041,         /* B2 = 0.336975 */
9617                  -10075,        /* B1 = -0.614960 */
9618                  11041,         /* B0 = 0.336975 */
9619                  30070,         /* A1 = -1.835388 */
9620                  -32702,        /* A2 = 0.997986 */
9621                  16762,         /* B2 = 0.511536 */
9622                  -15437,        /* B1 = -0.942230 */
9623                  16762,         /* B0 = 0.511536 */
9624                  5,             /* Internal filter scaling */
9625                  159,           /* Minimum in-band energy threshold */
9626                  21,            /* 21/32 in-band to broad-band ratio */
9627                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9628         },
9629         {                       /* f525 */
9630                 29936,          /* A1 = -1.827209 */
9631                  -32584,        /* A2 = 0.994415 */
9632                  -91,           /* B2 = -0.002806 */
9633                  0,             /* B1 = 0.000000 */
9634                  91,            /* B0 = 0.002806 */
9635                  29921,         /* A1 = -1.826233 */
9636                  -32688,        /* A2 = 0.997559 */
9637                  11449,         /* B2 = 0.349396 */
9638                  -10426,        /* B1 = -0.636383 */
9639                  11449,         /* B0 = 0.349396 */
9640                  30045,         /* A1 = -1.833862 */
9641                  -32688,        /* A2 = 0.997589 */
9642                  13055,         /* B2 = 0.398407 */
9643                  -12028,        /* B1 = -0.734161 */
9644                  13055,         /* B0 = 0.398407 */
9645                  5,             /* Internal filter scaling */
9646                  159,           /* Minimum in-band energy threshold */
9647                  21,            /* 21/32 in-band to broad-band ratio */
9648                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9649         },
9650         {                       /* f540_660[] */
9651                 28499,          /* A1 = 1.739441 */
9652                  -31129,        /* A2 = -0.949982 */
9653                  -849,          /* B2 = -0.025922 */
9654                  0,             /* B1 = 0 */
9655                  849,           /* B0 = 0.025922 */
9656                  28128,         /* A1 = 1.716797 */
9657                  -32130,        /* A2 = -0.98056 */
9658                  14556,         /* B2 = 0.444214 */
9659                  -12251,        /* B1 = -0.747772 */
9660                  14556,         /* B0 = 0.444244 */
9661                  29667,         /* A1 = 1.81073 */
9662                  -32244,        /* A2 = -0.984039 */
9663                  23038,         /* B2 = 0.703064 */
9664                  -21358,        /* B1 = -1.303589 */
9665                  23040,         /* B0 = 0.703125 */
9666                  7,             /* Internal filter scaling */
9667                  159,           /* Minimum in-band energy threshold */
9668                  21,            /* 21/32 in-band to broad-band ratio */
9669                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9670         },
9671         {                       /* f587 */
9672                 29271,          /* A1 = -1.786560 */
9673                  -32599,        /* A2 = 0.994873 */
9674                  -490,          /* B2 = -0.014957 */
9675                  0,             /* B1 = 0.000000 */
9676                  490,           /* B0 = 0.014957 */
9677                  29246,         /* A1 = -1.785095 */
9678                  -32700,        /* A2 = 0.997925 */
9679                  28961,         /* B2 = 0.883850 */
9680                  -25796,        /* B1 = -1.574463 */
9681                  28961,         /* B0 = 0.883850 */
9682                  29383,         /* A1 = -1.793396 */
9683                  -32700,        /* A2 = 0.997955 */
9684                  1299,          /* B2 = 0.039650 */
9685                  -1169,         /* B1 = -0.071396 */
9686                  1299,          /* B0 = 0.039650 */
9687                  5,             /* Internal filter scaling */
9688                  159,           /* Minimum in-band energy threshold */
9689                  21,            /* 21/32 in-band to broad-band ratio */
9690                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9691         },
9692         {                       /* f590 */
9693                 29230,          /* A1 = -1.784058 */
9694                  -32584,        /* A2 = 0.994415 */
9695                  -418,          /* B2 = -0.012757 */
9696                  0,             /* B1 = 0.000000 */
9697                  418,           /* B0 = 0.012757 */
9698                  29206,         /* A1 = -1.782593 */
9699                  -32688,        /* A2 = 0.997559 */
9700                  36556,         /* B2 = 1.115601 */
9701                  -32478,        /* B1 = -1.982300 */
9702                  36556,         /* B0 = 1.115601 */
9703                  29345,         /* A1 = -1.791077 */
9704                  -32688,        /* A2 = 0.997589 */
9705                  897,           /* B2 = 0.027397 */
9706                  -808,          /* B1 = -0.049334 */
9707                  897,           /* B0 = 0.027397 */
9708                  5,             /* Internal filter scaling */
9709                  159,           /* Minimum in-band energy threshold */
9710                  21,            /* 21/32 in-band to broad-band ratio */
9711                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9712         },
9713         {                       /* f600 */
9714                 29116,          /* A1 = -1.777100 */
9715                  -32603,        /* A2 = 0.994965 */
9716                  -165,          /* B2 = -0.005039 */
9717                  0,             /* B1 = 0.000000 */
9718                  165,           /* B0 = 0.005039 */
9719                  29089,         /* A1 = -1.775452 */
9720                  -32708,        /* A2 = 0.998199 */
9721                  6963,          /* B2 = 0.212494 */
9722                  -6172,         /* B1 = -0.376770 */
9723                  6963,          /* B0 = 0.212494 */
9724                  29237,         /* A1 = -1.784485 */
9725                  -32710,        /* A2 = 0.998230 */
9726                  24197,         /* B2 = 0.738464 */
9727                  -21657,        /* B1 = -1.321899 */
9728                  24197,         /* B0 = 0.738464 */
9729                  5,             /* Internal filter scaling */
9730                  159,           /* Minimum in-band energy threshold */
9731                  21,            /* 21/32 in-band to broad-band ratio */
9732                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9733         },
9734         {                       /* f660 */
9735                 28376,          /* A1 = -1.731934 */
9736                  -32567,        /* A2 = 0.993896 */
9737                  -363,          /* B2 = -0.011102 */
9738                  0,             /* B1 = 0.000000 */
9739                  363,           /* B0 = 0.011102 */
9740                  28337,         /* A1 = -1.729614 */
9741                  -32683,        /* A2 = 0.997434 */
9742                  21766,         /* B2 = 0.664246 */
9743                  -18761,        /* B1 = -1.145081 */
9744                  21766,         /* B0 = 0.664246 */
9745                  28513,         /* A1 = -1.740356 */
9746                  -32686,        /* A2 = 0.997498 */
9747                  2509,          /* B2 = 0.076584 */
9748                  -2196,         /* B1 = -0.134041 */
9749                  2509,          /* B0 = 0.076584 */
9750                  5,             /* Internal filter scaling */
9751                  159,           /* Minimum in-band energy threshold */
9752                  21,            /* 21/32 in-band to broad-band ratio */
9753                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9754         },
9755         {                       /* f700 */
9756                 27844,          /* A1 = -1.699463 */
9757                  -32563,        /* A2 = 0.993744 */
9758                  -366,          /* B2 = -0.011187 */
9759                  0,             /* B1 = 0.000000 */
9760                  366,           /* B0 = 0.011187 */
9761                  27797,         /* A1 = -1.696655 */
9762                  -32686,        /* A2 = 0.997498 */
9763                  22748,         /* B2 = 0.694214 */
9764                  -19235,        /* B1 = -1.174072 */
9765                  22748,         /* B0 = 0.694214 */
9766                  27995,         /* A1 = -1.708740 */
9767                  -32688,        /* A2 = 0.997559 */
9768                  2964,          /* B2 = 0.090477 */
9769                  -2546,         /* B1 = -0.155449 */
9770                  2964,          /* B0 = 0.090477 */
9771                  5,             /* Internal filter scaling */
9772                  159,           /* Minimum in-band energy threshold */
9773                  21,            /* 21/32 in-band to broad-band ratio */
9774                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9775         },
9776         {                       /* f740 */
9777                 27297,          /* A1 = -1.666077 */
9778                  -32551,        /* A2 = 0.993408 */
9779                  -345,          /* B2 = -0.010540 */
9780                  0,             /* B1 = 0.000000 */
9781                  345,           /* B0 = 0.010540 */
9782                  27240,         /* A1 = -1.662598 */
9783                  -32683,        /* A2 = 0.997406 */
9784                  22560,         /* B2 = 0.688477 */
9785                  -18688,        /* B1 = -1.140625 */
9786                  22560,         /* B0 = 0.688477 */
9787                  27461,         /* A1 = -1.676147 */
9788                  -32684,        /* A2 = 0.997467 */
9789                  3541,          /* B2 = 0.108086 */
9790                  -2985,         /* B1 = -0.182220 */
9791                  3541,          /* B0 = 0.108086 */
9792                  5,             /* Internal filter scaling */
9793                  159,           /* Minimum in-band energy threshold */
9794                  21,            /* 21/32 in-band to broad-band ratio */
9795                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9796         },
9797         {                       /* f750 */
9798                 27155,          /* A1 = -1.657410 */
9799                  -32551,        /* A2 = 0.993408 */
9800                  -462,          /* B2 = -0.014117 */
9801                  0,             /* B1 = 0.000000 */
9802                  462,           /* B0 = 0.014117 */
9803                  27097,         /* A1 = -1.653870 */
9804                  -32683,        /* A2 = 0.997406 */
9805                  32495,         /* B2 = 0.991699 */
9806                  -26776,        /* B1 = -1.634338 */
9807                  32495,         /* B0 = 0.991699 */
9808                  27321,         /* A1 = -1.667542 */
9809                  -32684,        /* A2 = 0.997467 */
9810                  1835,          /* B2 = 0.056007 */
9811                  -1539,         /* B1 = -0.093948 */
9812                  1835,          /* B0 = 0.056007 */
9813                  5,             /* Internal filter scaling */
9814                  159,           /* Minimum in-band energy threshold */
9815                  21,            /* 21/32 in-band to broad-band ratio */
9816                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9817         },
9818         {                       /* f750_1450[] */
9819                 19298,          /* A1 = 1.177917 */
9820                  -24471,        /* A2 = -0.746796 */
9821                  -4152,         /* B2 = -0.126709 */
9822                  0,             /* B1 = 0 */
9823                  4152,          /* B0 = 0.126709 */
9824                  12902,         /* A1 = 0.787476 */
9825                  -29091,        /* A2 = -0.887817 */
9826                  12491,         /* B2 = 0.38121 */
9827                  -1794,         /* B1 = -0.109528 */
9828                  12494,         /* B0 = 0.381317 */
9829                  26291,         /* A1 = 1.604736 */
9830                  -30470,        /* A2 = -0.929901 */
9831                  28859,         /* B2 = 0.880737 */
9832                  -26084,        /* B1 = -1.592102 */
9833                  28861,         /* B0 = 0.880798 */
9834                  7,             /* Internal filter scaling */
9835                  159,           /* Minimum in-band energy threshold */
9836                  21,            /* 21/32 in-band to broad-band ratio */
9837                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9838         },
9839         {                       /* f770 */
9840                 26867,          /* A1 = -1.639832 */
9841                  -32551,        /* A2 = 0.993408 */
9842                  -123,          /* B2 = -0.003755 */
9843                  0,             /* B1 = 0.000000 */
9844                  123,           /* B0 = 0.003755 */
9845                  26805,         /* A1 = -1.636108 */
9846                  -32683,        /* A2 = 0.997406 */
9847                  17297,         /* B2 = 0.527863 */
9848                  -14096,        /* B1 = -0.860382 */
9849                  17297,         /* B0 = 0.527863 */
9850                  27034,         /* A1 = -1.650085 */
9851                  -32684,        /* A2 = 0.997467 */
9852                  12958,         /* B2 = 0.395477 */
9853                  -10756,        /* B1 = -0.656525 */
9854                  12958,         /* B0 = 0.395477 */
9855                  5,             /* Internal filter scaling */
9856                  159,           /* Minimum in-band energy threshold */
9857                  21,            /* 21/32 in-band to broad-band ratio */
9858                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9859         },
9860         {                       /* f800 */
9861                 26413,          /* A1 = -1.612122 */
9862                  -32547,        /* A2 = 0.993286 */
9863                  -223,          /* B2 = -0.006825 */
9864                  0,             /* B1 = 0.000000 */
9865                  223,           /* B0 = 0.006825 */
9866                  26342,         /* A1 = -1.607849 */
9867                  -32686,        /* A2 = 0.997498 */
9868                  6391,          /* B2 = 0.195053 */
9869                  -5120,         /* B1 = -0.312531 */
9870                  6391,          /* B0 = 0.195053 */
9871                  26593,         /* A1 = -1.623108 */
9872                  -32688,        /* A2 = 0.997559 */
9873                  23681,         /* B2 = 0.722717 */
9874                  -19328,        /* B1 = -1.179688 */
9875                  23681,         /* B0 = 0.722717 */
9876                  5,             /* Internal filter scaling */
9877                  159,           /* Minimum in-band energy threshold */
9878                  21,            /* 21/32 in-band to broad-band ratio */
9879                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9880         },
9881         {                       /* f816 */
9882                 26168,          /* A1 = -1.597209 */
9883                  -32528,        /* A2 = 0.992706 */
9884                  -235,          /* B2 = -0.007182 */
9885                  0,             /* B1 = 0.000000 */
9886                  235,           /* B0 = 0.007182 */
9887                  26092,         /* A1 = -1.592590 */
9888                  -32675,        /* A2 = 0.997192 */
9889                  20823,         /* B2 = 0.635498 */
9890                  -16510,        /* B1 = -1.007751 */
9891                  20823,         /* B0 = 0.635498 */
9892                  26363,         /* A1 = -1.609070 */
9893                  -32677,        /* A2 = 0.997253 */
9894                  6739,          /* B2 = 0.205688 */
9895                  -5459,         /* B1 = -0.333206 */
9896                  6739,          /* B0 = 0.205688 */
9897                  5,             /* Internal filter scaling */
9898                  159,           /* Minimum in-band energy threshold */
9899                  21,            /* 21/32 in-band to broad-band ratio */
9900                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9901         },
9902         {                       /* f850 */
9903                 25641,          /* A1 = -1.565063 */
9904                  -32536,        /* A2 = 0.992950 */
9905                  -121,          /* B2 = -0.003707 */
9906                  0,             /* B1 = 0.000000 */
9907                  121,           /* B0 = 0.003707 */
9908                  25560,         /* A1 = -1.560059 */
9909                  -32684,        /* A2 = 0.997437 */
9910                  18341,         /* B2 = 0.559753 */
9911                  -14252,        /* B1 = -0.869904 */
9912                  18341,         /* B0 = 0.559753 */
9913                  25837,         /* A1 = -1.577026 */
9914                  -32684,        /* A2 = 0.997467 */
9915                  16679,         /* B2 = 0.509003 */
9916                  -13232,        /* B1 = -0.807648 */
9917                  16679,         /* B0 = 0.509003 */
9918                  5,             /* Internal filter scaling */
9919                  159,           /* Minimum in-band energy threshold */
9920                  21,            /* 21/32 in-band to broad-band ratio */
9921                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9922         },
9923         {                       /* f857_1645[] */
9924                 16415,          /* A1 = 1.001953 */
9925                  -23669,        /* A2 = -0.722321 */
9926                  -4549,         /* B2 = -0.138847 */
9927                  0,             /* B1 = 0 */
9928                  4549,          /* B0 = 0.138847 */
9929                  8456,          /* A1 = 0.516174 */
9930                  -28996,        /* A2 = -0.884918 */
9931                  13753,         /* B2 = 0.419724 */
9932                  -12,           /* B1 = -0.000763 */
9933                  13757,         /* B0 = 0.419846 */
9934                  24632,         /* A1 = 1.503418 */
9935                  -30271,        /* A2 = -0.923828 */
9936                  29070,         /* B2 = 0.887146 */
9937                  -25265,        /* B1 = -1.542114 */
9938                  29073,         /* B0 = 0.887268 */
9939                  7,             /* Internal filter scaling */
9940                  159,           /* Minimum in-band energy threshold */
9941                  21,            /* 21/32 in-band to broad-band ratio */
9942                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9943         },
9944         {                       /* f900 */
9945                 24806,          /* A1 = -1.514099 */
9946                  -32501,        /* A2 = 0.991852 */
9947                  -326,          /* B2 = -0.009969 */
9948                  0,             /* B1 = 0.000000 */
9949                  326,           /* B0 = 0.009969 */
9950                  24709,         /* A1 = -1.508118 */
9951                  -32659,        /* A2 = 0.996674 */
9952                  20277,         /* B2 = 0.618835 */
9953                  -15182,        /* B1 = -0.926636 */
9954                  20277,         /* B0 = 0.618835 */
9955                  25022,         /* A1 = -1.527222 */
9956                  -32661,        /* A2 = 0.996735 */
9957                  4320,          /* B2 = 0.131836 */
9958                  -3331,         /* B1 = -0.203339 */
9959                  4320,          /* B0 = 0.131836 */
9960                  5,             /* Internal filter scaling */
9961                  159,           /* Minimum in-band energy threshold */
9962                  21,            /* 21/32 in-band to broad-band ratio */
9963                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9964         },
9965         {                       /* f900_1300[] */
9966                 19776,          /* A1 = 1.207092 */
9967                  -27437,        /* A2 = -0.837341 */
9968                  -2666,         /* B2 = -0.081371 */
9969                  0,             /* B1 = 0 */
9970                  2666,          /* B0 = 0.081371 */
9971                  16302,         /* A1 = 0.995026 */
9972                  -30354,        /* A2 = -0.926361 */
9973                  10389,         /* B2 = 0.317062 */
9974                  -3327,         /* B1 = -0.203064 */
9975                  10389,         /* B0 = 0.317062 */
9976                  24299,         /* A1 = 1.483154 */
9977                  -30930,        /* A2 = -0.943909 */
9978                  25016,         /* B2 = 0.763428 */
9979                  -21171,        /* B1 = -1.292236 */
9980                  25016,         /* B0 = 0.763428 */
9981                  7,             /* Internal filter scaling */
9982                  159,           /* Minimum in-band energy threshold */
9983                  21,            /* 21/32 in-band to broad-band ratio */
9984                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9985         },
9986         {                       /* f935_1215[] */
9987                 20554,          /* A1 = 1.254517 */
9988                  -28764,        /* A2 = -0.877838 */
9989                  -2048,         /* B2 = -0.062515 */
9990                  0,             /* B1 = 0 */
9991                  2048,          /* B0 = 0.062515 */
9992                  18209,         /* A1 = 1.11145 */
9993                  -30951,        /* A2 = -0.94458 */
9994                  9390,          /* B2 = 0.286575 */
9995                  -3955,         /* B1 = -0.241455 */
9996                  9390,          /* B0 = 0.286575 */
9997                  23902,         /* A1 = 1.458923 */
9998                  -31286,        /* A2 = -0.954803 */
9999                  23252,         /* B2 = 0.709595 */
10000                  -19132,        /* B1 = -1.167725 */
10001                  23252,         /* B0 = 0.709595 */
10002                  7,             /* Internal filter scaling */
10003                  159,           /* Minimum in-band energy threshold */
10004                  21,            /* 21/32 in-band to broad-band ratio */
10005                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10006         },
10007         {                       /* f941_1477[] */
10008                 17543,          /* A1 = 1.07074 */
10009                  -26220,        /* A2 = -0.800201 */
10010                  -3298,         /* B2 = -0.100647 */
10011                  0,             /* B1 = 0 */
10012                  3298,          /* B0 = 0.100647 */
10013                  12423,         /* A1 = 0.75827 */
10014                  -30036,        /* A2 = -0.916626 */
10015                  12651,         /* B2 = 0.386078 */
10016                  -2444,         /* B1 = -0.14917 */
10017                  12653,         /* B0 = 0.386154 */
10018                  23518,         /* A1 = 1.435425 */
10019                  -30745,        /* A2 = -0.938293 */
10020                  27282,         /* B2 = 0.832581 */
10021                  -22529,        /* B1 = -1.375122 */
10022                  27286,         /* B0 = 0.832703 */
10023                  7,             /* Internal filter scaling */
10024                  159,           /* Minimum in-band energy threshold */
10025                  21,            /* 21/32 in-band to broad-band ratio */
10026                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10027         },
10028         {                       /* f942 */
10029                 24104,          /* A1 = -1.471252 */
10030                  -32507,        /* A2 = 0.992065 */
10031                  -351,          /* B2 = -0.010722 */
10032                  0,             /* B1 = 0.000000 */
10033                  351,           /* B0 = 0.010722 */
10034                  23996,         /* A1 = -1.464600 */
10035                  -32671,        /* A2 = 0.997040 */
10036                  22848,         /* B2 = 0.697266 */
10037                  -16639,        /* B1 = -1.015564 */
10038                  22848,         /* B0 = 0.697266 */
10039                  24332,         /* A1 = -1.485168 */
10040                  -32673,        /* A2 = 0.997101 */
10041                  4906,          /* B2 = 0.149727 */
10042                  -3672,         /* B1 = -0.224174 */
10043                  4906,          /* B0 = 0.149727 */
10044                  5,             /* Internal filter scaling */
10045                  159,           /* Minimum in-band energy threshold */
10046                  21,            /* 21/32 in-band to broad-band ratio */
10047                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10048         },
10049         {                       /* f950 */
10050                 23967,          /* A1 = -1.462830 */
10051                  -32507,        /* A2 = 0.992065 */
10052                  -518,          /* B2 = -0.015821 */
10053                  0,             /* B1 = 0.000000 */
10054                  518,           /* B0 = 0.015821 */
10055                  23856,         /* A1 = -1.456055 */
10056                  -32671,        /* A2 = 0.997040 */
10057                  26287,         /* B2 = 0.802246 */
10058                  -19031,        /* B1 = -1.161560 */
10059                  26287,         /* B0 = 0.802246 */
10060                  24195,         /* A1 = -1.476746 */
10061                  -32673,        /* A2 = 0.997101 */
10062                  2890,          /* B2 = 0.088196 */
10063                  -2151,         /* B1 = -0.131317 */
10064                  2890,          /* B0 = 0.088196 */
10065                  5,             /* Internal filter scaling */
10066                  159,           /* Minimum in-band energy threshold */
10067                  21,            /* 21/32 in-band to broad-band ratio */
10068                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10069         },
10070         {                       /* f950_1400[] */
10071                 18294,          /* A1 = 1.116638 */
10072                  -26962,        /* A2 = -0.822845 */
10073                  -2914,         /* B2 = -0.088936 */
10074                  0,             /* B1 = 0 */
10075                  2914,          /* B0 = 0.088936 */
10076                  14119,         /* A1 = 0.861786 */
10077                  -30227,        /* A2 = -0.922455 */
10078                  11466,         /* B2 = 0.349945 */
10079                  -2833,         /* B1 = -0.172943 */
10080                  11466,         /* B0 = 0.349945 */
10081                  23431,         /* A1 = 1.430115 */
10082                  -30828,        /* A2 = -0.940796 */
10083                  25331,         /* B2 = 0.773071 */
10084                  -20911,        /* B1 = -1.276367 */
10085                  25331,         /* B0 = 0.773071 */
10086                  7,             /* Internal filter scaling */
10087                  159,           /* Minimum in-band energy threshold */
10088                  21,            /* 21/32 in-band to broad-band ratio */
10089                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10090         },
10091         {                       /* f975 */
10092                 23521,          /* A1 = -1.435608 */
10093                  -32489,        /* A2 = 0.991516 */
10094                  -193,          /* B2 = -0.005915 */
10095                  0,             /* B1 = 0.000000 */
10096                  193,           /* B0 = 0.005915 */
10097                  23404,         /* A1 = -1.428467 */
10098                  -32655,        /* A2 = 0.996582 */
10099                  17740,         /* B2 = 0.541412 */
10100                  -12567,        /* B1 = -0.767029 */
10101                  17740,         /* B0 = 0.541412 */
10102                  23753,         /* A1 = -1.449829 */
10103                  -32657,        /* A2 = 0.996613 */
10104                  9090,          /* B2 = 0.277405 */
10105                  -6662,         /* B1 = -0.406647 */
10106                  9090,          /* B0 = 0.277405 */
10107                  5,             /* Internal filter scaling */
10108                  159,           /* Minimum in-band energy threshold */
10109                  21,            /* 21/32 in-band to broad-band ratio */
10110                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10111         },
10112         {                       /* f1000 */
10113                 23071,          /* A1 = -1.408203 */
10114                  -32489,        /* A2 = 0.991516 */
10115                  -293,          /* B2 = -0.008965 */
10116                  0,             /* B1 = 0.000000 */
10117                  293,           /* B0 = 0.008965 */
10118                  22951,         /* A1 = -1.400818 */
10119                  -32655,        /* A2 = 0.996582 */
10120                  5689,          /* B2 = 0.173645 */
10121                  -3951,         /* B1 = -0.241150 */
10122                  5689,          /* B0 = 0.173645 */
10123                  23307,         /* A1 = -1.422607 */
10124                  -32657,        /* A2 = 0.996613 */
10125                  18692,         /* B2 = 0.570435 */
10126                  -13447,        /* B1 = -0.820770 */
10127                  18692,         /* B0 = 0.570435 */
10128                  5,             /* Internal filter scaling */
10129                  159,           /* Minimum in-band energy threshold */
10130                  21,            /* 21/32 in-band to broad-band ratio */
10131                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10132         },
10133         {                       /* f1020 */
10134                 22701,          /* A1 = -1.385620 */
10135                  -32474,        /* A2 = 0.991058 */
10136                  -292,          /* B2 = -0.008933 */
10137                  0,             /*163840      , B1 = 10.000000 */
10138                  292,           /* B0 = 0.008933 */
10139                  22564,         /* A1 = -1.377258 */
10140                  -32655,        /* A2 = 0.996552 */
10141                  20756,         /* B2 = 0.633423 */
10142                  -14176,        /* B1 = -0.865295 */
10143                  20756,         /* B0 = 0.633423 */
10144                  22960,         /* A1 = -1.401428 */
10145                  -32657,        /* A2 = 0.996613 */
10146                  6520,          /* B2 = 0.198990 */
10147                  -4619,         /* B1 = -0.281937 */
10148                  6520,          /* B0 = 0.198990 */
10149                  5,             /* Internal filter scaling */
10150                  159,           /* Minimum in-band energy threshold */
10151                  21,            /* 21/32 in-band to broad-band ratio */
10152                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10153         },
10154         {                       /* f1050 */
10155                 22142,          /* A1 = -1.351501 */
10156                  -32474,        /* A2 = 0.991058 */
10157                  -147,          /* B2 = -0.004493 */
10158                  0,             /* B1 = 0.000000 */
10159                  147,           /* B0 = 0.004493 */
10160                  22000,         /* A1 = -1.342834 */
10161                  -32655,        /* A2 = 0.996552 */
10162                  15379,         /* B2 = 0.469360 */
10163                  -10237,        /* B1 = -0.624847 */
10164                  15379,         /* B0 = 0.469360 */
10165                  22406,         /* A1 = -1.367554 */
10166                  -32657,        /* A2 = 0.996613 */
10167                  17491,         /* B2 = 0.533783 */
10168                  -12096,        /* B1 = -0.738312 */
10169                  17491,         /* B0 = 0.533783 */
10170                  5,             /* Internal filter scaling */
10171                  159,           /* Minimum in-band energy threshold */
10172                  21,            /* 21/32 in-band to broad-band ratio */
10173                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10174         },
10175         {                       /* f1100_1750[] */
10176                 12973,          /* A1 = 0.79184 */
10177                  -24916,        /* A2 = -0.760376 */
10178                  6655,          /* B2 = 0.203102 */
10179                  367,           /* B1 = 0.0224 */
10180                  6657,          /* B0 = 0.203171 */
10181                  5915,          /* A1 = 0.361053 */
10182                  -29560,        /* A2 = -0.90213 */
10183                  -7777,         /* B2 = -0.23735 */
10184                  0,             /* B1 = 0 */
10185                  7777,          /* B0 = 0.23735 */
10186                  20510,         /* A1 = 1.251892 */
10187                  -30260,        /* A2 = -0.923462 */
10188                  26662,         /* B2 = 0.81366 */
10189                  -20573,        /* B1 = -1.255737 */
10190                  26668,         /* B0 = 0.813843 */
10191                  7,             /* Internal filter scaling */
10192                  159,           /* Minimum in-band energy threshold */
10193                  21,            /* 21/32 in-band to broad-band ratio */
10194                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10195         },
10196         {                       /* f1140 */
10197                 20392,          /* A1 = -1.244629 */
10198                  -32460,        /* A2 = 0.990601 */
10199                  -270,          /* B2 = -0.008240 */
10200                  0,             /* B1 = 0.000000 */
10201                  270,           /* B0 = 0.008240 */
10202                  20218,         /* A1 = -1.234009 */
10203                  -32655,        /* A2 = 0.996582 */
10204                  21337,         /* B2 = 0.651154 */
10205                  -13044,        /* B1 = -0.796143 */
10206                  21337,         /* B0 = 0.651154 */
10207                  20684,         /* A1 = -1.262512 */
10208                  -32657,        /* A2 = 0.996643 */
10209                  8572,          /* B2 = 0.261612 */
10210                  -5476,         /* B1 = -0.334244 */
10211                  8572,          /* B0 = 0.261612 */
10212                  5,             /* Internal filter scaling */
10213                  159,           /* Minimum in-band energy threshold */
10214                  21,            /* 21/32 in-band to broad-band ratio */
10215                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10216         },
10217         {                       /* f1200 */
10218                 19159,          /* A1 = -1.169373 */
10219                  -32456,        /* A2 = 0.990509 */
10220                  -335,          /* B2 = -0.010252 */
10221                  0,             /* B1 = 0.000000 */
10222                  335,           /* B0 = 0.010252 */
10223                  18966,         /* A1 = -1.157593 */
10224                  -32661,        /* A2 = 0.996735 */
10225                  6802,          /* B2 = 0.207588 */
10226                  -3900,         /* B1 = -0.238098 */
10227                  6802,          /* B0 = 0.207588 */
10228                  19467,         /* A1 = -1.188232 */
10229                  -32661,        /* A2 = 0.996765 */
10230                  25035,         /* B2 = 0.764008 */
10231                  -15049,        /* B1 = -0.918579 */
10232                  25035,         /* B0 = 0.764008 */
10233                  5,             /* Internal filter scaling */
10234                  159,           /* Minimum in-band energy threshold */
10235                  21,            /* 21/32 in-band to broad-band ratio */
10236                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10237         },
10238         {                       /* f1209 */
10239                 18976,          /* A1 = -1.158264 */
10240                  -32439,        /* A2 = 0.989990 */
10241                  -183,          /* B2 = -0.005588 */
10242                  0,             /* B1 = 0.000000 */
10243                  183,           /* B0 = 0.005588 */
10244                  18774,         /* A1 = -1.145874 */
10245                  -32650,        /* A2 = 0.996429 */
10246                  15468,         /* B2 = 0.472076 */
10247                  -8768,         /* B1 = -0.535217 */
10248                  15468,         /* B0 = 0.472076 */
10249                  19300,         /* A1 = -1.177979 */
10250                  -32652,        /* A2 = 0.996490 */
10251                  19840,         /* B2 = 0.605499 */
10252                  -11842,        /* B1 = -0.722809 */
10253                  19840,         /* B0 = 0.605499 */
10254                  5,             /* Internal filter scaling */
10255                  159,           /* Minimum in-band energy threshold */
10256                  21,            /* 21/32 in-band to broad-band ratio */
10257                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10258         },
10259         {                       /* f1330 */
10260                 16357,          /* A1 = -0.998413 */
10261                  -32368,        /* A2 = 0.987793 */
10262                  -217,          /* B2 = -0.006652 */
10263                  0,             /* B1 = 0.000000 */
10264                  217,           /* B0 = 0.006652 */
10265                  16107,         /* A1 = -0.983126 */
10266                  -32601,        /* A2 = 0.994904 */
10267                  11602,         /* B2 = 0.354065 */
10268                  -5555,         /* B1 = -0.339111 */
10269                  11602,         /* B0 = 0.354065 */
10270                  16722,         /* A1 = -1.020630 */
10271                  -32603,        /* A2 = 0.994965 */
10272                  15574,         /* B2 = 0.475311 */
10273                  -8176,         /* B1 = -0.499069 */
10274                  15574,         /* B0 = 0.475311 */
10275                  5,             /* Internal filter scaling */
10276                  159,           /* Minimum in-band energy threshold */
10277                  21,            /* 21/32 in-band to broad-band ratio */
10278                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10279         },
10280         {                       /* f1336 */
10281                 16234,          /* A1 = -0.990875 */
10282                  32404,         /* A2 = -0.988922 */
10283                  -193,          /* B2 = -0.005908 */
10284                  0,             /* B1 = 0.000000 */
10285                  193,           /* B0 = 0.005908 */
10286                  15986,         /* A1 = -0.975769 */
10287                  -32632,        /* A2 = 0.995880 */
10288                  18051,         /* B2 = 0.550903 */
10289                  -8658,         /* B1 = -0.528473 */
10290                  18051,         /* B0 = 0.550903 */
10291                  16591,         /* A1 = -1.012695 */
10292                  -32634,        /* A2 = 0.995941 */
10293                  15736,         /* B2 = 0.480240 */
10294                  -8125,         /* B1 = -0.495926 */
10295                  15736,         /* B0 = 0.480240 */
10296                  5,             /* Internal filter scaling */
10297                  159,           /* Minimum in-band energy threshold */
10298                  21,            /* 21/32 in-band to broad-band ratio */
10299                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10300         },
10301         {                       /* f1366 */
10302                 15564,          /* A1 = -0.949982 */
10303                  -32404,        /* A2 = 0.988922 */
10304                  -269,          /* B2 = -0.008216 */
10305                  0,             /* B1 = 0.000000 */
10306                  269,           /* B0 = 0.008216 */
10307                  15310,         /* A1 = -0.934479 */
10308                  -32632,        /* A2 = 0.995880 */
10309                  10815,         /* B2 = 0.330063 */
10310                  -4962,         /* B1 = -0.302887 */
10311                  10815,         /* B0 = 0.330063 */
10312                  15924,         /* A1 = -0.971924 */
10313                  -32634,        /* A2 = 0.995941 */
10314                  18880,         /* B2 = 0.576172 */
10315                  -9364,         /* B1 = -0.571594 */
10316                  18880,         /* B0 = 0.576172 */
10317                  5,             /* Internal filter scaling */
10318                  159,           /* Minimum in-band energy threshold */
10319                  21,            /* 21/32 in-band to broad-band ratio */
10320                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10321         },
10322         {                       /* f1380 */
10323                 15247,          /* A1 = -0.930603 */
10324                  -32397,        /* A2 = 0.988708 */
10325                  -244,          /* B2 = -0.007451 */
10326                  0,             /* B1 = 0.000000 */
10327                  244,           /* B0 = 0.007451 */
10328                  14989,         /* A1 = -0.914886 */
10329                  -32627,        /* A2 = 0.995697 */
10330                  18961,         /* B2 = 0.578644 */
10331                  -8498,         /* B1 = -0.518707 */
10332                  18961,         /* B0 = 0.578644 */
10333                  15608,         /* A1 = -0.952667 */
10334                  -32628,        /* A2 = 0.995758 */
10335                  11145,         /* B2 = 0.340134 */
10336                  -5430,         /* B1 = -0.331467 */
10337                  11145,         /* B0 = 0.340134 */
10338                  5,             /* Internal filter scaling */
10339                  159,           /* Minimum in-band energy threshold */
10340                  21,            /* 21/32 in-band to broad-band ratio */
10341                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10342         },
10343         {                       /* f1400 */
10344                 14780,          /* A1 = -0.902130 */
10345                  -32393,        /* A2 = 0.988586 */
10346                  -396,          /* B2 = -0.012086 */
10347                  0,             /* B1 = 0.000000 */
10348                  396,           /* B0 = 0.012086 */
10349                  14510,         /* A1 = -0.885651 */
10350                  -32630,        /* A2 = 0.995819 */
10351                  6326,          /* B2 = 0.193069 */
10352                  -2747,         /* B1 = -0.167671 */
10353                  6326,          /* B0 = 0.193069 */
10354                  15154,         /* A1 = -0.924957 */
10355                  -32632,        /* A2 = 0.995850 */
10356                  23235,         /* B2 = 0.709076 */
10357                  -10983,        /* B1 = -0.670380 */
10358                  23235,         /* B0 = 0.709076 */
10359                  5,             /* Internal filter scaling */
10360                  159,           /* Minimum in-band energy threshold */
10361                  21,            /* 21/32 in-band to broad-band ratio */
10362                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10363         },
10364         {                       /* f1477 */
10365                 13005,          /* A1 = -0.793793 */
10366                  -32368,        /* A2 = 0.987823 */
10367                  -500,          /* B2 = -0.015265 */
10368                  0,             /* B1 = 0.000000 */
10369                  500,           /* B0 = 0.015265 */
10370                  12708,         /* A1 = -0.775665 */
10371                  -32615,        /* A2 = 0.995331 */
10372                  11420,         /* B2 = 0.348526 */
10373                  -4306,         /* B1 = -0.262833 */
10374                  11420,         /* B0 = 0.348526 */
10375                  13397,         /* A1 = -0.817688 */
10376                  -32615,        /* A2 = 0.995361 */
10377                  9454,          /* B2 = 0.288528 */
10378                  -3981,         /* B1 = -0.243027 */
10379                  9454,          /* B0 = 0.288528 */
10380                  5,             /* Internal filter scaling */
10381                  159,           /* Minimum in-band energy threshold */
10382                  21,            /* 21/32 in-band to broad-band ratio */
10383                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10384         },
10385         {                       /* f1600 */
10386                 10046,          /* A1 = -0.613190 */
10387                  -32331,        /* A2 = 0.986694 */
10388                  -455,          /* B2 = -0.013915 */
10389                  0,             /* B1 = 0.000000 */
10390                  455,           /* B0 = 0.013915 */
10391                  9694,          /* A1 = -0.591705 */
10392                  -32601,        /* A2 = 0.994934 */
10393                  6023,          /* B2 = 0.183815 */
10394                  -1708,         /* B1 = -0.104279 */
10395                  6023,          /* B0 = 0.183815 */
10396                  10478,         /* A1 = -0.639587 */
10397                  -32603,        /* A2 = 0.994965 */
10398                  22031,         /* B2 = 0.672333 */
10399                  -7342,         /* B1 = -0.448151 */
10400                  22031,         /* B0 = 0.672333 */
10401                  5,             /* Internal filter scaling */
10402                  159,           /* Minimum in-band energy threshold */
10403                  21,            /* 21/32 in-band to broad-band ratio */
10404                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10405         },
10406         {                       /* f1633_1638[] */
10407                 9181,           /* A1 = 0.560394 */
10408                  -32256,        /* A2 = -0.984375 */
10409                  -556,          /* B2 = -0.016975 */
10410                  0,             /* B1 = 0 */
10411                  556,           /* B0 = 0.016975 */
10412                  8757,          /* A1 = 0.534515 */
10413                  -32574,        /* A2 = -0.99408 */
10414                  8443,          /* B2 = 0.25769 */
10415                  -2135,         /* B1 = -0.130341 */
10416                  8443,          /* B0 = 0.25769 */
10417                  9691,          /* A1 = 0.591522 */
10418                  -32574,        /* A2 = -0.99411 */
10419                  15446,         /* B2 = 0.471375 */
10420                  -4809,         /* B1 = -0.293579 */
10421                  15446,         /* B0 = 0.471375 */
10422                  7,             /* Internal filter scaling */
10423                  159,           /* Minimum in-band energy threshold */
10424                  21,            /* 21/32 in-band to broad-band ratio */
10425                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10426         },
10427         {                       /* f1800 */
10428                 5076,           /* A1 = -0.309875 */
10429                  -32304,        /* A2 = 0.985840 */
10430                  -508,          /* B2 = -0.015503 */
10431                  0,             /* B1 = 0.000000 */
10432                  508,           /* B0 = 0.015503 */
10433                  4646,          /* A1 = -0.283600 */
10434                  -32605,        /* A2 = 0.995026 */
10435                  6742,          /* B2 = 0.205780 */
10436                  -878,          /* B1 = -0.053635 */
10437                  6742,          /* B0 = 0.205780 */
10438                  5552,          /* A1 = -0.338928 */
10439                  -32605,        /* A2 = 0.995056 */
10440                  23667,         /* B2 = 0.722260 */
10441                  -4297,         /* B1 = -0.262329 */
10442                  23667,         /* B0 = 0.722260 */
10443                  5,             /* Internal filter scaling */
10444                  159,           /* Minimum in-band energy threshold */
10445                  21,            /* 21/32 in-band to broad-band ratio */
10446                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10447         },
10448         {                       /* f1860 */
10449                 3569,           /* A1 = -0.217865 */
10450                  -32292,        /* A2 = 0.985504 */
10451                  -239,          /* B2 = -0.007322 */
10452                  0,             /* B1 = 0.000000 */
10453                  239,           /* B0 = 0.007322 */
10454                  3117,          /* A1 = -0.190277 */
10455                  -32603,        /* A2 = 0.994965 */
10456                  18658,         /* B2 = 0.569427 */
10457                  -1557,         /* B1 = -0.095032 */
10458                  18658,         /* B0 = 0.569427 */
10459                  4054,          /* A1 = -0.247437 */
10460                  -32603,        /* A2 = 0.994965 */
10461                  18886,         /* B2 = 0.576385 */
10462                  -2566,         /* B1 = -0.156647 */
10463                  18886,         /* B0 = 0.576385 */
10464                  5,             /* Internal filter scaling */
10465                  159,           /* Minimum in-band energy threshold */
10466                  21,            /* 21/32 in-band to broad-band ratio */
10467                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10468         },
10469 };
10470 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf)
10471 {
10472         unsigned short cmd;
10473         int cnt, max;
10474
10475         if (jf->filter > 3) {
10476                 return -1;
10477         }
10478         if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))        /* Select Filter */
10479
10480                 return -1;
10481         if (!jf->enable) {
10482                 if (ixj_WriteDSPCommand(0x5152, j))             /* Disable Filter */
10483
10484                         return -1;
10485                 else
10486                         return 0;
10487         } else {
10488                 if (ixj_WriteDSPCommand(0x5153, j))             /* Enable Filter */
10489
10490                         return -1;
10491                 /* Select the filter (f0 - f3) to use. */
10492                 if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))
10493                         return -1;
10494         }
10495         if (jf->freq < 12 && jf->freq > 3) {
10496                 /* Select the frequency for the selected filter. */
10497                 if (ixj_WriteDSPCommand(0x5170 + jf->freq, j))
10498                         return -1;
10499         } else if (jf->freq > 11) {
10500                 /* We need to load a programmable filter set for undefined */
10501                 /* frequencies.  So we will point the filter to a programmable set. */
10502                 /* Since there are only 4 filters and 4 programmable sets, we will */
10503                 /* just point the filter to the same number set and program it for the */
10504                 /* frequency we want. */
10505                 if (ixj_WriteDSPCommand(0x5170 + jf->filter, j))
10506                         return -1;
10507                 if (j->ver.low != 0x12) {
10508                         cmd = 0x515B;
10509                         max = 19;
10510                 } else {
10511                         cmd = 0x515E;
10512                         max = 15;
10513                 }
10514                 if (ixj_WriteDSPCommand(cmd, j))
10515                         return -1;
10516                 for (cnt = 0; cnt < max; cnt++) {
10517                         if (ixj_WriteDSPCommand(tone_table[jf->freq - 12][cnt], j))
10518                                 return -1;
10519                 }
10520         }
10521         j->filter_en[jf->filter] = jf->enable;
10522         return 0;
10523 }
10524
10525 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr)
10526 {
10527         unsigned short cmd;
10528         int cnt, max;
10529         if (jfr->filter > 3) {
10530                 return -1;
10531         }
10532         if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))       /* Select Filter */
10533                 return -1;
10534
10535         if (!jfr->enable) {
10536                 if (ixj_WriteDSPCommand(0x5152, j))             /* Disable Filter */
10537                         return -1;
10538                 else
10539                         return 0;
10540         } else {
10541                 if (ixj_WriteDSPCommand(0x5153, j))             /* Enable Filter */
10542                         return -1;
10543                 /* Select the filter (f0 - f3) to use. */
10544                 if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))
10545                         return -1;
10546         }
10547         /* We need to load a programmable filter set for undefined */
10548         /* frequencies.  So we will point the filter to a programmable set. */
10549         /* Since there are only 4 filters and 4 programmable sets, we will */
10550         /* just point the filter to the same number set and program it for the */
10551         /* frequency we want. */
10552         if (ixj_WriteDSPCommand(0x5170 + jfr->filter, j))
10553                 return -1;
10554         if (j->ver.low != 0x12) {
10555                 cmd = 0x515B;
10556                 max = 19;
10557         } else {
10558                 cmd = 0x515E;
10559                 max = 15;
10560         }
10561         if (ixj_WriteDSPCommand(cmd, j))
10562                 return -1;
10563         for (cnt = 0; cnt < max; cnt++) {
10564                 if (ixj_WriteDSPCommand(jfr->coeff[cnt], j))
10565                         return -1;
10566         }
10567         j->filter_en[jfr->filter] = jfr->enable;
10568         return 0;
10569 }
10570
10571 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti)
10572 {
10573         int freq0, freq1;
10574         unsigned short data;
10575         if (ti->freq0) {
10576                 freq0 = ti->freq0;
10577         } else {
10578                 freq0 = 0x7FFF;
10579         }
10580
10581         if (ti->freq1) {
10582                 freq1 = ti->freq1;
10583         } else {
10584                 freq1 = 0x7FFF;
10585         }
10586
10587         if(ti->tone_index > 12 && ti->tone_index < 28)
10588         {
10589                 if (ixj_WriteDSPCommand(0x6800 + ti->tone_index, j))
10590                         return -1;
10591                 if (ixj_WriteDSPCommand(0x6000 + (ti->gain1 << 4) + ti->gain0, j))
10592                         return -1;
10593                 data = freq0;
10594                 if (ixj_WriteDSPCommand(data, j))
10595                         return -1;
10596                 data = freq1;
10597                 if (ixj_WriteDSPCommand(data, j))
10598                         return -1;
10599         }
10600         return freq0;
10601 }
10602