ath5k: Add Spur filter support on newer chips
[linux-2.6] / 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 /*
45  * Revision 4.8  2003/07/09 19:39:00  Daniele Bellucci
46  * Audit some copy_*_user and minor cleanup.
47  *
48  * Revision 4.7  2001/08/13 06:19:33  craigs
49  * Added additional changes from Alan Cox and John Anderson for
50  * 2.2 to 2.4 cleanup and bounds checking
51  *
52  * Revision 4.6  2001/08/13 01:05:05  craigs
53  * Really fixed PHONE_QUERY_CODEC problem this time
54  *
55  * Revision 4.5  2001/08/13 00:11:03  craigs
56  * Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson
57  *
58  * Revision 4.4  2001/08/07 07:58:12  craigs
59  * Changed back to three digit version numbers
60  * Added tagbuild target to allow automatic and easy tagging of versions
61  *
62  * Revision 4.3  2001/08/07 07:24:47  craigs
63  * Added ixj-ver.h to allow easy configuration management of driver
64  * Added display of version number in /prox/ixj
65  *
66  * Revision 4.2  2001/08/06 07:07:19  craigs
67  * Reverted IXJCTL_DSP_TYPE and IXJCTL_DSP_VERSION files to original
68  * behaviour of returning int rather than short *
69  *
70  * Revision 4.1  2001/08/05 00:17:37  craigs
71  * More changes for correct PCMCIA installation
72  * Start of changes for backward Linux compatibility
73  *
74  * Revision 4.0  2001/08/04 12:33:12  craigs
75  * New version using GNU autoconf
76  *
77  * Revision 3.105  2001/07/20 23:14:32  eokerson
78  * More work on CallerID generation when using ring cadences.
79  *
80  * Revision 3.104  2001/07/06 01:33:55  eokerson
81  * Some bugfixes from Robert Vojta <vojta@ipex.cz> and a few mods to the Makefile.
82  *
83  * Revision 3.103  2001/07/05 19:20:16  eokerson
84  * Updated HOWTO
85  * Changed mic gain to 30dB on Internet LineJACK mic/speaker port.
86  *
87  * Revision 3.102  2001/07/03 23:51:21  eokerson
88  * Un-mute mic on Internet LineJACK when in speakerphone mode.
89  *
90  * Revision 3.101  2001/07/02 19:26:56  eokerson
91  * Removed initialiazation of ixjdebug and ixj_convert_loaded so they will go in the .bss instead of the .data
92  *
93  * Revision 3.100  2001/07/02 19:18:27  eokerson
94  * Changed driver to make dynamic allocation possible.  We now pass IXJ * between functions instead of array indexes.
95  * Fixed the way the POTS and PSTN ports interact during a PSTN call to allow local answering.
96  * Fixed speaker mode on Internet LineJACK.
97  *
98  * Revision 3.99  2001/05/09 14:11:16  eokerson
99  * Fixed kmalloc error in ixj_build_filter_cadence.  Thanks David Chan <cat@waulogy.stanford.edu>.
100  *
101  * Revision 3.98  2001/05/08 19:55:33  eokerson
102  * Fixed POTS hookstate detection while it is connected to PSTN port.
103  *
104  * Revision 3.97  2001/05/08 00:01:04  eokerson
105  * Fixed kernel oops when sending caller ID data.
106  *
107  * Revision 3.96  2001/05/04 23:09:30  eokerson
108  * Now uses one kernel timer for each card, instead of one for the entire driver.
109  *
110  * Revision 3.95  2001/04/25 22:06:47  eokerson
111  * Fixed squawking at beginning of some G.723.1 calls.
112  *
113  * Revision 3.94  2001/04/03 23:42:00  eokerson
114  * Added linear volume ioctls
115  * Added raw filter load ioctl
116  *
117  * Revision 3.93  2001/02/27 01:00:06  eokerson
118  * Fixed blocking in CallerID.
119  * Reduced size of ixj structure for smaller driver footprint.
120  *
121  * Revision 3.92  2001/02/20 22:02:59  eokerson
122  * Fixed isapnp and pcmcia module compatibility for 2.4.x kernels.
123  * Improved PSTN ring detection.
124  * Fixed wink generation on POTS ports.
125  *
126  * Revision 3.91  2001/02/13 00:55:44  eokerson
127  * Turn AEC back on after changing frame sizes.
128  *
129  * Revision 3.90  2001/02/12 16:42:00  eokerson
130  * Added ALAW codec, thanks to Fabio Ferrari for the table based converters to make ALAW from ULAW.
131  *
132  * Revision 3.89  2001/02/12 15:41:16  eokerson
133  * Fix from Artis Kugevics - Tone gains were not being set correctly.
134  *
135  * Revision 3.88  2001/02/05 23:25:42  eokerson
136  * Fixed lockup bugs with deregister.
137  *
138  * Revision 3.87  2001/01/29 21:00:39  eokerson
139  * Fix from Fabio Ferrari <fabio.ferrari@digitro.com.br> to properly handle EAGAIN and EINTR during non-blocking write.
140  * Updated copyright date.
141  *
142  * Revision 3.86  2001/01/23 23:53:46  eokerson
143  * Fixes to G.729 compatibility.
144  *
145  * Revision 3.85  2001/01/23 21:30:36  eokerson
146  * Added verbage about cards supported.
147  * Removed commands that put the card in low power mode at some times that it should not be in low power mode.
148  *
149  * Revision 3.84  2001/01/22 23:32:10  eokerson
150  * Some bugfixes from David Huggins-Daines, <dhd@cepstral.com> and other cleanups.
151  *
152  * Revision 3.83  2001/01/19 14:51:41  eokerson
153  * Fixed ixj_WriteDSPCommand to decrement usage counter when command fails.
154  *
155  * Revision 3.82  2001/01/19 00:34:49  eokerson
156  * Added verbosity to write overlap errors.
157  *
158  * Revision 3.81  2001/01/18 23:56:54  eokerson
159  * Fixed PSTN line test functions.
160  *
161  * Revision 3.80  2001/01/18 22:29:27  eokerson
162  * Updated AEC/AGC values for different cards.
163  *
164  * Revision 3.79  2001/01/17 02:58:54  eokerson
165  * Fixed AEC reset after Caller ID.
166  * Fixed Codec lockup after Caller ID on Call Waiting when not using 30ms frames.
167  *
168  * Revision 3.78  2001/01/16 19:43:09  eokerson
169  * Added support for Linux 2.4.x kernels.
170  *
171  * Revision 3.77  2001/01/09 04:00:52  eokerson
172  * Linetest will now test the line, even if it has previously succeded.
173  *
174  * Revision 3.76  2001/01/08 19:27:00  eokerson
175  * Fixed problem with standard cable on Internet PhoneCARD.
176  *
177  * Revision 3.75  2000/12/22 16:52:14  eokerson
178  * Modified to allow hookstate detection on the POTS port when the PSTN port is selected.
179  *
180  * Revision 3.74  2000/12/08 22:41:50  eokerson
181  * Added capability for G729B.
182  *
183  * Revision 3.73  2000/12/07 23:35:16  eokerson
184  * Added capability to have different ring pattern before CallerID data.
185  * Added hookstate checks in CallerID routines to stop FSK.
186  *
187  * Revision 3.72  2000/12/06 19:31:31  eokerson
188  * Modified signal behavior to only send one signal per event.
189  *
190  * Revision 3.71  2000/12/06 03:23:08  eokerson
191  * Fixed CallerID on Call Waiting.
192  *
193  * Revision 3.70  2000/12/04 21:29:37  eokerson
194  * Added checking to Smart Cable gain functions.
195  *
196  * Revision 3.69  2000/12/04 21:05:20  eokerson
197  * Changed ixjdebug levels.
198  * Added ioctls to change gains in Internet Phone CARD Smart Cable.
199  *
200  * Revision 3.68  2000/12/04 00:17:21  craigs
201  * Changed mixer voice gain to +6dB rather than 0dB
202  *
203  * Revision 3.67  2000/11/30 21:25:51  eokerson
204  * Fixed write signal errors.
205  *
206  * Revision 3.66  2000/11/29 22:42:44  eokerson
207  * Fixed PSTN ring detect problems.
208  *
209  * Revision 3.65  2000/11/29 07:31:55  craigs
210  * Added new 425Hz filter co-efficients
211  * Added card-specific DTMF prescaler initialisation
212  *
213  * Revision 3.64  2000/11/28 14:03:32  craigs
214  * Changed certain mixer initialisations to be 0dB rather than 12dB
215  * Added additional information to /proc/ixj
216  *
217  * Revision 3.63  2000/11/28 11:38:41  craigs
218  * Added display of AEC modes in AUTO and AGC mode
219  *
220  * Revision 3.62  2000/11/28 04:05:44  eokerson
221  * Improved PSTN ring detection routine.
222  *
223  * Revision 3.61  2000/11/27 21:53:12  eokerson
224  * Fixed flash detection.
225  *
226  * Revision 3.60  2000/11/27 15:57:29  eokerson
227  * More work on G.729 load routines.
228  *
229  * Revision 3.59  2000/11/25 21:55:12  eokerson
230  * Fixed errors in G.729 load routine.
231  *
232  * Revision 3.58  2000/11/25 04:08:29  eokerson
233  * Added board locks around G.729 and TS85 load routines.
234  *
235  * Revision 3.57  2000/11/24 05:35:17  craigs
236  * Added ability to retrieve mixer values on LineJACK
237  * Added complete initialisation of all mixer values at startup
238  * Fixed spelling mistake
239  *
240  * Revision 3.56  2000/11/23 02:52:11  robertj
241  * Added cvs change log keyword.
242  * Fixed bug in capabilities list when using G.729 module.
243  *
244  */
245
246 #include "ixj-ver.h"
247
248 #define PERFMON_STATS
249 #define IXJDEBUG 0
250 #define MAXRINGS 5
251
252 #include <linux/module.h>
253
254 #include <linux/init.h>
255 #include <linux/sched.h>
256 #include <linux/kernel.h>       /* printk() */
257 #include <linux/fs.h>           /* everything... */
258 #include <linux/errno.h>        /* error codes */
259 #include <linux/slab.h>
260 #include <linux/mm.h>
261 #include <linux/ioport.h>
262 #include <linux/interrupt.h>
263 #include <linux/proc_fs.h>
264 #include <linux/poll.h>
265 #include <linux/timer.h>
266 #include <linux/delay.h>
267 #include <linux/pci.h>
268
269 #include <asm/io.h>
270 #include <asm/uaccess.h>
271
272 #include <linux/isapnp.h>
273
274 #include "ixj.h"
275
276 #define TYPE(inode) (iminor(inode) >> 4)
277 #define NUM(inode) (iminor(inode) & 0xf)
278
279 static int ixjdebug;
280 static int hertz = HZ;
281 static int samplerate = 100;
282
283 module_param(ixjdebug, int, 0);
284
285 static struct pci_device_id ixj_pci_tbl[] __devinitdata = {
286         { PCI_VENDOR_ID_QUICKNET, PCI_DEVICE_ID_QUICKNET_XJ,
287           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
288         { }
289 };
290
291 MODULE_DEVICE_TABLE(pci, ixj_pci_tbl);
292
293 /************************************************************************
294 *
295 * ixjdebug meanings are now bit mapped instead of level based
296 * Values can be or'ed together to turn on multiple messages
297 *
298 * bit  0 (0x0001) = any failure
299 * bit  1 (0x0002) = general messages
300 * bit  2 (0x0004) = POTS ringing related
301 * bit  3 (0x0008) = PSTN events
302 * bit  4 (0x0010) = PSTN Cadence state details
303 * bit  5 (0x0020) = Tone detection triggers
304 * bit  6 (0x0040) = Tone detection cadence details
305 * bit  7 (0x0080) = ioctl tracking
306 * bit  8 (0x0100) = signal tracking
307 * bit  9 (0x0200) = CallerID generation details
308 *
309 ************************************************************************/
310
311 #ifdef IXJ_DYN_ALLOC
312
313 static IXJ *ixj[IXJMAX];
314 #define get_ixj(b)      ixj[(b)]
315
316 /*
317  *      Allocate a free IXJ device
318  */
319  
320 static IXJ *ixj_alloc()
321 {
322         for(cnt=0; cnt<IXJMAX; cnt++)
323         {
324                 if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
325                 {
326                         j = kmalloc(sizeof(IXJ), GFP_KERNEL);
327                         if (j == NULL)
328                                 return NULL;
329                         ixj[cnt] = j;
330                         return j;
331                 }
332         }
333         return NULL;
334 }
335
336 static void ixj_fsk_free(IXJ *j)
337 {
338         kfree(j->fskdata);
339         j->fskdata = NULL;
340 }
341
342 static void ixj_fsk_alloc(IXJ *j)
343 {
344         if(!j->fskdata) {
345                 j->fskdata = kmalloc(8000, GFP_KERNEL);
346                 if (!j->fskdata) {
347                         if(ixjdebug & 0x0200) {
348                                 printk("IXJ phone%d - allocate failed\n", j->board);
349                         }
350                         return;
351                 } else {
352                         j->fsksize = 8000;
353                         if(ixjdebug & 0x0200) {
354                                 printk("IXJ phone%d - allocate succeded\n", j->board);
355                         }
356                 }
357         }
358 }
359
360 #else
361
362 static IXJ ixj[IXJMAX];
363 #define get_ixj(b)      (&ixj[(b)])
364
365 /*
366  *      Allocate a free IXJ device
367  */
368  
369 static IXJ *ixj_alloc(void)
370 {
371         int cnt;
372         for(cnt=0; cnt<IXJMAX; cnt++) {
373                 if(!ixj[cnt].DSPbase)
374                         return &ixj[cnt];
375         }
376         return NULL;
377 }
378
379 static inline void ixj_fsk_free(IXJ *j) {;}
380
381 static inline void ixj_fsk_alloc(IXJ *j)
382 {
383         j->fsksize = 8000;
384 }
385
386 #endif
387
388 #ifdef PERFMON_STATS
389 #define ixj_perfmon(x)  ((x)++)
390 #else
391 #define ixj_perfmon(x)  do { } while(0)
392 #endif
393
394 static int ixj_convert_loaded;
395
396 static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
397
398 /************************************************************************
399 *
400 * These are function definitions to allow external modules to register
401 * enhanced functionality call backs.
402 *
403 ************************************************************************/
404
405 static int Stub(IXJ * J, unsigned long arg)
406 {
407         return 0;
408 }
409
410 static IXJ_REGFUNC ixj_PreRead = &Stub;
411 static IXJ_REGFUNC ixj_PostRead = &Stub;
412 static IXJ_REGFUNC ixj_PreWrite = &Stub;
413 static IXJ_REGFUNC ixj_PostWrite = &Stub;
414
415 static void ixj_read_frame(IXJ *j);
416 static void ixj_write_frame(IXJ *j);
417 static void ixj_init_timer(IXJ *j);
418 static void ixj_add_timer(IXJ * j);
419 static void ixj_timeout(unsigned long ptr);
420 static int read_filters(IXJ *j);
421 static int LineMonitor(IXJ *j);
422 static int ixj_fasync(int fd, struct file *, int mode);
423 static int ixj_set_port(IXJ *j, int arg);
424 static int ixj_set_pots(IXJ *j, int arg);
425 static int ixj_hookstate(IXJ *j);
426 static int ixj_record_start(IXJ *j);
427 static void ixj_record_stop(IXJ *j);
428 static void set_rec_volume(IXJ *j, int volume);
429 static int get_rec_volume(IXJ *j);
430 static int set_rec_codec(IXJ *j, int rate);
431 static void ixj_vad(IXJ *j, int arg);
432 static int ixj_play_start(IXJ *j);
433 static void ixj_play_stop(IXJ *j);
434 static int ixj_set_tone_on(unsigned short arg, IXJ *j);
435 static int ixj_set_tone_off(unsigned short, IXJ *j);
436 static int ixj_play_tone(IXJ *j, char tone);
437 static void ixj_aec_start(IXJ *j, int level);
438 static int idle(IXJ *j);
439 static void ixj_ring_on(IXJ *j);
440 static void ixj_ring_off(IXJ *j);
441 static void aec_stop(IXJ *j);
442 static void ixj_ringback(IXJ *j);
443 static void ixj_busytone(IXJ *j);
444 static void ixj_dialtone(IXJ *j);
445 static void ixj_cpt_stop(IXJ *j);
446 static char daa_int_read(IXJ *j);
447 static char daa_CR_read(IXJ *j, int cr);
448 static int daa_set_mode(IXJ *j, int mode);
449 static int ixj_linetest(IXJ *j);
450 static int ixj_daa_write(IXJ *j);
451 static int ixj_daa_cid_read(IXJ *j);
452 static void DAA_Coeff_US(IXJ *j);
453 static void DAA_Coeff_UK(IXJ *j);
454 static void DAA_Coeff_France(IXJ *j);
455 static void DAA_Coeff_Germany(IXJ *j);
456 static void DAA_Coeff_Australia(IXJ *j);
457 static void DAA_Coeff_Japan(IXJ *j);
458 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
459 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
460 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
461 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
462 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
463 /* Serial Control Interface funtions */
464 static int SCI_Control(IXJ *j, int control);
465 static int SCI_Prepare(IXJ *j);
466 static int SCI_WaitHighSCI(IXJ *j);
467 static int SCI_WaitLowSCI(IXJ *j);
468 static DWORD PCIEE_GetSerialNumber(WORD wAddress);
469 static int ixj_PCcontrol_wait(IXJ *j);
470 static void ixj_pre_cid(IXJ *j);
471 static void ixj_write_cid(IXJ *j);
472 static void ixj_write_cid_bit(IXJ *j, int bit);
473 static int set_base_frame(IXJ *j, int size);
474 static int set_play_codec(IXJ *j, int rate);
475 static void set_rec_depth(IXJ *j, int depth);
476 static int ixj_mixer(long val, IXJ *j);
477
478 /************************************************************************
479 CT8020/CT8021 Host Programmers Model
480 Host address    Function                                        Access
481 DSPbase +
482 0-1             Aux Software Status Register (reserved)         Read Only
483 2-3             Software Status Register                        Read Only
484 4-5             Aux Software Control Register (reserved)        Read Write
485 6-7             Software Control Register                       Read Write
486 8-9             Hardware Status Register                        Read Only
487 A-B             Hardware Control Register                       Read Write
488 C-D Host Transmit (Write) Data Buffer Access Port (buffer input)Write Only
489 E-F Host Recieve (Read) Data Buffer Access Port (buffer input)  Read Only
490 ************************************************************************/
491
492 static inline void ixj_read_HSR(IXJ *j)
493 {
494         j->hsr.bytes.low = inb_p(j->DSPbase + 8);
495         j->hsr.bytes.high = inb_p(j->DSPbase + 9);
496 }
497
498 static inline int IsControlReady(IXJ *j)
499 {
500         ixj_read_HSR(j);
501         return j->hsr.bits.controlrdy ? 1 : 0;
502 }
503
504 static inline int IsPCControlReady(IXJ *j)
505 {
506         j->pccr1.byte = inb_p(j->XILINXbase + 3);
507         return j->pccr1.bits.crr ? 1 : 0;
508 }
509
510 static inline int IsStatusReady(IXJ *j)
511 {
512         ixj_read_HSR(j);
513         return j->hsr.bits.statusrdy ? 1 : 0;
514 }
515
516 static inline int IsRxReady(IXJ *j)
517 {
518         ixj_read_HSR(j);
519         ixj_perfmon(j->rxreadycheck);
520         return j->hsr.bits.rxrdy ? 1 : 0;
521 }
522
523 static inline int IsTxReady(IXJ *j)
524 {
525         ixj_read_HSR(j);
526         ixj_perfmon(j->txreadycheck);
527         return j->hsr.bits.txrdy ? 1 : 0;
528 }
529
530 static inline void set_play_volume(IXJ *j, int volume)
531 {
532         if (ixjdebug & 0x0002)
533                 printk(KERN_INFO "IXJ: /dev/phone%d Setting Play Volume to 0x%4.4x\n", j->board, volume);
534         ixj_WriteDSPCommand(0xCF02, j);
535         ixj_WriteDSPCommand(volume, j);
536 }
537
538 static int set_play_volume_linear(IXJ *j, int volume)
539 {
540         int newvolume, dspplaymax;
541
542         if (ixjdebug & 0x0002)
543                 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Play Volume to 0x%4.4x\n", j->board, volume);
544         if(volume > 100 || volume < 0) {
545                 return -1;
546         }
547
548         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
549         switch (j->cardtype) {
550         case QTI_PHONEJACK:
551                 dspplaymax = 0x380;
552                 break;
553         case QTI_LINEJACK:
554                 if(j->port == PORT_PSTN) {
555                         dspplaymax = 0x48;
556                 } else {
557                         dspplaymax = 0x100;
558                 }
559                 break;
560         case QTI_PHONEJACK_LITE:
561                 dspplaymax = 0x380;
562                 break;
563         case QTI_PHONEJACK_PCI:
564                 dspplaymax = 0x6C;
565                 break;
566         case QTI_PHONECARD:
567                 dspplaymax = 0x50;
568                 break;
569         default:
570                 return -1;
571         }
572         newvolume = (dspplaymax * volume) / 100;
573         set_play_volume(j, newvolume);
574         return 0;
575 }
576
577 static inline void set_play_depth(IXJ *j, int depth)
578 {
579         if (depth > 60)
580                 depth = 60;
581         if (depth < 0)
582                 depth = 0;
583         ixj_WriteDSPCommand(0x5280 + depth, j);
584 }
585
586 static inline int get_play_volume(IXJ *j)
587 {
588         ixj_WriteDSPCommand(0xCF00, j);
589         return j->ssr.high << 8 | j->ssr.low;
590 }
591
592 static int get_play_volume_linear(IXJ *j)
593 {
594         int volume, newvolume, dspplaymax;
595
596         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
597         switch (j->cardtype) {
598         case QTI_PHONEJACK:
599                 dspplaymax = 0x380;
600                 break;
601         case QTI_LINEJACK:
602                 if(j->port == PORT_PSTN) {
603                         dspplaymax = 0x48;
604                 } else {
605                         dspplaymax = 0x100;
606                 }
607                 break;
608         case QTI_PHONEJACK_LITE:
609                 dspplaymax = 0x380;
610                 break;
611         case QTI_PHONEJACK_PCI:
612                 dspplaymax = 0x6C;
613                 break;
614         case QTI_PHONECARD:
615                 dspplaymax = 100;
616                 break;
617         default:
618                 return -1;
619         }
620         volume = get_play_volume(j);
621         newvolume = (volume * 100) / dspplaymax;
622         if(newvolume > 100)
623                 newvolume = 100;
624         return newvolume;
625 }
626
627 static inline BYTE SLIC_GetState(IXJ *j)
628 {
629         if (j->cardtype == QTI_PHONECARD) {
630                 j->pccr1.byte = 0;
631                 j->psccr.bits.dev = 3;
632                 j->psccr.bits.rw = 1;
633                 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
634                 ixj_PCcontrol_wait(j);
635                 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
636                 ixj_PCcontrol_wait(j);
637                 if (j->pslic.bits.powerdown)
638                         return PLD_SLIC_STATE_OC;
639                 else if (!j->pslic.bits.ring0 && !j->pslic.bits.ring1)
640                         return PLD_SLIC_STATE_ACTIVE;
641                 else
642                         return PLD_SLIC_STATE_RINGING;
643         } else {
644                 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
645         }
646         return j->pld_slicr.bits.state;
647 }
648
649 static bool SLIC_SetState(BYTE byState, IXJ *j)
650 {
651         bool fRetVal = false;
652
653         if (j->cardtype == QTI_PHONECARD) {
654                 if (j->flags.pcmciasct) {
655                         switch (byState) {
656                         case PLD_SLIC_STATE_TIPOPEN:
657                         case PLD_SLIC_STATE_OC:
658                                 j->pslic.bits.powerdown = 1;
659                                 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
660                                 fRetVal = true;
661                                 break;
662                         case PLD_SLIC_STATE_RINGING:
663                                 if (j->readers || j->writers) {
664                                         j->pslic.bits.powerdown = 0;
665                                         j->pslic.bits.ring0 = 1;
666                                         j->pslic.bits.ring1 = 0;
667                                         fRetVal = true;
668                                 }
669                                 break;
670                         case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
671
672                         case PLD_SLIC_STATE_STANDBY:
673                         case PLD_SLIC_STATE_ACTIVE:
674                                 if (j->readers || j->writers) {
675                                         j->pslic.bits.powerdown = 0;
676                                 } else {
677                                         j->pslic.bits.powerdown = 1;
678                                 }
679                                 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
680                                 fRetVal = true;
681                                 break;
682                         case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
683
684                         case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
685
686                         default:
687                                 fRetVal = false;
688                                 break;
689                         }
690                         j->psccr.bits.dev = 3;
691                         j->psccr.bits.rw = 0;
692                         outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
693                         ixj_PCcontrol_wait(j);
694                 }
695         } else {
696                 /* Set the C1, C2, C3 & B2EN signals. */
697                 switch (byState) {
698                 case PLD_SLIC_STATE_OC:
699                         j->pld_slicw.bits.c1 = 0;
700                         j->pld_slicw.bits.c2 = 0;
701                         j->pld_slicw.bits.c3 = 0;
702                         j->pld_slicw.bits.b2en = 0;
703                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
704                         fRetVal = true;
705                         break;
706                 case PLD_SLIC_STATE_RINGING:
707                         j->pld_slicw.bits.c1 = 1;
708                         j->pld_slicw.bits.c2 = 0;
709                         j->pld_slicw.bits.c3 = 0;
710                         j->pld_slicw.bits.b2en = 1;
711                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
712                         fRetVal = true;
713                         break;
714                 case PLD_SLIC_STATE_ACTIVE:
715                         j->pld_slicw.bits.c1 = 0;
716                         j->pld_slicw.bits.c2 = 1;
717                         j->pld_slicw.bits.c3 = 0;
718                         j->pld_slicw.bits.b2en = 0;
719                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
720                         fRetVal = true;
721                         break;
722                 case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
723
724                         j->pld_slicw.bits.c1 = 1;
725                         j->pld_slicw.bits.c2 = 1;
726                         j->pld_slicw.bits.c3 = 0;
727                         j->pld_slicw.bits.b2en = 0;
728                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
729                         fRetVal = true;
730                         break;
731                 case PLD_SLIC_STATE_TIPOPEN:
732                         j->pld_slicw.bits.c1 = 0;
733                         j->pld_slicw.bits.c2 = 0;
734                         j->pld_slicw.bits.c3 = 1;
735                         j->pld_slicw.bits.b2en = 0;
736                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
737                         fRetVal = true;
738                         break;
739                 case PLD_SLIC_STATE_STANDBY:
740                         j->pld_slicw.bits.c1 = 1;
741                         j->pld_slicw.bits.c2 = 0;
742                         j->pld_slicw.bits.c3 = 1;
743                         j->pld_slicw.bits.b2en = 1;
744                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
745                         fRetVal = true;
746                         break;
747                 case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
748
749                         j->pld_slicw.bits.c1 = 0;
750                         j->pld_slicw.bits.c2 = 1;
751                         j->pld_slicw.bits.c3 = 1;
752                         j->pld_slicw.bits.b2en = 0;
753                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
754                         fRetVal = true;
755                         break;
756                 case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
757
758                         j->pld_slicw.bits.c1 = 1;
759                         j->pld_slicw.bits.c2 = 1;
760                         j->pld_slicw.bits.c3 = 1;
761                         j->pld_slicw.bits.b2en = 0;
762                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
763                         fRetVal = true;
764                         break;
765                 default:
766                         fRetVal = false;
767                         break;
768                 }
769         }
770
771         return fRetVal;
772 }
773
774 static int ixj_wink(IXJ *j)
775 {
776         BYTE slicnow;
777
778         slicnow = SLIC_GetState(j);
779
780         j->pots_winkstart = jiffies;
781         SLIC_SetState(PLD_SLIC_STATE_OC, j);
782
783         msleep(jiffies_to_msecs(j->winktime));
784
785         SLIC_SetState(slicnow, j);
786         return 0;
787 }
788
789 static void ixj_init_timer(IXJ *j)
790 {
791         init_timer(&j->timer);
792         j->timer.function = ixj_timeout;
793         j->timer.data = (unsigned long)j;
794 }
795
796 static void ixj_add_timer(IXJ *j)
797 {
798         j->timer.expires = jiffies + (hertz / samplerate);
799         add_timer(&j->timer);
800 }
801
802 static void ixj_tone_timeout(IXJ *j)
803 {
804         IXJ_TONE ti;
805
806         j->tone_state++;
807         if (j->tone_state == 3) {
808                 j->tone_state = 0;
809                 if (j->cadence_t) {
810                         j->tone_cadence_state++;
811                         if (j->tone_cadence_state >= j->cadence_t->elements_used) {
812                                 switch (j->cadence_t->termination) {
813                                 case PLAY_ONCE:
814                                         ixj_cpt_stop(j);
815                                         break;
816                                 case REPEAT_LAST_ELEMENT:
817                                         j->tone_cadence_state--;
818                                         ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
819                                         break;
820                                 case REPEAT_ALL:
821                                         j->tone_cadence_state = 0;
822                                         if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
823                                                 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
824                                                 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
825                                                 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
826                                                 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
827                                                 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
828                                                 ixj_init_tone(j, &ti);
829                                         }
830                                         ixj_set_tone_on(j->cadence_t->ce[0].tone_on_time, j);
831                                         ixj_set_tone_off(j->cadence_t->ce[0].tone_off_time, j);
832                                         ixj_play_tone(j, j->cadence_t->ce[0].index);
833                                         break;
834                                 }
835                         } else {
836                                 if (j->cadence_t->ce[j->tone_cadence_state].gain0) {
837                                         ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
838                                         ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
839                                         ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
840                                         ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
841                                         ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
842                                         ixj_init_tone(j, &ti);
843                                 }
844                                 ixj_set_tone_on(j->cadence_t->ce[j->tone_cadence_state].tone_on_time, j);
845                                 ixj_set_tone_off(j->cadence_t->ce[j->tone_cadence_state].tone_off_time, j);
846                                 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
847                         }
848                 }
849         }
850 }
851
852 static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
853 {
854         if(j->ixj_signals[event]) {
855                 if(ixjdebug & 0x0100)
856                         printk("Sending signal for event %d\n", event);
857                         /* Send apps notice of change */
858                 /* see config.h for macro definition */
859                 kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
860         }
861 }
862
863 static void ixj_pstn_state(IXJ *j)
864 {
865         int var;
866         union XOPXR0 XR0, daaint;
867
868         var = 10;
869
870         XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
871         daaint.reg = 0;
872         XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
873
874         j->pld_scrr.byte = inb_p(j->XILINXbase);
875         if (j->pld_scrr.bits.daaflag) {
876                 daa_int_read(j);
877                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.RING) {
878                         if(time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
879                                 daaint.bitreg.RING = 1;
880                                 if(ixjdebug & 0x0008) {
881                                         printk(KERN_INFO "IXJ DAA Ring Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
882                                 }
883                         } else {
884                                 daa_set_mode(j, SOP_PU_RESET);
885                         }
886                 }
887                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Caller_ID) {
888                         daaint.bitreg.Caller_ID = 1;
889                         j->pstn_cid_intr = 1;
890                         j->pstn_cid_received = jiffies;
891                         if(ixjdebug & 0x0008) {
892                                 printk(KERN_INFO "IXJ DAA Caller_ID Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
893                         }
894                 }
895                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Cadence) {
896                         daaint.bitreg.Cadence = 1;
897                         if(ixjdebug & 0x0008) {
898                                 printk(KERN_INFO "IXJ DAA Cadence Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
899                         }
900                 }
901                 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK != XR0.bitreg.VDD_OK) {
902                         daaint.bitreg.VDD_OK = 1;
903                         daaint.bitreg.SI_0 = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK;
904                 }
905         }
906         daa_CR_read(j, 1);
907         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)) {
908                 daaint.bitreg.RMR = 1;
909                 daaint.bitreg.SI_1 = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
910                 if(ixjdebug & 0x0008) {
911                         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);
912                 }
913                 j->pstn_prev_rmr = j->pstn_last_rmr;
914                 j->pstn_last_rmr = jiffies;
915         }
916         switch(j->daa_mode) {
917                 case SOP_PU_SLEEP:
918                         if (daaint.bitreg.RING) {
919                                 if (!j->flags.pstn_ringing) {
920                                         if (j->daa_mode != SOP_PU_RINGING) {
921                                                 j->pstn_ring_int = jiffies;
922                                                 daa_set_mode(j, SOP_PU_RINGING);
923                                         }
924                                 }
925                         }
926                         break;
927                 case SOP_PU_RINGING:
928                         if (daaint.bitreg.RMR) {
929                                 if (ixjdebug & 0x0008) {
930                                         printk(KERN_INFO "IXJ Ring Cadence a state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
931                                 }
932                                 if (daaint.bitreg.SI_1) {                /* Rising edge of RMR */
933                                         j->flags.pstn_rmr = 1;
934                                         j->pstn_ring_start = jiffies;
935                                         j->pstn_ring_stop = 0;
936                                         j->ex.bits.pstn_ring = 0;
937                                         if (j->cadence_f[4].state == 0) {
938                                                 j->cadence_f[4].state = 1;
939                                                 j->cadence_f[4].on1min = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 - var)) / 10000);
940                                                 j->cadence_f[4].on1dot = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100)) / 10000);
941                                                 j->cadence_f[4].on1max = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 + var)) / 10000);
942                                         } else if (j->cadence_f[4].state == 2) {
943                                                 if((time_after(jiffies, j->cadence_f[4].off1min) &&
944                                                     time_before(jiffies, j->cadence_f[4].off1max))) {
945                                                         if (j->cadence_f[4].on2) {
946                                                                 j->cadence_f[4].state = 3;
947                                                                 j->cadence_f[4].on2min = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 - var)) / 10000));
948                                                                 j->cadence_f[4].on2dot = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100)) / 10000));
949                                                                 j->cadence_f[4].on2max = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 + var)) / 10000));
950                                                         } else {
951                                                                 j->cadence_f[4].state = 7;
952                                                         }
953                                                 } else {
954                                                         if (ixjdebug & 0x0008) {
955                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
956                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
957                                                                                 j->cadence_f[4].off1);
958                                                         }
959                                                         j->cadence_f[4].state = 0;
960                                                 }
961                                         } else if (j->cadence_f[4].state == 4) {
962                                                 if((time_after(jiffies, j->cadence_f[4].off2min) &&
963                                                     time_before(jiffies, j->cadence_f[4].off2max))) {
964                                                         if (j->cadence_f[4].on3) {
965                                                                 j->cadence_f[4].state = 5;
966                                                                 j->cadence_f[4].on3min = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 - var)) / 10000));
967                                                                 j->cadence_f[4].on3dot = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100)) / 10000));
968                                                                 j->cadence_f[4].on3max = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 + var)) / 10000));
969                                                         } else {
970                                                                 j->cadence_f[4].state = 7;
971                                                         }
972                                                 } else {
973                                                         if (ixjdebug & 0x0008) {
974                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
975                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
976                                                                                 j->cadence_f[4].off2);
977                                                         }
978                                                         j->cadence_f[4].state = 0;
979                                                 }
980                                         } else if (j->cadence_f[4].state == 6) {
981                                                 if((time_after(jiffies, j->cadence_f[4].off3min) &&
982                                                     time_before(jiffies, j->cadence_f[4].off3max))) {
983                                                         j->cadence_f[4].state = 7;
984                                                 } else {
985                                                         if (ixjdebug & 0x0008) {
986                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
987                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
988                                                                                 j->cadence_f[4].off3);
989                                                         }
990                                                         j->cadence_f[4].state = 0;
991                                                 }
992                                         } else {
993                                                 j->cadence_f[4].state = 0;
994                                         }
995                                 } else {                                /* Falling edge of RMR */
996                                         j->pstn_ring_start = 0;
997                                         j->pstn_ring_stop = jiffies;
998                                         if (j->cadence_f[4].state == 1) {
999                                                 if(!j->cadence_f[4].on1) {
1000                                                         j->cadence_f[4].state = 7;
1001                                                 } else if((time_after(jiffies, j->cadence_f[4].on1min) &&
1002                                                   time_before(jiffies, j->cadence_f[4].on1max))) {
1003                                                         if (j->cadence_f[4].off1) {
1004                                                                 j->cadence_f[4].state = 2;
1005                                                                 j->cadence_f[4].off1min = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 - var)) / 10000));
1006                                                                 j->cadence_f[4].off1dot = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100)) / 10000));
1007                                                                 j->cadence_f[4].off1max = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 + var)) / 10000));
1008                                                         } else {
1009                                                                 j->cadence_f[4].state = 7;
1010                                                         }
1011                                                 } else {
1012                                                         if (ixjdebug & 0x0008) {
1013                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1014                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1015                                                                                 j->cadence_f[4].on1);
1016                                                         }
1017                                                         j->cadence_f[4].state = 0;
1018                                                 }
1019                                         } else if (j->cadence_f[4].state == 3) {
1020                                                 if((time_after(jiffies, j->cadence_f[4].on2min) &&
1021                                                     time_before(jiffies, j->cadence_f[4].on2max))) {
1022                                                         if (j->cadence_f[4].off2) {
1023                                                                 j->cadence_f[4].state = 4;
1024                                                                 j->cadence_f[4].off2min = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 - var)) / 10000));
1025                                                                 j->cadence_f[4].off2dot = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100)) / 10000));
1026                                                                 j->cadence_f[4].off2max = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 + var)) / 10000));
1027                                                         } else {
1028                                                                 j->cadence_f[4].state = 7;
1029                                                         }
1030                                                 } else {
1031                                                         if (ixjdebug & 0x0008) {
1032                                                                 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1033                                                                                 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1034                                                                                 j->cadence_f[4].on2);
1035                                                         }
1036                                                         j->cadence_f[4].state = 0;
1037                                                 }
1038                                         } else if (j->cadence_f[4].state == 5) {
1039                                                 if((time_after(jiffies, j->cadence_f[4].on3min) &&
1040                                                     time_before(jiffies, j->cadence_f[4].on3max))) {
1041                                                         if (j->cadence_f[4].off3) {
1042                                                                 j->cadence_f[4].state = 6;
1043                                                                 j->cadence_f[4].off3min = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 - var)) / 10000));
1044                                                                 j->cadence_f[4].off3dot = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100)) / 10000));
1045                                                                 j->cadence_f[4].off3max = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 + var)) / 10000));
1046                                                         } else {
1047                                                                 j->cadence_f[4].state = 7;
1048                                                         }
1049                                                 } else {
1050                                                         j->cadence_f[4].state = 0;
1051                                                 }
1052                                         } else {
1053                                                 if (ixjdebug & 0x0008) {
1054                                                         printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1055                                                                         j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1056                                                                         j->cadence_f[4].on3);
1057                                                 }
1058                                                 j->cadence_f[4].state = 0;
1059                                         }
1060                                 }
1061                                 if (ixjdebug & 0x0010) {
1062                                         printk(KERN_INFO "IXJ Ring Cadence b state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
1063                                 }
1064                                 if (ixjdebug & 0x0010) {
1065                                         switch(j->cadence_f[4].state) {
1066                                                 case 1:
1067                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1068                                                 j->cadence_f[4].on1, j->cadence_f[4].on1min, j->cadence_f[4].on1dot, j->cadence_f[4].on1max);
1069                                                         break;
1070                                                 case 2:
1071                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1072                                                 j->cadence_f[4].off1, j->cadence_f[4].off1min, j->cadence_f[4].off1dot, j->cadence_f[4].off1max);
1073                                                         break;
1074                                                 case 3:
1075                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1076                                                 j->cadence_f[4].on2, j->cadence_f[4].on2min, j->cadence_f[4].on2dot, j->cadence_f[4].on2max);
1077                                                         break;
1078                                                 case 4:
1079                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1080                                                 j->cadence_f[4].off2, j->cadence_f[4].off2min, j->cadence_f[4].off2dot, j->cadence_f[4].off2max);
1081                                                         break;
1082                                                 case 5:
1083                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1084                                                 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max);
1085                                                         break;
1086                                                 case 6: 
1087                                                         printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1088                                                 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max);
1089                                                         break;
1090                                         }
1091                                 }
1092                         }
1093                         if (j->cadence_f[4].state == 7) {
1094                                 j->cadence_f[4].state = 0;
1095                                 j->pstn_ring_stop = jiffies;
1096                                 j->ex.bits.pstn_ring = 1;
1097                                 ixj_kill_fasync(j, SIG_PSTN_RING, POLL_IN);
1098                                 if(ixjdebug & 0x0008) {
1099                                         printk(KERN_INFO "IXJ Ring int set /dev/phone%d at %ld\n", j->board, jiffies);
1100                                 }
1101                         }
1102                         if((j->pstn_ring_int != 0 && time_after(jiffies, j->pstn_ring_int + (hertz * 5)) && !j->flags.pstn_rmr) ||
1103                            (j->pstn_ring_stop != 0 && time_after(jiffies, j->pstn_ring_stop + (hertz * 5)))) {
1104                                 if(ixjdebug & 0x0008) {
1105                                         printk("IXJ DAA no ring in 5 seconds /dev/phone%d at %ld\n", j->board, jiffies);
1106                                         printk("IXJ DAA pstn ring int /dev/phone%d at %ld\n", j->board, j->pstn_ring_int);
1107                                         printk("IXJ DAA pstn ring stop /dev/phone%d at %ld\n", j->board, j->pstn_ring_stop);
1108                                 }
1109                                 j->pstn_ring_stop = j->pstn_ring_int = 0;
1110                                 daa_set_mode(j, SOP_PU_SLEEP);
1111                         } 
1112                         outb_p(j->pld_scrw.byte, j->XILINXbase);
1113                         if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) {
1114                                 ixj_daa_cid_read(j);
1115                                 j->ex.bits.caller_id = 1;
1116                                 ixj_kill_fasync(j, SIG_CALLER_ID, POLL_IN);
1117                                 j->pstn_cid_intr = 0;
1118                         }
1119                         if (daaint.bitreg.Cadence) {
1120                                 if(ixjdebug & 0x0008) {
1121                                         printk("IXJ DAA Cadence interrupt going to sleep /dev/phone%d\n", j->board);
1122                                 }
1123                                 daa_set_mode(j, SOP_PU_SLEEP);
1124                                 j->ex.bits.pstn_ring = 0;
1125                         }
1126                         break;
1127                 case SOP_PU_CONVERSATION:
1128                         if (daaint.bitreg.VDD_OK) {
1129                                 if(!daaint.bitreg.SI_0) {
1130                                         if (!j->pstn_winkstart) {
1131                                                 if(ixjdebug & 0x0008) {
1132                                                         printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies);
1133                                                 }
1134                                                 j->pstn_winkstart = jiffies;
1135                                         } 
1136                                 } else {
1137                                         if (j->pstn_winkstart) {
1138                                                 if(ixjdebug & 0x0008) {
1139                                                         printk("IXJ DAA possible wink end /dev/phone%d %ld\n", j->board, jiffies);
1140                                                 }
1141                                                 j->pstn_winkstart = 0;
1142                                         }
1143                                 }
1144                         }
1145                         if (j->pstn_winkstart && time_after(jiffies, j->pstn_winkstart + ((hertz * j->winktime) / 1000))) {
1146                                 if(ixjdebug & 0x0008) {
1147                                         printk("IXJ DAA wink detected going to sleep /dev/phone%d %ld\n", j->board, jiffies);
1148                                 }
1149                                 daa_set_mode(j, SOP_PU_SLEEP);
1150                                 j->pstn_winkstart = 0;
1151                                 j->ex.bits.pstn_wink = 1;
1152                                 ixj_kill_fasync(j, SIG_PSTN_WINK, POLL_IN);
1153                         }
1154                         break;
1155         }
1156 }
1157
1158 static void ixj_timeout(unsigned long ptr)
1159 {
1160         int board;
1161         unsigned long jifon;
1162         IXJ *j = (IXJ *)ptr;
1163         board = j->board;
1164
1165         if (j->DSPbase && atomic_read(&j->DSPWrite) == 0 && test_and_set_bit(board, (void *)&j->busyflags) == 0) {
1166                 ixj_perfmon(j->timerchecks);
1167                 j->hookstate = ixj_hookstate(j);
1168                 if (j->tone_state) {
1169                         if (!(j->hookstate)) {
1170                                 ixj_cpt_stop(j);
1171                                 if (j->m_hook) {
1172                                         j->m_hook = 0;
1173                                         j->ex.bits.hookstate = 1;
1174                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1175                                 }
1176                                 clear_bit(board, &j->busyflags);
1177                                 ixj_add_timer(j);
1178                                 return;
1179                         }
1180                         if (j->tone_state == 1)
1181                                 jifon = ((hertz * j->tone_on_time) * 25 / 100000);
1182                         else
1183                                 jifon = ((hertz * j->tone_on_time) * 25 / 100000) + ((hertz * j->tone_off_time) * 25 / 100000);
1184                         if (time_before(jiffies, j->tone_start_jif + jifon)) {
1185                                 if (j->tone_state == 1) {
1186                                         ixj_play_tone(j, j->tone_index);
1187                                         if (j->dsp.low == 0x20) {
1188                                                 clear_bit(board, &j->busyflags);
1189                                                 ixj_add_timer(j);
1190                                                 return;
1191                                         }
1192                                 } else {
1193                                         ixj_play_tone(j, 0);
1194                                         if (j->dsp.low == 0x20) {
1195                                                 clear_bit(board, &j->busyflags);
1196                                                 ixj_add_timer(j);
1197                                                 return;
1198                                         }
1199                                 }
1200                         } else {
1201                                 ixj_tone_timeout(j);
1202                                 if (j->flags.dialtone) {
1203                                         ixj_dialtone(j);
1204                                 }
1205                                 if (j->flags.busytone) {
1206                                         ixj_busytone(j);
1207                                         if (j->dsp.low == 0x20) {
1208                                                 clear_bit(board, &j->busyflags);
1209                                                 ixj_add_timer(j);
1210                                                 return;
1211                                         }
1212                                 }
1213                                 if (j->flags.ringback) {
1214                                         ixj_ringback(j);
1215                                         if (j->dsp.low == 0x20) {
1216                                                 clear_bit(board, &j->busyflags);
1217                                                 ixj_add_timer(j);
1218                                                 return;
1219                                         }
1220                                 }
1221                                 if (!j->tone_state) {
1222                                         ixj_cpt_stop(j);
1223                                 }
1224                         }
1225                 }
1226                 if (!(j->tone_state && j->dsp.low == 0x20)) {
1227                         if (IsRxReady(j)) {
1228                                 ixj_read_frame(j);
1229                         }
1230                         if (IsTxReady(j)) {
1231                                 ixj_write_frame(j);
1232                         }
1233                 }
1234                 if (j->flags.cringing) {
1235                         if (j->hookstate & 1) {
1236                                 j->flags.cringing = 0;
1237                                 ixj_ring_off(j);
1238                         } else if(j->cadence_f[5].enable && ((!j->cadence_f[5].en_filter) || (j->cadence_f[5].en_filter && j->flags.firstring))) {
1239                                 switch(j->cadence_f[5].state) {
1240                                         case 0:
1241                                                 j->cadence_f[5].on1dot = jiffies + (long)((j->cadence_f[5].on1 * (hertz * 100) / 10000));
1242                                                 if (time_before(jiffies, j->cadence_f[5].on1dot)) {
1243                                                         if(ixjdebug & 0x0004) {
1244                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1245                                                         }
1246                                                         ixj_ring_on(j);
1247                                                 }
1248                                                 j->cadence_f[5].state = 1;
1249                                                 break;
1250                                         case 1:
1251                                                 if (time_after(jiffies, j->cadence_f[5].on1dot)) {
1252                                                         j->cadence_f[5].off1dot = jiffies + (long)((j->cadence_f[5].off1 * (hertz * 100) / 10000));
1253                                                         if(ixjdebug & 0x0004) {
1254                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1255                                                         }
1256                                                         ixj_ring_off(j);
1257                                                         j->cadence_f[5].state = 2;
1258                                                 }
1259                                                 break;
1260                                         case 2:
1261                                                 if (time_after(jiffies, j->cadence_f[5].off1dot)) {
1262                                                         if(ixjdebug & 0x0004) {
1263                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1264                                                         }
1265                                                         ixj_ring_on(j);
1266                                                         if (j->cadence_f[5].on2) {
1267                                                                 j->cadence_f[5].on2dot = jiffies + (long)((j->cadence_f[5].on2 * (hertz * 100) / 10000));
1268                                                                 j->cadence_f[5].state = 3;
1269                                                         } else {
1270                                                                 j->cadence_f[5].state = 7;
1271                                                         }
1272                                                 }
1273                                                 break;
1274                                         case 3:
1275                                                 if (time_after(jiffies, j->cadence_f[5].on2dot)) {
1276                                                         if(ixjdebug & 0x0004) {
1277                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1278                                                         }
1279                                                         ixj_ring_off(j);
1280                                                         if (j->cadence_f[5].off2) {
1281                                                                 j->cadence_f[5].off2dot = jiffies + (long)((j->cadence_f[5].off2 * (hertz * 100) / 10000));
1282                                                                 j->cadence_f[5].state = 4;
1283                                                         } else {
1284                                                                 j->cadence_f[5].state = 7;
1285                                                         }
1286                                                 }
1287                                                 break;
1288                                         case 4:
1289                                                 if (time_after(jiffies, j->cadence_f[5].off2dot)) {
1290                                                         if(ixjdebug & 0x0004) {
1291                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1292                                                         }
1293                                                         ixj_ring_on(j);
1294                                                         if (j->cadence_f[5].on3) {
1295                                                                 j->cadence_f[5].on3dot = jiffies + (long)((j->cadence_f[5].on3 * (hertz * 100) / 10000));
1296                                                                 j->cadence_f[5].state = 5;
1297                                                         } else {
1298                                                                 j->cadence_f[5].state = 7;
1299                                                         }
1300                                                 }
1301                                                 break;
1302                                         case 5:
1303                                                 if (time_after(jiffies, j->cadence_f[5].on3dot)) {
1304                                                         if(ixjdebug & 0x0004) {
1305                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1306                                                         }
1307                                                         ixj_ring_off(j);
1308                                                         if (j->cadence_f[5].off3) {
1309                                                                 j->cadence_f[5].off3dot = jiffies + (long)((j->cadence_f[5].off3 * (hertz * 100) / 10000));
1310                                                                 j->cadence_f[5].state = 6;
1311                                                         } else {
1312                                                                 j->cadence_f[5].state = 7;
1313                                                         }
1314                                                 }
1315                                                 break;
1316                                         case 6:
1317                                                 if (time_after(jiffies, j->cadence_f[5].off3dot)) {
1318                                                         if(ixjdebug & 0x0004) {
1319                                                                 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1320                                                         }
1321                                                         j->cadence_f[5].state = 7;
1322                                                 }
1323                                                 break;
1324                                         case 7:
1325                                                 if(ixjdebug & 0x0004) {
1326                                                         printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1327                                                 }
1328                                                 j->flags.cidring = 1;
1329                                                 j->cadence_f[5].state = 0;
1330                                                 break;
1331                                 }
1332                                 if (j->flags.cidring && !j->flags.cidsent) {
1333                                         j->flags.cidsent = 1;
1334                                         if(j->fskdcnt) {
1335                                                 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1336                                                 ixj_pre_cid(j);
1337                                         }
1338                                         j->flags.cidring = 0;
1339                                 }
1340                                 clear_bit(board, &j->busyflags);
1341                                 ixj_add_timer(j);
1342                                 return;
1343                         } else {
1344                                 if (time_after(jiffies, j->ring_cadence_jif + (hertz / 2))) {
1345                                         if (j->flags.cidring && !j->flags.cidsent) {
1346                                                 j->flags.cidsent = 1;
1347                                                 if(j->fskdcnt) {
1348                                                         SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1349                                                         ixj_pre_cid(j);
1350                                                 }
1351                                                 j->flags.cidring = 0;
1352                                         }
1353                                         j->ring_cadence_t--;
1354                                         if (j->ring_cadence_t == -1)
1355                                                 j->ring_cadence_t = 15;
1356                                         j->ring_cadence_jif = jiffies;
1357
1358                                         if (j->ring_cadence & 1 << j->ring_cadence_t) {
1359                                                 if(j->flags.cidsent && j->cadence_f[5].en_filter)
1360                                                         j->flags.firstring = 1;
1361                                                 else
1362                                                         ixj_ring_on(j);
1363                                         } else {
1364                                                 ixj_ring_off(j);
1365                                                 if(!j->flags.cidsent)
1366                                                         j->flags.cidring = 1;
1367                                         }
1368                                 }
1369                                 clear_bit(board, &j->busyflags);
1370                                 ixj_add_timer(j);
1371                                 return;
1372                         }
1373                 }
1374                 if (!j->flags.ringing) {
1375                         if (j->hookstate) { /* & 1) { */
1376                                 if (j->dsp.low != 0x20 &&
1377                                     SLIC_GetState(j) != PLD_SLIC_STATE_ACTIVE) {
1378                                         SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1379                                 }
1380                                 LineMonitor(j);
1381                                 read_filters(j);
1382                                 ixj_WriteDSPCommand(0x511B, j);
1383                                 j->proc_load = j->ssr.high << 8 | j->ssr.low;
1384                                 if (!j->m_hook && (j->hookstate & 1)) {
1385                                         j->m_hook = j->ex.bits.hookstate = 1;
1386                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1387                                 }
1388                         } else {
1389                                 if (j->ex.bits.dtmf_ready) {
1390                                         j->dtmf_wp = j->dtmf_rp = j->ex.bits.dtmf_ready = 0;
1391                                 }
1392                                 if (j->m_hook) {
1393                                         j->m_hook = 0;
1394                                         j->ex.bits.hookstate = 1;
1395                                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1396                                 }
1397                         }
1398                 }
1399                 if (j->cardtype == QTI_LINEJACK && !j->flags.pstncheck && j->flags.pstn_present) {
1400                         ixj_pstn_state(j);
1401                 }
1402                 if (j->ex.bytes) {
1403                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
1404                 }
1405                 clear_bit(board, &j->busyflags);
1406         }
1407         ixj_add_timer(j);
1408 }
1409
1410 static int ixj_status_wait(IXJ *j)
1411 {
1412         unsigned long jif;
1413
1414         jif = jiffies + ((60 * hertz) / 100);
1415         while (!IsStatusReady(j)) {
1416                 ixj_perfmon(j->statuswait);
1417                 if (time_after(jiffies, jif)) {
1418                         ixj_perfmon(j->statuswaitfail);
1419                         return -1;
1420                 }
1421         }
1422         return 0;
1423 }
1424
1425 static int ixj_PCcontrol_wait(IXJ *j)
1426 {
1427         unsigned long jif;
1428
1429         jif = jiffies + ((60 * hertz) / 100);
1430         while (!IsPCControlReady(j)) {
1431                 ixj_perfmon(j->pcontrolwait);
1432                 if (time_after(jiffies, jif)) {
1433                         ixj_perfmon(j->pcontrolwaitfail);
1434                         return -1;
1435                 }
1436         }
1437         return 0;
1438 }
1439
1440 static int ixj_WriteDSPCommand(unsigned short cmd, IXJ *j)
1441 {
1442         BYTES bytes;
1443         unsigned long jif;
1444
1445         atomic_inc(&j->DSPWrite);
1446         if(atomic_read(&j->DSPWrite) > 1) {
1447                 printk("IXJ %d DSP write overlap attempting command 0x%4.4x\n", j->board, cmd);
1448                 return -1;
1449         }
1450         bytes.high = (cmd & 0xFF00) >> 8;
1451         bytes.low = cmd & 0x00FF;
1452         jif = jiffies + ((60 * hertz) / 100);
1453         while (!IsControlReady(j)) {
1454                 ixj_perfmon(j->iscontrolready);
1455                 if (time_after(jiffies, jif)) {
1456                         ixj_perfmon(j->iscontrolreadyfail);
1457                         atomic_dec(&j->DSPWrite);
1458                         if(atomic_read(&j->DSPWrite) > 0) {
1459                                 printk("IXJ %d DSP overlaped command 0x%4.4x during control ready failure.\n", j->board, cmd);
1460                                 while(atomic_read(&j->DSPWrite) > 0) {
1461                                         atomic_dec(&j->DSPWrite);
1462                                 }
1463                         }
1464                         return -1;
1465                 }
1466         }
1467         outb(bytes.low, j->DSPbase + 6);
1468         outb(bytes.high, j->DSPbase + 7);
1469
1470         if (ixj_status_wait(j)) {
1471                 j->ssr.low = 0xFF;
1472                 j->ssr.high = 0xFF;
1473                 atomic_dec(&j->DSPWrite);
1474                 if(atomic_read(&j->DSPWrite) > 0) {
1475                         printk("IXJ %d DSP overlaped command 0x%4.4x during status wait failure.\n", j->board, cmd);
1476                         while(atomic_read(&j->DSPWrite) > 0) {
1477                                 atomic_dec(&j->DSPWrite);
1478                         }
1479                 }
1480                 return -1;
1481         }
1482 /* Read Software Status Register */
1483         j->ssr.low = inb_p(j->DSPbase + 2);
1484         j->ssr.high = inb_p(j->DSPbase + 3);
1485         atomic_dec(&j->DSPWrite);
1486         if(atomic_read(&j->DSPWrite) > 0) {
1487                 printk("IXJ %d DSP overlaped command 0x%4.4x\n", j->board, cmd);
1488                 while(atomic_read(&j->DSPWrite) > 0) {
1489                         atomic_dec(&j->DSPWrite);
1490                 }
1491         }
1492         return 0;
1493 }
1494
1495 /***************************************************************************
1496 *
1497 *  General Purpose IO Register read routine
1498 *
1499 ***************************************************************************/
1500 static inline int ixj_gpio_read(IXJ *j)
1501 {
1502         if (ixj_WriteDSPCommand(0x5143, j))
1503                 return -1;
1504
1505         j->gpio.bytes.low = j->ssr.low;
1506         j->gpio.bytes.high = j->ssr.high;
1507
1508         return 0;
1509 }
1510
1511 static inline void LED_SetState(int state, IXJ *j)
1512 {
1513         if (j->cardtype == QTI_LINEJACK) {
1514                 j->pld_scrw.bits.led1 = state & 0x1 ? 1 : 0;
1515                 j->pld_scrw.bits.led2 = state & 0x2 ? 1 : 0;
1516                 j->pld_scrw.bits.led3 = state & 0x4 ? 1 : 0;
1517                 j->pld_scrw.bits.led4 = state & 0x8 ? 1 : 0;
1518
1519                 outb(j->pld_scrw.byte, j->XILINXbase);
1520         }
1521 }
1522
1523 /*********************************************************************
1524 *  GPIO Pins are configured as follows on the Quicknet Internet
1525 *  PhoneJACK Telephony Cards
1526
1527 * POTS Select        GPIO_6=0 GPIO_7=0
1528 * Mic/Speaker Select GPIO_6=0 GPIO_7=1
1529 * Handset Select     GPIO_6=1 GPIO_7=0
1530 *
1531 * SLIC Active        GPIO_1=0 GPIO_2=1 GPIO_5=0
1532 * SLIC Ringing       GPIO_1=1 GPIO_2=1 GPIO_5=0
1533 * SLIC Open Circuit  GPIO_1=0 GPIO_2=0 GPIO_5=0
1534 *
1535 * Hook Switch changes reported on GPIO_3
1536 *********************************************************************/
1537 static int ixj_set_port(IXJ *j, int arg)
1538 {
1539         if (j->cardtype == QTI_PHONEJACK_LITE) {
1540                 if (arg != PORT_POTS)
1541                         return 10;
1542                 else
1543                         return 0;
1544         }
1545         switch (arg) {
1546         case PORT_POTS:
1547                 j->port = PORT_POTS;
1548                 switch (j->cardtype) {
1549                 case QTI_PHONECARD:
1550                         if (j->flags.pcmciasct == 1)
1551                                 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1552                         else
1553                                 return 11;
1554                         break;
1555                 case QTI_PHONEJACK_PCI:
1556                         j->pld_slicw.pcib.mic = 0;
1557                         j->pld_slicw.pcib.spk = 0;
1558                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1559                         break;
1560                 case QTI_LINEJACK:
1561                         ixj_set_pots(j, 0);                     /* Disconnect POTS/PSTN relay */
1562                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to
1563                                                                            Software Control Register */
1564                                 return 2;
1565                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
1566
1567                         outb(j->pld_scrw.byte, j->XILINXbase);
1568                         j->pld_clock.byte = 0;
1569                         outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1570                         j->pld_slicw.bits.rly1 = 1;
1571                         j->pld_slicw.bits.spken = 0;
1572                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1573                         ixj_mixer(0x1200, j);   /* Turn Off MIC switch on mixer left */
1574                         ixj_mixer(0x1401, j);   /* Turn On Mono1 switch on mixer left */
1575                         ixj_mixer(0x1300, j);       /* Turn Off MIC switch on mixer right */
1576                         ixj_mixer(0x1501, j);       /* Turn On Mono1 switch on mixer right */
1577                         ixj_mixer(0x0E80, j);   /*Mic mute */
1578                         ixj_mixer(0x0F00, j);   /* Set mono out (SLIC) to 0dB */
1579                         ixj_mixer(0x0080, j);   /* Mute Master Left volume */
1580                         ixj_mixer(0x0180, j);   /* Mute Master Right volume */
1581                         SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
1582 /*                      SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
1583                         break;
1584                 case QTI_PHONEJACK:
1585                         j->gpio.bytes.high = 0x0B;
1586                         j->gpio.bits.gpio6 = 0;
1587                         j->gpio.bits.gpio7 = 0;
1588                         ixj_WriteDSPCommand(j->gpio.word, j);
1589                         break;
1590                 }
1591                 break;
1592         case PORT_PSTN:
1593                 if (j->cardtype == QTI_LINEJACK) {
1594                         ixj_WriteDSPCommand(0xC534, j); /* Write CODEC config to Software Control Register */
1595
1596                         j->pld_slicw.bits.rly3 = 0;
1597                         j->pld_slicw.bits.rly1 = 1;
1598                         j->pld_slicw.bits.spken = 0;
1599                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1600                         j->port = PORT_PSTN;
1601                 } else {
1602                         return 4;
1603                 }
1604                 break;
1605         case PORT_SPEAKER:
1606                 j->port = PORT_SPEAKER;
1607                 switch (j->cardtype) {
1608                 case QTI_PHONECARD:
1609                         if (j->flags.pcmciasct) {
1610                                 SLIC_SetState(PLD_SLIC_STATE_OC, j);
1611                         }
1612                         break;
1613                 case QTI_PHONEJACK_PCI:
1614                         j->pld_slicw.pcib.mic = 1;
1615                         j->pld_slicw.pcib.spk = 1;
1616                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1617                         break;
1618                 case QTI_LINEJACK:
1619                         ixj_set_pots(j, 0);                     /* Disconnect POTS/PSTN relay */
1620                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to
1621                                                                            Software Control Register */
1622                                 return 2;
1623                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
1624
1625                         outb(j->pld_scrw.byte, j->XILINXbase);
1626                         j->pld_clock.byte = 0;
1627                         outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1628                         j->pld_slicw.bits.rly1 = 1;
1629                         j->pld_slicw.bits.spken = 1;
1630                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1631                         ixj_mixer(0x1201, j);   /* Turn On MIC switch on mixer left */
1632                         ixj_mixer(0x1400, j);   /* Turn Off Mono1 switch on mixer left */
1633                         ixj_mixer(0x1301, j);       /* Turn On MIC switch on mixer right */
1634                         ixj_mixer(0x1500, j);       /* Turn Off Mono1 switch on mixer right */
1635                         ixj_mixer(0x0E06, j);   /*Mic un-mute 0dB */
1636                         ixj_mixer(0x0F80, j);   /* Mute mono out (SLIC) */
1637                         ixj_mixer(0x0000, j);   /* Set Master Left volume to 0dB */
1638                         ixj_mixer(0x0100, j);   /* Set Master Right volume to 0dB */
1639                         break;
1640                 case QTI_PHONEJACK:
1641                         j->gpio.bytes.high = 0x0B;
1642                         j->gpio.bits.gpio6 = 0;
1643                         j->gpio.bits.gpio7 = 1;
1644                         ixj_WriteDSPCommand(j->gpio.word, j);
1645                         break;
1646                 }
1647                 break;
1648         case PORT_HANDSET:
1649                 if (j->cardtype != QTI_PHONEJACK) {
1650                         return 5;
1651                 } else {
1652                         j->gpio.bytes.high = 0x0B;
1653                         j->gpio.bits.gpio6 = 1;
1654                         j->gpio.bits.gpio7 = 0;
1655                         ixj_WriteDSPCommand(j->gpio.word, j);
1656                         j->port = PORT_HANDSET;
1657                 }
1658                 break;
1659         default:
1660                 return 6;
1661                 break;
1662         }
1663         return 0;
1664 }
1665
1666 static int ixj_set_pots(IXJ *j, int arg)
1667 {
1668         if (j->cardtype == QTI_LINEJACK) {
1669                 if (arg) {
1670                         if (j->port == PORT_PSTN) {
1671                                 j->pld_slicw.bits.rly1 = 0;
1672                                 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1673                                 j->flags.pots_pstn = 1;
1674                                 return 1;
1675                         } else {
1676                                 j->flags.pots_pstn = 0;
1677                                 return 0;
1678                         }
1679                 } else {
1680                         j->pld_slicw.bits.rly1 = 1;
1681                         outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1682                         j->flags.pots_pstn = 0;
1683                         return 1;
1684                 }
1685         } else {
1686                 return 0;
1687         }
1688 }
1689
1690 static void ixj_ring_on(IXJ *j)
1691 {
1692         if (j->dsp.low == 0x20) /* Internet PhoneJACK */
1693          {
1694                 if (ixjdebug & 0x0004)
1695                         printk(KERN_INFO "IXJ Ring On /dev/phone%d\n",  j->board);
1696
1697                 j->gpio.bytes.high = 0x0B;
1698                 j->gpio.bytes.low = 0x00;
1699                 j->gpio.bits.gpio1 = 1;
1700                 j->gpio.bits.gpio2 = 1;
1701                 j->gpio.bits.gpio5 = 0;
1702                 ixj_WriteDSPCommand(j->gpio.word, j);   /* send the ring signal */
1703         } else                  /* Internet LineJACK, Internet PhoneJACK Lite or Internet PhoneJACK PCI */
1704         {
1705                 if (ixjdebug & 0x0004)
1706                         printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1707
1708                 SLIC_SetState(PLD_SLIC_STATE_RINGING, j);
1709         }
1710 }
1711
1712 static int ixj_siadc(IXJ *j, int val)
1713 {
1714         if(j->cardtype == QTI_PHONECARD){
1715                 if(j->flags.pcmciascp){
1716                         if(val == -1)
1717                                 return j->siadc.bits.rxg;
1718
1719                         if(val < 0 || val > 0x1F)
1720                                 return -1;
1721
1722                         j->siadc.bits.hom = 0;                          /* Handset Out Mute */
1723                         j->siadc.bits.lom = 0;                          /* Line Out Mute */
1724                         j->siadc.bits.rxg = val;                        /*(0xC000 - 0x41C8) / 0x4EF;    RX PGA Gain */
1725                         j->psccr.bits.addr = 6;                         /* R/W Smart Cable Register Address */
1726                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1727                         j->psccr.bits.dev = 0;
1728                         outb(j->siadc.byte, j->XILINXbase + 0x00);
1729                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1730                         ixj_PCcontrol_wait(j);
1731                         return j->siadc.bits.rxg;
1732                 }
1733         }
1734         return -1;
1735 }
1736
1737 static int ixj_sidac(IXJ *j, int val)
1738 {
1739         if(j->cardtype == QTI_PHONECARD){
1740                 if(j->flags.pcmciascp){
1741                         if(val == -1)
1742                                 return j->sidac.bits.txg;
1743
1744                         if(val < 0 || val > 0x1F)
1745                                 return -1;
1746
1747                         j->sidac.bits.srm = 1;                          /* Speaker Right Mute */
1748                         j->sidac.bits.slm = 1;                          /* Speaker Left Mute */
1749                         j->sidac.bits.txg = val;                        /* (0xC000 - 0x45E4) / 0x5D3;    TX PGA Gain */
1750                         j->psccr.bits.addr = 7;                         /* R/W Smart Cable Register Address */
1751                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1752                         j->psccr.bits.dev = 0;
1753                         outb(j->sidac.byte, j->XILINXbase + 0x00);
1754                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1755                         ixj_PCcontrol_wait(j);
1756                         return j->sidac.bits.txg;
1757                 }
1758         }
1759         return -1;
1760 }
1761
1762 static int ixj_pcmcia_cable_check(IXJ *j)
1763 {
1764         j->pccr1.byte = inb_p(j->XILINXbase + 0x03);
1765         if (!j->flags.pcmciastate) {
1766                 j->pccr2.byte = inb_p(j->XILINXbase + 0x02);
1767                 if (j->pccr1.bits.drf || j->pccr2.bits.rstc) {
1768                         j->flags.pcmciastate = 4;
1769                         return 0;
1770                 }
1771                 if (j->pccr1.bits.ed) {
1772                         j->pccr1.bits.ed = 0;
1773                         j->psccr.bits.dev = 3;
1774                         j->psccr.bits.rw = 1;
1775                         outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
1776                         ixj_PCcontrol_wait(j);
1777                         j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
1778                         j->pslic.bits.led2 = j->pslic.bits.det ? 1 : 0;
1779                         j->psccr.bits.dev = 3;
1780                         j->psccr.bits.rw = 0;
1781                         outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1782                         ixj_PCcontrol_wait(j);
1783                         return j->pslic.bits.led2 ? 1 : 0;
1784                 } else if (j->flags.pcmciasct) {
1785                         return j->r_hook;
1786                 } else {
1787                         return 1;
1788                 }
1789         } else if (j->flags.pcmciastate == 4) {
1790                 if (!j->pccr1.bits.drf) {
1791                         j->flags.pcmciastate = 3;
1792                 }
1793                 return 0;
1794         } else if (j->flags.pcmciastate == 3) {
1795                 j->pccr2.bits.pwr = 0;
1796                 j->pccr2.bits.rstc = 1;
1797                 outb(j->pccr2.byte, j->XILINXbase + 0x02);
1798                 j->checkwait = jiffies + (hertz * 2);
1799                 j->flags.incheck = 1;
1800                 j->flags.pcmciastate = 2;
1801                 return 0;
1802         } else if (j->flags.pcmciastate == 2) {
1803                 if (j->flags.incheck) {
1804                         if (time_before(jiffies, j->checkwait)) {
1805                                 return 0;
1806                         } else {
1807                                 j->flags.incheck = 0;
1808                         }
1809                 }
1810                 j->pccr2.bits.pwr = 0;
1811                 j->pccr2.bits.rstc = 0;
1812                 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1813                 j->flags.pcmciastate = 1;
1814                 return 0;
1815         } else if (j->flags.pcmciastate == 1) {
1816                 j->flags.pcmciastate = 0;
1817                 if (!j->pccr1.bits.drf) {
1818                         j->psccr.bits.dev = 3;
1819                         j->psccr.bits.rw = 1;
1820                         outb_p(j->psccr.byte, j->XILINXbase + 0x01);
1821                         ixj_PCcontrol_wait(j);
1822                         j->flags.pcmciascp = 1;         /* Set Cable Present Flag */
1823
1824                         j->flags.pcmciasct = (inw_p(j->XILINXbase + 0x00) >> 8) & 0x03;         /* Get Cable Type */
1825
1826                         if (j->flags.pcmciasct == 3) {
1827                                 j->flags.pcmciastate = 4;
1828                                 return 0;
1829                         } else if (j->flags.pcmciasct == 0) {
1830                                 j->pccr2.bits.pwr = 1;
1831                                 j->pccr2.bits.rstc = 0;
1832                                 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1833                                 j->port = PORT_SPEAKER;
1834                         } else {
1835                                 j->port = PORT_POTS;
1836                         }
1837                         j->sic1.bits.cpd = 0;                           /* Chip Power Down */
1838                         j->sic1.bits.mpd = 0;                           /* MIC Bias Power Down */
1839                         j->sic1.bits.hpd = 0;                           /* Handset Bias Power Down */
1840                         j->sic1.bits.lpd = 0;                           /* Line Bias Power Down */
1841                         j->sic1.bits.spd = 1;                           /* Speaker Drive Power Down */
1842                         j->psccr.bits.addr = 1;                         /* R/W Smart Cable Register Address */
1843                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1844                         j->psccr.bits.dev = 0;
1845                         outb(j->sic1.byte, j->XILINXbase + 0x00);
1846                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1847                         ixj_PCcontrol_wait(j);
1848
1849                         j->sic2.bits.al = 0;                            /* Analog Loopback DAC analog -> ADC analog */
1850                         j->sic2.bits.dl2 = 0;                           /* Digital Loopback DAC -> ADC one bit */
1851                         j->sic2.bits.dl1 = 0;                           /* Digital Loopback ADC -> DAC one bit */
1852                         j->sic2.bits.pll = 0;                           /* 1 = div 10, 0 = div 5 */
1853                         j->sic2.bits.hpd = 0;                           /* HPF disable */
1854                         j->psccr.bits.addr = 2;                         /* R/W Smart Cable Register Address */
1855                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1856                         j->psccr.bits.dev = 0;
1857                         outb(j->sic2.byte, j->XILINXbase + 0x00);
1858                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1859                         ixj_PCcontrol_wait(j);
1860
1861                         j->psccr.bits.addr = 3;                         /* R/W Smart Cable Register Address */
1862                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1863                         j->psccr.bits.dev = 0;
1864                         outb(0x00, j->XILINXbase + 0x00);               /* PLL Divide N1 */
1865                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1866                         ixj_PCcontrol_wait(j);
1867
1868                         j->psccr.bits.addr = 4;                         /* R/W Smart Cable Register Address */
1869                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1870                         j->psccr.bits.dev = 0;
1871                         outb(0x09, j->XILINXbase + 0x00);               /* PLL Multiply M1 */
1872                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1873                         ixj_PCcontrol_wait(j);
1874
1875                         j->sirxg.bits.lig = 1;                          /* Line In Gain */
1876                         j->sirxg.bits.lim = 1;                          /* Line In Mute */
1877                         j->sirxg.bits.mcg = 0;                          /* MIC In Gain was 3 */
1878                         j->sirxg.bits.mcm = 0;                          /* MIC In Mute */
1879                         j->sirxg.bits.him = 0;                          /* Handset In Mute */
1880                         j->sirxg.bits.iir = 1;                          /* IIR */
1881                         j->psccr.bits.addr = 5;                         /* R/W Smart Cable Register Address */
1882                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1883                         j->psccr.bits.dev = 0;
1884                         outb(j->sirxg.byte, j->XILINXbase + 0x00);
1885                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1886                         ixj_PCcontrol_wait(j);
1887
1888                         ixj_siadc(j, 0x17);
1889                         ixj_sidac(j, 0x1D);
1890
1891                         j->siaatt.bits.sot = 0;
1892                         j->psccr.bits.addr = 9;                         /* R/W Smart Cable Register Address */
1893                         j->psccr.bits.rw = 0;                           /* Read / Write flag */
1894                         j->psccr.bits.dev = 0;
1895                         outb(j->siaatt.byte, j->XILINXbase + 0x00);
1896                         outb(j->psccr.byte, j->XILINXbase + 0x01);
1897                         ixj_PCcontrol_wait(j);
1898
1899                         if (j->flags.pcmciasct == 1 && !j->readers && !j->writers) {
1900                                 j->psccr.byte = j->pslic.byte = 0;
1901                                 j->pslic.bits.powerdown = 1;
1902                                 j->psccr.bits.dev = 3;
1903                                 j->psccr.bits.rw = 0;
1904                                 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1905                                 ixj_PCcontrol_wait(j);
1906                         }
1907                 }
1908                 return 0;
1909         } else {
1910                 j->flags.pcmciascp = 0;
1911                 return 0;
1912         }
1913         return 0;
1914 }
1915
1916 static int ixj_hookstate(IXJ *j)
1917 {
1918         int fOffHook = 0;
1919
1920         switch (j->cardtype) {
1921         case QTI_PHONEJACK:
1922                 ixj_gpio_read(j);
1923                 fOffHook = j->gpio.bits.gpio3read ? 1 : 0;
1924                 break;
1925         case QTI_LINEJACK:
1926         case QTI_PHONEJACK_LITE:
1927         case QTI_PHONEJACK_PCI:
1928                 SLIC_GetState(j);
1929                 if(j->cardtype == QTI_LINEJACK && j->flags.pots_pstn == 1 && (j->readers || j->writers)) {
1930                         fOffHook = j->pld_slicr.bits.potspstn ? 1 : 0;
1931                         if(fOffHook != j->p_hook) {
1932                                 if(!j->checkwait) {
1933                                         j->checkwait = jiffies;
1934                                 } 
1935                                 if(time_before(jiffies, j->checkwait + 2)) {
1936                                         fOffHook ^= 1;
1937                                 } else {
1938                                         j->checkwait = 0;
1939                                 }
1940                                 j->p_hook = fOffHook;
1941                                 printk("IXJ : /dev/phone%d pots-pstn hookstate check %d at %ld\n", j->board, fOffHook, jiffies);
1942                         }
1943                 } else {
1944                         if (j->pld_slicr.bits.state == PLD_SLIC_STATE_ACTIVE ||
1945                             j->pld_slicr.bits.state == PLD_SLIC_STATE_STANDBY) {
1946                                 if (j->flags.ringing || j->flags.cringing) {
1947                                         if (!in_interrupt()) {
1948                                                 msleep(20);
1949                                         }
1950                                         SLIC_GetState(j);
1951                                         if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
1952                                                 ixj_ring_on(j);
1953                                         }
1954                                 }
1955                                 if (j->cardtype == QTI_PHONEJACK_PCI) {
1956                                         j->pld_scrr.byte = inb_p(j->XILINXbase);
1957                                         fOffHook = j->pld_scrr.pcib.det ? 1 : 0;
1958                                 } else
1959                                         fOffHook = j->pld_slicr.bits.det ? 1 : 0;
1960                         }
1961                 }
1962                 break;
1963         case QTI_PHONECARD:
1964                 fOffHook = ixj_pcmcia_cable_check(j);
1965                 break;
1966         }
1967         if (j->r_hook != fOffHook) {
1968                 j->r_hook = fOffHook;
1969                 if (j->port == PORT_SPEAKER || j->port == PORT_HANDSET) { // || (j->port == PORT_PSTN && j->flags.pots_pstn == 0)) {
1970                         j->ex.bits.hookstate = 1;
1971                         ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1972                 } else if (!fOffHook) {
1973                         j->flash_end = jiffies + ((60 * hertz) / 100);
1974                 }
1975         }
1976         if (fOffHook) {
1977                 if(time_before(jiffies, j->flash_end)) {
1978                         j->ex.bits.flash = 1;
1979                         j->flash_end = 0;
1980                         ixj_kill_fasync(j, SIG_FLASH, POLL_IN);
1981                 }
1982         } else {
1983                 if(time_before(jiffies, j->flash_end)) {
1984                         fOffHook = 1;
1985                 }
1986         }
1987
1988         if (j->port == PORT_PSTN && j->daa_mode == SOP_PU_CONVERSATION)
1989                 fOffHook |= 2;
1990
1991         if (j->port == PORT_SPEAKER) {
1992                 if(j->cardtype == QTI_PHONECARD) {
1993                         if(j->flags.pcmciascp && j->flags.pcmciasct) {
1994                                 fOffHook |= 2;
1995                         }
1996                 } else {
1997                         fOffHook |= 2;
1998                 }
1999         }
2000
2001         if (j->port == PORT_HANDSET)
2002                 fOffHook |= 2;
2003
2004         return fOffHook;
2005 }
2006
2007 static void ixj_ring_off(IXJ *j)
2008 {
2009         if (j->dsp.low == 0x20) /* Internet PhoneJACK */
2010          {
2011                 if (ixjdebug & 0x0004)
2012                         printk(KERN_INFO "IXJ Ring Off\n");
2013                 j->gpio.bytes.high = 0x0B;
2014                 j->gpio.bytes.low = 0x00;
2015                 j->gpio.bits.gpio1 = 0;
2016                 j->gpio.bits.gpio2 = 1;
2017                 j->gpio.bits.gpio5 = 0;
2018                 ixj_WriteDSPCommand(j->gpio.word, j);
2019         } else                  /* Internet LineJACK */
2020         {
2021                 if (ixjdebug & 0x0004)
2022                         printk(KERN_INFO "IXJ Ring Off\n");
2023
2024                 if(!j->flags.cidplay)
2025                         SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
2026
2027                 SLIC_GetState(j);
2028         }
2029 }
2030
2031 static void ixj_ring_start(IXJ *j)
2032 {
2033         j->flags.cringing = 1;
2034         if (ixjdebug & 0x0004)
2035                 printk(KERN_INFO "IXJ Cadence Ringing Start /dev/phone%d\n", j->board);
2036         if (ixj_hookstate(j) & 1) {
2037                 if (j->port == PORT_POTS)
2038                         ixj_ring_off(j);
2039                 j->flags.cringing = 0;
2040                 if (ixjdebug & 0x0004)
2041                         printk(KERN_INFO "IXJ Cadence Ringing Stopped /dev/phone%d off hook\n", j->board);
2042         } else if(j->cadence_f[5].enable && (!j->cadence_f[5].en_filter)) {
2043                 j->ring_cadence_jif = jiffies;
2044                 j->flags.cidsent = j->flags.cidring = 0;
2045                 j->cadence_f[5].state = 0;
2046                 if(j->cadence_f[5].on1)
2047                         ixj_ring_on(j);
2048         } else {
2049                 j->ring_cadence_jif = jiffies;
2050                 j->ring_cadence_t = 15;
2051                 if (j->ring_cadence & 1 << j->ring_cadence_t) {
2052                         ixj_ring_on(j);
2053                 } else {
2054                         ixj_ring_off(j);
2055                 }
2056                 j->flags.cidsent = j->flags.cidring = j->flags.firstring = 0;
2057         }
2058 }
2059
2060 static int ixj_ring(IXJ *j)
2061 {
2062         char cntr;
2063         unsigned long jif;
2064
2065         j->flags.ringing = 1;
2066         if (ixj_hookstate(j) & 1) {
2067                 ixj_ring_off(j);
2068                 j->flags.ringing = 0;
2069                 return 1;
2070         }
2071         for (cntr = 0; cntr < j->maxrings; cntr++) {
2072                 jif = jiffies + (1 * hertz);
2073                 ixj_ring_on(j);
2074                 while (time_before(jiffies, jif)) {
2075                         if (ixj_hookstate(j) & 1) {
2076                                 ixj_ring_off(j);
2077                                 j->flags.ringing = 0;
2078                                 return 1;
2079                         }
2080                         schedule_timeout_interruptible(1);
2081                         if (signal_pending(current))
2082                                 break;
2083                 }
2084                 jif = jiffies + (3 * hertz);
2085                 ixj_ring_off(j);
2086                 while (time_before(jiffies, jif)) {
2087                         if (ixj_hookstate(j) & 1) {
2088                                 msleep(10);
2089                                 if (ixj_hookstate(j) & 1) {
2090                                         j->flags.ringing = 0;
2091                                         return 1;
2092                                 }
2093                         }
2094                         schedule_timeout_interruptible(1);
2095                         if (signal_pending(current))
2096                                 break;
2097                 }
2098         }
2099         ixj_ring_off(j);
2100         j->flags.ringing = 0;
2101         return 0;
2102 }
2103
2104 static int ixj_open(struct phone_device *p, struct file *file_p)
2105 {
2106         IXJ *j = get_ixj(p->board);
2107         file_p->private_data = j;
2108
2109         if (!j->DSPbase)
2110                 return -ENODEV;
2111
2112         if (file_p->f_mode & FMODE_READ) {
2113                 if(!j->readers) {
2114                         j->readers++;
2115                 } else {
2116                         return -EBUSY;
2117                 }
2118         }
2119
2120         if (file_p->f_mode & FMODE_WRITE) {
2121                 if(!j->writers) {
2122                         j->writers++;
2123                 } else {
2124                         if (file_p->f_mode & FMODE_READ){
2125                                 j->readers--;
2126                         }
2127                         return -EBUSY;
2128                 }
2129         }
2130
2131         if (j->cardtype == QTI_PHONECARD) {
2132                 j->pslic.bits.powerdown = 0;
2133                 j->psccr.bits.dev = 3;
2134                 j->psccr.bits.rw = 0;
2135                 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
2136                 ixj_PCcontrol_wait(j);
2137         }
2138
2139         j->flags.cidplay = 0;
2140         j->flags.cidcw_ack = 0;
2141
2142         if (ixjdebug & 0x0002)
2143                 printk(KERN_INFO "Opening board %d\n", p->board);
2144
2145         j->framesread = j->frameswritten = 0;
2146         return 0;
2147 }
2148
2149 static int ixj_release(struct inode *inode, struct file *file_p)
2150 {
2151         IXJ_TONE ti;
2152         int cnt;
2153         IXJ *j = file_p->private_data;
2154         int board = j->p.board;
2155
2156         /*
2157          *    Set up locks to ensure that only one process is talking to the DSP at a time.
2158          *    This is necessary to keep the DSP from locking up.
2159          */
2160         while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
2161                 schedule_timeout_interruptible(1);
2162         if (ixjdebug & 0x0002)
2163                 printk(KERN_INFO "Closing board %d\n", NUM(inode));
2164
2165         if (j->cardtype == QTI_PHONECARD)
2166                 ixj_set_port(j, PORT_SPEAKER);
2167         else
2168                 ixj_set_port(j, PORT_POTS);
2169
2170         aec_stop(j);
2171         ixj_play_stop(j);
2172         ixj_record_stop(j);
2173         set_play_volume(j, 0x100);
2174         set_rec_volume(j, 0x100);
2175         ixj_ring_off(j);
2176
2177         /* Restore the tone table to default settings. */
2178         ti.tone_index = 10;
2179         ti.gain0 = 1;
2180         ti.freq0 = hz941;
2181         ti.gain1 = 0;
2182         ti.freq1 = hz1209;
2183         ixj_init_tone(j, &ti);
2184         ti.tone_index = 11;
2185         ti.gain0 = 1;
2186         ti.freq0 = hz941;
2187         ti.gain1 = 0;
2188         ti.freq1 = hz1336;
2189         ixj_init_tone(j, &ti);
2190         ti.tone_index = 12;
2191         ti.gain0 = 1;
2192         ti.freq0 = hz941;
2193         ti.gain1 = 0;
2194         ti.freq1 = hz1477;
2195         ixj_init_tone(j, &ti);
2196         ti.tone_index = 13;
2197         ti.gain0 = 1;
2198         ti.freq0 = hz800;
2199         ti.gain1 = 0;
2200         ti.freq1 = 0;
2201         ixj_init_tone(j, &ti);
2202         ti.tone_index = 14;
2203         ti.gain0 = 1;
2204         ti.freq0 = hz1000;
2205         ti.gain1 = 0;
2206         ti.freq1 = 0;
2207         ixj_init_tone(j, &ti);
2208         ti.tone_index = 15;
2209         ti.gain0 = 1;
2210         ti.freq0 = hz1250;
2211         ti.gain1 = 0;
2212         ti.freq1 = 0;
2213         ixj_init_tone(j, &ti);
2214         ti.tone_index = 16;
2215         ti.gain0 = 1;
2216         ti.freq0 = hz950;
2217         ti.gain1 = 0;
2218         ti.freq1 = 0;
2219         ixj_init_tone(j, &ti);
2220         ti.tone_index = 17;
2221         ti.gain0 = 1;
2222         ti.freq0 = hz1100;
2223         ti.gain1 = 0;
2224         ti.freq1 = 0;
2225         ixj_init_tone(j, &ti);
2226         ti.tone_index = 18;
2227         ti.gain0 = 1;
2228         ti.freq0 = hz1400;
2229         ti.gain1 = 0;
2230         ti.freq1 = 0;
2231         ixj_init_tone(j, &ti);
2232         ti.tone_index = 19;
2233         ti.gain0 = 1;
2234         ti.freq0 = hz1500;
2235         ti.gain1 = 0;
2236         ti.freq1 = 0;
2237         ixj_init_tone(j, &ti);
2238         ti.tone_index = 20;
2239         ti.gain0 = 1;
2240         ti.freq0 = hz1600;
2241         ti.gain1 = 0;
2242         ti.freq1 = 0;
2243         ixj_init_tone(j, &ti);
2244         ti.tone_index = 21;
2245         ti.gain0 = 1;
2246         ti.freq0 = hz1800;
2247         ti.gain1 = 0;
2248         ti.freq1 = 0;
2249         ixj_init_tone(j, &ti);
2250         ti.tone_index = 22;
2251         ti.gain0 = 1;
2252         ti.freq0 = hz2100;
2253         ti.gain1 = 0;
2254         ti.freq1 = 0;
2255         ixj_init_tone(j, &ti);
2256         ti.tone_index = 23;
2257         ti.gain0 = 1;
2258         ti.freq0 = hz1300;
2259         ti.gain1 = 0;
2260         ti.freq1 = 0;
2261         ixj_init_tone(j, &ti);
2262         ti.tone_index = 24;
2263         ti.gain0 = 1;
2264         ti.freq0 = hz2450;
2265         ti.gain1 = 0;
2266         ti.freq1 = 0;
2267         ixj_init_tone(j, &ti);
2268         ti.tone_index = 25;
2269         ti.gain0 = 1;
2270         ti.freq0 = hz350;
2271         ti.gain1 = 0;
2272         ti.freq1 = hz440;
2273         ixj_init_tone(j, &ti);
2274         ti.tone_index = 26;
2275         ti.gain0 = 1;
2276         ti.freq0 = hz440;
2277         ti.gain1 = 0;
2278         ti.freq1 = hz480;
2279         ixj_init_tone(j, &ti);
2280         ti.tone_index = 27;
2281         ti.gain0 = 1;
2282         ti.freq0 = hz480;
2283         ti.gain1 = 0;
2284         ti.freq1 = hz620;
2285         ixj_init_tone(j, &ti);
2286
2287         set_rec_depth(j, 2);    /* Set Record Channel Limit to 2 frames */
2288
2289         set_play_depth(j, 2);   /* Set Playback Channel Limit to 2 frames */
2290
2291         j->ex.bits.dtmf_ready = 0;
2292         j->dtmf_state = 0;
2293         j->dtmf_wp = j->dtmf_rp = 0;
2294         j->rec_mode = j->play_mode = -1;
2295         j->flags.ringing = 0;
2296         j->maxrings = MAXRINGS;
2297         j->ring_cadence = USA_RING_CADENCE;
2298         if(j->cadence_f[5].enable) {
2299                 j->cadence_f[5].enable = j->cadence_f[5].en_filter = j->cadence_f[5].state = 0;
2300         }
2301         j->drybuffer = 0;
2302         j->winktime = 320;
2303         j->flags.dtmf_oob = 0;
2304         for (cnt = 0; cnt < 4; cnt++)
2305                 j->cadence_f[cnt].enable = 0;
2306
2307         idle(j);
2308
2309         if(j->cardtype == QTI_PHONECARD) {
2310                 SLIC_SetState(PLD_SLIC_STATE_OC, j);
2311         }
2312
2313         if (file_p->f_mode & FMODE_READ)
2314                 j->readers--;
2315         if (file_p->f_mode & FMODE_WRITE)
2316                 j->writers--;
2317
2318         if (j->read_buffer && !j->readers) {
2319                 kfree(j->read_buffer);
2320                 j->read_buffer = NULL;
2321                 j->read_buffer_size = 0;
2322         }
2323         if (j->write_buffer && !j->writers) {
2324                 kfree(j->write_buffer);
2325                 j->write_buffer = NULL;
2326                 j->write_buffer_size = 0;
2327         }
2328         j->rec_codec = j->play_codec = 0;
2329         j->rec_frame_size = j->play_frame_size = 0;
2330         j->flags.cidsent = j->flags.cidring = 0;
2331
2332         if(j->cardtype == QTI_LINEJACK && !j->readers && !j->writers) {
2333                 ixj_set_port(j, PORT_PSTN);
2334                 daa_set_mode(j, SOP_PU_SLEEP);
2335                 ixj_set_pots(j, 1);
2336         }
2337         ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
2338
2339         /* Set up the default signals for events */
2340         for (cnt = 0; cnt < 35; cnt++)
2341                 j->ixj_signals[cnt] = SIGIO;
2342
2343         /* Set the excetion signal enable flags */
2344         j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 
2345         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 = 
2346         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;
2347
2348         file_p->private_data = NULL;
2349         clear_bit(board, &j->busyflags);
2350         return 0;
2351 }
2352
2353 static int read_filters(IXJ *j)
2354 {
2355         unsigned short fc, cnt, trg;
2356         int var;
2357
2358         trg = 0;
2359         if (ixj_WriteDSPCommand(0x5144, j)) {
2360                 if(ixjdebug & 0x0001) {
2361                         printk(KERN_INFO "Read Frame Counter failed!\n");
2362                 }
2363                 return -1;
2364         }
2365         fc = j->ssr.high << 8 | j->ssr.low;
2366         if (fc == j->frame_count)
2367                 return 1;
2368
2369         j->frame_count = fc;
2370
2371         if (j->dtmf_proc)
2372                 return 1;
2373
2374         var = 10;
2375
2376         for (cnt = 0; cnt < 4; cnt++) {
2377                 if (ixj_WriteDSPCommand(0x5154 + cnt, j)) {
2378                         if(ixjdebug & 0x0001) {
2379                                 printk(KERN_INFO "Select Filter %d failed!\n", cnt);
2380                         }
2381                         return -1;
2382                 }
2383                 if (ixj_WriteDSPCommand(0x515C, j)) {
2384                         if(ixjdebug & 0x0001) {
2385                                 printk(KERN_INFO "Read Filter History %d failed!\n", cnt);
2386                         }
2387                         return -1;
2388                 }
2389                 j->filter_hist[cnt] = j->ssr.high << 8 | j->ssr.low;
2390
2391                 if (j->cadence_f[cnt].enable) {
2392                         if (j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) {
2393                                 if (j->cadence_f[cnt].state == 0) {
2394                                         j->cadence_f[cnt].state = 1;
2395                                         j->cadence_f[cnt].on1min = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 - var)) / 10000));
2396                                         j->cadence_f[cnt].on1dot = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100)) / 10000));
2397                                         j->cadence_f[cnt].on1max = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 + var)) / 10000));
2398                                 } else if (j->cadence_f[cnt].state == 2 &&
2399                                            (time_after(jiffies, j->cadence_f[cnt].off1min) &&
2400                                             time_before(jiffies, j->cadence_f[cnt].off1max))) {
2401                                         if (j->cadence_f[cnt].on2) {
2402                                                 j->cadence_f[cnt].state = 3;
2403                                                 j->cadence_f[cnt].on2min = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 - var)) / 10000));
2404                                                 j->cadence_f[cnt].on2dot = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100)) / 10000));
2405                                                 j->cadence_f[cnt].on2max = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 + var)) / 10000));
2406                                         } else {
2407                                                 j->cadence_f[cnt].state = 7;
2408                                         }
2409                                 } else if (j->cadence_f[cnt].state == 4 &&
2410                                            (time_after(jiffies, j->cadence_f[cnt].off2min) &&
2411                                             time_before(jiffies, j->cadence_f[cnt].off2max))) {
2412                                         if (j->cadence_f[cnt].on3) {
2413                                                 j->cadence_f[cnt].state = 5;
2414                                                 j->cadence_f[cnt].on3min = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 - var)) / 10000));
2415                                                 j->cadence_f[cnt].on3dot = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100)) / 10000));
2416                                                 j->cadence_f[cnt].on3max = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 + var)) / 10000));
2417                                         } else {
2418                                                 j->cadence_f[cnt].state = 7;
2419                                         }
2420                                 } else {
2421                                         j->cadence_f[cnt].state = 0;
2422                                 }
2423                         } else if (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)) {
2424                                 if (j->cadence_f[cnt].state == 1) {
2425                                         if(!j->cadence_f[cnt].on1) {
2426                                                 j->cadence_f[cnt].state = 7;
2427                                         } else if((time_after(jiffies, j->cadence_f[cnt].on1min) &&
2428                                           time_before(jiffies, j->cadence_f[cnt].on1max))) {
2429                                                 if(j->cadence_f[cnt].off1) {
2430                                                         j->cadence_f[cnt].state = 2;
2431                                                         j->cadence_f[cnt].off1min = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 - var)) / 10000));
2432                                                         j->cadence_f[cnt].off1dot = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100)) / 10000));
2433                                                         j->cadence_f[cnt].off1max = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 + var)) / 10000));
2434                                                 } else {
2435                                                         j->cadence_f[cnt].state = 7;
2436                                                 }
2437                                         } else {
2438                                                 j->cadence_f[cnt].state = 0;
2439                                         }
2440                                 } else if (j->cadence_f[cnt].state == 3) {
2441                                         if((time_after(jiffies, j->cadence_f[cnt].on2min) &&
2442                                             time_before(jiffies, j->cadence_f[cnt].on2max))) {
2443                                                 if(j->cadence_f[cnt].off2) {
2444                                                         j->cadence_f[cnt].state = 4;
2445                                                         j->cadence_f[cnt].off2min = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 - var)) / 10000));
2446                                                         j->cadence_f[cnt].off2dot = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100)) / 10000));
2447                                                         j->cadence_f[cnt].off2max = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 + var)) / 10000));
2448                                                 } else {
2449                                                         j->cadence_f[cnt].state = 7;
2450                                                 }
2451                                         } else {
2452                                                 j->cadence_f[cnt].state = 0;
2453                                         }
2454                                 } else if (j->cadence_f[cnt].state == 5) {
2455                                         if ((time_after(jiffies, j->cadence_f[cnt].on3min) &&
2456                                             time_before(jiffies, j->cadence_f[cnt].on3max))) {
2457                                                 if(j->cadence_f[cnt].off3) {
2458                                                         j->cadence_f[cnt].state = 6;
2459                                                         j->cadence_f[cnt].off3min = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 - var)) / 10000));
2460                                                         j->cadence_f[cnt].off3dot = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100)) / 10000));
2461                                                         j->cadence_f[cnt].off3max = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 + var)) / 10000));
2462                                                 } else {
2463                                                         j->cadence_f[cnt].state = 7;
2464                                                 }
2465                                         } else {
2466                                                 j->cadence_f[cnt].state = 0;
2467                                         }
2468                                 } else {
2469                                         j->cadence_f[cnt].state = 0;
2470                                 }
2471                         } else {
2472                                 switch(j->cadence_f[cnt].state) {
2473                                         case 1:
2474                                                 if(time_after(jiffies, j->cadence_f[cnt].on1dot) &&
2475                                                    !j->cadence_f[cnt].off1 &&
2476                                                    !j->cadence_f[cnt].on2 && !j->cadence_f[cnt].off2 &&
2477                                                    !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2478                                                         j->cadence_f[cnt].state = 7;
2479                                                 }
2480                                                 break;
2481                                         case 3:
2482                                                 if(time_after(jiffies, j->cadence_f[cnt].on2dot) &&
2483                                                    !j->cadence_f[cnt].off2 &&
2484                                                    !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2485                                                         j->cadence_f[cnt].state = 7;
2486                                                 }
2487                                                 break;
2488                                         case 5:
2489                                                 if(time_after(jiffies, j->cadence_f[cnt].on3dot) &&
2490                                                    !j->cadence_f[cnt].off3) {
2491                                                         j->cadence_f[cnt].state = 7;
2492                                                 }
2493                                                 break;
2494                                 }
2495                         }
2496
2497                         if (ixjdebug & 0x0040) {
2498                                 printk(KERN_INFO "IXJ Tone Cadence state = %d /dev/phone%d at %ld\n", j->cadence_f[cnt].state, j->board, jiffies);
2499                                 switch(j->cadence_f[cnt].state) {
2500                                         case 0:
2501                                                 printk(KERN_INFO "IXJ /dev/phone%d No Tone detected\n", j->board);
2502                                                 break;
2503                                         case 1:
2504                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %u %ld - %ld - %ld\n", j->board,
2505                                         j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max);
2506                                                 break;
2507                                         case 2:
2508                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min, 
2509                                                                                                                         j->cadence_f[cnt].off1max);
2510                                                 break;
2511                                         case 3:
2512                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on2min,
2513                                                                                                                         j->cadence_f[cnt].on2max);
2514                                                 break;
2515                                         case 4:
2516                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off2min,
2517                                                                                                                         j->cadence_f[cnt].off2max);
2518                                                 break;
2519                                         case 5:
2520                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min,
2521                                                                                                                         j->cadence_f[cnt].on3max);
2522                                                 break;
2523                                         case 6: 
2524                                                 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min,
2525                                                                                                                         j->cadence_f[cnt].off3max);
2526                                                 break;
2527                                 }
2528                         } 
2529                 }
2530                 if (j->cadence_f[cnt].state == 7) {
2531                         j->cadence_f[cnt].state = 0;
2532                         if (j->cadence_f[cnt].enable == 1)
2533                                 j->cadence_f[cnt].enable = 0;
2534                         switch (cnt) {
2535                         case 0:
2536                                 if(ixjdebug & 0x0020) {
2537                                         printk(KERN_INFO "Filter Cadence 0 triggered %ld\n", jiffies);
2538                                 }
2539                                 j->ex.bits.fc0 = 1;
2540                                 ixj_kill_fasync(j, SIG_FC0, POLL_IN);
2541                                 break;
2542                         case 1:
2543                                 if(ixjdebug & 0x0020) {
2544                                         printk(KERN_INFO "Filter Cadence 1 triggered %ld\n", jiffies);
2545                                 }
2546                                 j->ex.bits.fc1 = 1;
2547                                 ixj_kill_fasync(j, SIG_FC1, POLL_IN);
2548                                 break;
2549                         case 2:
2550                                 if(ixjdebug & 0x0020) {
2551                                         printk(KERN_INFO "Filter Cadence 2 triggered %ld\n", jiffies);
2552                                 }
2553                                 j->ex.bits.fc2 = 1;
2554                                 ixj_kill_fasync(j, SIG_FC2, POLL_IN);
2555                                 break;
2556                         case 3:
2557                                 if(ixjdebug & 0x0020) {
2558                                         printk(KERN_INFO "Filter Cadence 3 triggered %ld\n", jiffies);
2559                                 }
2560                                 j->ex.bits.fc3 = 1;
2561                                 ixj_kill_fasync(j, SIG_FC3, POLL_IN);
2562                                 break;
2563                         }
2564                 }
2565                 if (j->filter_en[cnt] && ((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) ||
2566                                           (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)))) {
2567                         if((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12))) {
2568                                 trg = 1;
2569                         } else if((j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3))) {
2570                                 trg = 0;
2571                         }
2572                         switch (cnt) {
2573                         case 0:
2574                                 if(ixjdebug & 0x0020) {
2575                                         printk(KERN_INFO "Filter 0 triggered %d at %ld\n", trg, jiffies);
2576                                 }
2577                                 j->ex.bits.f0 = 1;
2578                                 ixj_kill_fasync(j, SIG_F0, POLL_IN);
2579                                 break;
2580                         case 1:
2581                                 if(ixjdebug & 0x0020) {
2582                                         printk(KERN_INFO "Filter 1 triggered %d at %ld\n", trg, jiffies);
2583                                 }
2584                                 j->ex.bits.f1 = 1;
2585                                 ixj_kill_fasync(j, SIG_F1, POLL_IN);
2586                                 break;
2587                         case 2:
2588                                 if(ixjdebug & 0x0020) {
2589                                         printk(KERN_INFO "Filter 2 triggered %d at %ld\n", trg, jiffies);
2590                                 }
2591                                 j->ex.bits.f2 = 1;
2592                                 ixj_kill_fasync(j, SIG_F2, POLL_IN);
2593                                 break;
2594                         case 3:
2595                                 if(ixjdebug & 0x0020) {
2596                                         printk(KERN_INFO "Filter 3 triggered %d at %ld\n", trg, jiffies);
2597                                 }
2598                                 j->ex.bits.f3 = 1;
2599                                 ixj_kill_fasync(j, SIG_F3, POLL_IN);
2600                                 break;
2601                         }
2602                 }
2603         }
2604         return 0;
2605 }
2606
2607 static int LineMonitor(IXJ *j)
2608 {
2609         if (j->dtmf_proc) {
2610                 return -1;
2611         }
2612         j->dtmf_proc = 1;
2613
2614         if (ixj_WriteDSPCommand(0x7000, j))             /* Line Monitor */
2615                 return -1;
2616
2617         j->dtmf.bytes.high = j->ssr.high;
2618         j->dtmf.bytes.low = j->ssr.low;
2619         if (!j->dtmf_state && j->dtmf.bits.dtmf_valid) {
2620                 j->dtmf_state = 1;
2621                 j->dtmf_current = j->dtmf.bits.digit;
2622         }
2623         if (j->dtmf_state && !j->dtmf.bits.dtmf_valid)  /* && j->dtmf_wp != j->dtmf_rp) */
2624          {
2625                 if(!j->cidcw_wait) {
2626                         j->dtmfbuffer[j->dtmf_wp] = j->dtmf_current;
2627                         j->dtmf_wp++;
2628                         if (j->dtmf_wp == 79)
2629                                 j->dtmf_wp = 0;
2630                         j->ex.bits.dtmf_ready = 1;
2631                         if(j->ex_sig.bits.dtmf_ready) {
2632                                 ixj_kill_fasync(j, SIG_DTMF_READY, POLL_IN);
2633                         }
2634                 }
2635                 else if(j->dtmf_current == 0x00 || j->dtmf_current == 0x0D) {
2636                         if(ixjdebug & 0x0020) {
2637                                 printk("IXJ phone%d saw CIDCW Ack DTMF %d from display at %ld\n", j->board, j->dtmf_current, jiffies);
2638                         }
2639                         j->flags.cidcw_ack = 1;
2640                 }
2641                 j->dtmf_state = 0;
2642         }
2643         j->dtmf_proc = 0;
2644
2645         return 0;
2646 }
2647
2648 /************************************************************************
2649 *
2650 * Functions to allow alaw <-> ulaw conversions.
2651 *
2652 ************************************************************************/
2653
2654 static void ulaw2alaw(unsigned char *buff, unsigned long len)
2655 {
2656         static unsigned char table_ulaw2alaw[] =
2657         {
2658                 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D, 
2659                 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, 
2660                 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D, 
2661                 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, 
2662                 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02, 
2663                 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A, 
2664                 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12, 
2665                 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B, 
2666                 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63, 
2667                 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79, 
2668                 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71, 
2669                 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D, 
2670                 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45, 
2671                 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D, 
2672                 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51, 
2673                 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5, 
2674                 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD, 
2675                 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5, 
2676                 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD, 
2677                 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5, 
2678                 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82, 
2679                 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A, 
2680                 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92, 
2681                 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB, 
2682                 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3, 
2683                 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9, 
2684                 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1, 
2685                 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD, 
2686                 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5, 
2687                 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD, 
2688                 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1, 
2689                 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5
2690         };
2691
2692         while (len--)
2693         {
2694                 *buff = table_ulaw2alaw[*(unsigned char *)buff];
2695                 buff++;
2696         }
2697 }
2698
2699 static void alaw2ulaw(unsigned char *buff, unsigned long len)
2700 {
2701         static unsigned char table_alaw2ulaw[] =
2702         {
2703                 0x29, 0x2A, 0x27, 0x28, 0x2D, 0x2E, 0x2B, 0x2C, 
2704                 0x21, 0x22, 0x1F, 0x20, 0x25, 0x26, 0x23, 0x24, 
2705                 0x39, 0x3A, 0x37, 0x38, 0x3D, 0x3E, 0x3B, 0x3C, 
2706                 0x31, 0x32, 0x2F, 0x30, 0x35, 0x36, 0x33, 0x34, 
2707                 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 
2708                 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 
2709                 0x1A, 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 
2710                 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 
2711                 0x62, 0x63, 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 
2712                 0x5D, 0x5D, 0x5C, 0x5C, 0x5F, 0x5F, 0x5E, 0x5E, 
2713                 0x74, 0x76, 0x70, 0x72, 0x7C, 0x7E, 0x78, 0x7A, 
2714                 0x6A, 0x6B, 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 
2715                 0x48, 0x49, 0x46, 0x47, 0x4C, 0x4D, 0x4A, 0x4B, 
2716                 0x40, 0x41, 0x3F, 0x3F, 0x44, 0x45, 0x42, 0x43, 
2717                 0x56, 0x57, 0x54, 0x55, 0x5A, 0x5B, 0x58, 0x59, 
2718                 0x4F, 0x4F, 0x4E, 0x4E, 0x52, 0x53, 0x50, 0x51, 
2719                 0xA9, 0xAA, 0xA7, 0xA8, 0xAD, 0xAE, 0xAB, 0xAC, 
2720                 0xA1, 0xA2, 0x9F, 0xA0, 0xA5, 0xA6, 0xA3, 0xA4, 
2721                 0xB9, 0xBA, 0xB7, 0xB8, 0xBD, 0xBE, 0xBB, 0xBC, 
2722                 0xB1, 0xB2, 0xAF, 0xB0, 0xB5, 0xB6, 0xB3, 0xB4, 
2723                 0x8A, 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 
2724                 0x82, 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 
2725                 0x9A, 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 
2726                 0x92, 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 
2727                 0xE2, 0xE3, 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 
2728                 0xDD, 0xDD, 0xDC, 0xDC, 0xDF, 0xDF, 0xDE, 0xDE, 
2729                 0xF4, 0xF6, 0xF0, 0xF2, 0xFC, 0xFE, 0xF8, 0xFA, 
2730                 0xEA, 0xEB, 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 
2731                 0xC8, 0xC9, 0xC6, 0xC7, 0xCC, 0xCD, 0xCA, 0xCB, 
2732                 0xC0, 0xC1, 0xBF, 0xBF, 0xC4, 0xC5, 0xC2, 0xC3, 
2733                 0xD6, 0xD7, 0xD4, 0xD5, 0xDA, 0xDB, 0xD8, 0xD9, 
2734                 0xCF, 0xCF, 0xCE, 0xCE, 0xD2, 0xD3, 0xD0, 0xD1
2735         };
2736
2737         while (len--)
2738         {
2739                 *buff = table_alaw2ulaw[*(unsigned char *)buff];
2740                 buff++;
2741         }
2742 }
2743
2744 static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos)
2745 {
2746         unsigned long i = *ppos;
2747         IXJ * j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2748
2749         DECLARE_WAITQUEUE(wait, current);
2750
2751         if (j->flags.inread)
2752                 return -EALREADY;
2753
2754         j->flags.inread = 1;
2755
2756         add_wait_queue(&j->read_q, &wait);
2757         set_current_state(TASK_INTERRUPTIBLE);
2758         mb();
2759
2760         while (!j->read_buffer_ready || (j->dtmf_state && j->flags.dtmf_oob)) {
2761                 ++j->read_wait;
2762                 if (file_p->f_flags & O_NONBLOCK) {
2763                         set_current_state(TASK_RUNNING);
2764                         remove_wait_queue(&j->read_q, &wait);
2765                         j->flags.inread = 0;
2766                         return -EAGAIN;
2767                 }
2768                 if (!ixj_hookstate(j)) {
2769                         set_current_state(TASK_RUNNING);
2770                         remove_wait_queue(&j->read_q, &wait);
2771                         j->flags.inread = 0;
2772                         return 0;
2773                 }
2774                 interruptible_sleep_on(&j->read_q);
2775                 if (signal_pending(current)) {
2776                         set_current_state(TASK_RUNNING);
2777                         remove_wait_queue(&j->read_q, &wait);
2778                         j->flags.inread = 0;
2779                         return -EINTR;
2780                 }
2781         }
2782
2783         remove_wait_queue(&j->read_q, &wait);
2784         set_current_state(TASK_RUNNING);
2785         /* Don't ever copy more than the user asks */
2786         if(j->rec_codec == ALAW)
2787                 ulaw2alaw(j->read_buffer, min(length, j->read_buffer_size));
2788         i = copy_to_user(buf, j->read_buffer, min(length, j->read_buffer_size));
2789         j->read_buffer_ready = 0;
2790         if (i) {
2791                 j->flags.inread = 0;
2792                 return -EFAULT;
2793         } else {
2794                 j->flags.inread = 0;
2795                 return min(length, j->read_buffer_size);
2796         }
2797 }
2798
2799 static ssize_t ixj_enhanced_read(struct file * file_p, char __user *buf, size_t length,
2800                           loff_t * ppos)
2801 {
2802         int pre_retval;
2803         ssize_t read_retval = 0;
2804         IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2805
2806         pre_retval = ixj_PreRead(j, 0L);
2807         switch (pre_retval) {
2808         case NORMAL:
2809                 read_retval = ixj_read(file_p, buf, length, ppos);
2810                 ixj_PostRead(j, 0L);
2811                 break;
2812         case NOPOST:
2813                 read_retval = ixj_read(file_p, buf, length, ppos);
2814                 break;
2815         case POSTONLY:
2816                 ixj_PostRead(j, 0L);
2817                 break;
2818         default:
2819                 read_retval = pre_retval;
2820         }
2821         return read_retval;
2822 }
2823
2824 static ssize_t ixj_write(struct file *file_p, const char __user *buf, size_t count, loff_t * ppos)
2825 {
2826         unsigned long i = *ppos;
2827         IXJ *j = file_p->private_data;
2828
2829         DECLARE_WAITQUEUE(wait, current);
2830
2831         if (j->flags.inwrite)
2832                 return -EALREADY;
2833
2834         j->flags.inwrite = 1;
2835
2836         add_wait_queue(&j->write_q, &wait);
2837         set_current_state(TASK_INTERRUPTIBLE);
2838         mb();
2839
2840
2841         while (!j->write_buffers_empty) {
2842                 ++j->write_wait;
2843                 if (file_p->f_flags & O_NONBLOCK) {
2844                         set_current_state(TASK_RUNNING);
2845                         remove_wait_queue(&j->write_q, &wait);
2846                         j->flags.inwrite = 0;
2847                         return -EAGAIN;
2848                 }
2849                 if (!ixj_hookstate(j)) {
2850                         set_current_state(TASK_RUNNING);
2851                         remove_wait_queue(&j->write_q, &wait);
2852                         j->flags.inwrite = 0;
2853                         return 0;
2854                 }
2855                 interruptible_sleep_on(&j->write_q);
2856                 if (signal_pending(current)) {
2857                         set_current_state(TASK_RUNNING);
2858                         remove_wait_queue(&j->write_q, &wait);
2859                         j->flags.inwrite = 0;
2860                         return -EINTR;
2861                 }
2862         }
2863         set_current_state(TASK_RUNNING);
2864         remove_wait_queue(&j->write_q, &wait);
2865         if (j->write_buffer_wp + count >= j->write_buffer_end)
2866                 j->write_buffer_wp = j->write_buffer;
2867         i = copy_from_user(j->write_buffer_wp, buf, min(count, j->write_buffer_size));
2868         if (i) {
2869                 j->flags.inwrite = 0;
2870                 return -EFAULT;
2871         }
2872        if(j->play_codec == ALAW)
2873                alaw2ulaw(j->write_buffer_wp, min(count, j->write_buffer_size));
2874         j->flags.inwrite = 0;
2875         return min(count, j->write_buffer_size);
2876 }
2877
2878 static ssize_t ixj_enhanced_write(struct file * file_p, const char __user *buf, size_t count, loff_t * ppos)
2879 {
2880         int pre_retval;
2881         ssize_t write_retval = 0;
2882
2883         IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2884
2885         pre_retval = ixj_PreWrite(j, 0L);
2886         switch (pre_retval) {
2887         case NORMAL:
2888                 write_retval = ixj_write(file_p, buf, count, ppos);
2889                 if (write_retval > 0) {
2890                         ixj_PostWrite(j, 0L);
2891                         j->write_buffer_wp += write_retval;
2892                         j->write_buffers_empty--;
2893                 }
2894                 break;
2895         case NOPOST:
2896                 write_retval = ixj_write(file_p, buf, count, ppos);
2897                 if (write_retval > 0) {
2898                         j->write_buffer_wp += write_retval;
2899                         j->write_buffers_empty--;
2900                 }
2901                 break;
2902         case POSTONLY:
2903                 ixj_PostWrite(j, 0L);
2904                 break;
2905         default:
2906                 write_retval = pre_retval;
2907         }
2908         return write_retval;
2909 }
2910
2911 static void ixj_read_frame(IXJ *j)
2912 {
2913         int cnt, dly;
2914
2915         if (j->read_buffer) {
2916                 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2917                         if (!(cnt % 16) && !IsRxReady(j)) {
2918                                 dly = 0;
2919                                 while (!IsRxReady(j)) {
2920                                         if (dly++ > 5) {
2921                                                 dly = 0;
2922                                                 break;
2923                                         }
2924                                         udelay(10);
2925                                 }
2926                         }
2927                         /* Throw away word 0 of the 8021 compressed format to get standard G.729. */
2928                         if (j->rec_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
2929                                 inb_p(j->DSPbase + 0x0E);
2930                                 inb_p(j->DSPbase + 0x0F);
2931                         }
2932                         *(j->read_buffer + cnt) = inb_p(j->DSPbase + 0x0E);
2933                         *(j->read_buffer + cnt + 1) = inb_p(j->DSPbase + 0x0F);
2934                 }
2935                 ++j->framesread;
2936                 if (j->intercom != -1) {
2937                         if (IsTxReady(get_ixj(j->intercom))) {
2938                                 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2939                                         if (!(cnt % 16) && !IsTxReady(j)) {
2940                                                 dly = 0;
2941                                                 while (!IsTxReady(j)) {
2942                                                         if (dly++ > 5) {
2943                                                                 dly = 0;
2944                                                                 break;
2945                                                         }
2946                                                         udelay(10);
2947                                                 }
2948                                         }
2949                                         outb_p(*(j->read_buffer + cnt), get_ixj(j->intercom)->DSPbase + 0x0C);
2950                                         outb_p(*(j->read_buffer + cnt + 1), get_ixj(j->intercom)->DSPbase + 0x0D);
2951                                 }
2952                                 get_ixj(j->intercom)->frameswritten++;
2953                         }
2954                 } else {
2955                         j->read_buffer_ready = 1;
2956                         wake_up_interruptible(&j->read_q);      /* Wake any blocked readers */
2957
2958                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
2959
2960                         if(j->ixj_signals[SIG_READ_READY])
2961                                 ixj_kill_fasync(j, SIG_READ_READY, POLL_OUT);
2962                 }
2963         }
2964 }
2965
2966 static short fsk[][6][20] =
2967 {
2968         {
2969                 {
2970                         0, 17846, 29934, 32364, 24351, 8481, -10126, -25465, -32587, -29196,
2971                         -16384, 1715, 19260, 30591, 32051, 23170, 6813, -11743, -26509, -32722
2972                 },
2973                 {
2974                         -28377, -14876, 3425, 20621, 31163, 31650, 21925, 5126, -13328, -27481,
2975                         -32767, -27481, -13328, 5126, 21925, 31650, 31163, 20621, 3425, -14876
2976                 },
2977                 {
2978                         -28377, -32722, -26509, -11743, 6813, 23170, 32051, 30591, 19260, 1715,
2979                         -16384, -29196, -32587, -25465, -10126, 8481, 24351, 32364, 29934, 17846
2980                 },
2981                 {
2982                         0, -17846, -29934, -32364, -24351, -8481, 10126, 25465, 32587, 29196,
2983                         16384, -1715, -19260, -30591, -32051, -23170, -6813, 11743, 26509, 32722
2984                 },
2985                 {
2986                         28377, 14876, -3425, -20621, -31163, -31650, -21925, -5126, 13328, 27481,
2987                         32767, 27481, 13328, -5126, -21925, -31650, -31163, -20621, -3425, 14876
2988                 },
2989                 {
2990                         28377, 32722, 26509, 11743, -6813, -23170, -32051, -30591, -19260, -1715,
2991                         16384, 29196, 32587, 25465, 10126, -8481, -24351, -32364, -29934, -17846
2992                 }
2993         },
2994         {
2995                 {
2996                         0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126,
2997                         0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126
2998                 },
2999                 {
3000                         -28377, -21925, -13328, -3425, 6813, 16384, 24351, 29934, 32587, 32051,
3001                         28377, 21925, 13328, 3425, -6813, -16384, -24351, -29934, -32587, -32051
3002                 },
3003                 {
3004                         -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925,
3005                         28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925
3006                 },
3007                 {
3008                         0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126,
3009                         0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126
3010                 },
3011                 {
3012                         28377, 21925, 13328, 3425, -6813, -16383, -24351, -29934, -32587, -32051,
3013                         -28377, -21925, -13328, -3425, 6813, 16383, 24351, 29934, 32587, 32051
3014                 },
3015                 {
3016                         28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925,
3017                         -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925
3018                 }
3019         }
3020 };
3021
3022
3023 static void ixj_write_cid_bit(IXJ *j, int bit)
3024 {
3025         while (j->fskcnt < 20) {
3026                 if(j->fskdcnt < (j->fsksize - 1))
3027                         j->fskdata[j->fskdcnt++] = fsk[bit][j->fskz][j->fskcnt];
3028
3029                 j->fskcnt += 3;
3030         }
3031         j->fskcnt %= 20;
3032
3033         if (!bit)
3034                 j->fskz++;
3035         if (j->fskz >= 6)
3036                 j->fskz = 0;
3037
3038 }
3039
3040 static void ixj_write_cid_byte(IXJ *j, char byte)
3041 {
3042         IXJ_CBYTE cb;
3043
3044                 cb.cbyte = byte;
3045                 ixj_write_cid_bit(j, 0);
3046                 ixj_write_cid_bit(j, cb.cbits.b0 ? 1 : 0);
3047                 ixj_write_cid_bit(j, cb.cbits.b1 ? 1 : 0);
3048                 ixj_write_cid_bit(j, cb.cbits.b2 ? 1 : 0);
3049                 ixj_write_cid_bit(j, cb.cbits.b3 ? 1 : 0);
3050                 ixj_write_cid_bit(j, cb.cbits.b4 ? 1 : 0);
3051                 ixj_write_cid_bit(j, cb.cbits.b5 ? 1 : 0);
3052                 ixj_write_cid_bit(j, cb.cbits.b6 ? 1 : 0);
3053                 ixj_write_cid_bit(j, cb.cbits.b7 ? 1 : 0);
3054                 ixj_write_cid_bit(j, 1);
3055 }
3056
3057 static void ixj_write_cid_seize(IXJ *j)
3058 {
3059         int cnt;
3060
3061         for (cnt = 0; cnt < 150; cnt++) {
3062                 ixj_write_cid_bit(j, 0);
3063                 ixj_write_cid_bit(j, 1);
3064         }
3065         for (cnt = 0; cnt < 180; cnt++) {
3066                 ixj_write_cid_bit(j, 1);
3067         }
3068 }
3069
3070 static void ixj_write_cidcw_seize(IXJ *j)
3071 {
3072         int cnt;
3073
3074         for (cnt = 0; cnt < 80; cnt++) {
3075                 ixj_write_cid_bit(j, 1);
3076         }
3077 }
3078
3079 static int ixj_write_cid_string(IXJ *j, char *s, int checksum)
3080 {
3081         int cnt;
3082
3083         for (cnt = 0; cnt < strlen(s); cnt++) {
3084                 ixj_write_cid_byte(j, s[cnt]);
3085                 checksum = (checksum + s[cnt]);
3086         }
3087         return checksum;
3088 }
3089
3090 static void ixj_pad_fsk(IXJ *j, int pad)
3091 {
3092         int cnt; 
3093
3094         for (cnt = 0; cnt < pad; cnt++) {
3095                 if(j->fskdcnt < (j->fsksize - 1))
3096                         j->fskdata[j->fskdcnt++] = 0x0000;
3097         }
3098         for (cnt = 0; cnt < 720; cnt++) {
3099                 if(j->fskdcnt < (j->fsksize - 1))
3100                         j->fskdata[j->fskdcnt++] = 0x0000;
3101         }
3102 }
3103
3104 static void ixj_pre_cid(IXJ *j)
3105 {
3106         j->cid_play_codec = j->play_codec;
3107         j->cid_play_frame_size = j->play_frame_size;
3108         j->cid_play_volume = get_play_volume(j);
3109         j->cid_play_flag = j->flags.playing;
3110
3111         j->cid_rec_codec = j->rec_codec;
3112         j->cid_rec_volume = get_rec_volume(j);
3113         j->cid_rec_flag = j->flags.recording;
3114
3115         j->cid_play_aec_level = j->aec_level;
3116
3117         switch(j->baseframe.low) {
3118                 case 0xA0:
3119                         j->cid_base_frame_size = 20;
3120                         break;
3121                 case 0x50:
3122                         j->cid_base_frame_size = 10;
3123                         break;
3124                 case 0xF0:
3125                         j->cid_base_frame_size = 30;
3126                         break;
3127         }
3128
3129         ixj_play_stop(j);
3130         ixj_cpt_stop(j);
3131
3132         j->flags.cidplay = 1;
3133
3134         set_base_frame(j, 30);
3135         set_play_codec(j, LINEAR16);
3136         set_play_volume(j, 0x1B);
3137         ixj_play_start(j);
3138 }
3139
3140 static void ixj_post_cid(IXJ *j)
3141 {
3142         ixj_play_stop(j);
3143
3144         if(j->cidsize > 5000) {
3145                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
3146         }
3147         j->flags.cidplay = 0;
3148         if(ixjdebug & 0x0200) {
3149                 printk("IXJ phone%d Finished Playing CallerID data %ld\n", j->board, jiffies);
3150         }
3151
3152         ixj_fsk_free(j);
3153
3154         j->fskdcnt = 0;
3155         set_base_frame(j, j->cid_base_frame_size);
3156         set_play_codec(j, j->cid_play_codec);
3157         ixj_aec_start(j, j->cid_play_aec_level);
3158         set_play_volume(j, j->cid_play_volume);
3159
3160         set_rec_codec(j, j->cid_rec_codec);
3161         set_rec_volume(j, j->cid_rec_volume);
3162
3163         if(j->cid_rec_flag)
3164                 ixj_record_start(j);
3165
3166         if(j->cid_play_flag)
3167                 ixj_play_start(j);
3168
3169         if(j->cid_play_flag) {
3170                 wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3171         }
3172 }
3173
3174 static void ixj_write_cid(IXJ *j)
3175 {
3176         char sdmf1[50];
3177         char sdmf2[50];
3178         char sdmf3[80];
3179         char mdmflen, len1, len2, len3;
3180         int pad;
3181
3182         int checksum = 0;
3183
3184         if (j->dsp.low == 0x20 || j->flags.cidplay)
3185                 return;
3186
3187         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3188         j->cidsize = j->cidcnt = 0;
3189
3190         ixj_fsk_alloc(j);
3191
3192         strcpy(sdmf1, j->cid_send.month);
3193         strcat(sdmf1, j->cid_send.day);
3194         strcat(sdmf1, j->cid_send.hour);
3195         strcat(sdmf1, j->cid_send.min);
3196         strcpy(sdmf2, j->cid_send.number);
3197         strcpy(sdmf3, j->cid_send.name);
3198
3199         len1 = strlen(sdmf1);
3200         len2 = strlen(sdmf2);
3201         len3 = strlen(sdmf3);
3202         mdmflen = len1 + len2 + len3 + 6;
3203
3204         while(1){
3205                 ixj_write_cid_seize(j);
3206
3207                 ixj_write_cid_byte(j, 0x80);
3208                 checksum = 0x80;
3209                 ixj_write_cid_byte(j, mdmflen);
3210                 checksum = checksum + mdmflen;
3211
3212                 ixj_write_cid_byte(j, 0x01);
3213                 checksum = checksum + 0x01;
3214                 ixj_write_cid_byte(j, len1);
3215                 checksum = checksum + len1;
3216                 checksum = ixj_write_cid_string(j, sdmf1, checksum);
3217                 if(ixj_hookstate(j) & 1)
3218                         break;
3219
3220                 ixj_write_cid_byte(j, 0x02);
3221                 checksum = checksum + 0x02;
3222                 ixj_write_cid_byte(j, len2);
3223                 checksum = checksum + len2;
3224                 checksum = ixj_write_cid_string(j, sdmf2, checksum);
3225                 if(ixj_hookstate(j) & 1)
3226                         break;
3227
3228                 ixj_write_cid_byte(j, 0x07);
3229                 checksum = checksum + 0x07;
3230                 ixj_write_cid_byte(j, len3);
3231                 checksum = checksum + len3;
3232                 checksum = ixj_write_cid_string(j, sdmf3, checksum);
3233                 if(ixj_hookstate(j) & 1)
3234                         break;
3235
3236                 checksum %= 256;
3237                 checksum ^= 0xFF;
3238                 checksum += 1;
3239
3240                 ixj_write_cid_byte(j, (char) checksum);
3241
3242                 pad = j->fskdcnt % 240;
3243                 if (pad) {
3244                         pad = 240 - pad;
3245                 }
3246                 ixj_pad_fsk(j, pad);
3247                 break;
3248         }
3249
3250         ixj_write_frame(j);
3251 }
3252
3253 static void ixj_write_cidcw(IXJ *j)
3254 {
3255         IXJ_TONE ti;
3256
3257         char sdmf1[50];
3258         char sdmf2[50];
3259         char sdmf3[80];
3260         char mdmflen, len1, len2, len3;
3261         int pad;
3262
3263         int checksum = 0;
3264
3265         if (j->dsp.low == 0x20 || j->flags.cidplay)
3266                 return;
3267
3268         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3269         j->cidsize = j->cidcnt = 0;
3270
3271         ixj_fsk_alloc(j);
3272
3273         j->flags.cidcw_ack = 0;
3274
3275         ti.tone_index = 23;
3276         ti.gain0 = 1;
3277         ti.freq0 = hz440;
3278         ti.gain1 = 0;
3279         ti.freq1 = 0;
3280         ixj_init_tone(j, &ti);
3281
3282         ixj_set_tone_on(1500, j);
3283         ixj_set_tone_off(32, j);
3284         if(ixjdebug & 0x0200) {
3285                 printk("IXJ cidcw phone%d first tone start at %ld\n", j->board, jiffies);
3286         }
3287         ixj_play_tone(j, 23);
3288
3289         clear_bit(j->board, &j->busyflags);
3290         while(j->tone_state)
3291                 schedule_timeout_interruptible(1);
3292         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3293                 schedule_timeout_interruptible(1);
3294         if(ixjdebug & 0x0200) {
3295                 printk("IXJ cidcw phone%d first tone end at %ld\n", j->board, jiffies);
3296         }
3297
3298         ti.tone_index = 24;
3299         ti.gain0 = 1;
3300         ti.freq0 = hz2130;
3301         ti.gain1 = 0;
3302         ti.freq1 = hz2750;
3303         ixj_init_tone(j, &ti);
3304
3305         ixj_set_tone_off(10, j);
3306         ixj_set_tone_on(600, j);
3307         if(ixjdebug & 0x0200) {
3308                 printk("IXJ cidcw phone%d second tone start at %ld\n", j->board, jiffies);
3309         }
3310         ixj_play_tone(j, 24);
3311
3312         clear_bit(j->board, &j->busyflags);
3313         while(j->tone_state)
3314                 schedule_timeout_interruptible(1);
3315         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3316                 schedule_timeout_interruptible(1);
3317         if(ixjdebug & 0x0200) {
3318                 printk("IXJ cidcw phone%d sent second tone at %ld\n", j->board, jiffies);
3319         }
3320
3321         j->cidcw_wait = jiffies + ((50 * hertz) / 100);
3322
3323         clear_bit(j->board, &j->busyflags);
3324         while(!j->flags.cidcw_ack && time_before(jiffies, j->cidcw_wait))
3325                 schedule_timeout_interruptible(1);
3326         while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3327                 schedule_timeout_interruptible(1);
3328         j->cidcw_wait = 0;
3329         if(!j->flags.cidcw_ack) {
3330                 if(ixjdebug & 0x0200) {
3331                         printk("IXJ cidcw phone%d did not receive ACK from display %ld\n", j->board, jiffies);
3332                 }
3333                 ixj_post_cid(j);
3334                 if(j->cid_play_flag) {
3335                         wake_up_interruptible(&j->write_q);     /* Wake any blocked readers */
3336                 }
3337                 return;
3338         } else {
3339                 ixj_pre_cid(j);
3340         }
3341         j->flags.cidcw_ack = 0;
3342         strcpy(sdmf1, j->cid_send.month);
3343         strcat(sdmf1, j->cid_send.day);
3344         strcat(sdmf1, j->cid_send.hour);
3345         strcat(sdmf1, j->cid_send.min);
3346         strcpy(sdmf2, j->cid_send.number);
3347         strcpy(sdmf3, j->cid_send.name);
3348
3349         len1 = strlen(sdmf1);
3350         len2 = strlen(sdmf2);
3351         len3 = strlen(sdmf3);
3352         mdmflen = len1 + len2 + len3 + 6;
3353
3354         ixj_write_cidcw_seize(j);
3355
3356         ixj_write_cid_byte(j, 0x80);
3357         checksum = 0x80;
3358         ixj_write_cid_byte(j, mdmflen);
3359         checksum = checksum + mdmflen;
3360
3361         ixj_write_cid_byte(j, 0x01);
3362         checksum = checksum + 0x01;
3363         ixj_write_cid_byte(j, len1);
3364         checksum = checksum + len1;
3365         checksum = ixj_write_cid_string(j, sdmf1, checksum);
3366
3367         ixj_write_cid_byte(j, 0x02);
3368         checksum = checksum + 0x02;
3369         ixj_write_cid_byte(j, len2);
3370         checksum = checksum + len2;
3371         checksum = ixj_write_cid_string(j, sdmf2, checksum);
3372
3373         ixj_write_cid_byte(j, 0x07);
3374         checksum = checksum + 0x07;
3375         ixj_write_cid_byte(j, len3);
3376         checksum = checksum + len3;
3377         checksum = ixj_write_cid_string(j, sdmf3, checksum);
3378
3379         checksum %= 256;
3380         checksum ^= 0xFF;
3381         checksum += 1;
3382
3383         ixj_write_cid_byte(j, (char) checksum);
3384
3385         pad = j->fskdcnt % 240;
3386         if (pad) {
3387                 pad = 240 - pad;
3388         }
3389         ixj_pad_fsk(j, pad);
3390         if(ixjdebug & 0x0200) {
3391                 printk("IXJ cidcw phone%d sent FSK data at %ld\n", j->board, jiffies);
3392         }
3393 }
3394
3395 static void ixj_write_vmwi(IXJ *j, int msg)
3396 {
3397         char mdmflen;
3398         int pad;
3399
3400         int checksum = 0;
3401
3402         if (j->dsp.low == 0x20 || j->flags.cidplay)
3403                 return;
3404
3405         j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3406         j->cidsize = j->cidcnt = 0;
3407
3408         ixj_fsk_alloc(j);
3409
3410         mdmflen = 3;
3411
3412         if (j->port == PORT_POTS)
3413                 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
3414
3415         ixj_write_cid_seize(j);
3416
3417         ixj_write_cid_byte(j, 0x82);
3418         checksum = 0x82;
3419         ixj_write_cid_byte(j, mdmflen);
3420         checksum = checksum + mdmflen;
3421
3422         ixj_write_cid_byte(j, 0x0B);
3423         checksum = checksum + 0x0B;
3424         ixj_write_cid_byte(j, 1);
3425         checksum = checksum + 1;
3426
3427         if(msg) {
3428                 ixj_write_cid_byte(j, 0xFF);
3429                 checksum = checksum + 0xFF;
3430         }
3431         else {
3432                 ixj_write_cid_byte(j, 0x00);
3433                 checksum = checksum + 0x00;
3434         }
3435
3436         checksum %= 256;
3437         checksum ^= 0xFF;
3438         checksum += 1;
3439
3440         ixj_write_cid_byte(j, (char) checksum);
3441
3442         pad = j->fskdcnt % 240;
3443         if (pad) {
3444                 pad = 240 - pad;
3445         }
3446         ixj_pad_fsk(j, pad);
3447 }
3448
3449 static void ixj_write_frame(IXJ *j)
3450 {
3451         int cnt, frame_count, dly;
3452         IXJ_WORD dat;
3453
3454         frame_count = 0;
3455         if(j->flags.cidplay) {
3456                 for(cnt = 0; cnt < 480; cnt++) {
3457                         if (!(cnt % 16) && !IsTxReady(j)) {
3458                                 dly = 0;
3459                                 while (!IsTxReady(j)) {
3460                                         if (dly++ > 5) {
3461                                                 dly = 0;
3462                                                 break;
3463                                         }
3464                                         udelay(10);
3465                                 }
3466                         }
3467                         dat.word = j->fskdata[j->cidcnt++];
3468                         outb_p(dat.bytes.low, j->DSPbase + 0x0C);
3469                         outb_p(dat.bytes.high, j->DSPbase + 0x0D);
3470                         cnt++;
3471                 }
3472                 if(j->cidcnt >= j->fskdcnt) {
3473                         ixj_post_cid(j);
3474                 }
3475                 /* This may seem rude, but if we just played one frame of FSK data for CallerID
3476                    and there is real audio data in the buffer, we need to throw it away because 
3477                    we just used it's time slot */
3478                 if (j->write_buffer_rp > j->write_buffer_wp) {
3479                         j->write_buffer_rp += j->cid_play_frame_size * 2;
3480                         if (j->write_buffer_rp >= j->write_buffer_end) {
3481                                 j->write_buffer_rp = j->write_buffer;
3482                         }
3483                         j->write_buffers_empty++;
3484                         wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3485
3486                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
3487                 }
3488         } else if (j->write_buffer && j->write_buffers_empty < 1) { 
3489                 if (j->write_buffer_wp > j->write_buffer_rp) {
3490                         frame_count =
3491                             (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2);
3492                 }
3493                 if (j->write_buffer_rp > j->write_buffer_wp) {
3494                         frame_count =
3495                             (j->write_buffer_wp - j->write_buffer) / (j->play_frame_size * 2) +
3496                             (j->write_buffer_end - j->write_buffer_rp) / (j->play_frame_size * 2);
3497                 }
3498                 if (frame_count >= 1) {
3499                         if (j->ver.low == 0x12 && j->play_mode && j->flags.play_first_frame) {
3500                                 BYTES blankword;
3501
3502                                 switch (j->play_mode) {
3503                                 case PLAYBACK_MODE_ULAW:
3504                                 case PLAYBACK_MODE_ALAW:
3505                                         blankword.low = blankword.high = 0xFF;
3506                                         break;
3507                                 case PLAYBACK_MODE_8LINEAR:
3508                                 case PLAYBACK_MODE_16LINEAR:
3509                                 default:
3510                                         blankword.low = blankword.high = 0x00;
3511                                         break;
3512                                 case PLAYBACK_MODE_8LINEAR_WSS:
3513                                         blankword.low = blankword.high = 0x80;
3514                                         break;
3515                                 }
3516                                 for (cnt = 0; cnt < 16; cnt++) {
3517                                         if (!(cnt % 16) && !IsTxReady(j)) {
3518                                                 dly = 0;
3519                                                 while (!IsTxReady(j)) {
3520                                                         if (dly++ > 5) {
3521                                                                 dly = 0;
3522                                                                 break;
3523                                                         }
3524                                                         udelay(10);
3525                                                 }
3526                                         }
3527                                         outb_p((blankword.low), j->DSPbase + 0x0C);
3528                                         outb_p((blankword.high), j->DSPbase + 0x0D);
3529                                 }
3530                                 j->flags.play_first_frame = 0;
3531                         } else  if (j->play_codec == G723_63 && j->flags.play_first_frame) {
3532                                 for (cnt = 0; cnt < 24; cnt++) {
3533                                         BYTES blankword;
3534
3535                                         if(cnt == 12) {
3536                                                 blankword.low = 0x02;
3537                                                 blankword.high = 0x00;
3538                                         }
3539                                         else {
3540                                                 blankword.low = blankword.high = 0x00;
3541                                         }
3542                                         if (!(cnt % 16) && !IsTxReady(j)) {
3543                                                 dly = 0;
3544                                                 while (!IsTxReady(j)) {
3545                                                         if (dly++ > 5) {
3546                                                                 dly = 0;
3547                                                                 break;
3548                                                         }
3549                                                         udelay(10);
3550                                                 }
3551                                         }
3552                                         outb_p((blankword.low), j->DSPbase + 0x0C);
3553                                         outb_p((blankword.high), j->DSPbase + 0x0D);
3554                                 }
3555                                 j->flags.play_first_frame = 0;
3556                         }
3557                         for (cnt = 0; cnt < j->play_frame_size * 2; cnt += 2) {
3558                                 if (!(cnt % 16) && !IsTxReady(j)) {
3559                                         dly = 0;
3560                                         while (!IsTxReady(j)) {
3561                                                 if (dly++ > 5) {
3562                                                         dly = 0;
3563                                                         break;
3564                                                 }
3565                                                 udelay(10);
3566                                         }
3567                                 }
3568                         /* Add word 0 to G.729 frames for the 8021.  Right now we don't do VAD/CNG  */
3569                                 if (j->play_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
3570                                         if (j->write_buffer_rp[cnt] == 0 &&
3571                                             j->write_buffer_rp[cnt + 1] == 0 &&
3572                                             j->write_buffer_rp[cnt + 2] == 0 &&
3573                                             j->write_buffer_rp[cnt + 3] == 0 &&
3574                                             j->write_buffer_rp[cnt + 4] == 0 &&
3575                                             j->write_buffer_rp[cnt + 5] == 0 &&
3576                                             j->write_buffer_rp[cnt + 6] == 0 &&
3577                                             j->write_buffer_rp[cnt + 7] == 0 &&
3578                                             j->write_buffer_rp[cnt + 8] == 0 &&
3579                                             j->write_buffer_rp[cnt + 9] == 0) {
3580                                         /* someone is trying to write silence lets make this a type 0 frame. */
3581                                                 outb_p(0x00, j->DSPbase + 0x0C);
3582                                                 outb_p(0x00, j->DSPbase + 0x0D);
3583                                         } else {
3584                                         /* so all other frames are type 1. */
3585                                                 outb_p(0x01, j->DSPbase + 0x0C);
3586                                                 outb_p(0x00, j->DSPbase + 0x0D);
3587                                         }
3588                                 }
3589                                 outb_p(*(j->write_buffer_rp + cnt), j->DSPbase + 0x0C);
3590                                 outb_p(*(j->write_buffer_rp + cnt + 1), j->DSPbase + 0x0D);
3591                                 *(j->write_buffer_rp + cnt) = 0;
3592                                 *(j->write_buffer_rp + cnt + 1) = 0;
3593                         }
3594                         j->write_buffer_rp += j->play_frame_size * 2;
3595                         if (j->write_buffer_rp >= j->write_buffer_end) {
3596                                 j->write_buffer_rp = j->write_buffer;
3597                         }
3598                         j->write_buffers_empty++;
3599                         wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
3600
3601                         wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
3602
3603                         ++j->frameswritten;
3604                 }
3605         } else {
3606                 j->drybuffer++;
3607         }
3608         if(j->ixj_signals[SIG_WRITE_READY]) {
3609                 ixj_kill_fasync(j, SIG_WRITE_READY, POLL_OUT);
3610         }
3611 }
3612
3613 static int idle(IXJ *j)
3614 {
3615         if (ixj_WriteDSPCommand(0x0000, j))             /* DSP Idle */
3616
3617                 return 0;
3618
3619         if (j->ssr.high || j->ssr.low) {
3620                 return 0;
3621         } else {
3622                 j->play_mode = -1;
3623                 j->flags.playing = 0;
3624                 j->rec_mode = -1;
3625                 j->flags.recording = 0;
3626                 return 1;
3627         }
3628 }
3629
3630 static int set_base_frame(IXJ *j, int size)
3631 {
3632         unsigned short cmd;
3633         int cnt;
3634
3635         idle(j);
3636         j->cid_play_aec_level = j->aec_level;
3637         aec_stop(j);
3638         for (cnt = 0; cnt < 10; cnt++) {
3639                 if (idle(j))
3640                         break;
3641         }
3642         if (j->ssr.high || j->ssr.low)
3643                 return -1;
3644         if (j->dsp.low != 0x20) {
3645                 switch (size) {
3646                 case 30:
3647                         cmd = 0x07F0;
3648                         /* Set Base Frame Size to 240 pg9-10 8021 */
3649                         break;
3650                 case 20:
3651                         cmd = 0x07A0;
3652                         /* Set Base Frame Size to 160 pg9-10 8021 */
3653                         break;
3654                 case 10:
3655                         cmd = 0x0750;
3656                         /* Set Base Frame Size to 80 pg9-10 8021 */
3657                         break;
3658                 default:
3659                         return -1;
3660                 }
3661         } else {
3662                 if (size == 30)
3663                         return size;
3664                 else
3665                         return -1;
3666         }
3667         if (ixj_WriteDSPCommand(cmd, j)) {
3668                 j->baseframe.high = j->baseframe.low = 0xFF;
3669                 return -1;
3670         } else {
3671                 j->baseframe.high = j->ssr.high;
3672                 j->baseframe.low = j->ssr.low;
3673                 /* If the status returned is 0x0000 (pg9-9 8021) the call failed */
3674                 if(j->baseframe.high == 0x00 && j->baseframe.low == 0x00) {
3675                         return -1;
3676                 }
3677         }
3678         ixj_aec_start(j, j->cid_play_aec_level);
3679         return size;
3680 }
3681
3682 static int set_rec_codec(IXJ *j, int rate)
3683 {
3684         int retval = 0;
3685
3686         j->rec_codec = rate;
3687
3688         switch (rate) {
3689         case G723_63:
3690                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3691                         j->rec_frame_size = 12;
3692                         j->rec_mode = 0;
3693                 } else {
3694                         retval = 1;
3695                 }
3696                 break;
3697         case G723_53:
3698                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3699                         j->rec_frame_size = 10;
3700                         j->rec_mode = 0;
3701                 } else {
3702                         retval = 1;
3703                 }
3704                 break;
3705         case TS85:
3706                 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
3707                         j->rec_frame_size = 16;
3708                         j->rec_mode = 0;
3709                 } else {
3710                         retval = 1;
3711                 }
3712                 break;
3713         case TS48:
3714                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3715                         j->rec_frame_size = 9;
3716                         j->rec_mode = 0;
3717                 } else {
3718                         retval = 1;
3719                 }
3720                 break;
3721         case TS41:
3722                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3723                         j->rec_frame_size = 8;
3724                         j->rec_mode = 0;
3725                 } else {
3726                         retval = 1;
3727                 }
3728                 break;
3729         case G728:
3730                 if (j->dsp.low != 0x20) {
3731                         j->rec_frame_size = 48;
3732                         j->rec_mode = 0;
3733                 } else {
3734                         retval = 1;
3735                 }
3736                 break;
3737         case G729:
3738                 if (j->dsp.low != 0x20) {
3739                         if (!j->flags.g729_loaded) {
3740                                 retval = 1;
3741                                 break;
3742                         }
3743                         switch (j->baseframe.low) {
3744                         case 0xA0:
3745                                 j->rec_frame_size = 10;
3746                                 break;
3747                         case 0x50:
3748                                 j->rec_frame_size = 5;
3749                                 break;
3750                         default:
3751                                 j->rec_frame_size = 15;
3752                                 break;
3753                         }
3754                         j->rec_mode = 0;
3755                 } else {
3756                         retval = 1;
3757                 }
3758                 break;
3759         case G729B:
3760                 if (j->dsp.low != 0x20) {
3761                         if (!j->flags.g729_loaded) {
3762                                 retval = 1;
3763                                 break;
3764                         }
3765                         switch (j->baseframe.low) {
3766                         case 0xA0:
3767                                 j->rec_frame_size = 12;
3768                                 break;
3769                         case 0x50:
3770                                 j->rec_frame_size = 6;
3771                                 break;
3772                         default:
3773                                 j->rec_frame_size = 18;
3774                                 break;
3775                         }
3776                         j->rec_mode = 0;
3777                 } else {
3778                         retval = 1;
3779                 }
3780                 break;
3781         case ULAW:
3782                 switch (j->baseframe.low) {
3783                 case 0xA0:
3784                         j->rec_frame_size = 80;
3785                         break;
3786                 case 0x50:
3787                         j->rec_frame_size = 40;
3788                         break;
3789                 default:
3790                         j->rec_frame_size = 120;
3791                         break;
3792                 }
3793                 j->rec_mode = 4;
3794                 break;
3795         case ALAW:
3796                 switch (j->baseframe.low) {
3797                 case 0xA0:
3798                         j->rec_frame_size = 80;
3799                         break;
3800                 case 0x50:
3801                         j->rec_frame_size = 40;
3802                         break;
3803                 default:
3804                         j->rec_frame_size = 120;
3805                         break;
3806                 }
3807                 j->rec_mode = 4;
3808                 break;
3809         case LINEAR16:
3810                 switch (j->baseframe.low) {
3811                 case 0xA0:
3812                         j->rec_frame_size = 160;
3813                         break;
3814                 case 0x50:
3815                         j->rec_frame_size = 80;
3816                         break;
3817                 default:
3818                         j->rec_frame_size = 240;
3819                         break;
3820                 }
3821                 j->rec_mode = 5;
3822                 break;
3823         case LINEAR8:
3824                 switch (j->baseframe.low) {
3825                 case 0xA0:
3826                         j->rec_frame_size = 80;
3827                         break;
3828                 case 0x50:
3829                         j->rec_frame_size = 40;
3830                         break;
3831                 default:
3832                         j->rec_frame_size = 120;
3833                         break;
3834                 }
3835                 j->rec_mode = 6;
3836                 break;
3837         case WSS:
3838                 switch (j->baseframe.low) {
3839                 case 0xA0:
3840                         j->rec_frame_size = 80;
3841                         break;
3842                 case 0x50:
3843                         j->rec_frame_size = 40;
3844                         break;
3845                 default:
3846                         j->rec_frame_size = 120;
3847                         break;
3848                 }
3849                 j->rec_mode = 7;
3850                 break;
3851         default:
3852                 kfree(j->read_buffer);
3853                 j->rec_frame_size = 0;
3854                 j->rec_mode = -1;
3855                 j->read_buffer = NULL;
3856                 j->read_buffer_size = 0;
3857                 retval = 1;
3858                 break;
3859         }
3860         return retval;
3861 }
3862
3863 static int ixj_record_start(IXJ *j)
3864 {
3865         unsigned short cmd = 0x0000;
3866
3867         if (j->read_buffer) {
3868                 ixj_record_stop(j);
3869         }
3870         j->flags.recording = 1;
3871         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
3872
3873         if(ixjdebug & 0x0002)
3874                 printk("IXJ %d Starting Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3875
3876         if (!j->rec_mode) {
3877                 switch (j->rec_codec) {
3878                 case G723_63:
3879                         cmd = 0x5131;
3880                         break;
3881                 case G723_53:
3882                         cmd = 0x5132;
3883                         break;
3884                 case TS85:
3885                         cmd = 0x5130;   /* TrueSpeech 8.5 */
3886
3887                         break;
3888                 case TS48:
3889                         cmd = 0x5133;   /* TrueSpeech 4.8 */
3890
3891                         break;
3892                 case TS41:
3893                         cmd = 0x5134;   /* TrueSpeech 4.1 */
3894
3895                         break;
3896                 case G728:
3897                         cmd = 0x5135;
3898                         break;
3899                 case G729:
3900                 case G729B:
3901                         cmd = 0x5136;
3902                         break;
3903                 default:
3904                         return 1;
3905                 }
3906                 if (ixj_WriteDSPCommand(cmd, j))
3907                         return -1;
3908         }
3909         if (!j->read_buffer) {
3910                 if (!j->read_buffer)
3911                         j->read_buffer = kmalloc(j->rec_frame_size * 2, GFP_ATOMIC);
3912                 if (!j->read_buffer) {
3913                         printk("Read buffer allocation for ixj board %d failed!\n", j->board);
3914                         return -ENOMEM;
3915                 }
3916         }
3917         j->read_buffer_size = j->rec_frame_size * 2;
3918
3919         if (ixj_WriteDSPCommand(0x5102, j))             /* Set Poll sync mode */
3920
3921                 return -1;
3922
3923         switch (j->rec_mode) {
3924         case 0:
3925                 cmd = 0x1C03;   /* Record C1 */
3926
3927                 break;
3928         case 4:
3929                 if (j->ver.low == 0x12) {
3930                         cmd = 0x1E03;   /* Record C1 */
3931
3932                 } else {
3933                         cmd = 0x1E01;   /* Record C1 */
3934
3935                 }
3936                 break;
3937         case 5:
3938                 if (j->ver.low == 0x12) {
3939                         cmd = 0x1E83;   /* Record C1 */
3940
3941                 } else {
3942                         cmd = 0x1E81;   /* Record C1 */
3943
3944                 }
3945                 break;
3946         case 6:
3947                 if (j->ver.low == 0x12) {
3948                         cmd = 0x1F03;   /* Record C1 */
3949
3950                 } else {
3951                         cmd = 0x1F01;   /* Record C1 */
3952
3953                 }
3954                 break;
3955         case 7:
3956                 if (j->ver.low == 0x12) {
3957                         cmd = 0x1F83;   /* Record C1 */
3958                 } else {
3959                         cmd = 0x1F81;   /* Record C1 */
3960                 }
3961                 break;
3962         }
3963         if (ixj_WriteDSPCommand(cmd, j))
3964                 return -1;
3965
3966         if (j->flags.playing) {
3967                 ixj_aec_start(j, j->aec_level);
3968         }
3969         return 0;
3970 }
3971
3972 static void ixj_record_stop(IXJ *j)
3973 {
3974         if (ixjdebug & 0x0002)
3975                 printk("IXJ %d Stopping Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3976
3977         kfree(j->read_buffer);
3978         j->read_buffer = NULL;
3979         j->read_buffer_size = 0;
3980         if (j->rec_mode > -1) {
3981                 ixj_WriteDSPCommand(0x5120, j);
3982                 j->rec_mode = -1;
3983         }
3984         j->flags.recording = 0;
3985 }
3986 static void ixj_vad(IXJ *j, int arg)
3987 {
3988         if (arg)
3989                 ixj_WriteDSPCommand(0x513F, j);
3990         else
3991                 ixj_WriteDSPCommand(0x513E, j);
3992 }
3993
3994 static void set_rec_depth(IXJ *j, int depth)
3995 {
3996         if (depth > 60)
3997                 depth = 60;
3998         if (depth < 0)
3999                 depth = 0;
4000         ixj_WriteDSPCommand(0x5180 + depth, j);
4001 }
4002
4003 static void set_dtmf_prescale(IXJ *j, int volume)
4004 {
4005         ixj_WriteDSPCommand(0xCF07, j);
4006         ixj_WriteDSPCommand(volume, j);
4007 }
4008
4009 static int get_dtmf_prescale(IXJ *j)
4010 {
4011         ixj_WriteDSPCommand(0xCF05, j);
4012         return j->ssr.high << 8 | j->ssr.low;
4013 }
4014
4015 static void set_rec_volume(IXJ *j, int volume)
4016 {
4017         if(j->aec_level == AEC_AGC) {
4018                 if (ixjdebug & 0x0002)
4019                         printk(KERN_INFO "IXJ: /dev/phone%d Setting AGC Threshold to 0x%4.4x\n", j->board, volume);
4020                 ixj_WriteDSPCommand(0xCF96, j);
4021                 ixj_WriteDSPCommand(volume, j);
4022         } else {
4023                 if (ixjdebug & 0x0002)
4024                         printk(KERN_INFO "IXJ: /dev/phone %d Setting Record Volume to 0x%4.4x\n", j->board, volume);
4025                 ixj_WriteDSPCommand(0xCF03, j);
4026                 ixj_WriteDSPCommand(volume, j);
4027         }
4028 }
4029
4030 static int set_rec_volume_linear(IXJ *j, int volume)
4031 {
4032         int newvolume, dsprecmax;
4033
4034         if (ixjdebug & 0x0002)
4035                 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Record Volume to 0x%4.4x\n", j->board, volume);
4036         if(volume > 100 || volume < 0) {
4037           return -1;
4038         }
4039
4040         /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
4041         switch (j->cardtype) {
4042         case QTI_PHONEJACK:
4043                 dsprecmax = 0x440;
4044                 break;
4045         case QTI_LINEJACK:
4046                 dsprecmax = 0x180;
4047                 ixj_mixer(0x0203, j);   /*Voice Left Volume unmute 6db */
4048                 ixj_mixer(0x0303, j);   /*Voice Right Volume unmute 6db */
4049                 ixj_mixer(0x0C00, j);   /*Mono1 unmute 12db */
4050                 break;
4051         case QTI_PHONEJACK_LITE:
4052                 dsprecmax = 0x4C0;
4053                 break;
4054         case QTI_PHONEJACK_PCI:
4055                 dsprecmax = 0x100;
4056                 break;
4057         case QTI_PHONECARD:
4058                 dsprecmax = 0x400;
4059                 break;
4060         default:
4061                 return -1;
4062         }
4063         newvolume = (dsprecmax * volume) / 100;
4064         set_rec_volume(j, newvolume);
4065         return 0;
4066 }
4067
4068 static int get_rec_volume(IXJ *j)
4069 {
4070         if(j->aec_level == AEC_AGC) {
4071                 if (ixjdebug & 0x0002)
4072                         printk(KERN_INFO "Getting AGC Threshold\n");
4073                 ixj_WriteDSPCommand(0xCF86, j);
4074                 if (ixjdebug & 0x0002)
4075                         printk(KERN_INFO "AGC Threshold is 0x%2.2x%2.2x\n", j->ssr.high, j->ssr.low);
4076                 return j->ssr.high << 8 | j->ssr.low;
4077         } else {
4078                 if (ixjdebug & 0x0002)
4079                         printk(KERN_INFO "Getting Record Volume\n");
4080                 ixj_WriteDSPCommand(0xCF01, j);
4081                 return j->ssr.high << 8 | j->ssr.low;
4082         }
4083 }
4084
4085 static int get_rec_volume_linear(IXJ *j)
4086 {
4087         int volume, newvolume, dsprecmax;
4088
4089         switch (j->cardtype) {
4090         case QTI_PHONEJACK:
4091                 dsprecmax = 0x440;
4092                 break;
4093         case QTI_LINEJACK:
4094                 dsprecmax = 0x180;
4095                 break;
4096         case QTI_PHONEJACK_LITE:
4097                 dsprecmax = 0x4C0;
4098                 break;
4099         case QTI_PHONEJACK_PCI:
4100                 dsprecmax = 0x100;
4101                 break;
4102         case QTI_PHONECARD:
4103                 dsprecmax = 0x400;
4104                 break;
4105         default:
4106                 return -1;
4107         }
4108         volume = get_rec_volume(j);
4109         newvolume = (volume * 100) / dsprecmax;
4110         if(newvolume > 100)
4111                 newvolume = 100;
4112         return newvolume;
4113 }
4114
4115 static int get_rec_level(IXJ *j)
4116 {
4117         int retval;
4118
4119         ixj_WriteDSPCommand(0xCF88, j);
4120
4121         retval = j->ssr.high << 8 | j->ssr.low;
4122         retval = (retval * 256) / 240;
4123         return retval;
4124 }
4125
4126 static void ixj_aec_start(IXJ *j, int level)
4127 {
4128         j->aec_level = level;
4129         if (ixjdebug & 0x0002)
4130                 printk(KERN_INFO "AGC set = 0x%2.2x\n", j->aec_level);
4131         if (!level) {
4132                 aec_stop(j);
4133         } else {
4134                 if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4135                         ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer */
4136
4137                         ixj_WriteDSPCommand(0x0300, j);
4138                 }
4139                 ixj_WriteDSPCommand(0xB001, j); /* AEC On */
4140
4141                 ixj_WriteDSPCommand(0xE013, j); /* Advanced AEC C1 */
4142
4143                 switch (level) {
4144                 case AEC_LOW:
4145                         ixj_WriteDSPCommand(0x0000, j); /* Advanced AEC C2 = off */
4146
4147                         ixj_WriteDSPCommand(0xE011, j);
4148                         ixj_WriteDSPCommand(0xFFFF, j);
4149
4150                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4151                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4152                         
4153                         break;
4154
4155                 case AEC_MED:
4156                         ixj_WriteDSPCommand(0x0600, j); /* Advanced AEC C2 = on medium */
4157
4158                         ixj_WriteDSPCommand(0xE011, j);
4159                         ixj_WriteDSPCommand(0x0080, j);
4160
4161                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4162                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4163                         
4164                         break;
4165
4166                 case AEC_HIGH:
4167                         ixj_WriteDSPCommand(0x0C00, j); /* Advanced AEC C2 = on high */
4168
4169                         ixj_WriteDSPCommand(0xE011, j);
4170                         ixj_WriteDSPCommand(0x0080, j);
4171
4172                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4173                         ixj_WriteDSPCommand(0x0000, j); /* to off */
4174                         
4175                         break;
4176
4177                 case AEC_AGC:
4178                         /* First we have to put the AEC into advance auto mode so that AGC will not conflict with it */
4179                         ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
4180
4181                         ixj_WriteDSPCommand(0xE011, j);
4182                         ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
4183
4184                         ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
4185
4186                         if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4187                                 ixj_WriteDSPCommand(0x0224, j);
4188                         else
4189                                 ixj_WriteDSPCommand(0x1224, j);
4190
4191                         ixj_WriteDSPCommand(0xE014, j);
4192                         ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
4193
4194                         ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
4195
4196                         /* Now we can set the AGC initial parameters and turn it on */
4197                         ixj_WriteDSPCommand(0xCF90, j); /* Set AGC Minumum gain */
4198                         ixj_WriteDSPCommand(0x0020, j); /* to 0.125 (-18dB) */
4199         
4200                         ixj_WriteDSPCommand(0xCF91, j); /* Set AGC Maximum gain */
4201                         ixj_WriteDSPCommand(0x1000, j); /* to 16 (24dB) */
4202                         
4203                         ixj_WriteDSPCommand(0xCF92, j); /* Set AGC start gain */
4204                         ixj_WriteDSPCommand(0x0800, j); /* to 8 (+18dB) */
4205                 
4206                         ixj_WriteDSPCommand(0xCF93, j); /* Set AGC hold time */
4207                         ixj_WriteDSPCommand(0x1F40, j); /* to 2 seconds (units are 250us) */
4208                         
4209                         ixj_WriteDSPCommand(0xCF94, j); /* Set AGC Attack Time Constant */
4210                         ixj_WriteDSPCommand(0x0005, j); /* to 8ms */
4211                         
4212                         ixj_WriteDSPCommand(0xCF95, j); /* Set AGC Decay Time Constant */
4213                         ixj_WriteDSPCommand(0x000D, j); /* to 4096ms */
4214                         
4215                         ixj_WriteDSPCommand(0xCF96, j); /* Set AGC Attack Threshold */
4216                         ixj_WriteDSPCommand(0x1200, j); /* to 25% */
4217                         
4218                         ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4219                         ixj_WriteDSPCommand(0x0001, j); /* to on */
4220                         
4221                         break;
4222
4223                 case AEC_AUTO:
4224                         ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
4225
4226                         ixj_WriteDSPCommand(0xE011, j);
4227                         ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
4228
4229                         ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
4230
4231                         if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4232                                 ixj_WriteDSPCommand(0x0224, j);
4233                         else
4234                                 ixj_WriteDSPCommand(0x1224, j);
4235
4236                         ixj_WriteDSPCommand(0xE014, j);
4237                         ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
4238
4239                         ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
4240
4241                         break;
4242                 }
4243         }
4244 }
4245
4246 static void aec_stop(IXJ *j)
4247 {
4248         j->aec_level = AEC_OFF;
4249         if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4250                 ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer back */
4251
4252                 ixj_WriteDSPCommand(0x0700, j);
4253         }
4254         if (j->play_mode != -1 && j->rec_mode != -1)
4255         {
4256                 ixj_WriteDSPCommand(0xB002, j); /* AEC Stop */
4257         }
4258 }
4259
4260 static int set_play_codec(IXJ *j, int rate)
4261 {
4262         int retval = 0;
4263
4264         j->play_codec = rate;
4265
4266         switch (rate) {
4267         case G723_63:
4268                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4269                         j->play_frame_size = 12;
4270                         j->play_mode = 0;
4271                 } else {
4272                         retval = 1;
4273                 }
4274                 break;
4275         case G723_53:
4276                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4277                         j->play_frame_size = 10;
4278                         j->play_mode = 0;
4279                 } else {
4280                         retval = 1;
4281                 }
4282                 break;
4283         case TS85:
4284                 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
4285                         j->play_frame_size = 16;
4286                         j->play_mode = 0;
4287                 } else {
4288                         retval = 1;
4289                 }
4290                 break;
4291         case TS48:
4292                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4293                         j->play_frame_size = 9;
4294                         j->play_mode = 0;
4295                 } else {
4296                         retval = 1;
4297                 }
4298                 break;
4299         case TS41:
4300                 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4301                         j->play_frame_size = 8;
4302                         j->play_mode = 0;
4303                 } else {
4304                         retval = 1;
4305                 }
4306                 break;
4307         case G728:
4308                 if (j->dsp.low != 0x20) {
4309                         j->play_frame_size = 48;
4310                         j->play_mode = 0;
4311                 } else {
4312                         retval = 1;
4313                 }
4314                 break;
4315         case G729:
4316                 if (j->dsp.low != 0x20) {
4317                         if (!j->flags.g729_loaded) {
4318                                 retval = 1;
4319                                 break;
4320                         }
4321                         switch (j->baseframe.low) {
4322                         case 0xA0:
4323                                 j->play_frame_size = 10;
4324                                 break;
4325                         case 0x50:
4326                                 j->play_frame_size = 5;
4327                                 break;
4328                         default:
4329                                 j->play_frame_size = 15;
4330                                 break;
4331                         }
4332                         j->play_mode = 0;
4333                 } else {
4334                         retval = 1;
4335                 }
4336                 break;
4337         case G729B:
4338                 if (j->dsp.low != 0x20) {
4339                         if (!j->flags.g729_loaded) {
4340                                 retval = 1;
4341                                 break;
4342                         }
4343                         switch (j->baseframe.low) {
4344                         case 0xA0:
4345                                 j->play_frame_size = 12;
4346                                 break;
4347                         case 0x50:
4348                                 j->play_frame_size = 6;
4349                                 break;
4350                         default:
4351                                 j->play_frame_size = 18;
4352                                 break;
4353                         }
4354                         j->play_mode = 0;
4355                 } else {
4356                         retval = 1;
4357                 }
4358                 break;
4359         case ULAW:
4360                 switch (j->baseframe.low) {
4361                 case 0xA0:
4362                         j->play_frame_size = 80;
4363                         break;
4364                 case 0x50:
4365                         j->play_frame_size = 40;
4366                         break;
4367                 default:
4368                         j->play_frame_size = 120;
4369                         break;
4370                 }
4371                 j->play_mode = 2;
4372                 break;
4373         case ALAW:
4374                 switch (j->baseframe.low) {
4375                 case 0xA0:
4376                         j->play_frame_size = 80;
4377                         break;
4378                 case 0x50:
4379                         j->play_frame_size = 40;
4380                         break;
4381                 default:
4382                         j->play_frame_size = 120;
4383                         break;
4384                 }
4385                 j->play_mode = 2;
4386                 break;
4387         case LINEAR16:
4388                 switch (j->baseframe.low) {
4389                 case 0xA0:
4390                         j->play_frame_size = 160;
4391                         break;
4392                 case 0x50:
4393                         j->play_frame_size = 80;
4394                         break;
4395                 default:
4396                         j->play_frame_size = 240;
4397                         break;
4398                 }
4399                 j->play_mode = 6;
4400                 break;
4401         case LINEAR8:
4402                 switch (j->baseframe.low) {
4403                 case 0xA0:
4404                         j->play_frame_size = 80;
4405                         break;
4406                 case 0x50:
4407                         j->play_frame_size = 40;
4408                         break;
4409                 default:
4410                         j->play_frame_size = 120;
4411                         break;
4412                 }
4413                 j->play_mode = 4;
4414                 break;
4415         case WSS:
4416                 switch (j->baseframe.low) {
4417                 case 0xA0:
4418                         j->play_frame_size = 80;
4419                         break;
4420                 case 0x50:
4421                         j->play_frame_size = 40;
4422                         break;
4423                 default:
4424                         j->play_frame_size = 120;
4425                         break;
4426                 }
4427                 j->play_mode = 5;
4428                 break;
4429         default:
4430                 kfree(j->write_buffer);
4431                 j->play_frame_size = 0;
4432                 j->play_mode = -1;
4433                 j->write_buffer = NULL;
4434                 j->write_buffer_size = 0;
4435                 retval = 1;
4436                 break;
4437         }
4438         return retval;
4439 }
4440
4441 static int ixj_play_start(IXJ *j)
4442 {
4443         unsigned short cmd = 0x0000;
4444
4445         if (j->write_buffer) {
4446                 ixj_play_stop(j);
4447         }
4448
4449         if(ixjdebug & 0x0002)
4450                 printk("IXJ %d Starting Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4451
4452         j->flags.playing = 1;
4453         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
4454
4455         j->flags.play_first_frame = 1;
4456         j->drybuffer = 0;
4457
4458         if (!j->play_mode) {
4459                 switch (j->play_codec) {
4460                 case G723_63:
4461                         cmd = 0x5231;
4462                         break;
4463                 case G723_53:
4464                         cmd = 0x5232;
4465                         break;
4466                 case TS85:
4467                         cmd = 0x5230;   /* TrueSpeech 8.5 */
4468
4469                         break;
4470                 case TS48:
4471                         cmd = 0x5233;   /* TrueSpeech 4.8 */
4472
4473                         break;
4474                 case TS41:
4475                         cmd = 0x5234;   /* TrueSpeech 4.1 */
4476
4477                         break;
4478                 case G728:
4479                         cmd = 0x5235;
4480                         break;
4481                 case G729:
4482                 case G729B:
4483                         cmd = 0x5236;
4484                         break;
4485                 default:
4486                         return 1;
4487                 }
4488                 if (ixj_WriteDSPCommand(cmd, j))
4489                         return -1;
4490         }
4491         j->write_buffer = kmalloc(j->play_frame_size * 2, GFP_ATOMIC);
4492         if (!j->write_buffer) {
4493                 printk("Write buffer allocation for ixj board %d failed!\n", j->board);
4494                 return -ENOMEM;
4495         }
4496 /*      j->write_buffers_empty = 2; */
4497         j->write_buffers_empty = 1; 
4498         j->write_buffer_size = j->play_frame_size * 2;
4499         j->write_buffer_end = j->write_buffer + j->play_frame_size * 2;
4500         j->write_buffer_rp = j->write_buffer_wp = j->write_buffer;
4501
4502         if (ixj_WriteDSPCommand(0x5202, j))             /* Set Poll sync mode */
4503
4504                 return -1;
4505
4506         switch (j->play_mode) {
4507         case 0:
4508                 cmd = 0x2C03;
4509                 break;
4510         case 2:
4511                 if (j->ver.low == 0x12) {
4512                         cmd = 0x2C23;
4513                 } else {
4514                         cmd = 0x2C21;
4515                 }
4516                 break;
4517         case 4:
4518                 if (j->ver.low == 0x12) {
4519                         cmd = 0x2C43;
4520                 } else {
4521                         cmd = 0x2C41;
4522                 }
4523                 break;
4524         case 5:
4525                 if (j->ver.low == 0x12) {
4526                         cmd = 0x2C53;
4527                 } else {
4528                         cmd = 0x2C51;
4529                 }
4530                 break;
4531         case 6:
4532                 if (j->ver.low == 0x12) {
4533                         cmd = 0x2C63;
4534                 } else {
4535                         cmd = 0x2C61;
4536                 }
4537                 break;
4538         }
4539         if (ixj_WriteDSPCommand(cmd, j))
4540                 return -1;
4541
4542         if (ixj_WriteDSPCommand(0x2000, j))             /* Playback C2 */
4543                 return -1;
4544
4545         if (ixj_WriteDSPCommand(0x2000 + j->play_frame_size, j))        /* Playback C3 */
4546                 return -1;
4547
4548         if (j->flags.recording) {
4549                 ixj_aec_start(j, j->aec_level);
4550         }
4551
4552         return 0;
4553 }
4554
4555 static void ixj_play_stop(IXJ *j)
4556 {
4557         if (ixjdebug & 0x0002)
4558                 printk("IXJ %d Stopping Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4559
4560         kfree(j->write_buffer);
4561         j->write_buffer = NULL;
4562         j->write_buffer_size = 0;
4563         if (j->play_mode > -1) {
4564                 ixj_WriteDSPCommand(0x5221, j); /* Stop playback and flush buffers.  8022 reference page 9-40 */
4565
4566                 j->play_mode = -1;
4567         }
4568         j->flags.playing = 0;
4569 }
4570
4571 static inline int get_play_level(IXJ *j)
4572 {
4573         int retval;
4574
4575         ixj_WriteDSPCommand(0xCF8F, j); /* 8022 Reference page 9-38 */
4576         return j->ssr.high << 8 | j->ssr.low;
4577         retval = j->ssr.high << 8 | j->ssr.low;
4578         retval = (retval * 256) / 240;
4579         return retval;
4580 }
4581
4582 static unsigned int ixj_poll(struct file *file_p, poll_table * wait)
4583 {
4584         unsigned int mask = 0;
4585
4586         IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
4587
4588         poll_wait(file_p, &(j->poll_q), wait);
4589         if (j->read_buffer_ready > 0)
4590                 mask |= POLLIN | POLLRDNORM;    /* readable */
4591         if (j->write_buffers_empty > 0)
4592                 mask |= POLLOUT | POLLWRNORM;   /* writable */
4593         if (j->ex.bytes)
4594                 mask |= POLLPRI;
4595         return mask;
4596 }
4597
4598 static int ixj_play_tone(IXJ *j, char tone)
4599 {
4600         if (!j->tone_state) {
4601                 if(ixjdebug & 0x0002) {
4602                         printk("IXJ %d starting tone %d at %ld\n", j->board, tone, jiffies);
4603                 }
4604                 if (j->dsp.low == 0x20) {
4605                         idle(j);
4606                 }
4607                 j->tone_start_jif = jiffies;
4608
4609                 j->tone_state = 1;
4610         }
4611
4612         j->tone_index = tone;
4613         if (ixj_WriteDSPCommand(0x6000 + j->tone_index, j))
4614                 return -1;
4615
4616         return 0;
4617 }
4618
4619 static int ixj_set_tone_on(unsigned short arg, IXJ *j)
4620 {
4621         j->tone_on_time = arg;
4622
4623         if (ixj_WriteDSPCommand(0x6E04, j))             /* Set Tone On Period */
4624
4625                 return -1;
4626
4627         if (ixj_WriteDSPCommand(arg, j))
4628                 return -1;
4629
4630         return 0;
4631 }
4632
4633 static int SCI_WaitHighSCI(IXJ *j)
4634 {
4635         int cnt;
4636
4637         j->pld_scrr.byte = inb_p(j->XILINXbase);
4638         if (!j->pld_scrr.bits.sci) {
4639                 for (cnt = 0; cnt < 10; cnt++) {
4640                         udelay(32);
4641                         j->pld_scrr.byte = inb_p(j->XILINXbase);
4642
4643                         if ((j->pld_scrr.bits.sci))
4644                                 return 1;
4645                 }
4646                 if (ixjdebug & 0x0001)
4647                         printk(KERN_INFO "SCI Wait High failed %x\n", j->pld_scrr.byte);
4648                 return 0;
4649         } else
4650                 return 1;
4651 }
4652
4653 static int SCI_WaitLowSCI(IXJ *j)
4654 {
4655         int cnt;
4656
4657         j->pld_scrr.byte = inb_p(j->XILINXbase);
4658         if (j->pld_scrr.bits.sci) {
4659                 for (cnt = 0; cnt < 10; cnt++) {
4660                         udelay(32);
4661                         j->pld_scrr.byte = inb_p(j->XILINXbase);
4662
4663                         if (!(j->pld_scrr.bits.sci))
4664                                 return 1;
4665                 }
4666                 if (ixjdebug & 0x0001)
4667                         printk(KERN_INFO "SCI Wait Low failed %x\n", j->pld_scrr.byte);
4668                 return 0;
4669         } else
4670                 return 1;
4671 }
4672
4673 static int SCI_Control(IXJ *j, int control)
4674 {
4675         switch (control) {
4676         case SCI_End:
4677                 j->pld_scrw.bits.c0 = 0;        /* Set PLD Serial control interface */
4678
4679                 j->pld_scrw.bits.c1 = 0;        /* to no selection */
4680
4681                 break;
4682         case SCI_Enable_DAA:
4683                 j->pld_scrw.bits.c0 = 1;        /* Set PLD Serial control interface */
4684
4685                 j->pld_scrw.bits.c1 = 0;        /* to write to DAA */
4686
4687                 break;
4688         case SCI_Enable_Mixer:
4689                 j->pld_scrw.bits.c0 = 0;        /* Set PLD Serial control interface */
4690
4691                 j->pld_scrw.bits.c1 = 1;        /* to write to mixer */
4692
4693                 break;
4694         case SCI_Enable_EEPROM:
4695                 j->pld_scrw.bits.c0 = 1;        /* Set PLD Serial control interface */
4696
4697                 j->pld_scrw.bits.c1 = 1;        /* to write to EEPROM */
4698
4699                 break;
4700         default:
4701                 return 0;
4702                 break;
4703         }
4704         outb_p(j->pld_scrw.byte, j->XILINXbase);
4705
4706         switch (control) {
4707         case SCI_End:
4708                 return 1;
4709                 break;
4710         case SCI_Enable_DAA:
4711         case SCI_Enable_Mixer:
4712         case SCI_Enable_EEPROM:
4713                 if (!SCI_WaitHighSCI(j))
4714                         return 0;
4715                 break;
4716         default:
4717                 return 0;
4718                 break;
4719         }
4720         return 1;
4721 }
4722
4723 static int SCI_Prepare(IXJ *j)
4724 {
4725         if (!SCI_Control(j, SCI_End))
4726                 return 0;
4727
4728         if (!SCI_WaitLowSCI(j))
4729                 return 0;
4730
4731         return 1;
4732 }
4733
4734 static int ixj_get_mixer(long val, IXJ *j)
4735 {
4736         int reg = (val & 0x1F00) >> 8;
4737         return j->mix.vol[reg];
4738 }
4739
4740 static int ixj_mixer(long val, IXJ *j)
4741 {
4742         BYTES bytes;
4743
4744         bytes.high = (val & 0x1F00) >> 8;
4745         bytes.low = val & 0x00FF;
4746
4747         /* save mixer value so we can get back later on */
4748         j->mix.vol[bytes.high] = bytes.low;
4749
4750         outb_p(bytes.high & 0x1F, j->XILINXbase + 0x03);        /* Load Mixer Address */
4751
4752         outb_p(bytes.low, j->XILINXbase + 0x02);        /* Load Mixer Data */
4753
4754         SCI_Control(j, SCI_Enable_Mixer);
4755
4756         SCI_Control(j, SCI_End);
4757
4758         return 0;
4759 }
4760
4761 static int daa_load(BYTES * p_bytes, IXJ *j)
4762 {
4763         outb_p(p_bytes->high, j->XILINXbase + 0x03);
4764         outb_p(p_bytes->low, j->XILINXbase + 0x02);
4765         if (!SCI_Control(j, SCI_Enable_DAA))
4766                 return 0;
4767         else
4768                 return 1;
4769 }
4770
4771 static int ixj_daa_cr4(IXJ *j, char reg)
4772 {
4773         BYTES bytes;
4774
4775         switch (j->daa_mode) {
4776         case SOP_PU_SLEEP:
4777                 bytes.high = 0x14;
4778                 break;
4779         case SOP_PU_RINGING:
4780                 bytes.high = 0x54;
4781                 break;
4782         case SOP_PU_CONVERSATION:
4783                 bytes.high = 0x94;
4784                 break;
4785         case SOP_PU_PULSEDIALING:
4786                 bytes.high = 0xD4;
4787                 break;
4788         }
4789
4790         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = reg;
4791
4792         switch (j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGX) {
4793         case 0:
4794                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 0;
4795                 break;
4796         case 1:
4797                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 2;
4798                 break;
4799         case 2:
4800                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 1;
4801                 break;
4802         case 3:
4803                 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 3;
4804                 break;
4805         }
4806
4807         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
4808
4809         if (!daa_load(&bytes, j))
4810                 return 0;
4811
4812         if (!SCI_Prepare(j))
4813                 return 0;
4814
4815         return 1;
4816 }
4817
4818 static char daa_int_read(IXJ *j)
4819 {
4820         BYTES bytes;
4821
4822         if (!SCI_Prepare(j))
4823                 return 0;
4824
4825         bytes.high = 0x38;
4826         bytes.low = 0x00;
4827         outb_p(bytes.high, j->XILINXbase + 0x03);
4828         outb_p(bytes.low, j->XILINXbase + 0x02);
4829
4830         if (!SCI_Control(j, SCI_Enable_DAA))
4831                 return 0;
4832
4833         bytes.high = inb_p(j->XILINXbase + 0x03);
4834         bytes.low = inb_p(j->XILINXbase + 0x02);
4835         if (bytes.low != ALISDAA_ID_BYTE) {
4836                 if (ixjdebug & 0x0001)
4837                         printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4838                 return 0;
4839         }
4840         if (!SCI_Control(j, SCI_Enable_DAA))
4841                 return 0;
4842         if (!SCI_Control(j, SCI_End))
4843                 return 0;
4844
4845         bytes.high = inb_p(j->XILINXbase + 0x03);
4846         bytes.low = inb_p(j->XILINXbase + 0x02);
4847
4848         j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg = bytes.high;
4849
4850         return 1;
4851 }
4852
4853 static char daa_CR_read(IXJ *j, int cr)
4854 {
4855         IXJ_WORD wdata;
4856         BYTES bytes;
4857
4858         if (!SCI_Prepare(j))
4859                 return 0;
4860
4861         switch (j->daa_mode) {
4862         case SOP_PU_SLEEP:
4863                 bytes.high = 0x30 + cr;
4864                 break;
4865         case SOP_PU_RINGING:
4866                 bytes.high = 0x70 + cr;
4867                 break;
4868         case SOP_PU_CONVERSATION:
4869                 bytes.high = 0xB0 + cr;
4870                 break;
4871         case SOP_PU_PULSEDIALING:
4872         default:
4873                 bytes.high = 0xF0 + cr;
4874                 break;
4875         }
4876
4877         bytes.low = 0x00;
4878
4879         outb_p(bytes.high, j->XILINXbase + 0x03);
4880         outb_p(bytes.low, j->XILINXbase + 0x02);
4881
4882         if (!SCI_Control(j, SCI_Enable_DAA))
4883                 return 0;
4884
4885         bytes.high = inb_p(j->XILINXbase + 0x03);
4886         bytes.low = inb_p(j->XILINXbase + 0x02);
4887         if (bytes.low != ALISDAA_ID_BYTE) {
4888                 if (ixjdebug & 0x0001)
4889                         printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4890                 return 0;
4891         }
4892         if (!SCI_Control(j, SCI_Enable_DAA))
4893                 return 0;
4894         if (!SCI_Control(j, SCI_End))
4895                 return 0;
4896
4897         wdata.word = inw_p(j->XILINXbase + 0x02);
4898
4899         switch(cr){
4900                 case 5:
4901                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = wdata.bytes.high;
4902                         break;
4903                 case 4:
4904                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = wdata.bytes.high;
4905                         break;
4906                 case 3:
4907                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = wdata.bytes.high;
4908                         break;
4909                 case 2:
4910                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = wdata.bytes.high;
4911                         break;
4912                 case 1:
4913                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = wdata.bytes.high;
4914                         break;
4915                 case 0:
4916                         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = wdata.bytes.high;
4917                         break;
4918                 default:
4919                         return 0;
4920         }
4921         return 1;
4922 }
4923
4924 static int ixj_daa_cid_reset(IXJ *j)
4925 {
4926         int i;
4927         BYTES bytes;
4928
4929         if (ixjdebug & 0x0002)
4930                 printk("DAA Clearing CID ram\n");
4931
4932         if (!SCI_Prepare(j))
4933                 return 0;
4934
4935         bytes.high = 0x58;
4936         bytes.low = 0x00;
4937         outb_p(bytes.high, j->XILINXbase + 0x03);
4938         outb_p(bytes.low, j->XILINXbase + 0x02);
4939
4940         if (!SCI_Control(j, SCI_Enable_DAA))
4941                 return 0;
4942
4943         if (!SCI_WaitHighSCI(j))
4944                 return 0;
4945
4946         for (i = 0; i < ALISDAA_CALLERID_SIZE - 1; i += 2) {
4947                 bytes.high = bytes.low = 0x00;
4948                 outb_p(bytes.high, j->XILINXbase + 0x03);
4949
4950                 if (i < ALISDAA_CALLERID_SIZE - 1)
4951                         outb_p(bytes.low, j->XILINXbase + 0x02);
4952
4953                 if (!SCI_Control(j, SCI_Enable_DAA))
4954                         return 0;
4955
4956                 if (!SCI_WaitHighSCI(j))
4957                         return 0;
4958
4959         }
4960
4961         if (!SCI_Control(j, SCI_End))
4962                 return 0;
4963
4964         if (ixjdebug & 0x0002)
4965                 printk("DAA CID ram cleared\n");
4966
4967         return 1;
4968 }
4969
4970 static int ixj_daa_cid_read(IXJ *j)
4971 {
4972         int i;
4973         BYTES bytes;
4974         char CID[ALISDAA_CALLERID_SIZE];
4975         bool mContinue;
4976         char *pIn, *pOut;
4977
4978         if (!SCI_Prepare(j))
4979                 return 0;
4980
4981         bytes.high = 0x78;
4982         bytes.low = 0x00;
4983         outb_p(bytes.high, j->XILINXbase + 0x03);
4984         outb_p(bytes.low, j->XILINXbase + 0x02);
4985
4986         if (!SCI_Control(j, SCI_Enable_DAA))
4987                 return 0;
4988
4989         if (!SCI_WaitHighSCI(j))
4990                 return 0;
4991
4992         bytes.high = inb_p(j->XILINXbase + 0x03);
4993         bytes.low = inb_p(j->XILINXbase + 0x02);
4994         if (bytes.low != ALISDAA_ID_BYTE) {
4995                 if (ixjdebug & 0x0001)
4996                         printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4997                 return 0;
4998         }
4999         for (i = 0; i < ALISDAA_CALLERID_SIZE; i += 2) {
5000                 bytes.high = bytes.low = 0x00;
5001                 outb_p(bytes.high, j->XILINXbase + 0x03);
5002                 outb_p(bytes.low, j->XILINXbase + 0x02);
5003
5004                 if (!SCI_Control(j, SCI_Enable_DAA))
5005                         return 0;
5006
5007                 if (!SCI_WaitHighSCI(j))
5008                         return 0;
5009
5010                 CID[i + 0] = inb_p(j->XILINXbase + 0x03);
5011                 CID[i + 1] = inb_p(j->XILINXbase + 0x02);
5012         }
5013
5014         if (!SCI_Control(j, SCI_End))
5015                 return 0;
5016
5017         pIn = CID;
5018         pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5019         mContinue = true;
5020         while (mContinue) {
5021                 if ((pIn[1] & 0x03) == 0x01) {
5022                         pOut[0] = pIn[0];
5023                 }
5024                 if ((pIn[2] & 0x0c) == 0x04) {
5025                         pOut[1] = ((pIn[2] & 0x03) << 6) | ((pIn[1] & 0xfc) >> 2);
5026                 }
5027                 if ((pIn[3] & 0x30) == 0x10) {
5028                         pOut[2] = ((pIn[3] & 0x0f) << 4) | ((pIn[2] & 0xf0) >> 4);
5029                 }
5030                 if ((pIn[4] & 0xc0) == 0x40) {
5031                         pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6);
5032                 } else {
5033                         mContinue = false;
5034                 }
5035                 pIn += 5, pOut += 4;
5036         }
5037         memset(&j->cid, 0, sizeof(PHONE_CID));
5038         pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5039         pOut += 4;
5040         strncpy(j->cid.month, pOut, 2);
5041         pOut += 2;
5042         strncpy(j->cid.day, pOut, 2);
5043         pOut += 2;
5044         strncpy(j->cid.hour, pOut, 2);
5045         pOut += 2;
5046         strncpy(j->cid.min, pOut, 2);
5047         pOut += 3;
5048         j->cid.numlen = *pOut;
5049         pOut += 1;
5050         strncpy(j->cid.number, pOut, j->cid.numlen);
5051         pOut += j->cid.numlen + 1;
5052         j->cid.namelen = *pOut;
5053         pOut += 1;
5054         strncpy(j->cid.name, pOut, j->cid.namelen);
5055
5056         ixj_daa_cid_reset(j);
5057         return 1;
5058 }
5059
5060 static char daa_get_version(IXJ *j)
5061 {
5062         BYTES bytes;
5063
5064         if (!SCI_Prepare(j))
5065                 return 0;
5066
5067         bytes.high = 0x35;
5068         bytes.low = 0x00;
5069         outb_p(bytes.high, j->XILINXbase + 0x03);
5070         outb_p(bytes.low, j->XILINXbase + 0x02);
5071
5072         if (!SCI_Control(j, SCI_Enable_DAA))
5073                 return 0;
5074
5075         bytes.high = inb_p(j->XILINXbase + 0x03);
5076         bytes.low = inb_p(j->XILINXbase + 0x02);
5077         if (bytes.low != ALISDAA_ID_BYTE) {
5078                 if (ixjdebug & 0x0001)
5079                         printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
5080                 return 0;
5081         }
5082         if (!SCI_Control(j, SCI_Enable_DAA))
5083                 return 0;
5084
5085         if (!SCI_Control(j, SCI_End))
5086                 return 0;
5087
5088         bytes.high = inb_p(j->XILINXbase + 0x03);
5089         bytes.low = inb_p(j->XILINXbase + 0x02);
5090         if (ixjdebug & 0x0002)
5091                 printk("DAA CR5 Byte high = 0x%x low = 0x%x\n", bytes.high, bytes.low);
5092         j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = bytes.high;
5093         return bytes.high;
5094 }
5095
5096 static int daa_set_mode(IXJ *j, int mode)
5097 {
5098         /* NOTE:
5099               The DAA *MUST* be in the conversation mode if the
5100               PSTN line is to be seized (PSTN line off-hook).
5101               Taking the PSTN line off-hook while the DAA is in
5102               a mode other than conversation mode will cause a
5103               hardware failure of the ALIS-A part.
5104
5105            NOTE:
5106               The DAA can only go to SLEEP, RINGING or PULSEDIALING modes
5107               if the PSTN line is on-hook.  Failure to have the PSTN line
5108               in the on-hook state WILL CAUSE A HARDWARE FAILURE OF THE
5109               ALIS-A part.
5110         */
5111
5112         BYTES bytes;
5113
5114         j->flags.pstn_rmr = 0;
5115
5116         if (!SCI_Prepare(j))
5117                 return 0;
5118
5119         switch (mode) {
5120         case SOP_PU_RESET:
5121                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5122
5123                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5124                 j->pld_slicw.bits.rly2 = 0;
5125                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5126                 bytes.high = 0x10;
5127                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5128                 daa_load(&bytes, j);
5129                 if (!SCI_Prepare(j))
5130                         return 0;
5131
5132                 j->daa_mode = SOP_PU_SLEEP;
5133                 break;
5134         case SOP_PU_SLEEP:
5135                 if(j->daa_mode == SOP_PU_SLEEP)
5136                 {
5137                         break;
5138                 }
5139                 if (ixjdebug & 0x0008)
5140                         printk(KERN_INFO "phone DAA: SOP_PU_SLEEP at %ld\n", jiffies);
5141 /*              if(j->daa_mode == SOP_PU_CONVERSATION) */
5142                 {
5143                         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5144
5145                         outb_p(j->pld_scrw.byte, j->XILINXbase);
5146                         j->pld_slicw.bits.rly2 = 0;
5147                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5148                         bytes.high = 0x10;
5149                         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5150                         daa_load(&bytes, j);
5151                         if (!SCI_Prepare(j))
5152                                 return 0;
5153                 }
5154                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5155
5156                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5157                 j->pld_slicw.bits.rly2 = 0;
5158                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5159                 bytes.high = 0x10;
5160                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5161                 daa_load(&bytes, j);
5162                 if (!SCI_Prepare(j))
5163                         return 0;
5164
5165                 j->daa_mode = SOP_PU_SLEEP;
5166                 j->flags.pstn_ringing = 0;
5167                 j->ex.bits.pstn_ring = 0;
5168                 j->pstn_sleeptil = jiffies + (hertz / 4);
5169                 wake_up_interruptible(&j->read_q);      /* Wake any blocked readers */
5170                 wake_up_interruptible(&j->write_q);     /* Wake any blocked writers */
5171                 wake_up_interruptible(&j->poll_q);      /* Wake any blocked selects */
5172                 break;
5173         case SOP_PU_RINGING:
5174                 if (ixjdebug & 0x0008)
5175                         printk(KERN_INFO "phone DAA: SOP_PU_RINGING at %ld\n", jiffies);
5176                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5177
5178                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5179                 j->pld_slicw.bits.rly2 = 0;
5180                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5181                 bytes.high = 0x50;
5182                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5183                 daa_load(&bytes, j);
5184                 if (!SCI_Prepare(j))
5185                         return 0;
5186                 j->daa_mode = SOP_PU_RINGING;
5187                 break;
5188         case SOP_PU_CONVERSATION:
5189                 if (ixjdebug & 0x0008)
5190                         printk(KERN_INFO "phone DAA: SOP_PU_CONVERSATION at %ld\n", jiffies);
5191                 bytes.high = 0x90;
5192                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5193                 daa_load(&bytes, j);
5194                 if (!SCI_Prepare(j))
5195                         return 0;
5196                 j->pld_slicw.bits.rly2 = 1;
5197                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5198                 j->pld_scrw.bits.daafsyncen = 1;        /* Turn on DAA Frame Sync */
5199
5200                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5201                 j->daa_mode = SOP_PU_CONVERSATION;
5202                 j->flags.pstn_ringing = 0;
5203                 j->ex.bits.pstn_ring = 0;
5204                 j->pstn_sleeptil = jiffies;
5205                 j->pstn_ring_start = j->pstn_ring_stop = j->pstn_ring_int = 0;
5206                 break;
5207         case SOP_PU_PULSEDIALING:
5208                 if (ixjdebug & 0x0008)
5209                         printk(KERN_INFO "phone DAA: SOP_PU_PULSEDIALING at %ld\n", jiffies);
5210                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
5211
5212                 outb_p(j->pld_scrw.byte, j->XILINXbase);
5213                 j->pld_slicw.bits.rly2 = 0;
5214                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5215                 bytes.high = 0xD0;
5216                 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5217                 daa_load(&bytes, j);
5218                 if (!SCI_Prepare(j))
5219                         return 0;
5220                 j->daa_mode = SOP_PU_PULSEDIALING;
5221                 break;
5222         default:
5223                 break;
5224         }
5225         return 1;
5226 }
5227
5228 static int ixj_daa_write(IXJ *j)
5229 {
5230         BYTES bytes;
5231
5232         j->flags.pstncheck = 1;
5233
5234         daa_set_mode(j, SOP_PU_SLEEP);
5235
5236         if (!SCI_Prepare(j))
5237                 return 0;
5238
5239         outb_p(j->pld_scrw.byte, j->XILINXbase);
5240
5241         bytes.high = 0x14;
5242         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
5243         if (!daa_load(&bytes, j))
5244                 return 0;
5245
5246         bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg;
5247         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg;
5248         if (!daa_load(&bytes, j))
5249                 return 0;
5250
5251         bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg;
5252         bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5253         if (!daa_load(&bytes, j))
5254                 return 0;
5255
5256         if (!SCI_Prepare(j))
5257                 return 0;
5258
5259         bytes.high = 0x1F;
5260         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg;
5261         if (!daa_load(&bytes, j))
5262                 return 0;
5263
5264         bytes.high = j->m_DAAShadowRegs.XOP_xr6_W.reg;
5265         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg;
5266         if (!daa_load(&bytes, j))
5267                 return 0;
5268
5269         bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg;
5270         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg;
5271         if (!daa_load(&bytes, j))
5272                 return 0;
5273
5274         bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg;
5275         bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg;
5276         if (!daa_load(&bytes, j))
5277                 return 0;
5278
5279         bytes.high = j->m_DAAShadowRegs.XOP_xr0_W.reg;
5280         bytes.low = 0x00;
5281         if (!daa_load(&bytes, j))
5282                 return 0;
5283
5284         if (!SCI_Prepare(j))
5285                 return 0;
5286
5287         bytes.high = 0x00;
5288         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7];
5289         if (!daa_load(&bytes, j))
5290                 return 0;
5291
5292         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6];
5293         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5];
5294         if (!daa_load(&bytes, j))
5295                 return 0;
5296
5297         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4];
5298         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3];
5299         if (!daa_load(&bytes, j))
5300                 return 0;
5301
5302         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2];
5303         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1];
5304         if (!daa_load(&bytes, j))
5305                 return 0;
5306
5307         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0];
5308         bytes.low = 0x00;
5309         if (!daa_load(&bytes, j))
5310                 return 0;
5311
5312         if (!SCI_Control(j, SCI_End))
5313                 return 0;
5314         if (!SCI_WaitLowSCI(j))
5315                 return 0;
5316
5317         bytes.high = 0x01;
5318         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7];
5319         if (!daa_load(&bytes, j))
5320                 return 0;
5321
5322         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6];
5323         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5];
5324         if (!daa_load(&bytes, j))
5325                 return 0;
5326
5327         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4];
5328         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3];
5329         if (!daa_load(&bytes, j))
5330                 return 0;
5331
5332         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2];
5333         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1];
5334         if (!daa_load(&bytes, j))
5335                 return 0;
5336
5337         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0];
5338         bytes.low = 0x00;
5339         if (!daa_load(&bytes, j))
5340                 return 0;
5341
5342         if (!SCI_Control(j, SCI_End))
5343                 return 0;
5344         if (!SCI_WaitLowSCI(j))
5345                 return 0;
5346
5347         bytes.high = 0x02;
5348         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7];
5349         if (!daa_load(&bytes, j))
5350                 return 0;
5351
5352         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6];
5353         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5];
5354         if (!daa_load(&bytes, j))
5355                 return 0;
5356
5357         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4];
5358         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3];
5359         if (!daa_load(&bytes, j))
5360                 return 0;
5361
5362         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2];
5363         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1];
5364         if (!daa_load(&bytes, j))
5365                 return 0;
5366
5367         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0];
5368         bytes.low = 0x00;
5369         if (!daa_load(&bytes, j))
5370                 return 0;
5371
5372         if (!SCI_Control(j, SCI_End))
5373                 return 0;
5374         if (!SCI_WaitLowSCI(j))
5375                 return 0;
5376
5377         bytes.high = 0x03;
5378         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7];
5379         if (!daa_load(&bytes, j))
5380                 return 0;
5381
5382         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6];
5383         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5];
5384         if (!daa_load(&bytes, j))
5385                 return 0;
5386
5387         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4];
5388         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3];
5389         if (!daa_load(&bytes, j))
5390                 return 0;
5391
5392         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2];
5393         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1];
5394         if (!daa_load(&bytes, j))
5395                 return 0;
5396
5397         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0];
5398         bytes.low = 0x00;
5399         if (!daa_load(&bytes, j))
5400                 return 0;
5401
5402         if (!SCI_Control(j, SCI_End))
5403                 return 0;
5404         if (!SCI_WaitLowSCI(j))
5405                 return 0;
5406
5407         bytes.high = 0x04;
5408         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7];
5409         if (!daa_load(&bytes, j))
5410                 return 0;
5411
5412         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6];
5413         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5];
5414         if (!daa_load(&bytes, j))
5415                 return 0;
5416
5417         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4];
5418         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3];
5419         if (!daa_load(&bytes, j))
5420                 return 0;
5421
5422         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2];
5423         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1];
5424         if (!daa_load(&bytes, j))
5425                 return 0;
5426
5427         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0];
5428         bytes.low = 0x00;
5429         if (!daa_load(&bytes, j))
5430                 return 0;
5431
5432         if (!SCI_Control(j, SCI_End))
5433                 return 0;
5434         if (!SCI_WaitLowSCI(j))
5435                 return 0;
5436
5437         bytes.high = 0x05;
5438         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7];
5439         if (!daa_load(&bytes, j))
5440                 return 0;
5441
5442         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6];
5443         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5];
5444         if (!daa_load(&bytes, j))
5445                 return 0;
5446
5447         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4];
5448         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3];
5449         if (!daa_load(&bytes, j))
5450                 return 0;
5451
5452         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2];
5453         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1];
5454         if (!daa_load(&bytes, j))
5455                 return 0;
5456
5457         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0];
5458         bytes.low = 0x00;
5459         if (!daa_load(&bytes, j))
5460                 return 0;
5461
5462         if (!SCI_Control(j, SCI_End))
5463                 return 0;
5464         if (!SCI_WaitLowSCI(j))
5465                 return 0;
5466
5467         bytes.high = 0x06;
5468         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7];
5469         if (!daa_load(&bytes, j))
5470                 return 0;
5471
5472         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6];
5473         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5];
5474         if (!daa_load(&bytes, j))
5475                 return 0;
5476
5477         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4];
5478         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3];
5479         if (!daa_load(&bytes, j))
5480                 return 0;
5481
5482         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2];
5483         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1];
5484         if (!daa_load(&bytes, j))
5485                 return 0;
5486
5487         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0];
5488         bytes.low = 0x00;
5489         if (!daa_load(&bytes, j))
5490                 return 0;
5491
5492         if (!SCI_Control(j, SCI_End))
5493                 return 0;
5494         if (!SCI_WaitLowSCI(j))
5495                 return 0;
5496
5497         bytes.high = 0x07;
5498         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7];
5499         if (!daa_load(&bytes, j))
5500                 return 0;
5501
5502         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6];
5503         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5];
5504         if (!daa_load(&bytes, j))
5505                 return 0;
5506
5507         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4];
5508         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3];
5509         if (!daa_load(&bytes, j))
5510                 return 0;
5511
5512         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2];
5513         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1];
5514         if (!daa_load(&bytes, j))
5515                 return 0;
5516
5517         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0];
5518         bytes.low = 0x00;
5519         if (!daa_load(&bytes, j))
5520                 return 0;
5521
5522         if (!SCI_Control(j, SCI_End))
5523                 return 0;
5524         if (!SCI_WaitLowSCI(j))
5525                 return 0;
5526
5527         bytes.high = 0x08;
5528         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7];
5529         if (!daa_load(&bytes, j))
5530                 return 0;
5531
5532         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6];
5533         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5];
5534         if (!daa_load(&bytes, j))
5535                 return 0;
5536
5537         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4];
5538         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3];
5539         if (!daa_load(&bytes, j))
5540                 return 0;
5541
5542         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2];
5543         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1];
5544         if (!daa_load(&bytes, j))
5545                 return 0;
5546
5547         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0];
5548         bytes.low = 0x00;
5549         if (!daa_load(&bytes, j))
5550                 return 0;
5551
5552         if (!SCI_Control(j, SCI_End))
5553                 return 0;
5554         if (!SCI_WaitLowSCI(j))
5555                 return 0;
5556
5557         bytes.high = 0x09;
5558         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3];
5559         if (!daa_load(&bytes, j))
5560                 return 0;
5561
5562         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2];
5563         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1];
5564         if (!daa_load(&bytes, j))
5565                 return 0;
5566
5567         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0];
5568         bytes.low = 0x00;
5569         if (!daa_load(&bytes, j))
5570                 return 0;
5571
5572         if (!SCI_Control(j, SCI_End))
5573                 return 0;
5574         if (!SCI_WaitLowSCI(j))
5575                 return 0;
5576
5577         bytes.high = 0x0A;
5578         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3];
5579         if (!daa_load(&bytes, j))
5580                 return 0;
5581
5582         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2];
5583         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1];
5584         if (!daa_load(&bytes, j))
5585                 return 0;
5586
5587         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0];
5588         bytes.low = 0x00;
5589         if (!daa_load(&bytes, j))
5590                 return 0;
5591
5592         if (!SCI_Control(j, SCI_End))
5593                 return 0;
5594         if (!SCI_WaitLowSCI(j))
5595                 return 0;
5596
5597         bytes.high = 0x0B;
5598         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3];
5599         if (!daa_load(&bytes, j))
5600                 return 0;
5601
5602         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2];
5603         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1];
5604         if (!daa_load(&bytes, j))
5605                 return 0;
5606
5607         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0];
5608         bytes.low = 0x00;
5609         if (!daa_load(&bytes, j))
5610                 return 0;
5611
5612         if (!SCI_Control(j, SCI_End))
5613                 return 0;
5614         if (!SCI_WaitLowSCI(j))
5615                 return 0;
5616
5617         bytes.high = 0x0C;
5618         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3];
5619         if (!daa_load(&bytes, j))
5620                 return 0;
5621
5622         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2];
5623         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1];
5624         if (!daa_load(&bytes, j))
5625                 return 0;
5626
5627         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0];
5628         bytes.low = 0x00;
5629         if (!daa_load(&bytes, j))
5630                 return 0;
5631
5632         if (!SCI_Control(j, SCI_End))
5633                 return 0;
5634         if (!SCI_WaitLowSCI(j))
5635                 return 0;
5636
5637         bytes.high = 0x0D;
5638         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3];
5639         if (!daa_load(&bytes, j))
5640                 return 0;
5641
5642         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2];
5643         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1];
5644         if (!daa_load(&bytes, j))
5645                 return 0;
5646
5647         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0];
5648         bytes.low = 0x00;
5649         if (!daa_load(&bytes, j))
5650                 return 0;
5651
5652         if (!SCI_Control(j, SCI_End))
5653                 return 0;
5654         if (!SCI_WaitLowSCI(j))
5655                 return 0;
5656
5657         bytes.high = 0x0E;
5658         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7];
5659         if (!daa_load(&bytes, j))
5660                 return 0;
5661
5662         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6];
5663         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5];
5664         if (!daa_load(&bytes, j))
5665                 return 0;
5666
5667         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4];
5668         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3];
5669         if (!daa_load(&bytes, j))
5670                 return 0;
5671
5672         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2];
5673         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1];
5674         if (!daa_load(&bytes, j))
5675                 return 0;
5676
5677         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0];
5678         bytes.low = 0x00;
5679         if (!daa_load(&bytes, j))
5680                 return 0;
5681
5682         if (!SCI_Control(j, SCI_End))
5683                 return 0;
5684         if (!SCI_WaitLowSCI(j))
5685                 return 0;
5686
5687         bytes.high = 0x0F;
5688         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7];
5689         if (!daa_load(&bytes, j))
5690                 return 0;
5691
5692         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6];
5693         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5];
5694         if (!daa_load(&bytes, j))
5695                 return 0;
5696
5697         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4];
5698         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3];
5699         if (!daa_load(&bytes, j))
5700                 return 0;
5701
5702         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2];
5703         bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1];
5704         if (!daa_load(&bytes, j))
5705                 return 0;
5706
5707         bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0];
5708         bytes.low = 0x00;
5709         if (!daa_load(&bytes, j))
5710                 return 0;
5711
5712         udelay(32);
5713         j->pld_scrr.byte = inb_p(j->XILINXbase);
5714         if (!SCI_Control(j, SCI_End))
5715                 return 0;
5716
5717         outb_p(j->pld_scrw.byte, j->XILINXbase);
5718
5719         if (ixjdebug & 0x0002)
5720                 printk("DAA Coefficients Loaded\n");
5721
5722         j->flags.pstncheck = 0;
5723         return 1;
5724 }
5725
5726 static int ixj_set_tone_off(unsigned short arg, IXJ *j)
5727 {
5728         j->tone_off_time = arg;
5729         if (ixj_WriteDSPCommand(0x6E05, j))             /* Set Tone Off Period */
5730
5731                 return -1;
5732         if (ixj_WriteDSPCommand(arg, j))
5733                 return -1;
5734         return 0;
5735 }
5736
5737 static int ixj_get_tone_on(IXJ *j)
5738 {
5739         if (ixj_WriteDSPCommand(0x6E06, j))             /* Get Tone On Period */
5740
5741                 return -1;
5742         return 0;
5743 }
5744
5745 static int ixj_get_tone_off(IXJ *j)
5746 {
5747         if (ixj_WriteDSPCommand(0x6E07, j))             /* Get Tone Off Period */
5748
5749                 return -1;
5750         return 0;
5751 }
5752
5753 static void ixj_busytone(IXJ *j)
5754 {
5755         j->flags.ringback = 0;
5756         j->flags.dialtone = 0;
5757         j->flags.busytone = 1;
5758         ixj_set_tone_on(0x07D0, j);
5759         ixj_set_tone_off(0x07D0, j);
5760         ixj_play_tone(j, 27);
5761 }
5762
5763 static void ixj_dialtone(IXJ *j)
5764 {
5765         j->flags.ringback = 0;
5766         j->flags.dialtone = 1;
5767         j->flags.busytone = 0;
5768         if (j->dsp.low == 0x20) {
5769                 return;
5770         } else {
5771                 ixj_set_tone_on(0xFFFF, j);
5772                 ixj_set_tone_off(0x0000, j);
5773                 ixj_play_tone(j, 25);
5774         }
5775 }
5776
5777 static void ixj_cpt_stop(IXJ *j)
5778 {
5779         if(j->tone_state || j->tone_cadence_state)
5780         {
5781                 j->flags.dialtone = 0;
5782                 j->flags.busytone = 0;
5783                 j->flags.ringback = 0;
5784                 ixj_set_tone_on(0x0001, j);
5785                 ixj_set_tone_off(0x0000, j);
5786                 ixj_play_tone(j, 0);
5787                 j->tone_state = j->tone_cadence_state = 0;
5788                 if (j->cadence_t) {
5789                         kfree(j->cadence_t->ce);
5790                         kfree(j->cadence_t);
5791                         j->cadence_t = NULL;
5792                 }
5793         }
5794         if (j->play_mode == -1 && j->rec_mode == -1)
5795                 idle(j);
5796         if (j->play_mode != -1 && j->dsp.low == 0x20)
5797                 ixj_play_start(j);
5798         if (j->rec_mode != -1 && j->dsp.low == 0x20)
5799                 ixj_record_start(j);
5800 }
5801
5802 static void ixj_ringback(IXJ *j)
5803 {
5804         j->flags.busytone = 0;
5805         j->flags.dialtone = 0;
5806         j->flags.ringback = 1;
5807         ixj_set_tone_on(0x0FA0, j);
5808         ixj_set_tone_off(0x2EE0, j);
5809         ixj_play_tone(j, 26);
5810 }
5811
5812 static void ixj_testram(IXJ *j)
5813 {
5814         ixj_WriteDSPCommand(0x3001, j); /* Test External SRAM */
5815 }
5816
5817 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp)
5818 {
5819         ixj_cadence *lcp;
5820         IXJ_CADENCE_ELEMENT __user *cep;
5821         IXJ_CADENCE_ELEMENT *lcep;
5822         IXJ_TONE ti;
5823         int err;
5824
5825         lcp = kmalloc(sizeof(ixj_cadence), GFP_KERNEL);
5826         if (lcp == NULL)
5827                 return -ENOMEM;
5828
5829         err = -EFAULT;
5830         if (copy_from_user(&lcp->elements_used,
5831                            &cp->elements_used, sizeof(int)))
5832                 goto out;
5833         if (copy_from_user(&lcp->termination,
5834                            &cp->termination, sizeof(IXJ_CADENCE_TERM)))
5835                 goto out;
5836         if (get_user(cep, &cp->ce))
5837                 goto out;
5838
5839         err = -EINVAL;
5840         if ((unsigned)lcp->elements_used >= ~0U/sizeof(IXJ_CADENCE_ELEMENT))
5841                 goto out;
5842
5843         err = -ENOMEM;
5844         lcep = kmalloc(sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used, GFP_KERNEL);
5845         if (!lcep)
5846                 goto out;
5847
5848         err = -EFAULT;
5849         if (copy_from_user(lcep, cep, sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used))
5850                 goto out1;
5851
5852         if (j->cadence_t) {
5853                 kfree(j->cadence_t->ce);
5854                 kfree(j->cadence_t);
5855         }
5856         lcp->ce = (void *) lcep;
5857         j->cadence_t = lcp;
5858         j->tone_cadence_state = 0;
5859         ixj_set_tone_on(lcp->ce[0].tone_on_time, j);
5860         ixj_set_tone_off(lcp->ce[0].tone_off_time, j);
5861         if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
5862                 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
5863                 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
5864                 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
5865                 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
5866                 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
5867                 ixj_init_tone(j, &ti);
5868         }
5869         ixj_play_tone(j, lcp->ce[0].index);
5870         return 1;
5871 out1:
5872         kfree(lcep);
5873 out:
5874         kfree(lcp);
5875         return err;
5876 }
5877
5878 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp)
5879 {
5880         IXJ_FILTER_CADENCE *lcp;
5881         lcp = kmalloc(sizeof(IXJ_FILTER_CADENCE), GFP_KERNEL);
5882         if (lcp == NULL) {
5883                 if(ixjdebug & 0x0001) {
5884                         printk(KERN_INFO "Could not allocate memory for cadence\n");
5885                 }
5886                 return -ENOMEM;
5887         }
5888         if (copy_from_user(lcp, cp, sizeof(IXJ_FILTER_CADENCE))) {
5889                 if(ixjdebug & 0x0001) {
5890                         printk(KERN_INFO "Could not copy cadence to kernel\n");
5891                 }
5892                 kfree(lcp);
5893                 return -EFAULT;
5894         }
5895         if (lcp->filter > 5) {
5896                 if(ixjdebug & 0x0001) {
5897                         printk(KERN_INFO "Cadence out of range\n");
5898                 }
5899                 kfree(lcp);
5900                 return -1;
5901         }
5902         j->cadence_f[lcp->filter].state = 0;
5903         j->cadence_f[lcp->filter].enable = lcp->enable;
5904         j->filter_en[lcp->filter] = j->cadence_f[lcp->filter].en_filter = lcp->en_filter;
5905         j->cadence_f[lcp->filter].on1 = lcp->on1;
5906         j->cadence_f[lcp->filter].on1min = 0;
5907         j->cadence_f[lcp->filter].on1max = 0;
5908         j->cadence_f[lcp->filter].off1 = lcp->off1;
5909         j->cadence_f[lcp->filter].off1min = 0;
5910         j->cadence_f[lcp->filter].off1max = 0;
5911         j->cadence_f[lcp->filter].on2 = lcp->on2;
5912         j->cadence_f[lcp->filter].on2min = 0;
5913         j->cadence_f[lcp->filter].on2max = 0;
5914         j->cadence_f[lcp->filter].off2 = lcp->off2;
5915         j->cadence_f[lcp->filter].off2min = 0;
5916         j->cadence_f[lcp->filter].off2max = 0;
5917         j->cadence_f[lcp->filter].on3 = lcp->on3;
5918         j->cadence_f[lcp->filter].on3min = 0;
5919         j->cadence_f[lcp->filter].on3max = 0;
5920         j->cadence_f[lcp->filter].off3 = lcp->off3;
5921         j->cadence_f[lcp->filter].off3min = 0;
5922         j->cadence_f[lcp->filter].off3max = 0;
5923         if(ixjdebug & 0x0002) {
5924                 printk(KERN_INFO "Cadence %d loaded\n", lcp->filter);
5925         }
5926         kfree(lcp);
5927         return 0;
5928 }
5929
5930 static void add_caps(IXJ *j)
5931 {
5932         j->caps = 0;
5933         j->caplist[j->caps].cap = PHONE_VENDOR_QUICKNET;
5934         strcpy(j->caplist[j->caps].desc, "Quicknet Technologies, Inc. (www.quicknet.net)");
5935         j->caplist[j->caps].captype = vendor;
5936         j->caplist[j->caps].handle = j->caps++;
5937         j->caplist[j->caps].captype = device;
5938         switch (j->cardtype) {
5939         case QTI_PHONEJACK:
5940                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK");
5941                 break;
5942         case QTI_LINEJACK:
5943                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet LineJACK");
5944                 break;
5945         case QTI_PHONEJACK_LITE:
5946                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK Lite");
5947                 break;
5948         case QTI_PHONEJACK_PCI:
5949                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK PCI");
5950                 break;
5951         case QTI_PHONECARD:
5952                 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneCARD");
5953                 break;
5954         }
5955         j->caplist[j->caps].cap = j->cardtype;
5956         j->caplist[j->caps].handle = j->caps++;
5957         strcpy(j->caplist[j->caps].desc, "POTS");
5958         j->caplist[j->caps].captype = port;
5959         j->caplist[j->caps].cap = pots;
5960         j->caplist[j->caps].handle = j->caps++;
5961
5962         /* add devices that can do speaker/mic */
5963         switch (j->cardtype) {
5964         case QTI_PHONEJACK:
5965         case QTI_LINEJACK:
5966         case QTI_PHONEJACK_PCI:
5967         case QTI_PHONECARD:
5968                 strcpy(j->caplist[j->caps].desc, "SPEAKER");
5969                 j->caplist[j->caps].captype = port;
5970                 j->caplist[j->caps].cap = speaker;
5971                 j->caplist[j->caps].handle = j->caps++;
5972         default:
5973                 break;
5974         }
5975
5976         /* add devices that can do handset */
5977         switch (j->cardtype) {
5978         case QTI_PHONEJACK:
5979                 strcpy(j->caplist[j->caps].desc, "HANDSET");
5980                 j->caplist[j->caps].captype = port;
5981                 j->caplist[j->caps].cap = handset;
5982                 j->caplist[j->caps].handle = j->caps++;
5983                 break;
5984         default:
5985                 break;
5986         }
5987
5988         /* add devices that can do PSTN */
5989         switch (j->cardtype) {
5990         case QTI_LINEJACK:
5991                 strcpy(j->caplist[j->caps].desc, "PSTN");
5992                 j->caplist[j->caps].captype = port;
5993                 j->caplist[j->caps].cap = pstn;
5994                 j->caplist[j->caps].handle = j->caps++;
5995                 break;
5996         default:
5997                 break;
5998         }
5999
6000         /* add codecs - all cards can do uLaw, linear 8/16, and Windows sound system */
6001         strcpy(j->caplist[j->caps].desc, "ULAW");
6002         j->caplist[j->caps].captype = codec;
6003         j->caplist[j->caps].cap = ULAW;
6004         j->caplist[j->caps].handle = j->caps++;
6005
6006         strcpy(j->caplist[j->caps].desc, "LINEAR 16 bit");
6007         j->caplist[j->caps].captype = codec;
6008         j->caplist[j->caps].cap = LINEAR16;
6009         j->caplist[j->caps].handle = j->caps++;
6010
6011         strcpy(j->caplist[j->caps].desc, "LINEAR 8 bit");
6012         j->caplist[j->caps].captype = codec;
6013         j->caplist[j->caps].cap = LINEAR8;
6014         j->caplist[j->caps].handle = j->caps++;
6015
6016         strcpy(j->caplist[j->caps].desc, "Windows Sound System");
6017         j->caplist[j->caps].captype = codec;
6018         j->caplist[j->caps].cap = WSS;
6019         j->caplist[j->caps].handle = j->caps++;
6020
6021         /* software ALAW codec, made from ULAW */
6022         strcpy(j->caplist[j->caps].desc, "ALAW");
6023         j->caplist[j->caps].captype = codec;
6024         j->caplist[j->caps].cap = ALAW;
6025         j->caplist[j->caps].handle = j->caps++;
6026
6027         /* version 12 of the 8020 does the following codecs in a broken way */
6028         if (j->dsp.low != 0x20 || j->ver.low != 0x12) {
6029                 strcpy(j->caplist[j->caps].desc, "G.723.1 6.3kbps");
6030                 j->caplist[j->caps].captype = codec;
6031                 j->caplist[j->caps].cap = G723_63;
6032                 j->caplist[j->caps].handle = j->caps++;
6033
6034                 strcpy(j->caplist[j->caps].desc, "G.723.1 5.3kbps");
6035                 j->caplist[j->caps].captype = codec;
6036                 j->caplist[j->caps].cap = G723_53;
6037                 j->caplist[j->caps].handle = j->caps++;
6038
6039                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.8kbps");
6040                 j->caplist[j->caps].captype = codec;
6041                 j->caplist[j->caps].cap = TS48;
6042                 j->caplist[j->caps].handle = j->caps++;
6043
6044                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.1kbps");
6045                 j->caplist[j->caps].captype = codec;
6046                 j->caplist[j->caps].cap = TS41;
6047                 j->caplist[j->caps].handle = j->caps++;
6048         }
6049
6050         /* 8020 chips can do TS8.5 native, and 8021/8022 can load it */
6051         if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
6052                 strcpy(j->caplist[j->caps].desc, "TrueSpeech 8.5kbps");
6053                 j->caplist[j->caps].captype = codec;
6054                 j->caplist[j->caps].cap = TS85;
6055                 j->caplist[j->caps].handle = j->caps++;
6056         }
6057
6058         /* 8021 chips can do G728 */
6059         if (j->dsp.low == 0x21) {
6060                 strcpy(j->caplist[j->caps].desc, "G.728 16kbps");
6061                 j->caplist[j->caps].captype = codec;
6062                 j->caplist[j->caps].cap = G728;
6063                 j->caplist[j->caps].handle = j->caps++;
6064         }
6065
6066         /* 8021/8022 chips can do G729 if loaded */
6067         if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6068                 strcpy(j->caplist[j->caps].desc, "G.729A 8kbps");
6069                 j->caplist[j->caps].captype = codec;
6070                 j->caplist[j->caps].cap = G729;
6071                 j->caplist[j->caps].handle = j->caps++;
6072         }
6073         if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6074                 strcpy(j->caplist[j->caps].desc, "G.729B 8kbps");
6075                 j->caplist[j->caps].captype = codec;
6076                 j->caplist[j->caps].cap = G729B;
6077                 j->caplist[j->caps].handle = j->caps++;
6078         }
6079 }
6080
6081 static int capabilities_check(IXJ *j, struct phone_capability *pcreq)
6082 {
6083         int cnt;
6084         int retval = 0;
6085         for (cnt = 0; cnt < j->caps; cnt++) {
6086                 if (pcreq->captype == j->caplist[cnt].captype
6087                     && pcreq->cap == j->caplist[cnt].cap) {
6088                         retval = 1;
6089                         break;
6090                 }
6091         }
6092         return retval;
6093 }
6094
6095 static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6096 {
6097         IXJ_TONE ti;
6098         IXJ_FILTER jf;
6099         IXJ_FILTER_RAW jfr;
6100         void __user *argp = (void __user *)arg;
6101         struct inode *inode = file_p->f_path.dentry->d_inode;
6102         unsigned int minor = iminor(inode);
6103         unsigned int raise, mant;
6104         int board = NUM(inode);
6105
6106         IXJ *j = get_ixj(NUM(inode));
6107
6108         int retval = 0;
6109
6110         /*
6111          *    Set up locks to ensure that only one process is talking to the DSP at a time.
6112          *    This is necessary to keep the DSP from locking up.
6113          */
6114         while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
6115                 schedule_timeout_interruptible(1);
6116         if (ixjdebug & 0x0040)
6117                 printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6118         if (minor >= IXJMAX) {
6119                 clear_bit(board, &j->busyflags);
6120                 return -ENODEV;
6121         }
6122         /*
6123          *    Check ioctls only root can use.
6124          */
6125         if (!capable(CAP_SYS_ADMIN)) {
6126                 switch (cmd) {
6127                 case IXJCTL_TESTRAM:
6128                 case IXJCTL_HZ:
6129                         retval = -EPERM;
6130                 }
6131         }
6132         switch (cmd) {
6133         case IXJCTL_TESTRAM:
6134                 ixj_testram(j);
6135                 retval = (j->ssr.high << 8) + j->ssr.low;
6136                 break;
6137         case IXJCTL_CARDTYPE:
6138                 retval = j->cardtype;
6139                 break;
6140         case IXJCTL_SERIAL:
6141                 retval = j->serial;
6142                 break;
6143         case IXJCTL_VERSION:
6144                 {
6145                         char arg_str[100];
6146                         snprintf(arg_str, sizeof(arg_str),
6147                                 "\nDriver version %i.%i.%i", IXJ_VER_MAJOR,
6148                                 IXJ_VER_MINOR, IXJ_BLD_VER);
6149                         if (copy_to_user(argp, arg_str, strlen(arg_str)))
6150                                 retval = -EFAULT;
6151                 }
6152                 break;
6153         case PHONE_RING_CADENCE:
6154                 j->ring_cadence = arg;
6155                 break;
6156         case IXJCTL_CIDCW:
6157                 if(arg) {
6158                         if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6159                                 retval = -EFAULT;
6160                                 break;
6161                         }
6162                 } else {
6163                         memset(&j->cid_send, 0, sizeof(PHONE_CID));
6164                 }
6165                 ixj_write_cidcw(j);
6166                 break;
6167         /* Binary compatbility */
6168         case OLD_PHONE_RING_START:
6169                 arg = 0;
6170                 /* Fall through */
6171         case PHONE_RING_START:
6172                 if(arg) {
6173                         if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6174                                 retval = -EFAULT;
6175                                 break;
6176                         }
6177                         ixj_write_cid(j);
6178                 } else {
6179                         memset(&j->cid_send, 0, sizeof(PHONE_CID));
6180                 }
6181                 ixj_ring_start(j);
6182                 break;
6183         case PHONE_RING_STOP:
6184                 j->flags.cringing = 0;
6185                 if(j->cadence_f[5].enable) {
6186                         j->cadence_f[5].state = 0;
6187                 }
6188                 ixj_ring_off(j);
6189                 break;
6190         case PHONE_RING:
6191                 retval = ixj_ring(j);
6192                 break;
6193         case PHONE_EXCEPTION:
6194                 retval = j->ex.bytes;
6195                 if(j->ex.bits.flash) {
6196                         j->flash_end = 0;
6197                         j->ex.bits.flash = 0;
6198                 }
6199                 j->ex.bits.pstn_ring = 0;
6200                 j->ex.bits.caller_id = 0;
6201                 j->ex.bits.pstn_wink = 0;
6202                 j->ex.bits.f0 = 0;
6203                 j->ex.bits.f1 = 0;
6204                 j->ex.bits.f2 = 0;
6205                 j->ex.bits.f3 = 0;
6206                 j->ex.bits.fc0 = 0;
6207                 j->ex.bits.fc1 = 0;
6208                 j->ex.bits.fc2 = 0;
6209                 j->ex.bits.fc3 = 0;
6210                 j->ex.bits.reserved = 0;
6211                 break;
6212         case PHONE_HOOKSTATE:
6213                 j->ex.bits.hookstate = 0;
6214                 retval = j->hookstate;  //j->r_hook;
6215                 break;
6216         case IXJCTL_SET_LED:
6217                 LED_SetState(arg, j);
6218                 break;
6219         case PHONE_FRAME:
6220                 retval = set_base_frame(j, arg);
6221                 break;
6222         case PHONE_REC_CODEC:
6223                 retval = set_rec_codec(j, arg);
6224                 break;
6225         case PHONE_VAD:
6226                 ixj_vad(j, arg);
6227                 break;
6228         case PHONE_REC_START:
6229                 ixj_record_start(j);
6230                 break;
6231         case PHONE_REC_STOP:
6232                 ixj_record_stop(j);
6233                 break;
6234         case PHONE_REC_DEPTH:
6235                 set_rec_depth(j, arg);
6236                 break;
6237         case PHONE_REC_VOLUME:
6238                 if(arg == -1) {
6239                         retval = get_rec_volume(j);
6240                 }
6241                 else {
6242                         set_rec_volume(j, arg);
6243                         retval = arg;
6244                 }
6245                 break;
6246         case PHONE_REC_VOLUME_LINEAR:
6247                 if(arg == -1) {
6248                         retval = get_rec_volume_linear(j);
6249                 }
6250                 else {
6251                         set_rec_volume_linear(j, arg);
6252                         retval = arg;
6253                 }
6254                 break;
6255         case IXJCTL_DTMF_PRESCALE:
6256                 if(arg == -1) {
6257                         retval = get_dtmf_prescale(j);
6258                 }
6259                 else {
6260                         set_dtmf_prescale(j, arg);
6261                         retval = arg;
6262                 }
6263                 break;
6264         case PHONE_REC_LEVEL:
6265                 retval = get_rec_level(j);
6266                 break;
6267         case IXJCTL_SC_RXG:
6268                 retval = ixj_siadc(j, arg);
6269                 break;
6270         case IXJCTL_SC_TXG:
6271                 retval = ixj_sidac(j, arg);
6272                 break;
6273         case IXJCTL_AEC_START:
6274                 ixj_aec_start(j, arg);
6275                 break;
6276         case IXJCTL_AEC_STOP:
6277                 aec_stop(j);
6278                 break;
6279         case IXJCTL_AEC_GET_LEVEL:
6280                 retval = j->aec_level;
6281                 break;
6282         case PHONE_PLAY_CODEC:
6283                 retval = set_play_codec(j, arg);
6284                 break;
6285         case PHONE_PLAY_START:
6286                 retval = ixj_play_start(j);
6287                 break;
6288         case PHONE_PLAY_STOP:
6289                 ixj_play_stop(j);
6290                 break;
6291         case PHONE_PLAY_DEPTH:
6292                 set_play_depth(j, arg);
6293                 break;
6294         case PHONE_PLAY_VOLUME:
6295                 if(arg == -1) {
6296                         retval = get_play_volume(j);
6297                 }
6298                 else {
6299                         set_play_volume(j, arg);
6300                         retval = arg;
6301                 }
6302                 break;
6303         case PHONE_PLAY_VOLUME_LINEAR:
6304                 if(arg == -1) {
6305                         retval = get_play_volume_linear(j);
6306                 }
6307                 else {
6308                         set_play_volume_linear(j, arg);
6309                         retval = arg;
6310                 }
6311                 break;
6312         case PHONE_PLAY_LEVEL:
6313                 retval = get_play_level(j);
6314                 break;
6315         case IXJCTL_DSP_TYPE:
6316                 retval = (j->dsp.high << 8) + j->dsp.low;
6317                 break;
6318         case IXJCTL_DSP_VERSION:
6319                 retval = (j->ver.high << 8) + j->ver.low;
6320                 break;
6321         case IXJCTL_HZ:
6322                 hertz = arg;
6323                 break;
6324         case IXJCTL_RATE:
6325                 if (arg > hertz)
6326                         retval = -1;
6327                 else
6328                         samplerate = arg;
6329                 break;
6330         case IXJCTL_DRYBUFFER_READ:
6331                 put_user(j->drybuffer, (unsigned long __user *) argp);
6332                 break;
6333         case IXJCTL_DRYBUFFER_CLEAR:
6334                 j->drybuffer = 0;
6335                 break;
6336         case IXJCTL_FRAMES_READ:
6337                 put_user(j->framesread, (unsigned long __user *) argp);
6338                 break;
6339         case IXJCTL_FRAMES_WRITTEN:
6340                 put_user(j->frameswritten, (unsigned long __user *) argp);
6341                 break;
6342         case IXJCTL_READ_WAIT:
6343                 put_user(j->read_wait, (unsigned long __user *) argp);
6344                 break;
6345         case IXJCTL_WRITE_WAIT:
6346                 put_user(j->write_wait, (unsigned long __user *) argp);
6347                 break;
6348         case PHONE_MAXRINGS:
6349                 j->maxrings = arg;
6350                 break;
6351         case PHONE_SET_TONE_ON_TIME:
6352                 ixj_set_tone_on(arg, j);
6353                 break;
6354         case PHONE_SET_TONE_OFF_TIME:
6355                 ixj_set_tone_off(arg, j);
6356                 break;
6357         case PHONE_GET_TONE_ON_TIME:
6358                 if (ixj_get_tone_on(j)) {
6359                         retval = -1;
6360                 } else {
6361                         retval = (j->ssr.high << 8) + j->ssr.low;
6362                 }
6363                 break;
6364         case PHONE_GET_TONE_OFF_TIME:
6365                 if (ixj_get_tone_off(j)) {
6366                         retval = -1;
6367                 } else {
6368                         retval = (j->ssr.high << 8) + j->ssr.low;
6369                 }
6370                 break;
6371         case PHONE_PLAY_TONE:
6372                 if (!j->tone_state)
6373                         retval = ixj_play_tone(j, arg);
6374                 else
6375                         retval = -1;
6376                 break;
6377         case PHONE_GET_TONE_STATE:
6378                 retval = j->tone_state;
6379                 break;
6380         case PHONE_DTMF_READY:
6381                 retval = j->ex.bits.dtmf_ready;
6382                 break;
6383         case PHONE_GET_DTMF:
6384                 if (ixj_hookstate(j)) {
6385                         if (j->dtmf_rp != j->dtmf_wp) {
6386                                 retval = j->dtmfbuffer[j->dtmf_rp];
6387                                 j->dtmf_rp++;
6388                                 if (j->dtmf_rp == 79)
6389                                         j->dtmf_rp = 0;
6390                                 if (j->dtmf_rp == j->dtmf_wp) {
6391                                         j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6392                                 }
6393                         }
6394                 }
6395                 break;
6396         case PHONE_GET_DTMF_ASCII:
6397                 if (ixj_hookstate(j)) {
6398                         if (j->dtmf_rp != j->dtmf_wp) {
6399                                 switch (j->dtmfbuffer[j->dtmf_rp]) {
6400                                 case 10:
6401                                         retval = 42;    /* '*'; */
6402
6403                                         break;
6404                                 case 11:
6405                                         retval = 48;    /*'0'; */
6406
6407                                         break;
6408                                 case 12:
6409                                         retval = 35;    /*'#'; */
6410
6411                                         break;
6412                                 case 28:
6413                                         retval = 65;    /*'A'; */
6414
6415                                         break;
6416                                 case 29:
6417                                         retval = 66;    /*'B'; */
6418
6419                                         break;
6420                                 case 30:
6421                                         retval = 67;    /*'C'; */
6422
6423                                         break;
6424                                 case 31:
6425                                         retval = 68;    /*'D'; */
6426
6427                                         break;
6428                                 default:
6429                                         retval = 48 + j->dtmfbuffer[j->dtmf_rp];
6430                                         break;
6431                                 }
6432                                 j->dtmf_rp++;
6433                                 if (j->dtmf_rp == 79)
6434                                         j->dtmf_rp = 0;
6435                                 if(j->dtmf_rp == j->dtmf_wp)
6436                                 {
6437                                         j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6438                                 }
6439                         }
6440                 }
6441                 break;
6442         case PHONE_DTMF_OOB:
6443                 j->flags.dtmf_oob = arg;
6444                 break;
6445         case PHONE_DIALTONE:
6446                 ixj_dialtone(j);
6447                 break;
6448         case PHONE_BUSY:
6449                 ixj_busytone(j);
6450                 break;
6451         case PHONE_RINGBACK:
6452                 ixj_ringback(j);
6453                 break;
6454         case PHONE_WINK:
6455                 if(j->cardtype == QTI_PHONEJACK) 
6456                         retval = -1;
6457                 else 
6458                         retval = ixj_wink(j);
6459                 break;
6460         case PHONE_CPT_STOP:
6461                 ixj_cpt_stop(j);
6462                 break;
6463         case PHONE_QUERY_CODEC:
6464         {
6465                 struct phone_codec_data pd;
6466                 int val;
6467                 int proto_size[] = {
6468                         -1,
6469                         12, 10, 16, 9, 8, 48, 5,
6470                         40, 40, 80, 40, 40, 6
6471                 };
6472                 if(copy_from_user(&pd, argp, sizeof(pd))) {
6473                         retval = -EFAULT;
6474                         break;
6475                 }
6476                 if(pd.type<1 || pd.type>13) {
6477                         retval = -EPROTONOSUPPORT;
6478                         break;
6479                 }
6480                 if(pd.type<G729)
6481                         val=proto_size[pd.type];
6482                 else switch(j->baseframe.low)
6483                 {
6484                         case 0xA0:val=2*proto_size[pd.type];break;
6485                         case 0x50:val=proto_size[pd.type];break;
6486                         default:val=proto_size[pd.type]*3;break;
6487                 }
6488                 pd.buf_min=pd.buf_max=pd.buf_opt=val;
6489                 if(copy_to_user(argp, &pd, sizeof(pd)))
6490                         retval = -EFAULT;
6491                 break;
6492         }
6493         case IXJCTL_DSP_IDLE:
6494                 idle(j);
6495                 break;
6496         case IXJCTL_MIXER:
6497                 if ((arg & 0xff) == 0xff)
6498                         retval = ixj_get_mixer(arg, j);
6499                 else
6500                         ixj_mixer(arg, j);
6501                 break;
6502         case IXJCTL_DAA_COEFF_SET:
6503                 switch (arg) {
6504                 case DAA_US:
6505                         DAA_Coeff_US(j);
6506                         retval = ixj_daa_write(j);
6507                         break;
6508                 case DAA_UK:
6509                         DAA_Coeff_UK(j);
6510                         retval = ixj_daa_write(j);
6511                         break;
6512                 case DAA_FRANCE:
6513                         DAA_Coeff_France(j);
6514                         retval = ixj_daa_write(j);
6515                         break;
6516                 case DAA_GERMANY:
6517                         DAA_Coeff_Germany(j);
6518                         retval = ixj_daa_write(j);
6519                         break;
6520                 case DAA_AUSTRALIA:
6521                         DAA_Coeff_Australia(j);
6522                         retval = ixj_daa_write(j);
6523                         break;
6524                 case DAA_JAPAN:
6525                         DAA_Coeff_Japan(j);
6526                         retval = ixj_daa_write(j);
6527                         break;
6528                 default:
6529                         retval = 1;
6530                         break;
6531                 }
6532                 break;
6533         case IXJCTL_DAA_AGAIN:
6534                 ixj_daa_cr4(j, arg | 0x02);
6535                 break;
6536         case IXJCTL_PSTN_LINETEST:
6537                 retval = ixj_linetest(j);
6538                 break;
6539         case IXJCTL_VMWI:
6540                 ixj_write_vmwi(j, arg);
6541                 break;
6542         case IXJCTL_CID:
6543                 if (copy_to_user(argp, &j->cid, sizeof(PHONE_CID))) 
6544                         retval = -EFAULT;
6545                 j->ex.bits.caller_id = 0;
6546                 break;
6547         case IXJCTL_WINK_DURATION:
6548                 j->winktime = arg;
6549                 break;
6550         case IXJCTL_PORT:
6551                 if (arg)
6552                         retval = ixj_set_port(j, arg);
6553                 else
6554                         retval = j->port;
6555                 break;
6556         case IXJCTL_POTS_PSTN:
6557                 retval = ixj_set_pots(j, arg);
6558                 break;
6559         case PHONE_CAPABILITIES:
6560                 add_caps(j);
6561                 retval = j->caps;
6562                 break;
6563         case PHONE_CAPABILITIES_LIST:
6564                 add_caps(j);
6565                 if (copy_to_user(argp, j->caplist, sizeof(struct phone_capability) * j->caps)) 
6566                         retval = -EFAULT;
6567                 break;
6568         case PHONE_CAPABILITIES_CHECK:
6569                 {
6570                         struct phone_capability cap;
6571                         if (copy_from_user(&cap, argp, sizeof(cap))) 
6572                                 retval = -EFAULT;
6573                         else {
6574                                 add_caps(j);
6575                                 retval = capabilities_check(j, &cap);
6576                         }
6577                 }
6578                 break;
6579         case PHONE_PSTN_SET_STATE:
6580                 daa_set_mode(j, arg);
6581                 break;
6582         case PHONE_PSTN_GET_STATE:
6583                 retval = j->daa_mode;
6584                 j->ex.bits.pstn_ring = 0;
6585                 break;
6586         case IXJCTL_SET_FILTER:
6587                 if (copy_from_user(&jf, argp, sizeof(jf))) 
6588                         retval = -EFAULT;
6589                 retval = ixj_init_filter(j, &jf);
6590                 break;
6591         case IXJCTL_SET_FILTER_RAW:
6592                 if (copy_from_user(&jfr, argp, sizeof(jfr))) 
6593                         retval = -EFAULT;
6594                 else
6595                         retval = ixj_init_filter_raw(j, &jfr);
6596                 break;
6597         case IXJCTL_GET_FILTER_HIST:
6598                 if(arg<0||arg>3)
6599                         retval = -EINVAL;
6600                 else
6601                         retval = j->filter_hist[arg];
6602                 break;
6603         case IXJCTL_INIT_TONE:
6604                 if (copy_from_user(&ti, argp, sizeof(ti)))
6605                         retval = -EFAULT;
6606                 else
6607                         retval = ixj_init_tone(j, &ti);
6608                 break;
6609         case IXJCTL_TONE_CADENCE:
6610                 retval = ixj_build_cadence(j, argp);
6611                 break;
6612         case IXJCTL_FILTER_CADENCE:
6613                 retval = ixj_build_filter_cadence(j, argp);
6614                 break;
6615         case IXJCTL_SIGCTL:
6616                 if (copy_from_user(&j->sigdef, argp, sizeof(IXJ_SIGDEF))) {
6617                         retval = -EFAULT;
6618                         break;
6619                 }
6620                 j->ixj_signals[j->sigdef.event] = j->sigdef.signal;
6621                 if(j->sigdef.event < 33) {
6622                         raise = 1;
6623                         for(mant = 0; mant < j->sigdef.event; mant++){
6624                                 raise *= 2;
6625                         }
6626                         if(j->sigdef.signal)
6627                                 j->ex_sig.bytes |= raise; 
6628                         else
6629                                 j->ex_sig.bytes &= (raise^0xffff); 
6630                 }
6631                 break;
6632         case IXJCTL_INTERCOM_STOP:
6633                 if(arg < 0 || arg >= IXJMAX)
6634                         return -EINVAL;
6635                 j->intercom = -1;
6636                 ixj_record_stop(j);
6637                 ixj_play_stop(j);
6638                 idle(j);
6639                 get_ixj(arg)->intercom = -1;
6640                 ixj_record_stop(get_ixj(arg));
6641                 ixj_play_stop(get_ixj(arg));
6642                 idle(get_ixj(arg));
6643                 break;
6644         case IXJCTL_INTERCOM_START:
6645                 if(arg < 0 || arg >= IXJMAX)
6646                         return -EINVAL;
6647                 j->intercom = arg;
6648                 ixj_record_start(j);
6649                 ixj_play_start(j);
6650                 get_ixj(arg)->intercom = board;
6651                 ixj_play_start(get_ixj(arg));
6652                 ixj_record_start(get_ixj(arg));
6653                 break;
6654         }
6655         if (ixjdebug & 0x0040)
6656                 printk("phone%d ioctl end, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6657         clear_bit(board, &j->busyflags);
6658         return retval;
6659 }
6660
6661 static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6662 {
6663         long ret;
6664         lock_kernel();
6665         ret = do_ixj_ioctl(file_p, cmd, arg);
6666         unlock_kernel();
6667         return ret;
6668 }
6669
6670 static int ixj_fasync(int fd, struct file *file_p, int mode)
6671 {
6672         IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
6673
6674         return fasync_helper(fd, file_p, mode, &j->async_queue);
6675 }
6676
6677 static const struct file_operations ixj_fops =
6678 {
6679         .owner          = THIS_MODULE,
6680         .read           = ixj_enhanced_read,
6681         .write          = ixj_enhanced_write,
6682         .poll           = ixj_poll,
6683         .unlocked_ioctl = ixj_ioctl,
6684         .release        = ixj_release,
6685         .fasync         = ixj_fasync
6686 };
6687
6688 static int ixj_linetest(IXJ *j)
6689 {
6690         j->flags.pstncheck = 1; /* Testing */
6691         j->flags.pstn_present = 0; /* Assume the line is not there */
6692
6693         daa_int_read(j);        /*Clear DAA Interrupt flags */
6694         /* */
6695         /* Hold all relays in the normally de-energized position. */
6696         /* */
6697
6698         j->pld_slicw.bits.rly1 = 0;
6699         j->pld_slicw.bits.rly2 = 0;
6700         j->pld_slicw.bits.rly3 = 0;
6701         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6702         j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6703
6704         outb_p(j->pld_scrw.byte, j->XILINXbase);
6705         j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
6706         if (j->pld_slicr.bits.potspstn) {
6707                 j->flags.pots_pstn = 1;
6708                 j->flags.pots_correct = 0;
6709                 LED_SetState(0x4, j);
6710         } else {
6711                 j->flags.pots_pstn = 0;
6712                 j->pld_slicw.bits.rly1 = 0;
6713                 j->pld_slicw.bits.rly2 = 0;
6714                 j->pld_slicw.bits.rly3 = 1;
6715                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6716                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6717
6718                 outb_p(j->pld_scrw.byte, j->XILINXbase);
6719                 daa_set_mode(j, SOP_PU_CONVERSATION);
6720                 msleep(1000);
6721                 daa_int_read(j);
6722                 daa_set_mode(j, SOP_PU_RESET);
6723                 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6724                         j->flags.pots_correct = 0;      /* Should not be line voltage on POTS port. */
6725                         LED_SetState(0x4, j);
6726                         j->pld_slicw.bits.rly3 = 0;
6727                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6728                 } else {
6729                         j->flags.pots_correct = 1;
6730                         LED_SetState(0x8, j);
6731                         j->pld_slicw.bits.rly1 = 1;
6732                         j->pld_slicw.bits.rly2 = 0;
6733                         j->pld_slicw.bits.rly3 = 0;
6734                         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6735                 }
6736         }
6737         j->pld_slicw.bits.rly3 = 0;
6738         outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6739         daa_set_mode(j, SOP_PU_CONVERSATION);
6740         msleep(1000);
6741         daa_int_read(j);
6742         daa_set_mode(j, SOP_PU_RESET);
6743         if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6744                 j->pstn_sleeptil = jiffies + (hertz / 4);
6745                 j->flags.pstn_present = 1;
6746         } else {
6747                 j->flags.pstn_present = 0;
6748         }
6749         if (j->flags.pstn_present) {
6750                 if (j->flags.pots_correct) {
6751                         LED_SetState(0xA, j);
6752                 } else {
6753                         LED_SetState(0x6, j);
6754                 }
6755         } else {
6756                 if (j->flags.pots_correct) {
6757                         LED_SetState(0x9, j);
6758                 } else {
6759                         LED_SetState(0x5, j);
6760                 }
6761         }
6762         j->flags.pstncheck = 0; /* Testing */
6763         return j->flags.pstn_present;
6764 }
6765
6766 static int ixj_selfprobe(IXJ *j)
6767 {
6768         unsigned short cmd;
6769         int cnt;
6770         BYTES bytes;
6771
6772         init_waitqueue_head(&j->poll_q);
6773         init_waitqueue_head(&j->read_q);
6774         init_waitqueue_head(&j->write_q);
6775
6776         while(atomic_read(&j->DSPWrite) > 0)
6777                 atomic_dec(&j->DSPWrite);
6778         if (ixjdebug & 0x0002)
6779                 printk(KERN_INFO "Write IDLE to Software Control Register\n");
6780         ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
6781
6782         if (ixj_WriteDSPCommand(0x0000, j))             /* Write IDLE to Software Control Register */
6783                 return -1;
6784 /* The read values of the SSR should be 0x00 for the IDLE command */
6785         if (j->ssr.low || j->ssr.high)
6786                 return -1;
6787         if (ixjdebug & 0x0002)
6788                 printk(KERN_INFO "Get Device ID Code\n");
6789         if (ixj_WriteDSPCommand(0x3400, j))             /* Get Device ID Code */
6790                 return -1;
6791         j->dsp.low = j->ssr.low;
6792         j->dsp.high = j->ssr.high;
6793         if (ixjdebug & 0x0002)
6794                 printk(KERN_INFO "Get Device Version Code\n");
6795         if (ixj_WriteDSPCommand(0x3800, j))             /* Get Device Version Code */
6796                 return -1;
6797         j->ver.low = j->ssr.low;
6798         j->ver.high = j->ssr.high;
6799         if (!j->cardtype) {
6800                 if (j->dsp.low == 0x21) {
6801                         bytes.high = bytes.low = inb_p(j->XILINXbase + 0x02);
6802                         outb_p(bytes.low ^ 0xFF, j->XILINXbase + 0x02);
6803 /* Test for Internet LineJACK or Internet PhoneJACK Lite */
6804                         bytes.low = inb_p(j->XILINXbase + 0x02);
6805                         if (bytes.low == bytes.high)    /*  Register is read only on */
6806                                 /*  Internet PhoneJack Lite */
6807                          {
6808                                 j->cardtype = QTI_PHONEJACK_LITE;
6809                                 if (!request_region(j->XILINXbase, 4, "ixj control")) {
6810                                         printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6811                                         return -1;
6812                                 }
6813                                 j->pld_slicw.pcib.e1 = 1;
6814                                 outb_p(j->pld_slicw.byte, j->XILINXbase);
6815                         } else {
6816                                 j->cardtype = QTI_LINEJACK;
6817
6818                                 if (!request_region(j->XILINXbase, 8, "ixj control")) {
6819                                         printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6820                                         return -1;
6821                                 }
6822                         }
6823                 } else if (j->dsp.low == 0x22) {
6824                         j->cardtype = QTI_PHONEJACK_PCI;
6825                         request_region(j->XILINXbase, 4, "ixj control");
6826                         j->pld_slicw.pcib.e1 = 1;
6827                         outb_p(j->pld_slicw.byte, j->XILINXbase);
6828                 } else
6829                         j->cardtype = QTI_PHONEJACK;
6830         } else {
6831                 switch (j->cardtype) {
6832                 case QTI_PHONEJACK:
6833                         if (!j->dsp.low != 0x20) {
6834                                 j->dsp.high = 0x80;
6835                                 j->dsp.low = 0x20;
6836                                 ixj_WriteDSPCommand(0x3800, j);
6837                                 j->ver.low = j->ssr.low;
6838                                 j->ver.high = j->ssr.high;
6839                         }
6840                         break;
6841                 case QTI_LINEJACK:
6842                         if (!request_region(j->XILINXbase, 8, "ixj control")) {
6843                                 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6844                                 return -1;
6845                         }
6846                         break;
6847                 case QTI_PHONEJACK_LITE:
6848                 case QTI_PHONEJACK_PCI:
6849                         if (!request_region(j->XILINXbase, 4, "ixj control")) {
6850                                 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6851                                 return -1;
6852                         }
6853                         j->pld_slicw.pcib.e1 = 1;
6854                         outb_p(j->pld_slicw.byte, j->XILINXbase);
6855                         break;
6856                 case QTI_PHONECARD:
6857                         break;
6858                 }
6859         }
6860         if (j->dsp.low == 0x20 || j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
6861                 if (ixjdebug & 0x0002)
6862                         printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6863                 if (ixj_WriteDSPCommand(0xC462, j))             /* Write CODEC config to Software Control Register */
6864                         return -1;
6865                 if (ixjdebug & 0x0002)
6866                         printk(KERN_INFO "Write CODEC timing to Software Control Register\n");
6867                 if (j->cardtype == QTI_PHONEJACK) {
6868                         cmd = 0x9FF2;
6869                 } else {
6870                         cmd = 0x9FF5;
6871                 }
6872                 if (ixj_WriteDSPCommand(cmd, j))        /* Write CODEC timing to Software Control Register */
6873                         return -1;
6874         } else {
6875                 if (set_base_frame(j, 30) != 30)
6876                         return -1;
6877                 if (ixjdebug & 0x0002)
6878                         printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6879                 if (j->cardtype == QTI_PHONECARD) {
6880                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to Software Control Register */
6881                                 return -1;
6882                 }
6883                 if (j->cardtype == QTI_LINEJACK) {
6884                         if (ixj_WriteDSPCommand(0xC528, j))             /* Write CODEC config to Software Control Register */
6885                                 return -1;
6886                         if (ixjdebug & 0x0002)
6887                                 printk(KERN_INFO "Turn on the PLD Clock at 8Khz\n");
6888                         j->pld_clock.byte = 0;
6889                         outb_p(j->pld_clock.byte, j->XILINXbase + 0x04);
6890                 }
6891         }
6892
6893         if (j->dsp.low == 0x20) {
6894                 if (ixjdebug & 0x0002)
6895                         printk(KERN_INFO "Configure GPIO pins\n");
6896                 j->gpio.bytes.high = 0x09;
6897 /*  bytes.low = 0xEF;  0xF7 */
6898                 j->gpio.bits.gpio1 = 1;
6899                 j->gpio.bits.gpio2 = 1;
6900                 j->gpio.bits.gpio3 = 0;
6901                 j->gpio.bits.gpio4 = 1;
6902                 j->gpio.bits.gpio5 = 1;
6903                 j->gpio.bits.gpio6 = 1;
6904                 j->gpio.bits.gpio7 = 1;
6905                 ixj_WriteDSPCommand(j->gpio.word, j);   /* Set GPIO pin directions */
6906                 if (ixjdebug & 0x0002)
6907                         printk(KERN_INFO "Enable SLIC\n");
6908                 j->gpio.bytes.high = 0x0B;
6909                 j->gpio.bytes.low = 0x00;
6910                 j->gpio.bits.gpio1 = 0;
6911                 j->gpio.bits.gpio2 = 1;
6912                 j->gpio.bits.gpio5 = 0;
6913                 ixj_WriteDSPCommand(j->gpio.word, j);   /* send the ring stop signal */
6914                 j->port = PORT_POTS;
6915         } else {
6916                 if (j->cardtype == QTI_LINEJACK) {
6917                         LED_SetState(0x1, j);
6918                         msleep(100);
6919                         LED_SetState(0x2, j);
6920                         msleep(100);
6921                         LED_SetState(0x4, j);
6922                         msleep(100);
6923                         LED_SetState(0x8, j);
6924                         msleep(100);
6925                         LED_SetState(0x0, j);
6926                         daa_get_version(j);
6927                         if (ixjdebug & 0x0002)
6928                                 printk("Loading DAA Coefficients\n");
6929                         DAA_Coeff_US(j);
6930                         if (!ixj_daa_write(j)) {
6931                                 printk("DAA write failed on board %d\n", j->board);
6932                                 return -1;
6933                         }
6934                         if(!ixj_daa_cid_reset(j)) {
6935                                 printk("DAA CID reset failed on board %d\n", j->board);
6936                                 return -1;
6937                         }
6938                         j->flags.pots_correct = 0;
6939                         j->flags.pstn_present = 0;
6940                         ixj_linetest(j);
6941                         if (j->flags.pots_correct) {
6942                                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
6943
6944                                 outb_p(j->pld_scrw.byte, j->XILINXbase);
6945                                 j->pld_slicw.bits.rly1 = 1;
6946                                 j->pld_slicw.bits.spken = 1;
6947                                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6948                                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
6949 /*                              SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
6950                                 j->port = PORT_POTS;
6951                         }
6952                         ixj_set_port(j, PORT_PSTN);
6953                         ixj_set_pots(j, 1);
6954                         if (ixjdebug & 0x0002)
6955                                 printk(KERN_INFO "Enable Mixer\n");
6956                         ixj_mixer(0x0000, j);   /*Master Volume Left unmute 0db */
6957                         ixj_mixer(0x0100, j);   /*Master Volume Right unmute 0db */
6958
6959                         ixj_mixer(0x0203, j);   /*Voice Left Volume unmute 6db */
6960                         ixj_mixer(0x0303, j);   /*Voice Right Volume unmute 6db */
6961
6962                         ixj_mixer(0x0480, j);   /*FM Left mute */
6963                         ixj_mixer(0x0580, j);   /*FM Right mute */
6964
6965                         ixj_mixer(0x0680, j);   /*CD Left mute */
6966                         ixj_mixer(0x0780, j);   /*CD Right mute */
6967
6968                         ixj_mixer(0x0880, j);   /*Line Left mute */
6969                         ixj_mixer(0x0980, j);   /*Line Right mute */
6970
6971                         ixj_mixer(0x0A80, j);   /*Aux left mute  */
6972                         ixj_mixer(0x0B80, j);   /*Aux right mute */
6973
6974                         ixj_mixer(0x0C00, j);   /*Mono1 unmute 12db */
6975                         ixj_mixer(0x0D80, j);   /*Mono2 mute */
6976
6977                         ixj_mixer(0x0E80, j);   /*Mic mute */
6978
6979                         ixj_mixer(0x0F00, j);   /*Mono Out Volume unmute 0db */
6980
6981                         ixj_mixer(0x1000, j);   /*Voice Left and Right out only */
6982                         ixj_mixer(0x110C, j);
6983
6984
6985                         ixj_mixer(0x1200, j);   /*Mono1 switch on mixer left */
6986                         ixj_mixer(0x1401, j);
6987
6988                         ixj_mixer(0x1300, j);       /*Mono1 switch on mixer right */
6989                         ixj_mixer(0x1501, j);
6990
6991                         ixj_mixer(0x1700, j);   /*Clock select */
6992
6993                         ixj_mixer(0x1800, j);   /*ADC input from mixer */
6994
6995                         ixj_mixer(0x1901, j);   /*Mic gain 30db */
6996
6997                         if (ixjdebug & 0x0002)
6998                                 printk(KERN_INFO "Setting Default US Ring Cadence Detection\n");
6999                         j->cadence_f[4].state = 0;
7000                         j->cadence_f[4].on1 = 0;        /*Cadence Filter 4 is used for PSTN ring cadence */
7001                         j->cadence_f[4].off1 = 0;
7002                         j->cadence_f[4].on2 = 0;
7003                         j->cadence_f[4].off2 = 0;
7004                         j->cadence_f[4].on3 = 0;
7005                         j->cadence_f[4].off3 = 0;       /* These should represent standard US ring pulse. */
7006                         j->pstn_last_rmr = jiffies;
7007
7008                 } else {
7009                         if (j->cardtype == QTI_PHONECARD) {
7010                                 ixj_WriteDSPCommand(0xCF07, j);
7011                                 ixj_WriteDSPCommand(0x00B0, j);
7012                                 ixj_set_port(j, PORT_SPEAKER);
7013                         } else {
7014                                 ixj_set_port(j, PORT_POTS);
7015                                 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
7016 /*                              SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
7017                         }
7018                 }
7019         }
7020
7021         j->intercom = -1;
7022         j->framesread = j->frameswritten = 0;
7023         j->read_wait = j->write_wait = 0;
7024         j->rxreadycheck = j->txreadycheck = 0;
7025
7026         /* initialise the DTMF prescale to a sensible value */
7027         if (j->cardtype == QTI_LINEJACK) {
7028                 set_dtmf_prescale(j, 0x10); 
7029         } else {
7030                 set_dtmf_prescale(j, 0x40); 
7031         }
7032         set_play_volume(j, 0x100);
7033         set_rec_volume(j, 0x100);
7034
7035         if (ixj_WriteDSPCommand(0x0000, j))             /* Write IDLE to Software Control Register */
7036                 return -1;
7037 /* The read values of the SSR should be 0x00 for the IDLE command */
7038         if (j->ssr.low || j->ssr.high)
7039                 return -1;
7040
7041         if (ixjdebug & 0x0002)
7042                 printk(KERN_INFO "Enable Line Monitor\n");
7043
7044         if (ixjdebug & 0x0002)
7045                 printk(KERN_INFO "Set Line Monitor to Asyncronous Mode\n");
7046
7047         if (ixj_WriteDSPCommand(0x7E01, j))             /* Asynchronous Line Monitor */
7048                 return -1;
7049
7050         if (ixjdebug & 0x002)
7051                 printk(KERN_INFO "Enable DTMF Detectors\n");
7052
7053         if (ixj_WriteDSPCommand(0x5151, j))             /* Enable DTMF detection */
7054                 return -1;
7055
7056         if (ixj_WriteDSPCommand(0x6E01, j))             /* Set Asyncronous Tone Generation */
7057                 return -1;
7058
7059         set_rec_depth(j, 2);    /* Set Record Channel Limit to 2 frames */
7060
7061         set_play_depth(j, 2);   /* Set Playback Channel Limit to 2 frames */
7062
7063         j->ex.bits.dtmf_ready = 0;
7064         j->dtmf_state = 0;
7065         j->dtmf_wp = j->dtmf_rp = 0;
7066         j->rec_mode = j->play_mode = -1;
7067         j->flags.ringing = 0;
7068         j->maxrings = MAXRINGS;
7069         j->ring_cadence = USA_RING_CADENCE;
7070         j->drybuffer = 0;
7071         j->winktime = 320;
7072         j->flags.dtmf_oob = 0;
7073         for (cnt = 0; cnt < 4; cnt++)
7074                 j->cadence_f[cnt].enable = 0;
7075         /* must be a device on the specified address */
7076         ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
7077
7078         /* Set up the default signals for events */
7079         for (cnt = 0; cnt < 35; cnt++)
7080                 j->ixj_signals[cnt] = SIGIO;
7081
7082         /* Set the excetion signal enable flags */
7083         j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 
7084         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 = 
7085         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;
7086 #ifdef IXJ_DYN_ALLOC
7087         j->fskdata = NULL;
7088 #endif
7089         j->fskdcnt = 0;
7090         j->cidcw_wait = 0;
7091  
7092         /* Register with the Telephony for Linux subsystem */
7093         j->p.f_op = &ixj_fops;
7094         j->p.open = ixj_open;
7095         j->p.board = j->board;
7096         phone_register_device(&j->p, PHONE_UNIT_ANY);
7097
7098         ixj_init_timer(j);
7099         ixj_add_timer(j);
7100         return 0;
7101 }
7102
7103 /*
7104  *      Exported service for pcmcia card handling
7105  */
7106  
7107 IXJ *ixj_pcmcia_probe(unsigned long dsp, unsigned long xilinx)
7108 {
7109         IXJ *j = ixj_alloc();
7110
7111         j->board = 0;
7112
7113         j->DSPbase = dsp;
7114         j->XILINXbase = xilinx;
7115         j->cardtype = QTI_PHONECARD;
7116         ixj_selfprobe(j);
7117         return j;
7118 }
7119
7120 EXPORT_SYMBOL(ixj_pcmcia_probe);                /* Fpr PCMCIA */
7121
7122 static int ixj_get_status_proc(char *buf)
7123 {
7124         int len;
7125         int cnt;
7126         IXJ *j;
7127         len = 0;
7128         len += sprintf(buf + len, "\nDriver version %i.%i.%i", IXJ_VER_MAJOR, IXJ_VER_MINOR, IXJ_BLD_VER);
7129         len += sprintf(buf + len, "\nsizeof IXJ struct %Zd bytes", sizeof(IXJ));
7130         len += sprintf(buf + len, "\nsizeof DAA struct %Zd bytes", sizeof(DAA_REGS));
7131         len += sprintf(buf + len, "\nUsing old telephony API");
7132         len += sprintf(buf + len, "\nDebug Level %d\n", ixjdebug);
7133
7134         for (cnt = 0; cnt < IXJMAX; cnt++) {
7135                 j = get_ixj(cnt);
7136                 if(j==NULL)
7137                         continue;
7138                 if (j->DSPbase) {
7139                         len += sprintf(buf + len, "\nCard Num %d", cnt);
7140                         len += sprintf(buf + len, "\nDSP Base Address 0x%4.4x", j->DSPbase);
7141                         if (j->cardtype != QTI_PHONEJACK)
7142                                 len += sprintf(buf + len, "\nXILINX Base Address 0x%4.4x", j->XILINXbase);
7143                         len += sprintf(buf + len, "\nDSP Type %2.2x%2.2x", j->dsp.high, j->dsp.low);
7144                         len += sprintf(buf + len, "\nDSP Version %2.2x.%2.2x", j->ver.high, j->ver.low);
7145                         len += sprintf(buf + len, "\nSerial Number %8.8x", j->serial);
7146                         switch (j->cardtype) {
7147                         case (QTI_PHONEJACK):
7148                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK");
7149                                 break;
7150                         case (QTI_LINEJACK):
7151                                 len += sprintf(buf + len, "\nCard Type = Internet LineJACK");
7152                                 if (j->flags.g729_loaded)
7153                                         len += sprintf(buf + len, " w/G.729 A/B");
7154                                 len += sprintf(buf + len, " Country = %d", j->daa_country);
7155                                 break;
7156                         case (QTI_PHONEJACK_LITE):
7157                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK Lite");
7158                                 if (j->flags.g729_loaded)
7159                                         len += sprintf(buf + len, " w/G.729 A/B");
7160                                 break;
7161                         case (QTI_PHONEJACK_PCI):
7162                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK PCI");
7163                                 if (j->flags.g729_loaded)
7164                                         len += sprintf(buf + len, " w/G.729 A/B");
7165                                 break;
7166                         case (QTI_PHONECARD):
7167                                 len += sprintf(buf + len, "\nCard Type = Internet PhoneCARD");
7168                                 if (j->flags.g729_loaded)
7169                                         len += sprintf(buf + len, " w/G.729 A/B");
7170                                 len += sprintf(buf + len, "\nSmart Cable %spresent", j->pccr1.bits.drf ? "not " : "");
7171                                 if (!j->pccr1.bits.drf)
7172                                         len += sprintf(buf + len, "\nSmart Cable type %d", j->flags.pcmciasct);
7173                                 len += sprintf(buf + len, "\nSmart Cable state %d", j->flags.pcmciastate);
7174                                 break;
7175                         default:
7176                                 len += sprintf(buf + len, "\nCard Type = %d", j->cardtype);
7177                                 break;
7178                         }
7179                         len += sprintf(buf + len, "\nReaders %d", j->readers);
7180                         len += sprintf(buf + len, "\nWriters %d", j->writers);
7181                         add_caps(j);
7182                         len += sprintf(buf + len, "\nCapabilities %d", j->caps);
7183                         if (j->dsp.low != 0x20)
7184                                 len += sprintf(buf + len, "\nDSP Processor load %d", j->proc_load);
7185                         if (j->flags.cidsent)
7186                                 len += sprintf(buf + len, "\nCaller ID data sent");
7187                         else
7188                                 len += sprintf(buf + len, "\nCaller ID data not sent");
7189
7190                         len += sprintf(buf + len, "\nPlay CODEC ");
7191                         switch (j->play_codec) {
7192                         case G723_63:
7193                                 len += sprintf(buf + len, "G.723.1 6.3");
7194                                 break;
7195                         case G723_53:
7196                                 len += sprintf(buf + len, "G.723.1 5.3");
7197                                 break;
7198                         case TS85:
7199                                 len += sprintf(buf + len, "TrueSpeech 8.5");
7200                                 break;
7201                         case TS48:
7202                                 len += sprintf(buf + len, "TrueSpeech 4.8");
7203                                 break;
7204                         case TS41:
7205                                 len += sprintf(buf + len, "TrueSpeech 4.1");
7206                                 break;
7207                         case G728:
7208                                 len += sprintf(buf + len, "G.728");
7209                                 break;
7210                         case G729:
7211                                 len += sprintf(buf + len, "G.729");
7212                                 break;
7213                         case G729B:
7214                                 len += sprintf(buf + len, "G.729B");
7215                                 break;
7216                         case ULAW:
7217                                 len += sprintf(buf + len, "uLaw");
7218                                 break;
7219                         case ALAW:
7220                                 len += sprintf(buf + len, "aLaw");
7221                                 break;
7222                         case LINEAR16:
7223                                 len += sprintf(buf + len, "16 bit Linear");
7224                                 break;
7225                         case LINEAR8:
7226                                 len += sprintf(buf + len, "8 bit Linear");
7227                                 break;
7228                         case WSS:
7229                                 len += sprintf(buf + len, "Windows Sound System");
7230                                 break;
7231                         default:
7232                                 len += sprintf(buf + len, "NO CODEC CHOSEN");
7233                                 break;
7234                         }
7235                         len += sprintf(buf + len, "\nRecord CODEC ");
7236                         switch (j->rec_codec) {
7237                         case G723_63:
7238                                 len += sprintf(buf + len, "G.723.1 6.3");
7239                                 break;
7240                         case G723_53:
7241                                 len += sprintf(buf + len, "G.723.1 5.3");
7242                                 break;
7243                         case TS85:
7244                                 len += sprintf(buf + len, "TrueSpeech 8.5");
7245                                 break;
7246                         case TS48:
7247                                 len += sprintf(buf + len, "TrueSpeech 4.8");
7248                                 break;
7249                         case TS41:
7250                                 len += sprintf(buf + len, "TrueSpeech 4.1");
7251                                 break;
7252                         case G728:
7253                                 len += sprintf(buf + len, "G.728");
7254                                 break;
7255                         case G729:
7256                                 len += sprintf(buf + len, "G.729");
7257                                 break;
7258                         case G729B:
7259                                 len += sprintf(buf + len, "G.729B");
7260                                 break;
7261                         case ULAW:
7262                                 len += sprintf(buf + len, "uLaw");
7263                                 break;
7264                         case ALAW:
7265                                 len += sprintf(buf + len, "aLaw");
7266                                 break;
7267                         case LINEAR16:
7268                                 len += sprintf(buf + len, "16 bit Linear");
7269                                 break;
7270                         case LINEAR8:
7271                                 len += sprintf(buf + len, "8 bit Linear");
7272                                 break;
7273                         case WSS:
7274                                 len += sprintf(buf + len, "Windows Sound System");
7275                                 break;
7276                         default:
7277                                 len += sprintf(buf + len, "NO CODEC CHOSEN");
7278                                 break;
7279                         }
7280                         len += sprintf(buf + len, "\nAEC ");
7281                         switch (j->aec_level) {
7282                         case AEC_OFF:
7283                                 len += sprintf(buf + len, "Off");
7284                                 break;
7285                         case AEC_LOW:
7286                                 len += sprintf(buf + len, "Low");
7287                                 break;
7288                         case AEC_MED:
7289                                 len += sprintf(buf + len, "Med");
7290                                 break;
7291                         case AEC_HIGH:
7292                                 len += sprintf(buf + len, "High");
7293                                 break;
7294                         case AEC_AUTO:
7295                                 len += sprintf(buf + len, "Auto");
7296                                 break;
7297                         case AEC_AGC:
7298                                 len += sprintf(buf + len, "AEC/AGC");
7299                                 break;
7300                         default:
7301                                 len += sprintf(buf + len, "unknown(%i)", j->aec_level);
7302                                 break;
7303                         }
7304
7305                         len += sprintf(buf + len, "\nRec volume 0x%x", get_rec_volume(j));
7306                         len += sprintf(buf + len, "\nPlay volume 0x%x", get_play_volume(j));
7307                         len += sprintf(buf + len, "\nDTMF prescale 0x%x", get_dtmf_prescale(j));
7308                         
7309                         len += sprintf(buf + len, "\nHook state %d", j->hookstate); /* j->r_hook);      */
7310
7311                         if (j->cardtype == QTI_LINEJACK) {
7312                                 len += sprintf(buf + len, "\nPOTS Correct %d", j->flags.pots_correct);
7313                                 len += sprintf(buf + len, "\nPSTN Present %d", j->flags.pstn_present);
7314                                 len += sprintf(buf + len, "\nPSTN Check %d", j->flags.pstncheck);
7315                                 len += sprintf(buf + len, "\nPOTS to PSTN %d", j->flags.pots_pstn);
7316                                 switch (j->daa_mode) {
7317                                 case SOP_PU_SLEEP:
7318                                         len += sprintf(buf + len, "\nDAA PSTN On Hook");
7319                                         break;
7320                                 case SOP_PU_RINGING:
7321                                         len += sprintf(buf + len, "\nDAA PSTN Ringing");
7322                                         len += sprintf(buf + len, "\nRinging state = %d", j->cadence_f[4].state);
7323                                         break;
7324                                 case SOP_PU_CONVERSATION:
7325                                         len += sprintf(buf + len, "\nDAA PSTN Off Hook");
7326                                         break;
7327                                 case SOP_PU_PULSEDIALING:
7328                                         len += sprintf(buf + len, "\nDAA PSTN Pulse Dialing");
7329                                         break;
7330                                 }
7331                                 len += sprintf(buf + len, "\nDAA RMR = %d", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR);
7332                                 len += sprintf(buf + len, "\nDAA VDD OK = %d", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK);
7333                                 len += sprintf(buf + len, "\nDAA CR0 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg);
7334                                 len += sprintf(buf + len, "\nDAA CR1 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg);
7335                                 len += sprintf(buf + len, "\nDAA CR2 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg);
7336                                 len += sprintf(buf + len, "\nDAA CR3 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg);
7337                                 len += sprintf(buf + len, "\nDAA CR4 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg);
7338                                 len += sprintf(buf + len, "\nDAA CR5 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg);
7339                                 len += sprintf(buf + len, "\nDAA XR0 = 0x%02x", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg);
7340                                 len += sprintf(buf + len, "\nDAA ringstop %ld - jiffies %ld", j->pstn_ring_stop, jiffies);
7341                         }
7342                         switch (j->port) {
7343                         case PORT_POTS:
7344                                 len += sprintf(buf + len, "\nPort POTS");
7345                                 break;
7346                         case PORT_PSTN:
7347                                 len += sprintf(buf + len, "\nPort PSTN");
7348                                 break;
7349                         case PORT_SPEAKER:
7350                                 len += sprintf(buf + len, "\nPort SPEAKER/MIC");
7351                                 break;
7352                         case PORT_HANDSET:
7353                                 len += sprintf(buf + len, "\nPort HANDSET");
7354                                 break;
7355                         }
7356                         if (j->dsp.low == 0x21 || j->dsp.low == 0x22) {
7357                                 len += sprintf(buf + len, "\nSLIC state ");
7358                                 switch (SLIC_GetState(j)) {
7359                                 case PLD_SLIC_STATE_OC:
7360                                         len += sprintf(buf + len, "OC");
7361                                         break;
7362                                 case PLD_SLIC_STATE_RINGING:
7363                                         len += sprintf(buf + len, "RINGING");
7364                                         break;
7365                                 case PLD_SLIC_STATE_ACTIVE:
7366                                         len += sprintf(buf + len, "ACTIVE");
7367                                         break;
7368                                 case PLD_SLIC_STATE_OHT:        /* On-hook transmit */
7369                                         len += sprintf(buf + len, "OHT");
7370                                         break;
7371                                 case PLD_SLIC_STATE_TIPOPEN:
7372                                         len += sprintf(buf + len, "TIPOPEN");
7373                                         break;
7374                                 case PLD_SLIC_STATE_STANDBY:
7375                                         len += sprintf(buf + len, "STANDBY");
7376                                         break;
7377                                 case PLD_SLIC_STATE_APR:        /* Active polarity reversal */
7378                                         len += sprintf(buf + len, "APR");
7379                                         break;
7380                                 case PLD_SLIC_STATE_OHTPR:      /* OHT polarity reversal */
7381                                         len += sprintf(buf + len, "OHTPR");
7382                                         break;
7383                                 default:
7384                                         len += sprintf(buf + len, "%d", SLIC_GetState(j));
7385                                         break;
7386                                 }
7387                         }
7388                         len += sprintf(buf + len, "\nBase Frame %2.2x.%2.2x", j->baseframe.high, j->baseframe.low);
7389                         len += sprintf(buf + len, "\nCID Base Frame %2d", j->cid_base_frame_size);
7390 #ifdef PERFMON_STATS
7391                         len += sprintf(buf + len, "\nTimer Checks %ld", j->timerchecks);
7392                         len += sprintf(buf + len, "\nRX Ready Checks %ld", j->rxreadycheck);
7393                         len += sprintf(buf + len, "\nTX Ready Checks %ld", j->txreadycheck);
7394                         len += sprintf(buf + len, "\nFrames Read %ld", j->framesread);
7395                         len += sprintf(buf + len, "\nFrames Written %ld", j->frameswritten);
7396                         len += sprintf(buf + len, "\nDry Buffer %ld", j->drybuffer);
7397                         len += sprintf(buf + len, "\nRead Waits %ld", j->read_wait);
7398                         len += sprintf(buf + len, "\nWrite Waits %ld", j->write_wait);
7399                         len += sprintf(buf + len, "\nStatus Waits %ld", j->statuswait);
7400                         len += sprintf(buf + len, "\nStatus Wait Fails %ld", j->statuswaitfail);
7401                         len += sprintf(buf + len, "\nPControl Waits %ld", j->pcontrolwait);
7402                         len += sprintf(buf + len, "\nPControl Wait Fails %ld", j->pcontrolwaitfail);
7403                         len += sprintf(buf + len, "\nIs Control Ready Checks %ld", j->iscontrolready);
7404                         len += sprintf(buf + len, "\nIs Control Ready Check failures %ld", j->iscontrolreadyfail);
7405  
7406 #endif
7407                         len += sprintf(buf + len, "\n");
7408                 }
7409         }
7410         return len;
7411 }
7412
7413 static int ixj_read_proc(char *page, char **start, off_t off,
7414                               int count, int *eof, void *data)
7415 {
7416         int len = ixj_get_status_proc(page);
7417         if (len <= off+count) *eof = 1;
7418         *start = page + off;
7419         len -= off;
7420         if (len>count) len = count;
7421         if (len<0) len = 0;
7422         return len;
7423 }
7424
7425
7426 static void cleanup(void)
7427 {
7428         int cnt;
7429         IXJ *j;
7430
7431         for (cnt = 0; cnt < IXJMAX; cnt++) {
7432                 j = get_ixj(cnt);
7433                 if(j != NULL && j->DSPbase) {
7434                         if (ixjdebug & 0x0002)
7435                                 printk(KERN_INFO "IXJ: Deleting timer for /dev/phone%d\n", cnt);
7436                         del_timer(&j->timer);
7437                         if (j->cardtype == QTI_LINEJACK) {
7438                                 j->pld_scrw.bits.daafsyncen = 0;        /* Turn off DAA Frame Sync */
7439
7440                                 outb_p(j->pld_scrw.byte, j->XILINXbase);
7441                                 j->pld_slicw.bits.rly1 = 0;
7442                                 j->pld_slicw.bits.rly2 = 0;
7443                                 j->pld_slicw.bits.rly3 = 0;
7444                                 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
7445                                 LED_SetState(0x0, j);
7446                                 if (ixjdebug & 0x0002)
7447                                         printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7448                                 release_region(j->XILINXbase, 8);
7449                         } else if (j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
7450                                 if (ixjdebug & 0x0002)
7451                                         printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7452                                 release_region(j->XILINXbase, 4);
7453                         }
7454                         kfree(j->read_buffer);
7455                         kfree(j->write_buffer);
7456                         if (j->dev)
7457                                 pnp_device_detach(j->dev);
7458                         if (ixjdebug & 0x0002)
7459                                 printk(KERN_INFO "IXJ: Unregistering /dev/phone%d from LTAPI\n", cnt);
7460                         phone_unregister_device(&j->p);
7461                         if (ixjdebug & 0x0002)
7462                                 printk(KERN_INFO "IXJ: Releasing DSP address for /dev/phone%d\n", cnt);
7463                         release_region(j->DSPbase, 16);
7464 #ifdef IXJ_DYN_ALLOC
7465                         if (ixjdebug & 0x0002)
7466                                 printk(KERN_INFO "IXJ: Freeing memory for /dev/phone%d\n", cnt);
7467                         kfree(j);
7468                         ixj[cnt] = NULL;
7469 #endif
7470                 }
7471         }
7472         if (ixjdebug & 0x0002)
7473                 printk(KERN_INFO "IXJ: Removing /proc/ixj\n");
7474         remove_proc_entry ("ixj", NULL);
7475 }
7476
7477 /* Typedefs */
7478 typedef struct {
7479         BYTE length;
7480         DWORD bits;
7481 } DATABLOCK;
7482
7483 static void PCIEE_WriteBit(WORD wEEPROMAddress, BYTE lastLCC, BYTE byData)
7484 {
7485         lastLCC = lastLCC & 0xfb;
7486         lastLCC = lastLCC | (byData ? 4 : 0);
7487         outb(lastLCC, wEEPROMAddress);  /*set data out bit as appropriate */
7488
7489         mdelay(1);
7490         lastLCC = lastLCC | 0x01;
7491         outb(lastLCC, wEEPROMAddress);  /*SK rising edge */
7492
7493         byData = byData << 1;
7494         lastLCC = lastLCC & 0xfe;
7495         mdelay(1);
7496         outb(lastLCC, wEEPROMAddress);  /*after delay, SK falling edge */
7497
7498 }
7499
7500 static BYTE PCIEE_ReadBit(WORD wEEPROMAddress, BYTE lastLCC)
7501 {
7502         mdelay(1);
7503         lastLCC = lastLCC | 0x01;
7504         outb(lastLCC, wEEPROMAddress);  /*SK rising edge */
7505
7506         lastLCC = lastLCC & 0xfe;
7507         mdelay(1);
7508         outb(lastLCC, wEEPROMAddress);  /*after delay, SK falling edge */
7509
7510         return ((inb(wEEPROMAddress) >> 3) & 1);
7511 }
7512
7513 static bool PCIEE_ReadWord(WORD wAddress, WORD wLoc, WORD * pwResult)
7514 {
7515         BYTE lastLCC;
7516         WORD wEEPROMAddress = wAddress + 3;
7517         DWORD i;
7518         BYTE byResult;
7519         *pwResult = 0;
7520         lastLCC = inb(wEEPROMAddress);
7521         lastLCC = lastLCC | 0x02;
7522         lastLCC = lastLCC & 0xfe;
7523         outb(lastLCC, wEEPROMAddress);  /* CS hi, SK lo */
7524
7525         mdelay(1);              /* delay */
7526
7527         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7528         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7529         PCIEE_WriteBit(wEEPROMAddress, lastLCC, 0);
7530         for (i = 0; i < 8; i++) {
7531                 PCIEE_WriteBit(wEEPROMAddress, lastLCC, wLoc & 0x80 ? 1 : 0);
7532                 wLoc <<= 1;
7533         }
7534
7535         for (i = 0; i < 16; i++) {
7536                 byResult = PCIEE_ReadBit(wEEPROMAddress, lastLCC);
7537                 *pwResult = (*pwResult << 1) | byResult;
7538         }
7539
7540         mdelay(1);              /* another delay */
7541
7542         lastLCC = lastLCC & 0xfd;
7543         outb(lastLCC, wEEPROMAddress);  /* negate CS */
7544
7545         return 0;
7546 }
7547
7548 static DWORD PCIEE_GetSerialNumber(WORD wAddress)
7549 {
7550         WORD wLo, wHi;
7551         if (PCIEE_ReadWord(wAddress, 62, &wLo))
7552                 return 0;
7553         if (PCIEE_ReadWord(wAddress, 63, &wHi))
7554                 return 0;
7555         return (((DWORD) wHi << 16) | wLo);
7556 }
7557
7558 static int dspio[IXJMAX + 1] =
7559 {
7560         0,
7561 };
7562 static int xio[IXJMAX + 1] =
7563 {
7564         0,
7565 };
7566
7567 module_param_array(dspio, int, NULL, 0);
7568 module_param_array(xio, int, NULL, 0);
7569 MODULE_DESCRIPTION("Quicknet VoIP Telephony card module - www.quicknet.net");
7570 MODULE_AUTHOR("Ed Okerson <eokerson@quicknet.net>");
7571 MODULE_LICENSE("GPL");
7572
7573 static void __exit ixj_exit(void)
7574 {
7575         cleanup();
7576 }
7577
7578 static IXJ *new_ixj(unsigned long port)
7579 {
7580         IXJ *res;
7581         if (!request_region(port, 16, "ixj DSP")) {
7582                 printk(KERN_INFO "ixj: can't get I/O address 0x%lx\n", port);
7583                 return NULL;
7584         }
7585         res = ixj_alloc();
7586         if (!res) {
7587                 release_region(port, 16);
7588                 printk(KERN_INFO "ixj: out of memory\n");
7589                 return NULL;
7590         }
7591         res->DSPbase = port;
7592         return res;
7593 }
7594
7595 static int __init ixj_probe_isapnp(int *cnt)
7596 {               
7597         int probe = 0;
7598         int func = 0x110;
7599         struct pnp_dev *dev = NULL, *old_dev = NULL;
7600
7601         while (1) {
7602                 do {
7603                         IXJ *j;
7604                         int result;
7605
7606                         old_dev = dev;
7607                         dev = pnp_find_dev(NULL, ISAPNP_VENDOR('Q', 'T', 'I'),
7608                                          ISAPNP_FUNCTION(func), old_dev);
7609                         if (!dev || !dev->card)
7610                                 break;
7611                         result = pnp_device_attach(dev);
7612                         if (result < 0) {
7613                                 printk("pnp attach failed %d \n", result);
7614                                 break;
7615                         }
7616                         if (pnp_activate_dev(dev) < 0) {
7617                                 printk("pnp activate failed (out of resources?)\n");
7618                                 pnp_device_detach(dev);
7619                                 return -ENOMEM;
7620                         }
7621
7622                         if (!pnp_port_valid(dev, 0)) {
7623                                 pnp_device_detach(dev);
7624                                 return -ENODEV;
7625                         }
7626
7627                         j = new_ixj(pnp_port_start(dev, 0));
7628                         if (!j)
7629                                 break;
7630
7631                         if (func != 0x110)
7632                                 j->XILINXbase = pnp_port_start(dev, 1); /* get real port */
7633
7634                         switch (func) {
7635                         case (0x110):
7636                                 j->cardtype = QTI_PHONEJACK;
7637                                 break;
7638                         case (0x310):
7639                                 j->cardtype = QTI_LINEJACK;
7640                                 break;
7641                         case (0x410):
7642                                 j->cardtype = QTI_PHONEJACK_LITE;
7643                                 break;
7644                         }
7645                         j->board = *cnt;
7646                         probe = ixj_selfprobe(j);
7647                         if(!probe) {
7648                                 j->serial = dev->card->serial;
7649                                 j->dev = dev;
7650                                 switch (func) {
7651                                 case 0x110:
7652                                         printk(KERN_INFO "ixj: found Internet PhoneJACK at 0x%x\n", j->DSPbase);
7653                                         break;
7654                                 case 0x310:
7655                                         printk(KERN_INFO "ixj: found Internet LineJACK at 0x%x\n", j->DSPbase);
7656                                         break;
7657                                 case 0x410:
7658                                         printk(KERN_INFO "ixj: found Internet PhoneJACK Lite at 0x%x\n", j->DSPbase);
7659                                         break;
7660                                 }
7661                         }
7662                         ++*cnt;
7663                 } while (dev);
7664                 if (func == 0x410)
7665                         break;
7666                 if (func == 0x310)
7667                         func = 0x410;
7668                 if (func == 0x110)
7669                         func = 0x310;
7670                 dev = NULL;
7671         }
7672         return probe;
7673 }
7674                         
7675 static int __init ixj_probe_isa(int *cnt)
7676 {
7677         int i, probe;
7678
7679         /* Use passed parameters for older kernels without PnP */
7680         for (i = 0; i < IXJMAX; i++) {
7681                 if (dspio[i]) {
7682                         IXJ *j = new_ixj(dspio[i]);
7683
7684                         if (!j)
7685                                 break;
7686
7687                         j->XILINXbase = xio[i];
7688                         j->cardtype = 0;
7689
7690                         j->board = *cnt;
7691                         probe = ixj_selfprobe(j);
7692                         j->dev = NULL;
7693                         ++*cnt;
7694                 }
7695         }
7696         return 0;
7697 }
7698
7699 static int __init ixj_probe_pci(int *cnt)
7700 {
7701         struct pci_dev *pci = NULL;   
7702         int i, probe = 0;
7703         IXJ *j = NULL;
7704
7705         for (i = 0; i < IXJMAX - *cnt; i++) {
7706                 pci = pci_get_device(PCI_VENDOR_ID_QUICKNET,
7707                                       PCI_DEVICE_ID_QUICKNET_XJ, pci);
7708                 if (!pci)
7709                         break;
7710
7711                 if (pci_enable_device(pci))
7712                         break;
7713                 j = new_ixj(pci_resource_start(pci, 0));
7714                 if (!j)
7715                         break;
7716
7717                 j->serial = (PCIEE_GetSerialNumber)pci_resource_start(pci, 2);
7718                 j->XILINXbase = j->DSPbase + 0x10;
7719                 j->cardtype = QTI_PHONEJACK_PCI;
7720                 j->board = *cnt;
7721                 probe = ixj_selfprobe(j);
7722                 if (!probe)
7723                         printk(KERN_INFO "ixj: found Internet PhoneJACK PCI at 0x%x\n", j->DSPbase);
7724                 ++*cnt;
7725         }
7726         pci_dev_put(pci);
7727         return probe;
7728 }
7729
7730 static int __init ixj_init(void)
7731 {
7732         int cnt = 0;
7733         int probe = 0;   
7734
7735         cnt = 0;
7736
7737         /* These might be no-ops, see above. */
7738         if ((probe = ixj_probe_isapnp(&cnt)) < 0) {
7739                 return probe;
7740         }
7741         if ((probe = ixj_probe_isa(&cnt)) < 0) {
7742                 return probe;
7743         }
7744         if ((probe = ixj_probe_pci(&cnt)) < 0) {
7745                 return probe;
7746         }
7747         printk(KERN_INFO "ixj driver initialized.\n");
7748         create_proc_read_entry ("ixj", 0, NULL, ixj_read_proc, NULL);
7749         return probe;
7750 }
7751
7752 module_init(ixj_init);
7753 module_exit(ixj_exit);
7754
7755 static void DAA_Coeff_US(IXJ *j)
7756 {
7757         int i;
7758
7759         j->daa_country = DAA_US;
7760         /*----------------------------------------------- */
7761         /* CAO */
7762         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
7763                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
7764         }
7765
7766 /* Bytes for IM-filter part 1 (04): 0E,32,E2,2F,C2,5A,C0,00 */
7767         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x03;
7768         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0x4B;
7769         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x5D;
7770         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xCD;
7771         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x24;
7772         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xC5;
7773         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
7774         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
7775 /* Bytes for IM-filter part 2 (05): 72,85,00,0E,2B,3A,D0,08 */
7776         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x71;
7777         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x1A;
7778         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
7779         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
7780         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xB5;
7781         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
7782         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
7783         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
7784 /* Bytes for FRX-filter       (08): 03,8F,48,F2,8F,48,70,08 */
7785         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x05;
7786         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xA3;
7787         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x72;
7788         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
7789         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x3F;
7790         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x3B;
7791         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
7792         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
7793 /* Bytes for FRR-filter       (07): 04,8F,38,7F,9B,EA,B0,08 */
7794         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x05;
7795         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
7796         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
7797         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x3E;
7798         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x32;
7799         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xDA;
7800         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
7801         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
7802 /* Bytes for AX-filter        (0A): 16,55,DD,CA */
7803         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x41;
7804         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
7805         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
7806         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
7807 /* Bytes for AR-filter        (09): 52,D3,11,42 */
7808         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
7809         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
7810         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
7811         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
7812 /* Bytes for TH-filter part 1 (00): 00,42,48,81,B3,80,00,98 */
7813         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
7814         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
7815         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
7816         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
7817         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA5;
7818         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
7819         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
7820         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
7821 /* Bytes for TH-filter part 2 (01): 02,F2,33,A0,68,AB,8A,AD */
7822         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
7823         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xA2;
7824         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2B;
7825         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
7826         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
7827         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAB;
7828         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
7829         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xCC;
7830 /* Bytes for TH-filter part 3 (02): 00,88,DA,54,A4,BA,2D,BB */
7831         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
7832         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
7833         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xD2;
7834         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x24;
7835         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBA;
7836         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xA9;
7837         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x3B;
7838         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xA6;
7839 /* ;  (10K, 0.68uF) */
7840         /*  */
7841         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
7842         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
7843         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
7844         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
7845         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
7846         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
7847         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
7848         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
7849         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
7850         /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */
7851         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
7852         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
7853         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
7854         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
7855         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
7856         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
7857         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
7858         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
7859
7860         /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
7861         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
7862         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
7863         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
7864         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
7865
7866         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
7867 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1C; */
7868 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0xB3; */
7869 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0xAB; */
7870 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0xAB; */
7871 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x54; */
7872 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x2D; */
7873 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0x62; */
7874 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x2D; */
7875         /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */ 
7876 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x2D; */
7877 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x62; */
7878 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6; */
7879 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBB; */
7880 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x2A; */
7881 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7D; */
7882 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A; */
7883 /*      j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD4; */
7884 /* */
7885         /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
7886 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA; */
7887 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x05; */
7888 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F; */
7889 /*      j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E; */
7890
7891         /* Caller ID 1st Tone           (0E):CA,0E,CA,09,99,99,99,99 */
7892         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
7893         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
7894         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
7895         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
7896         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
7897         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
7898         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
7899         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
7900 /* Caller ID 2nd Tone           (0F):FD,B5,BA,07,DA,00,00,00 */
7901         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
7902         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
7903         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
7904         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
7905         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
7906         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
7907         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
7908         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
7909 /*  */
7910         /* ;CR Registers */
7911         /* Config. Reg. 0 (filters)       (cr0):FE ; CLK gen. by crystal */
7912         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
7913 /* Config. Reg. 1 (dialing)       (cr1):05 */
7914         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
7915 /* Config. Reg. 2 (caller ID)     (cr2):04 */
7916         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
7917 /* Config. Reg. 3 (testloops)     (cr3):03 ; SEL Bit==0, HP-disabled */
7918         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
7919 /* Config. Reg. 4 (analog gain)   (cr4):02 */
7920         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
7921         /* Config. Reg. 5 (Version)       (cr5):02 */
7922         /* Config. Reg. 6 (Reserved)      (cr6):00 */
7923         /* Config. Reg. 7 (Reserved)      (cr7):00 */
7924         /*  */
7925         /* ;xr Registers */
7926         /* Ext. Reg. 0 (Interrupt Reg.)   (xr0):02 */
7927
7928         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
7929         /* Ext. Reg. 1 (Interrupt enable) (xr1):3C Cadence, RING, Caller ID, VDD_OK */
7930
7931         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x3C;
7932 /* Ext. Reg. 2 (Cadence Time Out) (xr2):7D */
7933         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
7934 /* Ext. Reg. 3 (DC Char)          (xr3):32 ; B-Filter Off == 1 */
7935         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x3B;         /*0x32; */
7936         /* Ext. Reg. 4 (Cadence)          (xr4):00 */
7937
7938         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
7939 /* Ext. Reg. 5 (Ring timer)       (xr5):22 */
7940         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
7941 /* Ext. Reg. 6 (Power State)      (xr6):00 */
7942         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
7943 /* Ext. Reg. 7 (Vdd)              (xr7):40 */
7944         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
7945         /*  */
7946         /* DTMF Tone 1                     (0B): 11,B3,5A,2C ;   697 Hz   */
7947         /*                                       12,33,5A,C3 ;  770 Hz   */
7948         /*                                       13,3C,5B,32 ;  852 Hz   */
7949         /*                                       1D,1B,5C,CC ;  941 Hz   */
7950
7951         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
7952         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
7953         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
7954         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
7955 /* DTMF Tone 2                     (0C): 32,32,52,B3 ;  1209 Hz   */
7956         /*                                       EC,1D,52,22 ;  1336 Hz   */
7957         /*                                       AA,AC,51,D2 ;  1477 Hz   */
7958         /*                                       9B,3B,51,25 ;  1633 Hz   */
7959         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
7960         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
7961         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
7962         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
7963 }
7964
7965 static void DAA_Coeff_UK(IXJ *j)
7966 {
7967         int i;
7968
7969         j->daa_country = DAA_UK;
7970         /*----------------------------------------------- */
7971         /* CAO */
7972         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
7973                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
7974         }
7975
7976 /*  Bytes for IM-filter part 1 (04): 00,C2,BB,A8,CB,81,A0,00 */
7977         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
7978         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xC2;
7979         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
7980         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xA8;
7981         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xCB;
7982         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
7983         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
7984         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
7985 /* Bytes for IM-filter part 2 (05): 40,00,00,0A,A4,33,E0,08 */
7986         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x40;
7987         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x00;
7988         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
7989         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
7990         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xA4;
7991         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
7992         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
7993         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
7994 /* Bytes for FRX-filter       (08): 07,9B,ED,24,B2,A2,A0,08 */
7995         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
7996         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9B;
7997         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xED;
7998         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x24;
7999         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0xB2;
8000         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0xA2;
8001         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xA0;
8002         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8003 /* Bytes for FRR-filter       (07): 0F,92,F2,B2,87,D2,30,08 */
8004         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8005         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x92;
8006         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF2;
8007         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0xB2;
8008         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8009         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xD2;
8010         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x30;
8011         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8012 /* Bytes for AX-filter        (0A): 1B,A5,DD,CA */
8013         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x1B;
8014         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xA5;
8015         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8016         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8017 /* Bytes for AR-filter        (09): E2,27,10,D6 */
8018         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8019         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x27;
8020         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8021         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8022 /* Bytes for TH-filter part 1 (00): 80,2D,38,8B,D0,00,00,98 */
8023         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8024         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x2D;
8025         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x38;
8026         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x8B;
8027         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xD0;
8028         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x00;
8029         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8030         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8031 /* Bytes for TH-filter part 2 (01): 02,5A,53,F0,0B,5F,84,D4 */
8032         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8033         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x5A;
8034         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x53;
8035         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xF0;
8036         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x0B;
8037         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5F;
8038         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x84;
8039         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xD4;
8040 /* Bytes for TH-filter part 3 (02): 00,88,6A,A4,8F,52,F5,32 */
8041         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8042         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8043         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x6A;
8044         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA4;
8045         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x8F;
8046         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x52;
8047         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xF5;
8048         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x32;
8049 /* ; idle */
8050         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8051         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8052         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8053         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8054         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8055         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8056         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8057         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8058         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8059 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8060         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8061         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8062         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8063         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8064         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8065         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8066         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8067         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8068 /* Levelmetering Ringing           (0D):AA,35,0F,8E     ; 25Hz 30V less possible? */
8069         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8070         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8071         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8072         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8073 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8074         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8075         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8076         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8077         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8078         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8079         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8080         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8081         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8082 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8083         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8084         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8085         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8086         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8087         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8088         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8089         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8090         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8091 /* ;CR Registers */
8092         /* Config. Reg. 0 (filters)        (cr0):FF */
8093         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8094 /* Config. Reg. 1 (dialing)        (cr1):05 */
8095         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8096 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8097         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8098 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8099         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8100 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8101         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8102         /* Config. Reg. 5 (Version)        (cr5):02 */
8103         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8104         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8105         /* ;xr Registers */
8106         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8107
8108         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8109         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8110
8111         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8112         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8113
8114         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8115 /* Ext. Reg. 3 (DC Char)           (xr3):36        ;  */
8116         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8117 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8118         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8119 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8120         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8121 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8122         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8123 /* Ext. Reg. 7 (Vdd)               (xr7):46 */
8124         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;         /* 0x46 ??? Should it be 0x00? */
8125         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8126         /*                                       12,33,5A,C3    ;  770 Hz   */
8127         /*                                       13,3C,5B,32    ;  852 Hz   */
8128         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8129
8130         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8131         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8132         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8133         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8134 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8135         /*                                       EC,1D,52,22    ;  1336 Hz   */
8136         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8137         /*                                       9B,3B,51,25    ;  1633 Hz   */
8138         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8139         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8140         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8141         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8142 }
8143
8144
8145 static void DAA_Coeff_France(IXJ *j)
8146 {
8147         int i;
8148
8149         j->daa_country = DAA_FRANCE;
8150         /*----------------------------------------------- */
8151         /* CAO */
8152         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8153                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8154         }
8155
8156 /* Bytes for IM-filter part 1 (04): 02,A2,43,2C,22,AF,A0,00 */
8157         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x02;
8158         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA2;
8159         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x43;
8160         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2C;
8161         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x22;
8162         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xAF;
8163         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8164         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8165 /* Bytes for IM-filter part 2 (05): 67,CE,00,0C,22,33,E0,08 */
8166         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x67;
8167         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xCE;
8168         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8169         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x2C;
8170         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x22;
8171         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8172         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8173         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8174 /* Bytes for FRX-filter       (08): 07,9A,28,F6,23,4A,B0,08 */
8175         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8176         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9A;
8177         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x28;
8178         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0xF6;
8179         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x23;
8180         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x4A;
8181         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xB0;
8182         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8183 /* Bytes for FRR-filter       (07): 03,8F,F9,2F,9E,FA,20,08 */
8184         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8185         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8186         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
8187         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8188         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9E;
8189         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xFA;
8190         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8191         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8192 /* Bytes for AX-filter        (0A): 16,B5,DD,CA */
8193         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x16;
8194         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
8195         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8196         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8197 /* Bytes for AR-filter        (09): 52,C7,10,D6 */
8198         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8199         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
8200         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8201         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8202 /* Bytes for TH-filter part 1 (00): 00,42,48,81,A6,80,00,98 */
8203         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8204         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8205         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8206         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8207         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA6;
8208         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8209         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8210         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8211 /* Bytes for TH-filter part 2 (01): 02,AC,2A,30,78,AC,8A,2C */
8212         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8213         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAC;
8214         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8215         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x30;
8216         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x78;
8217         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAC;
8218         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x8A;
8219         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x2C;
8220 /* Bytes for TH-filter part 3 (02): 00,88,DA,A5,22,BA,2C,45 */
8221         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8222         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8223         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8224         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA5;
8225         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x22;
8226         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xBA;
8227         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x2C;
8228         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x45;
8229 /* ; idle */
8230         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8231         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8232         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8233         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8234         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8235         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8236         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8237         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8238         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8239 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8240         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8241         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8242         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8243         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8244         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8245         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8246         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8247         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8248 /* Levelmetering Ringing           (0D):32,45,B5,84     ; 50Hz 20V */
8249         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8250         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8251         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8252         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8253 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8254         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8255         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8256         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8257         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8258         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8259         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8260         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8261         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8262 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8263         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8264         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8265         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8266         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8267         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8268         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8269         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8270         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8271 /* ;CR Registers */
8272         /* Config. Reg. 0 (filters)        (cr0):FF */
8273         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8274 /* Config. Reg. 1 (dialing)        (cr1):05 */
8275         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8276 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8277         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8278 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8279         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8280 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8281         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8282         /* Config. Reg. 5 (Version)        (cr5):02 */
8283         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8284         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8285         /* ;xr Registers */
8286         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8287
8288         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8289         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8290
8291         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8292         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8293
8294         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8295 /* Ext. Reg. 3 (DC Char)           (xr3):36        ;  */
8296         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8297 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8298         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8299 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8300         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8301 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8302         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8303 /* Ext. Reg. 7 (Vdd)               (xr7):46 */
8304         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;         /* 0x46 ??? Should it be 0x00? */
8305         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8306         /*                                       12,33,5A,C3    ;  770 Hz   */
8307         /*                                       13,3C,5B,32    ;  852 Hz   */
8308         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8309
8310         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8311         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8312         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8313         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8314 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8315         /*                                       EC,1D,52,22    ;  1336 Hz   */
8316         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8317         /*                                       9B,3B,51,25    ;  1633 Hz   */
8318         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8319         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8320         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8321         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8322 }
8323
8324
8325 static void DAA_Coeff_Germany(IXJ *j)
8326 {
8327         int i;
8328
8329         j->daa_country = DAA_GERMANY;
8330         /*----------------------------------------------- */
8331         /* CAO */
8332         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8333                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8334         }
8335
8336 /* Bytes for IM-filter part 1 (04): 00,CE,BB,B8,D2,81,B0,00 */
8337         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8338         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xCE;
8339         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
8340         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xB8;
8341         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xD2;
8342         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
8343         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xB0;
8344         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8345 /* Bytes for IM-filter part 2 (05): 45,8F,00,0C,D2,3A,D0,08 */
8346         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x45;
8347         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x8F;
8348         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8349         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0C;
8350         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xD2;
8351         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x3A;
8352         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xD0;
8353         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8354 /* Bytes for FRX-filter       (08): 07,AA,E2,34,24,89,20,08 */
8355         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8356         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xAA;
8357         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8358         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8359         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x24;
8360         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x89;
8361         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x20;
8362         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8363 /* Bytes for FRR-filter       (07): 02,87,FA,37,9A,CA,B0,08 */
8364         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x02;
8365         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
8366         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xFA;
8367         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x37;
8368         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9A;
8369         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCA;
8370         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
8371         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8372 /* Bytes for AX-filter        (0A): 72,D5,DD,CA */
8373         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x72;
8374         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xD5;
8375         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8376         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8377 /* Bytes for AR-filter        (09): 72,42,13,4B */
8378         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x72;
8379         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x42;
8380         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x13;
8381         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0x4B;
8382 /* Bytes for TH-filter part 1 (00): 80,52,48,81,AD,80,00,98 */
8383         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8384         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8385         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8386         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8387         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAD;
8388         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8389         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8390         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8391 /* Bytes for TH-filter part 2 (01): 02,42,5A,20,E8,1A,81,27 */
8392         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8393         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x42;
8394         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x5A;
8395         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8396         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
8397         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x1A;
8398         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
8399         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x27;
8400 /* Bytes for TH-filter part 3 (02): 00,88,63,26,BD,4B,A3,C2 */
8401         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8402         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8403         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x63;
8404         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x26;
8405         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBD;
8406         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x4B;
8407         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xA3;
8408         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xC2;
8409 /* ;  (10K, 0.68uF) */
8410         /* Bytes for Ringing part 1 (03):1B,3B,9B,BA,D4,1C,B3,23 */
8411         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8412         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3B;
8413         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x9B;
8414         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0xBA;
8415         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0xD4;
8416         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x1C;
8417         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xB3;
8418         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8419 /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */
8420         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x13;
8421         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x42;
8422         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8423         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8424         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0xD4;
8425         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x73;
8426         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0xCA;
8427         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8428 /* Levelmetering Ringing        (0D):B2,45,0F,8E       */
8429         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xB2;
8430         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8431         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8432         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8433 /* Caller ID 1st Tone           (0E):CA,0E,CA,09,99,99,99,99 */
8434         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8435         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8436         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8437         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8438         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8439         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8440         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8441         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8442 /* Caller ID 2nd Tone           (0F):FD,B5,BA,07,DA,00,00,00 */
8443         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8444         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8445         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8446         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8447         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8448         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8449         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8450         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8451 /* ;CR Registers */
8452         /* Config. Reg. 0 (filters)        (cr0):FF ; all Filters enabled, CLK from ext. source */
8453         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8454 /* Config. Reg. 1 (dialing)        (cr1):05 ; Manual Ring, Ring metering enabled */
8455         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8456 /* Config. Reg. 2 (caller ID)      (cr2):04 ; Analog Gain 0dB, FSC internal */
8457         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8458 /* Config. Reg. 3 (testloops)      (cr3):00 ; SEL Bit==0, HP-enabled */
8459         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8460 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8461         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8462         /* Config. Reg. 5 (Version)        (cr5):02 */
8463         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8464         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8465         /* ;xr Registers */
8466         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8467
8468         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8469         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C ; Ring, CID, VDDOK Interrupts enabled */
8470
8471         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8472         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8473
8474         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8475 /* Ext. Reg. 3 (DC Char)           (xr3):32 ; B-Filter Off==1, U0=3.5V, R=200Ohm */
8476         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x32;
8477 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8478         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8479 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8480         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8481 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8482         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8483 /* Ext. Reg. 7 (Vdd)               (xr7):40 ; VDD=4.25 V */
8484         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8485         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8486         /*                                       12,33,5A,C3    ;  770 Hz   */
8487         /*                                       13,3C,5B,32    ;  852 Hz   */
8488         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8489
8490         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8491         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8492         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8493         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8494 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8495         /*                                       EC,1D,52,22    ;  1336 Hz   */
8496         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8497         /*                                       9B,3B,51,25    ;  1633 Hz   */
8498         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8499         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8500         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8501         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8502 }
8503
8504
8505 static void DAA_Coeff_Australia(IXJ *j)
8506 {
8507         int i;
8508
8509         j->daa_country = DAA_AUSTRALIA;
8510         /*----------------------------------------------- */
8511         /* CAO */
8512         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8513                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8514         }
8515
8516 /* Bytes for IM-filter part 1 (04): 00,A3,AA,28,B3,82,D0,00 */
8517         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8518         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA3;
8519         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xAA;
8520         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x28;
8521         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xB3;
8522         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x82;
8523         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xD0;
8524         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8525 /* Bytes for IM-filter part 2 (05): 70,96,00,09,32,6B,C0,08 */
8526         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x70;
8527         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x96;
8528         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8529         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x09;
8530         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x32;
8531         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x6B;
8532         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xC0;
8533         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8534 /* Bytes for FRX-filter       (08): 07,96,E2,34,32,9B,30,08 */
8535         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8536         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x96;
8537         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8538         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8539         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x32;
8540         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x9B;
8541         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
8542         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8543 /* Bytes for FRR-filter       (07): 0F,9A,E9,2F,22,CC,A0,08 */
8544         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8545         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x9A;
8546         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xE9;
8547         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8548         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x22;
8549         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCC;
8550         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xA0;
8551         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8552 /* Bytes for AX-filter        (0A): CB,45,DD,CA */
8553         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0xCB;
8554         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0x45;
8555         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8556         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8557 /* Bytes for AR-filter        (09): 1B,67,10,D6 */
8558         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x1B;
8559         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x67;
8560         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8561         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8562 /* Bytes for TH-filter part 1 (00): 80,52,48,81,AF,80,00,98 */
8563         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8564         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8565         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8566         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8567         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAF;
8568         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8569         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8570         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8571 /* Bytes for TH-filter part 2 (01): 02,DB,52,B0,38,01,82,AC */
8572         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8573         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xDB;
8574         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x52;
8575         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
8576         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x38;
8577         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x01;
8578         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x82;
8579         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xAC;
8580 /* Bytes for TH-filter part 3 (02): 00,88,4A,3E,2C,3B,24,46 */
8581         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8582         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8583         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x4A;
8584         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x3E;
8585         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x2C;
8586         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x3B;
8587         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x24;
8588         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x46;
8589 /* ;  idle */
8590         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8591         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8592         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8593         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8594         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8595         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8596         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8597         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8598         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8599 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8600         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8601         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8602         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8603         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8604         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8605         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8606         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8607         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8608 /* Levelmetering Ringing           (0D):32,45,B5,84   ; 50Hz 20V */
8609         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8610         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8611         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8612         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8613 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8614         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8615         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8616         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8617         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8618         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8619         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8620         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8621         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8622 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8623         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8624         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8625         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8626         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8627         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8628         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8629         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8630         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8631 /* ;CR Registers */
8632         /* Config. Reg. 0 (filters)        (cr0):FF */
8633         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8634 /* Config. Reg. 1 (dialing)        (cr1):05 */
8635         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8636 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8637         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8638 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8639         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8640 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8641         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8642         /* Config. Reg. 5 (Version)        (cr5):02 */
8643         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8644         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8645         /* ;xr Registers */
8646         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8647
8648         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8649         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8650
8651         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8652         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8653
8654         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8655 /* Ext. Reg. 3 (DC Char)           (xr3):2B      ;  */
8656         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x2B;
8657 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8658         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8659 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8660         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8661 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8662         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8663 /* Ext. Reg. 7 (Vdd)               (xr7):40 */
8664         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8665
8666         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;  697 Hz   */
8667         /*                                       12,33,5A,C3    ;  770 Hz   */
8668         /*                                       13,3C,5B,32    ;  852 Hz   */
8669         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8670         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8671         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8672         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8673         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8674
8675         /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8676         /*                                       EC,1D,52,22    ;  1336 Hz   */
8677         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8678         /*                                       9B,3B,51,25    ;  1633 Hz   */
8679         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8680         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8681         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8682         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8683 }
8684
8685 static void DAA_Coeff_Japan(IXJ *j)
8686 {
8687         int i;
8688
8689         j->daa_country = DAA_JAPAN;
8690         /*----------------------------------------------- */
8691         /* CAO */
8692         for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8693                 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8694         }
8695
8696 /* Bytes for IM-filter part 1 (04): 06,BD,E2,2D,BA,F9,A0,00 */
8697         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x06;
8698         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xBD;
8699         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xE2;
8700         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2D;
8701         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xBA;
8702         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xF9;
8703         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8704         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8705 /* Bytes for IM-filter part 2 (05): 6F,F7,00,0E,34,33,E0,08 */
8706         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x6F;
8707         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xF7;
8708         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8709         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0E;
8710         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x34;
8711         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8712         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8713         j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8714 /* Bytes for FRX-filter       (08): 02,8F,68,77,9C,58,F0,08 */
8715         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x02;
8716         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x8F;
8717         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x68;
8718         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x77;
8719         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x9C;
8720         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x58;
8721         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xF0;
8722         j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8723 /* Bytes for FRR-filter       (07): 03,8F,38,73,87,EA,20,08 */
8724         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8725         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8726         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0x38;
8727         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x73;
8728         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8729         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xEA;
8730         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8731         j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8732 /* Bytes for AX-filter        (0A): 51,C5,DD,CA */
8733         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x51;
8734         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xC5;
8735         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8736         j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8737 /* Bytes for AR-filter        (09): 25,A7,10,D6 */
8738         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
8739         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xA7;
8740         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8741         j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8742 /* Bytes for TH-filter part 1 (00): 00,42,48,81,AE,80,00,98 */
8743         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8744         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8745         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8746         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8747         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAE;
8748         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8749         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8750         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8751 /* Bytes for TH-filter part 2 (01): 02,AB,2A,20,99,5B,89,28 */
8752         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8753         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAB;
8754         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8755         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8756         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x99;
8757         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5B;
8758         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x89;
8759         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x28;
8760 /* Bytes for TH-filter part 3 (02): 00,88,DA,25,34,C5,4C,BA */
8761         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8762         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8763         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8764         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x25;
8765         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x34;
8766         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xC5;
8767         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x4C;
8768         j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xBA;
8769 /* ;  idle */
8770         /* Bytes for Ringing part 1 (03):1B,3C,93,3A,22,12,A3,23 */
8771         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8772         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8773         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8774         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8775         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8776         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8777         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8778         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8779 /* Bytes for Ringing part 2 (06):12,A2,A6,BA,22,7A,0A,D5 */
8780         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8781         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8782         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8783         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8784         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8785         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8786         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8787         j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8788 /* Levelmetering Ringing           (0D):AA,35,0F,8E    ; 25Hz 30V ????????? */
8789         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8790         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8791         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8792         j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8793 /* Caller ID 1st Tone              (0E):CA,0E,CA,09,99,99,99,99 */
8794         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8795         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8796         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8797         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8798         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8799         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8800         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8801         j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8802 /* Caller ID 2nd Tone              (0F):FD,B5,BA,07,DA,00,00,00 */
8803         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8804         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8805         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8806         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8807         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8808         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8809         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8810         j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8811 /* ;CR Registers */
8812         /* Config. Reg. 0 (filters)        (cr0):FF */
8813         j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8814 /* Config. Reg. 1 (dialing)        (cr1):05 */
8815         j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8816 /* Config. Reg. 2 (caller ID)      (cr2):04 */
8817         j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8818 /* Config. Reg. 3 (testloops)      (cr3):00        ;  */
8819         j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8820 /* Config. Reg. 4 (analog gain)    (cr4):02 */
8821         j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8822         /* Config. Reg. 5 (Version)        (cr5):02 */
8823         /* Config. Reg. 6 (Reserved)       (cr6):00 */
8824         /* Config. Reg. 7 (Reserved)       (cr7):00 */
8825         /* ;xr Registers */
8826         /* Ext. Reg. 0 (Interrupt Reg.)    (xr0):02 */
8827
8828         j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;        /* SO_1 set to '1' because it is inverted. */
8829         /* Ext. Reg. 1 (Interrupt enable)  (xr1):1C */
8830
8831         j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;         /* RING, Caller ID, VDD_OK */
8832         /* Ext. Reg. 2 (Cadence Time Out)  (xr2):7D */
8833
8834         j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8835 /* Ext. Reg. 3 (DC Char)           (xr3):22        ;  */
8836         j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x22;
8837 /* Ext. Reg. 4 (Cadence)           (xr4):00 */
8838         j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8839 /* Ext. Reg. 5 (Ring timer)        (xr5):22 */
8840         j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8841 /* Ext. Reg. 6 (Power State)       (xr6):00 */
8842         j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8843 /* Ext. Reg. 7 (Vdd)               (xr7):40 */
8844         j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;         /* 0x40 ??? Should it be 0x00? */
8845         /* DTMF Tone 1                     (0B): 11,B3,5A,2C    ;   697 Hz   */
8846         /*                                       12,33,5A,C3    ;  770 Hz   */
8847         /*                                       13,3C,5B,32    ;  852 Hz   */
8848         /*                                       1D,1B,5C,CC    ;  941 Hz   */
8849
8850         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8851         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8852         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8853         j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8854 /* DTMF Tone 2                     (0C): 32,32,52,B3    ;  1209 Hz   */
8855         /*                                       EC,1D,52,22    ;  1336 Hz   */
8856         /*                                       AA,AC,51,D2    ;  1477 Hz   */
8857         /*                                       9B,3B,51,25    ;  1633 Hz   */
8858         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8859         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8860         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8861         j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8862 }
8863
8864 static s16 tone_table[][19] =
8865 {
8866         {                       /* f20_50[] 11 */
8867                 32538,          /* A1 = 1.985962 */
8868                  -32325,        /* A2 = -0.986511 */
8869                  -343,          /* B2 = -0.010493 */
8870                  0,             /* B1 = 0 */
8871                  343,           /* B0 = 0.010493 */
8872                  32619,         /* A1 = 1.990906 */
8873                  -32520,        /* A2 = -0.992462 */
8874                  19179,         /* B2 = 0.585327 */
8875                  -19178,        /* B1 = -1.170593 */
8876                  19179,         /* B0 = 0.585327 */
8877                  32723,         /* A1 = 1.997314 */
8878                  -32686,        /* A2 = -0.997528 */
8879                  9973,          /* B2 = 0.304352 */
8880                  -9955,         /* B1 = -0.607605 */
8881                  9973,          /* B0 = 0.304352 */
8882                  7,             /* Internal filter scaling */
8883                  159,           /* Minimum in-band energy threshold */
8884                  21,            /* 21/32 in-band to broad-band ratio */
8885                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8886         },
8887         {                       /* f133_200[] 12 */
8888                 32072,          /* A1 = 1.95752 */
8889                  -31896,        /* A2 = -0.973419 */
8890                  -435,          /* B2 = -0.013294 */
8891                  0,             /* B1 = 0 */
8892                  435,           /* B0 = 0.013294 */
8893                  32188,         /* A1 = 1.9646 */
8894                  -32400,        /* A2 = -0.98877 */
8895                  15139,         /* B2 = 0.462036 */
8896                  -14882,        /* B1 = -0.908356 */
8897                  15139,         /* B0 = 0.462036 */
8898                  32473,         /* A1 = 1.981995 */
8899                  -32524,        /* A2 = -0.992584 */
8900                  23200,         /* B2 = 0.708008 */
8901                  -23113,        /* B1 = -1.410706 */
8902                  23200,         /* B0 = 0.708008 */
8903                  7,             /* Internal filter scaling */
8904                  159,           /* Minimum in-band energy threshold */
8905                  21,            /* 21/32 in-band to broad-band ratio */
8906                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8907         },
8908         {                       /* f300 13 */
8909                 31769,          /* A1 = -1.939026 */
8910                  -32584,        /* A2 = 0.994385 */
8911                  -475,          /* B2 = -0.014522 */
8912                  0,             /* B1 = 0.000000 */
8913                  475,           /* B0 = 0.014522 */
8914                  31789,         /* A1 = -1.940247 */
8915                  -32679,        /* A2 = 0.997284 */
8916                  17280,         /* B2 = 0.527344 */
8917                  -16865,        /* B1 = -1.029358 */
8918                  17280,         /* B0 = 0.527344 */
8919                  31841,         /* A1 = -1.943481 */
8920                  -32681,        /* A2 = 0.997345 */
8921                  543,           /* B2 = 0.016579 */
8922                  -525,          /* B1 = -0.032097 */
8923                  543,           /* B0 = 0.016579 */
8924                  5,             /* Internal filter scaling */
8925                  159,           /* Minimum in-band energy threshold */
8926                  21,            /* 21/32 in-band to broad-band ratio */
8927                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8928         },
8929         {                       /* f300_420[] 14 */
8930                 30750,          /* A1 = 1.876892 */
8931                  -31212,        /* A2 = -0.952515 */
8932                  -804,          /* B2 = -0.024541 */
8933                  0,             /* B1 = 0 */
8934                  804,           /* B0 = 0.024541 */
8935                  30686,         /* A1 = 1.872925 */
8936                  -32145,        /* A2 = -0.980988 */
8937                  14747,         /* B2 = 0.450043 */
8938                  -13703,        /* B1 = -0.836395 */
8939                  14747,         /* B0 = 0.450043 */
8940                  31651,         /* A1 = 1.931824 */
8941                  -32321,        /* A2 = -0.986389 */
8942                  24425,         /* B2 = 0.745422 */
8943                  -23914,        /* B1 = -1.459595 */
8944                  24427,         /* B0 = 0.745483 */
8945                  7,             /* Internal filter scaling */
8946                  159,           /* Minimum in-band energy threshold */
8947                  21,            /* 21/32 in-band to broad-band ratio */
8948                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8949         },
8950         {                       /* f330 15 */
8951                 31613,          /* A1 = -1.929565 */
8952                  -32646,        /* A2 = 0.996277 */
8953                  -185,          /* B2 = -0.005657 */
8954                  0,             /* B1 = 0.000000 */
8955                  185,           /* B0 = 0.005657 */
8956                  31620,         /* A1 = -1.929932 */
8957                  -32713,        /* A2 = 0.998352 */
8958                  19253,         /* B2 = 0.587585 */
8959                  -18566,        /* B1 = -1.133179 */
8960                  19253,         /* B0 = 0.587585 */
8961                  31674,         /* A1 = -1.933228 */
8962                  -32715,        /* A2 = 0.998413 */
8963                  2575,          /* B2 = 0.078590 */
8964                  -2495,         /* B1 = -0.152283 */
8965                  2575,          /* B0 = 0.078590 */
8966                  5,             /* Internal filter scaling */
8967                  159,           /* Minimum in-band energy threshold */
8968                  21,            /* 21/32 in-band to broad-band ratio */
8969                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8970         },
8971         {                       /* f300_425[] 16 */
8972                 30741,          /* A1 = 1.876282 */
8973                  -31475,        /* A2 = -0.960541 */
8974                  -703,          /* B2 = -0.021484 */
8975                  0,             /* B1 = 0 */
8976                  703,           /* B0 = 0.021484 */
8977                  30688,         /* A1 = 1.873047 */
8978                  -32248,        /* A2 = -0.984161 */
8979                  14542,         /* B2 = 0.443787 */
8980                  -13523,        /* B1 = -0.825439 */
8981                  14542,         /* B0 = 0.443817 */
8982                  31494,         /* A1 = 1.922302 */
8983                  -32366,        /* A2 = -0.987762 */
8984                  21577,         /* B2 = 0.658508 */
8985                  -21013,        /* B1 = -1.282532 */
8986                  21577,         /* B0 = 0.658508 */
8987                  7,             /* Internal filter scaling */
8988                  159,           /* Minimum in-band energy threshold */
8989                  21,            /* 21/32 in-band to broad-band ratio */
8990                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
8991         },
8992         {                       /* f330_440[] 17 */
8993                 30627,          /* A1 = 1.869324 */
8994                  -31338,        /* A2 = -0.95636 */
8995                  -843,          /* B2 = -0.025749 */
8996                  0,             /* B1 = 0 */
8997                  843,           /* B0 = 0.025749 */
8998                  30550,         /* A1 = 1.864685 */
8999                  -32221,        /* A2 = -0.983337 */
9000                  13594,         /* B2 = 0.414886 */
9001                  -12589,        /* B1 = -0.768402 */
9002                  13594,         /* B0 = 0.414886 */
9003                  31488,         /* A1 = 1.921936 */
9004                  -32358,        /* A2 = -0.987518 */
9005                  24684,         /* B2 = 0.753296 */
9006                  -24029,        /* B1 = -1.466614 */
9007                  24684,         /* B0 = 0.753296 */
9008                  7,             /* Internal filter scaling */
9009                  159,           /* Minimum in-band energy threshold */
9010                  21,            /* 21/32 in-band to broad-band ratio */
9011                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9012         },
9013         {                       /* f340 18 */
9014                 31546,          /* A1 = -1.925476 */
9015                  -32646,        /* A2 = 0.996277 */
9016                  -445,          /* B2 = -0.013588 */
9017                  0,             /* B1 = 0.000000 */
9018                  445,           /* B0 = 0.013588 */
9019                  31551,         /* A1 = -1.925781 */
9020                  -32713,        /* A2 = 0.998352 */
9021                  23884,         /* B2 = 0.728882 */
9022                  -22979,        /* B1 = -1.402527 */
9023                  23884,         /* B0 = 0.728882 */
9024                  31606,         /* A1 = -1.929138 */
9025                  -32715,        /* A2 = 0.998413 */
9026                  863,           /* B2 = 0.026367 */
9027                  -835,          /* B1 = -0.050985 */
9028                  863,           /* B0 = 0.026367 */
9029                  5,             /* Internal filter scaling */
9030                  159,           /* Minimum in-band energy threshold */
9031                  21,            /* 21/32 in-band to broad-band ratio */
9032                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9033         },
9034         {                       /* f350_400[] 19 */
9035                 31006,          /* A1 = 1.892517 */
9036                  -32029,        /* A2 = -0.977448 */
9037                  -461,          /* B2 = -0.014096 */
9038                  0,             /* B1 = 0 */
9039                  461,           /* B0 = 0.014096 */
9040                  30999,         /* A1 = 1.892029 */
9041                  -32487,        /* A2 = -0.991455 */
9042                  11325,         /* B2 = 0.345612 */
9043                  -10682,        /* B1 = -0.651978 */
9044                  11325,         /* B0 = 0.345612 */
9045                  31441,         /* A1 = 1.919067 */
9046                  -32526,        /* A2 = -0.992615 */
9047                  24324,         /* B2 = 0.74231 */
9048                  -23535,        /* B1 = -1.436523 */
9049                  24324,         /* B0 = 0.74231 */
9050                  7,             /* Internal filter scaling */
9051                  159,           /* Minimum in-band energy threshold */
9052                  21,            /* 21/32 in-band to broad-band ratio */
9053                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9054         },
9055         {                       /* f350_440[] */
9056                 30634,          /* A1 = 1.869751 */
9057                  -31533,        /* A2 = -0.962341 */
9058                  -680,          /* B2 = -0.020782 */
9059                  0,             /* B1 = 0 */
9060                  680,           /* B0 = 0.020782 */
9061                  30571,         /* A1 = 1.865906 */
9062                  -32277,        /* A2 = -0.985016 */
9063                  12894,         /* B2 = 0.393524 */
9064                  -11945,        /* B1 = -0.729065 */
9065                  12894,         /* B0 = 0.393524 */
9066                  31367,         /* A1 = 1.91449 */
9067                  -32379,        /* A2 = -0.988129 */
9068                  23820,         /* B2 = 0.726929 */
9069                  -23104,        /* B1 = -1.410217 */
9070                  23820,         /* B0 = 0.726929 */
9071                  7,             /* Internal filter scaling */
9072                  159,           /* Minimum in-band energy threshold */
9073                  21,            /* 21/32 in-band to broad-band ratio */
9074                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9075         },
9076         {                       /* f350_450[] */
9077                 30552,          /* A1 = 1.864807 */
9078                  -31434,        /* A2 = -0.95929 */
9079                  -690,          /* B2 = -0.021066 */
9080                  0,             /* B1 = 0 */
9081                  690,           /* B0 = 0.021066 */
9082                  30472,         /* A1 = 1.859924 */
9083                  -32248,        /* A2 = -0.984161 */
9084                  13385,         /* B2 = 0.408478 */
9085                  -12357,        /* B1 = -0.754242 */
9086                  13385,         /* B0 = 0.408478 */
9087                  31358,         /* A1 = 1.914001 */
9088                  -32366,        /* A2 = -0.987732 */
9089                  26488,         /* B2 = 0.80835 */
9090                  -25692,        /* B1 = -1.568176 */
9091                  26490,         /* B0 = 0.808411 */
9092                  7,             /* Internal filter scaling */
9093                  159,           /* Minimum in-band energy threshold */
9094                  21,            /* 21/32 in-band to broad-band ratio */
9095                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9096         },
9097         {                       /* f360 */
9098                 31397,          /* A1 = -1.916321 */
9099                  -32623,        /* A2 = 0.995605 */
9100                  -117,          /* B2 = -0.003598 */
9101                  0,             /* B1 = 0.000000 */
9102                  117,           /* B0 = 0.003598 */
9103                  31403,         /* A1 = -1.916687 */
9104                  -32700,        /* A2 = 0.997925 */
9105                  3388,          /* B2 = 0.103401 */
9106                  -3240,         /* B1 = -0.197784 */
9107                  3388,          /* B0 = 0.103401 */
9108                  31463,         /* A1 = -1.920410 */
9109                  -32702,        /* A2 = 0.997986 */
9110                  13346,         /* B2 = 0.407288 */
9111                  -12863,        /* B1 = -0.785126 */
9112                  13346,         /* B0 = 0.407288 */
9113                  5,             /* Internal filter scaling */
9114                  159,           /* Minimum in-band energy threshold */
9115                  21,            /* 21/32 in-band to broad-band ratio */
9116                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9117         },
9118         {                       /* f380_420[] */
9119                 30831,          /* A1 = 1.881775 */
9120                  -32064,        /* A2 = -0.978546 */
9121                  -367,          /* B2 = -0.01122 */
9122                  0,             /* B1 = 0 */
9123                  367,           /* B0 = 0.01122 */
9124                  30813,         /* A1 = 1.880737 */
9125                  -32456,        /* A2 = -0.990509 */
9126                  11068,         /* B2 = 0.337769 */
9127                  -10338,        /* B1 = -0.631042 */
9128                  11068,         /* B0 = 0.337769 */
9129                  31214,         /* A1 = 1.905212 */
9130                  -32491,        /* A2 = -0.991577 */
9131                  16374,         /* B2 = 0.499695 */
9132                  -15781,        /* B1 = -0.963196 */
9133                  16374,         /* B0 = 0.499695 */
9134                  7,             /* Internal filter scaling */
9135                  159,           /* Minimum in-band energy threshold */
9136                  21,            /* 21/32 in-band to broad-band ratio */
9137                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9138         },
9139         {                       /* f392 */
9140                 31152,          /* A1 = -1.901428 */
9141                  -32613,        /* A2 = 0.995300 */
9142                  -314,          /* B2 = -0.009605 */
9143                  0,             /* B1 = 0.000000 */
9144                  314,           /* B0 = 0.009605 */
9145                  31156,         /* A1 = -1.901672 */
9146                  -32694,        /* A2 = 0.997742 */
9147                  28847,         /* B2 = 0.880371 */
9148                  -2734,         /* B1 = -0.166901 */
9149                  28847,         /* B0 = 0.880371 */
9150                  31225,         /* A1 = -1.905823 */
9151                  -32696,        /* A2 = 0.997803 */
9152                  462,           /* B2 = 0.014108 */
9153                  -442,          /* B1 = -0.027019 */
9154                  462,           /* B0 = 0.014108 */
9155                  5,             /* Internal filter scaling */
9156                  159,           /* Minimum in-band energy threshold */
9157                  21,            /* 21/32 in-band to broad-band ratio */
9158                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9159         },
9160         {                       /* f400_425[] */
9161                 30836,          /* A1 = 1.882141 */
9162                  -32296,        /* A2 = -0.985596 */
9163                  -324,          /* B2 = -0.009903 */
9164                  0,             /* B1 = 0 */
9165                  324,           /* B0 = 0.009903 */
9166                  30825,         /* A1 = 1.881409 */
9167                  -32570,        /* A2 = -0.993958 */
9168                  16847,         /* B2 = 0.51416 */
9169                  -15792,        /* B1 = -0.963898 */
9170                  16847,         /* B0 = 0.51416 */
9171                  31106,         /* A1 = 1.89856 */
9172                  -32584,        /* A2 = -0.994415 */
9173                  9579,          /* B2 = 0.292328 */
9174                  -9164,         /* B1 = -0.559357 */
9175                  9579,          /* B0 = 0.292328 */
9176                  7,             /* Internal filter scaling */
9177                  159,           /* Minimum in-band energy threshold */
9178                  21,            /* 21/32 in-band to broad-band ratio */
9179                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9180         },
9181         {                       /* f400_440[] */
9182                 30702,          /* A1 = 1.873962 */
9183                  -32134,        /* A2 = -0.980682 */
9184                  -517,          /* B2 = -0.015793 */
9185                  0,             /* B1 = 0 */
9186                  517,           /* B0 = 0.015793 */
9187                  30676,         /* A1 = 1.872375 */
9188                  -32520,        /* A2 = -0.992462 */
9189                  8144,          /* B2 = 0.24855 */
9190                  -7596,         /* B1 = -0.463684 */
9191                  8144,          /* B0 = 0.24855 */
9192                  31084,         /* A1 = 1.897217 */
9193                  -32547,        /* A2 = -0.993256 */
9194                  22713,         /* B2 = 0.693176 */
9195                  -21734,        /* B1 = -1.326599 */
9196                  22713,         /* B0 = 0.693176 */
9197                  7,             /* Internal filter scaling */
9198                  159,           /* Minimum in-band energy threshold */
9199                  21,            /* 21/32 in-band to broad-band ratio */
9200                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9201         },
9202         {                       /* f400_450[] */
9203                 30613,          /* A1 = 1.86853 */
9204                  -32031,        /* A2 = -0.977509 */
9205                  -618,          /* B2 = -0.018866 */
9206                  0,             /* B1 = 0 */
9207                  618,           /* B0 = 0.018866 */
9208                  30577,         /* A1 = 1.866272 */
9209                  -32491,        /* A2 = -0.991577 */
9210                  9612,          /* B2 = 0.293335 */
9211                  -8935,         /* B1 = -0.54541 */
9212                  9612,          /* B0 = 0.293335 */
9213                  31071,         /* A1 = 1.896484 */
9214                  -32524,        /* A2 = -0.992584 */
9215                  21596,         /* B2 = 0.659058 */
9216                  -20667,        /* B1 = -1.261414 */
9217                  21596,         /* B0 = 0.659058 */
9218                  7,             /* Internal filter scaling */
9219                  159,           /* Minimum in-band energy threshold */
9220                  21,            /* 21/32 in-band to broad-band ratio */
9221                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9222         },
9223         {                       /* f420 */
9224                 30914,          /* A1 = -1.886841 */
9225                  -32584,        /* A2 = 0.994385 */
9226                  -426,          /* B2 = -0.013020 */
9227                  0,             /* B1 = 0.000000 */
9228                  426,           /* B0 = 0.013020 */
9229                  30914,         /* A1 = -1.886841 */
9230                  -32679,        /* A2 = 0.997314 */
9231                  17520,         /* B2 = 0.534668 */
9232                  -16471,        /* B1 = -1.005310 */
9233                  17520,         /* B0 = 0.534668 */
9234                  31004,         /* A1 = -1.892334 */
9235                  -32683,        /* A2 = 0.997406 */
9236                  819,           /* B2 = 0.025023 */
9237                  -780,          /* B1 = -0.047619 */
9238                  819,           /* B0 = 0.025023 */
9239                  5,             /* Internal filter scaling */
9240                  159,           /* Minimum in-band energy threshold */
9241                  21,            /* 21/32 in-band to broad-band ratio */
9242                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9243         },
9244 #if 0
9245         {                       /* f425 */
9246                 30881,          /* A1 = -1.884827 */
9247                  -32603,        /* A2 = 0.994965 */
9248                  -496,          /* B2 = -0.015144 */
9249                  0,             /* B1 = 0.000000 */
9250                  496,           /* B0 = 0.015144 */
9251                  30880,         /* A1 = -1.884766 */
9252                  -32692,        /* A2 = 0.997711 */
9253                  24767,         /* B2 = 0.755859 */
9254                  -23290,        /* B1 = -1.421509 */
9255                  24767,         /* B0 = 0.755859 */
9256                  30967,         /* A1 = -1.890076 */
9257                  -32694,        /* A2 = 0.997772 */
9258                  728,           /* B2 = 0.022232 */
9259                  -691,          /* B1 = -0.042194 */
9260                  728,           /* B0 = 0.022232 */
9261                  5,             /* Internal filter scaling */
9262                  159,           /* Minimum in-band energy threshold */
9263                  21,            /* 21/32 in-band to broad-band ratio */
9264                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9265         },
9266 #else
9267         {
9268                 30850,
9269                 -32534,
9270                 -504,
9271                 0,
9272                 504,
9273                 30831,
9274                 -32669,
9275                 24303,
9276                 -22080,
9277                 24303,
9278                 30994,
9279                 -32673,
9280                 1905,
9281                 -1811,
9282                 1905,
9283                 5,
9284                 129,
9285                 17,
9286                 0xff5
9287         },
9288 #endif
9289         {                       /* f425_450[] */
9290                 30646,          /* A1 = 1.870544 */
9291                  -32327,        /* A2 = -0.986572 */
9292                  -287,          /* B2 = -0.008769 */
9293                  0,             /* B1 = 0 */
9294                  287,           /* B0 = 0.008769 */
9295                  30627,         /* A1 = 1.869324 */
9296                  -32607,        /* A2 = -0.995087 */
9297                  13269,         /* B2 = 0.404968 */
9298                  -12376,        /* B1 = -0.755432 */
9299                  13269,         /* B0 = 0.404968 */
9300                  30924,         /* A1 = 1.887512 */
9301                  -32619,        /* A2 = -0.995453 */
9302                  19950,         /* B2 = 0.608826 */
9303                  -18940,        /* B1 = -1.156006 */
9304                  19950,         /* B0 = 0.608826 */
9305                  7,             /* Internal filter scaling */
9306                  159,           /* Minimum in-band energy threshold */
9307                  21,            /* 21/32 in-band to broad-band ratio */
9308                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9309         },
9310         {                       /* f425_475[] */
9311                 30396,          /* A1 = 1.855225 */
9312                  -32014,        /* A2 = -0.97699 */
9313                  -395,          /* B2 = -0.012055 */
9314                  0,             /* B1 = 0 */
9315                  395,           /* B0 = 0.012055 */
9316                  30343,         /* A1 = 1.85199 */
9317                  -32482,        /* A2 = -0.991302 */
9318                  17823,         /* B2 = 0.543945 */
9319                  -16431,        /* B1 = -1.002869 */
9320                  17823,         /* B0 = 0.543945 */
9321                  30872,         /* A1 = 1.884338 */
9322                  -32516,        /* A2 = -0.99231 */
9323                  18124,         /* B2 = 0.553101 */
9324                  -17246,        /* B1 = -1.052673 */
9325                  18124,         /* B0 = 0.553101 */
9326                  7,             /* Internal filter scaling */
9327                  159,           /* Minimum in-band energy threshold */
9328                  21,            /* 21/32 in-band to broad-band ratio */
9329                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9330         },
9331         {                       /* f435 */
9332                 30796,          /* A1 = -1.879639 */
9333                  -32603,        /* A2 = 0.994965 */
9334                  -254,          /* B2 = -0.007762 */
9335                  0,             /* B1 = 0.000000 */
9336                  254,           /* B0 = 0.007762 */
9337                  30793,         /* A1 = -1.879456 */
9338                  -32692,        /* A2 = 0.997711 */
9339                  18934,         /* B2 = 0.577820 */
9340                  -17751,        /* B1 = -1.083496 */
9341                  18934,         /* B0 = 0.577820 */
9342                  30882,         /* A1 = -1.884888 */
9343                  -32694,        /* A2 = 0.997772 */
9344                  1858,          /* B2 = 0.056713 */
9345                  -1758,         /* B1 = -0.107357 */
9346                  1858,          /* B0 = 0.056713 */
9347                  5,             /* Internal filter scaling */
9348                  159,           /* Minimum in-band energy threshold */
9349                  21,            /* 21/32 in-band to broad-band ratio */
9350                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9351         },
9352         {                       /* f440_450[] */
9353                 30641,          /* A1 = 1.870239 */
9354                  -32458,        /* A2 = -0.99057 */
9355                  -155,          /* B2 = -0.004735 */
9356                  0,             /* B1 = 0 */
9357                  155,           /* B0 = 0.004735 */
9358                  30631,         /* A1 = 1.869568 */
9359                  -32630,        /* A2 = -0.995789 */
9360                  11453,         /* B2 = 0.349548 */
9361                  -10666,        /* B1 = -0.651001 */
9362                  11453,         /* B0 = 0.349548 */
9363                  30810,         /* A1 = 1.880554 */
9364                  -32634,        /* A2 = -0.995941 */
9365                  12237,         /* B2 = 0.373474 */
9366                  -11588,        /* B1 = -0.707336 */
9367                  12237,         /* B0 = 0.373474 */
9368                  7,             /* Internal filter scaling */
9369                  159,           /* Minimum in-band energy threshold */
9370                  21,            /* 21/32 in-band to broad-band ratio */
9371                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9372         },
9373         {                       /* f440_480[] */
9374                 30367,          /* A1 = 1.853455 */
9375                  -32147,        /* A2 = -0.981079 */
9376                  -495,          /* B2 = -0.015113 */
9377                  0,             /* B1 = 0 */
9378                  495,           /* B0 = 0.015113 */
9379                  30322,         /* A1 = 1.850769 */
9380                  -32543,        /* A2 = -0.993134 */
9381                  10031,         /* B2 = 0.306152 */
9382                  -9252,         /* B1 = -0.564728 */
9383                  10031,         /* B0 = 0.306152 */
9384                  30770,         /* A1 = 1.878052 */
9385                  -32563,        /* A2 = -0.993774 */
9386                  22674,         /* B2 = 0.691956 */
9387                  -21465,        /* B1 = -1.31012 */
9388                  22674,         /* B0 = 0.691956 */
9389                  7,             /* Internal filter scaling */
9390                  159,           /* Minimum in-band energy threshold */
9391                  21,            /* 21/32 in-band to broad-band ratio */
9392                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9393         },
9394         {                       /* f445 */
9395                 30709,          /* A1 = -1.874329 */
9396                  -32603,        /* A2 = 0.994965 */
9397                  -83,           /* B2 = -0.002545 */
9398                  0,             /* B1 = 0.000000 */
9399                  83,            /* B0 = 0.002545 */
9400                  30704,         /* A1 = -1.874084 */
9401                  -32692,        /* A2 = 0.997711 */
9402                  10641,         /* B2 = 0.324738 */
9403                  -9947,         /* B1 = -0.607147 */
9404                  10641,         /* B0 = 0.324738 */
9405                  30796,         /* A1 = -1.879639 */
9406                  -32694,        /* A2 = 0.997772 */
9407                  10079,         /* B2 = 0.307587 */
9408                  9513,          /* B1 = 0.580688 */
9409                  10079,         /* B0 = 0.307587 */
9410                  5,             /* Internal filter scaling */
9411                  159,           /* Minimum in-band energy threshold */
9412                  21,            /* 21/32 in-band to broad-band ratio */
9413                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9414         },
9415         {                       /* f450 */
9416                 30664,          /* A1 = -1.871643 */
9417                  -32603,        /* A2 = 0.994965 */
9418                  -164,          /* B2 = -0.005029 */
9419                  0,             /* B1 = 0.000000 */
9420                  164,           /* B0 = 0.005029 */
9421                  30661,         /* A1 = -1.871399 */
9422                  -32692,        /* A2 = 0.997711 */
9423                  15294,         /* B2 = 0.466736 */
9424                  -14275,        /* B1 = -0.871307 */
9425                  15294,         /* B0 = 0.466736 */
9426                  30751,         /* A1 = -1.876953 */
9427                  -32694,        /* A2 = 0.997772 */
9428                  3548,          /* B2 = 0.108284 */
9429                  -3344,         /* B1 = -0.204155 */
9430                  3548,          /* B0 = 0.108284 */
9431                  5,             /* Internal filter scaling */
9432                  159,           /* Minimum in-band energy threshold */
9433                  21,            /* 21/32 in-band to broad-band ratio */
9434                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9435         },
9436         {                       /* f452 */
9437                 30653,          /* A1 = -1.870911 */
9438                  -32615,        /* A2 = 0.995361 */
9439                  -209,          /* B2 = -0.006382 */
9440                  0,             /* B1 = 0.000000 */
9441                  209,           /* B0 = 0.006382 */
9442                  30647,         /* A1 = -1.870605 */
9443                  -32702,        /* A2 = 0.997986 */
9444                  18971,         /* B2 = 0.578979 */
9445                  -17716,        /* B1 = -1.081299 */
9446                  18971,         /* B0 = 0.578979 */
9447                  30738,         /* A1 = -1.876099 */
9448                  -32702,        /* A2 = 0.998016 */
9449                  2967,          /* B2 = 0.090561 */
9450                  -2793,         /* B1 = -0.170502 */
9451                  2967,          /* B0 = 0.090561 */
9452                  5,             /* Internal filter scaling */
9453                  159,           /* Minimum in-band energy threshold */
9454                  21,            /* 21/32 in-band to broad-band ratio */
9455                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9456         },
9457         {                       /* f475 */
9458                 30437,          /* A1 = -1.857727 */
9459                  -32603,        /* A2 = 0.994965 */
9460                  -264,          /* B2 = -0.008062 */
9461                  0,             /* B1 = 0.000000 */
9462                  264,           /* B0 = 0.008062 */
9463                  30430,         /* A1 = -1.857300 */
9464                  -32692,        /* A2 = 0.997711 */
9465                  21681,         /* B2 = 0.661682 */
9466                  -20082,        /* B1 = -1.225708 */
9467                  21681,         /* B0 = 0.661682 */
9468                  30526,         /* A1 = -1.863220 */
9469                  -32694,        /* A2 = 0.997742 */
9470                  1559,          /* B2 = 0.047600 */
9471                  -1459,         /* B1 = -0.089096 */
9472                  1559,          /* B0 = 0.047600 */
9473                  5,             /* Internal filter scaling */
9474                  159,           /* Minimum in-band energy threshold */
9475                  21,            /* 21/32 in-band to broad-band ratio */
9476                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9477         },
9478         {                       /* f480_620[] */
9479                 28975,          /* A1 = 1.768494 */
9480                  -30955,        /* A2 = -0.944672 */
9481                  -1026,         /* B2 = -0.03133 */
9482                  0,             /* B1 = 0 */
9483                  1026,          /* B0 = 0.03133 */
9484                  28613,         /* A1 = 1.746399 */
9485                  -32089,        /* A2 = -0.979309 */
9486                  14214,         /* B2 = 0.433807 */
9487                  -12202,        /* B1 = -0.744812 */
9488                  14214,         /* B0 = 0.433807 */
9489                  30243,         /* A1 = 1.845947 */
9490                  -32238,        /* A2 = -0.983856 */
9491                  24825,         /* B2 = 0.757629 */
9492                  -23402,        /* B1 = -1.428345 */
9493                  24825,         /* B0 = 0.757629 */
9494                  7,             /* Internal filter scaling */
9495                  159,           /* Minimum in-band energy threshold */
9496                  21,            /* 21/32 in-band to broad-band ratio */
9497                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9498         },
9499         {                       /* f494 */
9500                 30257,          /* A1 = -1.846741 */
9501                  -32605,        /* A2 = 0.995056 */
9502                  -249,          /* B2 = -0.007625 */
9503                  0,             /* B1 = 0.000000 */
9504                  249,           /* B0 = 0.007625 */
9505                  30247,         /* A1 = -1.846191 */
9506                  -32694,        /* A2 = 0.997772 */
9507                  18088,         /* B2 = 0.552002 */
9508                  -16652,        /* B1 = -1.016418 */
9509                  18088,         /* B0 = 0.552002 */
9510                  30348,         /* A1 = -1.852295 */
9511                  -32696,        /* A2 = 0.997803 */
9512                  2099,          /* B2 = 0.064064 */
9513                  -1953,         /* B1 = -0.119202 */
9514                  2099,          /* B0 = 0.064064 */
9515                  5,             /* Internal filter scaling */
9516                  159,           /* Minimum in-band energy threshold */
9517                  21,            /* 21/32 in-band to broad-band ratio */
9518                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9519         },
9520         {                       /* f500 */
9521                 30202,          /* A1 = -1.843431 */
9522                  -32624,        /* A2 = 0.995622 */
9523                  -413,          /* B2 = -0.012622 */
9524                  0,             /* B1 = 0.000000 */
9525                  413,           /* B0 = 0.012622 */
9526                  30191,         /* A1 = -1.842721 */
9527                  -32714,        /* A2 = 0.998364 */
9528                  25954,         /* B2 = 0.792057 */
9529                  -23890,        /* B1 = -1.458131 */
9530                  25954,         /* B0 = 0.792057 */
9531                  30296,         /* A1 = -1.849172 */
9532                  -32715,        /* A2 = 0.998397 */
9533                  2007,          /* B2 = 0.061264 */
9534                  -1860,         /* B1 = -0.113568 */
9535                  2007,          /* B0 = 0.061264 */
9536                  5,             /* Internal filter scaling */
9537                  159,           /* Minimum in-band energy threshold */
9538                  21,            /* 21/32 in-band to broad-band ratio */
9539                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9540         },
9541         {                       /* f520 */
9542                 30001,          /* A1 = -1.831116 */
9543                  -32613,        /* A2 = 0.995270 */
9544                  -155,          /* B2 = -0.004750 */
9545                  0,             /* B1 = 0.000000 */
9546                  155,           /* B0 = 0.004750 */
9547                  29985,         /* A1 = -1.830200 */
9548                  -32710,        /* A2 = 0.998260 */
9549                  6584,          /* B2 = 0.200928 */
9550                  -6018,         /* B1 = -0.367355 */
9551                  6584,          /* B0 = 0.200928 */
9552                  30105,         /* A1 = -1.837524 */
9553                  -32712,        /* A2 = 0.998291 */
9554                  23812,         /* B2 = 0.726685 */
9555                  -21936,        /* B1 = -1.338928 */
9556                  23812,         /* B0 = 0.726685 */
9557                  5,             /* Internal filter scaling */
9558                  159,           /* Minimum in-band energy threshold */
9559                  21,            /* 21/32 in-band to broad-band ratio */
9560                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9561         },
9562         {                       /* f523 */
9563                 29964,          /* A1 = -1.828918 */
9564                  -32601,        /* A2 = 0.994904 */
9565                  -101,          /* B2 = -0.003110 */
9566                  0,             /* B1 = 0.000000 */
9567                  101,           /* B0 = 0.003110 */
9568                  29949,         /* A1 = -1.827942 */
9569                  -32700,        /* A2 = 0.997925 */
9570                  11041,         /* B2 = 0.336975 */
9571                  -10075,        /* B1 = -0.614960 */
9572                  11041,         /* B0 = 0.336975 */
9573                  30070,         /* A1 = -1.835388 */
9574                  -32702,        /* A2 = 0.997986 */
9575                  16762,         /* B2 = 0.511536 */
9576                  -15437,        /* B1 = -0.942230 */
9577                  16762,         /* B0 = 0.511536 */
9578                  5,             /* Internal filter scaling */
9579                  159,           /* Minimum in-band energy threshold */
9580                  21,            /* 21/32 in-band to broad-band ratio */
9581                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9582         },
9583         {                       /* f525 */
9584                 29936,          /* A1 = -1.827209 */
9585                  -32584,        /* A2 = 0.994415 */
9586                  -91,           /* B2 = -0.002806 */
9587                  0,             /* B1 = 0.000000 */
9588                  91,            /* B0 = 0.002806 */
9589                  29921,         /* A1 = -1.826233 */
9590                  -32688,        /* A2 = 0.997559 */
9591                  11449,         /* B2 = 0.349396 */
9592                  -10426,        /* B1 = -0.636383 */
9593                  11449,         /* B0 = 0.349396 */
9594                  30045,         /* A1 = -1.833862 */
9595                  -32688,        /* A2 = 0.997589 */
9596                  13055,         /* B2 = 0.398407 */
9597                  -12028,        /* B1 = -0.734161 */
9598                  13055,         /* B0 = 0.398407 */
9599                  5,             /* Internal filter scaling */
9600                  159,           /* Minimum in-band energy threshold */
9601                  21,            /* 21/32 in-band to broad-band ratio */
9602                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9603         },
9604         {                       /* f540_660[] */
9605                 28499,          /* A1 = 1.739441 */
9606                  -31129,        /* A2 = -0.949982 */
9607                  -849,          /* B2 = -0.025922 */
9608                  0,             /* B1 = 0 */
9609                  849,           /* B0 = 0.025922 */
9610                  28128,         /* A1 = 1.716797 */
9611                  -32130,        /* A2 = -0.98056 */
9612                  14556,         /* B2 = 0.444214 */
9613                  -12251,        /* B1 = -0.747772 */
9614                  14556,         /* B0 = 0.444244 */
9615                  29667,         /* A1 = 1.81073 */
9616                  -32244,        /* A2 = -0.984039 */
9617                  23038,         /* B2 = 0.703064 */
9618                  -21358,        /* B1 = -1.303589 */
9619                  23040,         /* B0 = 0.703125 */
9620                  7,             /* Internal filter scaling */
9621                  159,           /* Minimum in-band energy threshold */
9622                  21,            /* 21/32 in-band to broad-band ratio */
9623                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9624         },
9625         {                       /* f587 */
9626                 29271,          /* A1 = -1.786560 */
9627                  -32599,        /* A2 = 0.994873 */
9628                  -490,          /* B2 = -0.014957 */
9629                  0,             /* B1 = 0.000000 */
9630                  490,           /* B0 = 0.014957 */
9631                  29246,         /* A1 = -1.785095 */
9632                  -32700,        /* A2 = 0.997925 */
9633                  28961,         /* B2 = 0.883850 */
9634                  -25796,        /* B1 = -1.574463 */
9635                  28961,         /* B0 = 0.883850 */
9636                  29383,         /* A1 = -1.793396 */
9637                  -32700,        /* A2 = 0.997955 */
9638                  1299,          /* B2 = 0.039650 */
9639                  -1169,         /* B1 = -0.071396 */
9640                  1299,          /* B0 = 0.039650 */
9641                  5,             /* Internal filter scaling */
9642                  159,           /* Minimum in-band energy threshold */
9643                  21,            /* 21/32 in-band to broad-band ratio */
9644                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9645         },
9646         {                       /* f590 */
9647                 29230,          /* A1 = -1.784058 */
9648                  -32584,        /* A2 = 0.994415 */
9649                  -418,          /* B2 = -0.012757 */
9650                  0,             /* B1 = 0.000000 */
9651                  418,           /* B0 = 0.012757 */
9652                  29206,         /* A1 = -1.782593 */
9653                  -32688,        /* A2 = 0.997559 */
9654                  36556,         /* B2 = 1.115601 */
9655                  -32478,        /* B1 = -1.982300 */
9656                  36556,         /* B0 = 1.115601 */
9657                  29345,         /* A1 = -1.791077 */
9658                  -32688,        /* A2 = 0.997589 */
9659                  897,           /* B2 = 0.027397 */
9660                  -808,          /* B1 = -0.049334 */
9661                  897,           /* B0 = 0.027397 */
9662                  5,             /* Internal filter scaling */
9663                  159,           /* Minimum in-band energy threshold */
9664                  21,            /* 21/32 in-band to broad-band ratio */
9665                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9666         },
9667         {                       /* f600 */
9668                 29116,          /* A1 = -1.777100 */
9669                  -32603,        /* A2 = 0.994965 */
9670                  -165,          /* B2 = -0.005039 */
9671                  0,             /* B1 = 0.000000 */
9672                  165,           /* B0 = 0.005039 */
9673                  29089,         /* A1 = -1.775452 */
9674                  -32708,        /* A2 = 0.998199 */
9675                  6963,          /* B2 = 0.212494 */
9676                  -6172,         /* B1 = -0.376770 */
9677                  6963,          /* B0 = 0.212494 */
9678                  29237,         /* A1 = -1.784485 */
9679                  -32710,        /* A2 = 0.998230 */
9680                  24197,         /* B2 = 0.738464 */
9681                  -21657,        /* B1 = -1.321899 */
9682                  24197,         /* B0 = 0.738464 */
9683                  5,             /* Internal filter scaling */
9684                  159,           /* Minimum in-band energy threshold */
9685                  21,            /* 21/32 in-band to broad-band ratio */
9686                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9687         },
9688         {                       /* f660 */
9689                 28376,          /* A1 = -1.731934 */
9690                  -32567,        /* A2 = 0.993896 */
9691                  -363,          /* B2 = -0.011102 */
9692                  0,             /* B1 = 0.000000 */
9693                  363,           /* B0 = 0.011102 */
9694                  28337,         /* A1 = -1.729614 */
9695                  -32683,        /* A2 = 0.997434 */
9696                  21766,         /* B2 = 0.664246 */
9697                  -18761,        /* B1 = -1.145081 */
9698                  21766,         /* B0 = 0.664246 */
9699                  28513,         /* A1 = -1.740356 */
9700                  -32686,        /* A2 = 0.997498 */
9701                  2509,          /* B2 = 0.076584 */
9702                  -2196,         /* B1 = -0.134041 */
9703                  2509,          /* B0 = 0.076584 */
9704                  5,             /* Internal filter scaling */
9705                  159,           /* Minimum in-band energy threshold */
9706                  21,            /* 21/32 in-band to broad-band ratio */
9707                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9708         },
9709         {                       /* f700 */
9710                 27844,          /* A1 = -1.699463 */
9711                  -32563,        /* A2 = 0.993744 */
9712                  -366,          /* B2 = -0.011187 */
9713                  0,             /* B1 = 0.000000 */
9714                  366,           /* B0 = 0.011187 */
9715                  27797,         /* A1 = -1.696655 */
9716                  -32686,        /* A2 = 0.997498 */
9717                  22748,         /* B2 = 0.694214 */
9718                  -19235,        /* B1 = -1.174072 */
9719                  22748,         /* B0 = 0.694214 */
9720                  27995,         /* A1 = -1.708740 */
9721                  -32688,        /* A2 = 0.997559 */
9722                  2964,          /* B2 = 0.090477 */
9723                  -2546,         /* B1 = -0.155449 */
9724                  2964,          /* B0 = 0.090477 */
9725                  5,             /* Internal filter scaling */
9726                  159,           /* Minimum in-band energy threshold */
9727                  21,            /* 21/32 in-band to broad-band ratio */
9728                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9729         },
9730         {                       /* f740 */
9731                 27297,          /* A1 = -1.666077 */
9732                  -32551,        /* A2 = 0.993408 */
9733                  -345,          /* B2 = -0.010540 */
9734                  0,             /* B1 = 0.000000 */
9735                  345,           /* B0 = 0.010540 */
9736                  27240,         /* A1 = -1.662598 */
9737                  -32683,        /* A2 = 0.997406 */
9738                  22560,         /* B2 = 0.688477 */
9739                  -18688,        /* B1 = -1.140625 */
9740                  22560,         /* B0 = 0.688477 */
9741                  27461,         /* A1 = -1.676147 */
9742                  -32684,        /* A2 = 0.997467 */
9743                  3541,          /* B2 = 0.108086 */
9744                  -2985,         /* B1 = -0.182220 */
9745                  3541,          /* B0 = 0.108086 */
9746                  5,             /* Internal filter scaling */
9747                  159,           /* Minimum in-band energy threshold */
9748                  21,            /* 21/32 in-band to broad-band ratio */
9749                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9750         },
9751         {                       /* f750 */
9752                 27155,          /* A1 = -1.657410 */
9753                  -32551,        /* A2 = 0.993408 */
9754                  -462,          /* B2 = -0.014117 */
9755                  0,             /* B1 = 0.000000 */
9756                  462,           /* B0 = 0.014117 */
9757                  27097,         /* A1 = -1.653870 */
9758                  -32683,        /* A2 = 0.997406 */
9759                  32495,         /* B2 = 0.991699 */
9760                  -26776,        /* B1 = -1.634338 */
9761                  32495,         /* B0 = 0.991699 */
9762                  27321,         /* A1 = -1.667542 */
9763                  -32684,        /* A2 = 0.997467 */
9764                  1835,          /* B2 = 0.056007 */
9765                  -1539,         /* B1 = -0.093948 */
9766                  1835,          /* B0 = 0.056007 */
9767                  5,             /* Internal filter scaling */
9768                  159,           /* Minimum in-band energy threshold */
9769                  21,            /* 21/32 in-band to broad-band ratio */
9770                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9771         },
9772         {                       /* f750_1450[] */
9773                 19298,          /* A1 = 1.177917 */
9774                  -24471,        /* A2 = -0.746796 */
9775                  -4152,         /* B2 = -0.126709 */
9776                  0,             /* B1 = 0 */
9777                  4152,          /* B0 = 0.126709 */
9778                  12902,         /* A1 = 0.787476 */
9779                  -29091,        /* A2 = -0.887817 */
9780                  12491,         /* B2 = 0.38121 */
9781                  -1794,         /* B1 = -0.109528 */
9782                  12494,         /* B0 = 0.381317 */
9783                  26291,         /* A1 = 1.604736 */
9784                  -30470,        /* A2 = -0.929901 */
9785                  28859,         /* B2 = 0.880737 */
9786                  -26084,        /* B1 = -1.592102 */
9787                  28861,         /* B0 = 0.880798 */
9788                  7,             /* Internal filter scaling */
9789                  159,           /* Minimum in-band energy threshold */
9790                  21,            /* 21/32 in-band to broad-band ratio */
9791                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9792         },
9793         {                       /* f770 */
9794                 26867,          /* A1 = -1.639832 */
9795                  -32551,        /* A2 = 0.993408 */
9796                  -123,          /* B2 = -0.003755 */
9797                  0,             /* B1 = 0.000000 */
9798                  123,           /* B0 = 0.003755 */
9799                  26805,         /* A1 = -1.636108 */
9800                  -32683,        /* A2 = 0.997406 */
9801                  17297,         /* B2 = 0.527863 */
9802                  -14096,        /* B1 = -0.860382 */
9803                  17297,         /* B0 = 0.527863 */
9804                  27034,         /* A1 = -1.650085 */
9805                  -32684,        /* A2 = 0.997467 */
9806                  12958,         /* B2 = 0.395477 */
9807                  -10756,        /* B1 = -0.656525 */
9808                  12958,         /* B0 = 0.395477 */
9809                  5,             /* Internal filter scaling */
9810                  159,           /* Minimum in-band energy threshold */
9811                  21,            /* 21/32 in-band to broad-band ratio */
9812                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9813         },
9814         {                       /* f800 */
9815                 26413,          /* A1 = -1.612122 */
9816                  -32547,        /* A2 = 0.993286 */
9817                  -223,          /* B2 = -0.006825 */
9818                  0,             /* B1 = 0.000000 */
9819                  223,           /* B0 = 0.006825 */
9820                  26342,         /* A1 = -1.607849 */
9821                  -32686,        /* A2 = 0.997498 */
9822                  6391,          /* B2 = 0.195053 */
9823                  -5120,         /* B1 = -0.312531 */
9824                  6391,          /* B0 = 0.195053 */
9825                  26593,         /* A1 = -1.623108 */
9826                  -32688,        /* A2 = 0.997559 */
9827                  23681,         /* B2 = 0.722717 */
9828                  -19328,        /* B1 = -1.179688 */
9829                  23681,         /* B0 = 0.722717 */
9830                  5,             /* Internal filter scaling */
9831                  159,           /* Minimum in-band energy threshold */
9832                  21,            /* 21/32 in-band to broad-band ratio */
9833                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9834         },
9835         {                       /* f816 */
9836                 26168,          /* A1 = -1.597209 */
9837                  -32528,        /* A2 = 0.992706 */
9838                  -235,          /* B2 = -0.007182 */
9839                  0,             /* B1 = 0.000000 */
9840                  235,           /* B0 = 0.007182 */
9841                  26092,         /* A1 = -1.592590 */
9842                  -32675,        /* A2 = 0.997192 */
9843                  20823,         /* B2 = 0.635498 */
9844                  -16510,        /* B1 = -1.007751 */
9845                  20823,         /* B0 = 0.635498 */
9846                  26363,         /* A1 = -1.609070 */
9847                  -32677,        /* A2 = 0.997253 */
9848                  6739,          /* B2 = 0.205688 */
9849                  -5459,         /* B1 = -0.333206 */
9850                  6739,          /* B0 = 0.205688 */
9851                  5,             /* Internal filter scaling */
9852                  159,           /* Minimum in-band energy threshold */
9853                  21,            /* 21/32 in-band to broad-band ratio */
9854                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9855         },
9856         {                       /* f850 */
9857                 25641,          /* A1 = -1.565063 */
9858                  -32536,        /* A2 = 0.992950 */
9859                  -121,          /* B2 = -0.003707 */
9860                  0,             /* B1 = 0.000000 */
9861                  121,           /* B0 = 0.003707 */
9862                  25560,         /* A1 = -1.560059 */
9863                  -32684,        /* A2 = 0.997437 */
9864                  18341,         /* B2 = 0.559753 */
9865                  -14252,        /* B1 = -0.869904 */
9866                  18341,         /* B0 = 0.559753 */
9867                  25837,         /* A1 = -1.577026 */
9868                  -32684,        /* A2 = 0.997467 */
9869                  16679,         /* B2 = 0.509003 */
9870                  -13232,        /* B1 = -0.807648 */
9871                  16679,         /* B0 = 0.509003 */
9872                  5,             /* Internal filter scaling */
9873                  159,           /* Minimum in-band energy threshold */
9874                  21,            /* 21/32 in-band to broad-band ratio */
9875                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9876         },
9877         {                       /* f857_1645[] */
9878                 16415,          /* A1 = 1.001953 */
9879                  -23669,        /* A2 = -0.722321 */
9880                  -4549,         /* B2 = -0.138847 */
9881                  0,             /* B1 = 0 */
9882                  4549,          /* B0 = 0.138847 */
9883                  8456,          /* A1 = 0.516174 */
9884                  -28996,        /* A2 = -0.884918 */
9885                  13753,         /* B2 = 0.419724 */
9886                  -12,           /* B1 = -0.000763 */
9887                  13757,         /* B0 = 0.419846 */
9888                  24632,         /* A1 = 1.503418 */
9889                  -30271,        /* A2 = -0.923828 */
9890                  29070,         /* B2 = 0.887146 */
9891                  -25265,        /* B1 = -1.542114 */
9892                  29073,         /* B0 = 0.887268 */
9893                  7,             /* Internal filter scaling */
9894                  159,           /* Minimum in-band energy threshold */
9895                  21,            /* 21/32 in-band to broad-band ratio */
9896                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9897         },
9898         {                       /* f900 */
9899                 24806,          /* A1 = -1.514099 */
9900                  -32501,        /* A2 = 0.991852 */
9901                  -326,          /* B2 = -0.009969 */
9902                  0,             /* B1 = 0.000000 */
9903                  326,           /* B0 = 0.009969 */
9904                  24709,         /* A1 = -1.508118 */
9905                  -32659,        /* A2 = 0.996674 */
9906                  20277,         /* B2 = 0.618835 */
9907                  -15182,        /* B1 = -0.926636 */
9908                  20277,         /* B0 = 0.618835 */
9909                  25022,         /* A1 = -1.527222 */
9910                  -32661,        /* A2 = 0.996735 */
9911                  4320,          /* B2 = 0.131836 */
9912                  -3331,         /* B1 = -0.203339 */
9913                  4320,          /* B0 = 0.131836 */
9914                  5,             /* Internal filter scaling */
9915                  159,           /* Minimum in-band energy threshold */
9916                  21,            /* 21/32 in-band to broad-band ratio */
9917                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9918         },
9919         {                       /* f900_1300[] */
9920                 19776,          /* A1 = 1.207092 */
9921                  -27437,        /* A2 = -0.837341 */
9922                  -2666,         /* B2 = -0.081371 */
9923                  0,             /* B1 = 0 */
9924                  2666,          /* B0 = 0.081371 */
9925                  16302,         /* A1 = 0.995026 */
9926                  -30354,        /* A2 = -0.926361 */
9927                  10389,         /* B2 = 0.317062 */
9928                  -3327,         /* B1 = -0.203064 */
9929                  10389,         /* B0 = 0.317062 */
9930                  24299,         /* A1 = 1.483154 */
9931                  -30930,        /* A2 = -0.943909 */
9932                  25016,         /* B2 = 0.763428 */
9933                  -21171,        /* B1 = -1.292236 */
9934                  25016,         /* B0 = 0.763428 */
9935                  7,             /* Internal filter scaling */
9936                  159,           /* Minimum in-band energy threshold */
9937                  21,            /* 21/32 in-band to broad-band ratio */
9938                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9939         },
9940         {                       /* f935_1215[] */
9941                 20554,          /* A1 = 1.254517 */
9942                  -28764,        /* A2 = -0.877838 */
9943                  -2048,         /* B2 = -0.062515 */
9944                  0,             /* B1 = 0 */
9945                  2048,          /* B0 = 0.062515 */
9946                  18209,         /* A1 = 1.11145 */
9947                  -30951,        /* A2 = -0.94458 */
9948                  9390,          /* B2 = 0.286575 */
9949                  -3955,         /* B1 = -0.241455 */
9950                  9390,          /* B0 = 0.286575 */
9951                  23902,         /* A1 = 1.458923 */
9952                  -31286,        /* A2 = -0.954803 */
9953                  23252,         /* B2 = 0.709595 */
9954                  -19132,        /* B1 = -1.167725 */
9955                  23252,         /* B0 = 0.709595 */
9956                  7,             /* Internal filter scaling */
9957                  159,           /* Minimum in-band energy threshold */
9958                  21,            /* 21/32 in-band to broad-band ratio */
9959                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9960         },
9961         {                       /* f941_1477[] */
9962                 17543,          /* A1 = 1.07074 */
9963                  -26220,        /* A2 = -0.800201 */
9964                  -3298,         /* B2 = -0.100647 */
9965                  0,             /* B1 = 0 */
9966                  3298,          /* B0 = 0.100647 */
9967                  12423,         /* A1 = 0.75827 */
9968                  -30036,        /* A2 = -0.916626 */
9969                  12651,         /* B2 = 0.386078 */
9970                  -2444,         /* B1 = -0.14917 */
9971                  12653,         /* B0 = 0.386154 */
9972                  23518,         /* A1 = 1.435425 */
9973                  -30745,        /* A2 = -0.938293 */
9974                  27282,         /* B2 = 0.832581 */
9975                  -22529,        /* B1 = -1.375122 */
9976                  27286,         /* B0 = 0.832703 */
9977                  7,             /* Internal filter scaling */
9978                  159,           /* Minimum in-band energy threshold */
9979                  21,            /* 21/32 in-band to broad-band ratio */
9980                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
9981         },
9982         {                       /* f942 */
9983                 24104,          /* A1 = -1.471252 */
9984                  -32507,        /* A2 = 0.992065 */
9985                  -351,          /* B2 = -0.010722 */
9986                  0,             /* B1 = 0.000000 */
9987                  351,           /* B0 = 0.010722 */
9988                  23996,         /* A1 = -1.464600 */
9989                  -32671,        /* A2 = 0.997040 */
9990                  22848,         /* B2 = 0.697266 */
9991                  -16639,        /* B1 = -1.015564 */
9992                  22848,         /* B0 = 0.697266 */
9993                  24332,         /* A1 = -1.485168 */
9994                  -32673,        /* A2 = 0.997101 */
9995                  4906,          /* B2 = 0.149727 */
9996                  -3672,         /* B1 = -0.224174 */
9997                  4906,          /* B0 = 0.149727 */
9998                  5,             /* Internal filter scaling */
9999                  159,           /* Minimum in-band energy threshold */
10000                  21,            /* 21/32 in-band to broad-band ratio */
10001                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10002         },
10003         {                       /* f950 */
10004                 23967,          /* A1 = -1.462830 */
10005                  -32507,        /* A2 = 0.992065 */
10006                  -518,          /* B2 = -0.015821 */
10007                  0,             /* B1 = 0.000000 */
10008                  518,           /* B0 = 0.015821 */
10009                  23856,         /* A1 = -1.456055 */
10010                  -32671,        /* A2 = 0.997040 */
10011                  26287,         /* B2 = 0.802246 */
10012                  -19031,        /* B1 = -1.161560 */
10013                  26287,         /* B0 = 0.802246 */
10014                  24195,         /* A1 = -1.476746 */
10015                  -32673,        /* A2 = 0.997101 */
10016                  2890,          /* B2 = 0.088196 */
10017                  -2151,         /* B1 = -0.131317 */
10018                  2890,          /* B0 = 0.088196 */
10019                  5,             /* Internal filter scaling */
10020                  159,           /* Minimum in-band energy threshold */
10021                  21,            /* 21/32 in-band to broad-band ratio */
10022                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10023         },
10024         {                       /* f950_1400[] */
10025                 18294,          /* A1 = 1.116638 */
10026                  -26962,        /* A2 = -0.822845 */
10027                  -2914,         /* B2 = -0.088936 */
10028                  0,             /* B1 = 0 */
10029                  2914,          /* B0 = 0.088936 */
10030                  14119,         /* A1 = 0.861786 */
10031                  -30227,        /* A2 = -0.922455 */
10032                  11466,         /* B2 = 0.349945 */
10033                  -2833,         /* B1 = -0.172943 */
10034                  11466,         /* B0 = 0.349945 */
10035                  23431,         /* A1 = 1.430115 */
10036                  -30828,        /* A2 = -0.940796 */
10037                  25331,         /* B2 = 0.773071 */
10038                  -20911,        /* B1 = -1.276367 */
10039                  25331,         /* B0 = 0.773071 */
10040                  7,             /* Internal filter scaling */
10041                  159,           /* Minimum in-band energy threshold */
10042                  21,            /* 21/32 in-band to broad-band ratio */
10043                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10044         },
10045         {                       /* f975 */
10046                 23521,          /* A1 = -1.435608 */
10047                  -32489,        /* A2 = 0.991516 */
10048                  -193,          /* B2 = -0.005915 */
10049                  0,             /* B1 = 0.000000 */
10050                  193,           /* B0 = 0.005915 */
10051                  23404,         /* A1 = -1.428467 */
10052                  -32655,        /* A2 = 0.996582 */
10053                  17740,         /* B2 = 0.541412 */
10054                  -12567,        /* B1 = -0.767029 */
10055                  17740,         /* B0 = 0.541412 */
10056                  23753,         /* A1 = -1.449829 */
10057                  -32657,        /* A2 = 0.996613 */
10058                  9090,          /* B2 = 0.277405 */
10059                  -6662,         /* B1 = -0.406647 */
10060                  9090,          /* B0 = 0.277405 */
10061                  5,             /* Internal filter scaling */
10062                  159,           /* Minimum in-band energy threshold */
10063                  21,            /* 21/32 in-band to broad-band ratio */
10064                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10065         },
10066         {                       /* f1000 */
10067                 23071,          /* A1 = -1.408203 */
10068                  -32489,        /* A2 = 0.991516 */
10069                  -293,          /* B2 = -0.008965 */
10070                  0,             /* B1 = 0.000000 */
10071                  293,           /* B0 = 0.008965 */
10072                  22951,         /* A1 = -1.400818 */
10073                  -32655,        /* A2 = 0.996582 */
10074                  5689,          /* B2 = 0.173645 */
10075                  -3951,         /* B1 = -0.241150 */
10076                  5689,          /* B0 = 0.173645 */
10077                  23307,         /* A1 = -1.422607 */
10078                  -32657,        /* A2 = 0.996613 */
10079                  18692,         /* B2 = 0.570435 */
10080                  -13447,        /* B1 = -0.820770 */
10081                  18692,         /* B0 = 0.570435 */
10082                  5,             /* Internal filter scaling */
10083                  159,           /* Minimum in-band energy threshold */
10084                  21,            /* 21/32 in-band to broad-band ratio */
10085                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10086         },
10087         {                       /* f1020 */
10088                 22701,          /* A1 = -1.385620 */
10089                  -32474,        /* A2 = 0.991058 */
10090                  -292,          /* B2 = -0.008933 */
10091                  0,             /*163840      , B1 = 10.000000 */
10092                  292,           /* B0 = 0.008933 */
10093                  22564,         /* A1 = -1.377258 */
10094                  -32655,        /* A2 = 0.996552 */
10095                  20756,         /* B2 = 0.633423 */
10096                  -14176,        /* B1 = -0.865295 */
10097                  20756,         /* B0 = 0.633423 */
10098                  22960,         /* A1 = -1.401428 */
10099                  -32657,        /* A2 = 0.996613 */
10100                  6520,          /* B2 = 0.198990 */
10101                  -4619,         /* B1 = -0.281937 */
10102                  6520,          /* B0 = 0.198990 */
10103                  5,             /* Internal filter scaling */
10104                  159,           /* Minimum in-band energy threshold */
10105                  21,            /* 21/32 in-band to broad-band ratio */
10106                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10107         },
10108         {                       /* f1050 */
10109                 22142,          /* A1 = -1.351501 */
10110                  -32474,        /* A2 = 0.991058 */
10111                  -147,          /* B2 = -0.004493 */
10112                  0,             /* B1 = 0.000000 */
10113                  147,           /* B0 = 0.004493 */
10114                  22000,         /* A1 = -1.342834 */
10115                  -32655,        /* A2 = 0.996552 */
10116                  15379,         /* B2 = 0.469360 */
10117                  -10237,        /* B1 = -0.624847 */
10118                  15379,         /* B0 = 0.469360 */
10119                  22406,         /* A1 = -1.367554 */
10120                  -32657,        /* A2 = 0.996613 */
10121                  17491,         /* B2 = 0.533783 */
10122                  -12096,        /* B1 = -0.738312 */
10123                  17491,         /* B0 = 0.533783 */
10124                  5,             /* Internal filter scaling */
10125                  159,           /* Minimum in-band energy threshold */
10126                  21,            /* 21/32 in-band to broad-band ratio */
10127                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10128         },
10129         {                       /* f1100_1750[] */
10130                 12973,          /* A1 = 0.79184 */
10131                  -24916,        /* A2 = -0.760376 */
10132                  6655,          /* B2 = 0.203102 */
10133                  367,           /* B1 = 0.0224 */
10134                  6657,          /* B0 = 0.203171 */
10135                  5915,          /* A1 = 0.361053 */
10136                  -29560,        /* A2 = -0.90213 */
10137                  -7777,         /* B2 = -0.23735 */
10138                  0,             /* B1 = 0 */
10139                  7777,          /* B0 = 0.23735 */
10140                  20510,         /* A1 = 1.251892 */
10141                  -30260,        /* A2 = -0.923462 */
10142                  26662,         /* B2 = 0.81366 */
10143                  -20573,        /* B1 = -1.255737 */
10144                  26668,         /* B0 = 0.813843 */
10145                  7,             /* Internal filter scaling */
10146                  159,           /* Minimum in-band energy threshold */
10147                  21,            /* 21/32 in-band to broad-band ratio */
10148                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10149         },
10150         {                       /* f1140 */
10151                 20392,          /* A1 = -1.244629 */
10152                  -32460,        /* A2 = 0.990601 */
10153                  -270,          /* B2 = -0.008240 */
10154                  0,             /* B1 = 0.000000 */
10155                  270,           /* B0 = 0.008240 */
10156                  20218,         /* A1 = -1.234009 */
10157                  -32655,        /* A2 = 0.996582 */
10158                  21337,         /* B2 = 0.651154 */
10159                  -13044,        /* B1 = -0.796143 */
10160                  21337,         /* B0 = 0.651154 */
10161                  20684,         /* A1 = -1.262512 */
10162                  -32657,        /* A2 = 0.996643 */
10163                  8572,          /* B2 = 0.261612 */
10164                  -5476,         /* B1 = -0.334244 */
10165                  8572,          /* B0 = 0.261612 */
10166                  5,             /* Internal filter scaling */
10167                  159,           /* Minimum in-band energy threshold */
10168                  21,            /* 21/32 in-band to broad-band ratio */
10169                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10170         },
10171         {                       /* f1200 */
10172                 19159,          /* A1 = -1.169373 */
10173                  -32456,        /* A2 = 0.990509 */
10174                  -335,          /* B2 = -0.010252 */
10175                  0,             /* B1 = 0.000000 */
10176                  335,           /* B0 = 0.010252 */
10177                  18966,         /* A1 = -1.157593 */
10178                  -32661,        /* A2 = 0.996735 */
10179                  6802,          /* B2 = 0.207588 */
10180                  -3900,         /* B1 = -0.238098 */
10181                  6802,          /* B0 = 0.207588 */
10182                  19467,         /* A1 = -1.188232 */
10183                  -32661,        /* A2 = 0.996765 */
10184                  25035,         /* B2 = 0.764008 */
10185                  -15049,        /* B1 = -0.918579 */
10186                  25035,         /* B0 = 0.764008 */
10187                  5,             /* Internal filter scaling */
10188                  159,           /* Minimum in-band energy threshold */
10189                  21,            /* 21/32 in-band to broad-band ratio */
10190                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10191         },
10192         {                       /* f1209 */
10193                 18976,          /* A1 = -1.158264 */
10194                  -32439,        /* A2 = 0.989990 */
10195                  -183,          /* B2 = -0.005588 */
10196                  0,             /* B1 = 0.000000 */
10197                  183,           /* B0 = 0.005588 */
10198                  18774,         /* A1 = -1.145874 */
10199                  -32650,        /* A2 = 0.996429 */
10200                  15468,         /* B2 = 0.472076 */
10201                  -8768,         /* B1 = -0.535217 */
10202                  15468,         /* B0 = 0.472076 */
10203                  19300,         /* A1 = -1.177979 */
10204                  -32652,        /* A2 = 0.996490 */
10205                  19840,         /* B2 = 0.605499 */
10206                  -11842,        /* B1 = -0.722809 */
10207                  19840,         /* B0 = 0.605499 */
10208                  5,             /* Internal filter scaling */
10209                  159,           /* Minimum in-band energy threshold */
10210                  21,            /* 21/32 in-band to broad-band ratio */
10211                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10212         },
10213         {                       /* f1330 */
10214                 16357,          /* A1 = -0.998413 */
10215                  -32368,        /* A2 = 0.987793 */
10216                  -217,          /* B2 = -0.006652 */
10217                  0,             /* B1 = 0.000000 */
10218                  217,           /* B0 = 0.006652 */
10219                  16107,         /* A1 = -0.983126 */
10220                  -32601,        /* A2 = 0.994904 */
10221                  11602,         /* B2 = 0.354065 */
10222                  -5555,         /* B1 = -0.339111 */
10223                  11602,         /* B0 = 0.354065 */
10224                  16722,         /* A1 = -1.020630 */
10225                  -32603,        /* A2 = 0.994965 */
10226                  15574,         /* B2 = 0.475311 */
10227                  -8176,         /* B1 = -0.499069 */
10228                  15574,         /* B0 = 0.475311 */
10229                  5,             /* Internal filter scaling */
10230                  159,           /* Minimum in-band energy threshold */
10231                  21,            /* 21/32 in-band to broad-band ratio */
10232                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10233         },
10234         {                       /* f1336 */
10235                 16234,          /* A1 = -0.990875 */
10236                  32404,         /* A2 = -0.988922 */
10237                  -193,          /* B2 = -0.005908 */
10238                  0,             /* B1 = 0.000000 */
10239                  193,           /* B0 = 0.005908 */
10240                  15986,         /* A1 = -0.975769 */
10241                  -32632,        /* A2 = 0.995880 */
10242                  18051,         /* B2 = 0.550903 */
10243                  -8658,         /* B1 = -0.528473 */
10244                  18051,         /* B0 = 0.550903 */
10245                  16591,         /* A1 = -1.012695 */
10246                  -32634,        /* A2 = 0.995941 */
10247                  15736,         /* B2 = 0.480240 */
10248                  -8125,         /* B1 = -0.495926 */
10249                  15736,         /* B0 = 0.480240 */
10250                  5,             /* Internal filter scaling */
10251                  159,           /* Minimum in-band energy threshold */
10252                  21,            /* 21/32 in-band to broad-band ratio */
10253                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10254         },
10255         {                       /* f1366 */
10256                 15564,          /* A1 = -0.949982 */
10257                  -32404,        /* A2 = 0.988922 */
10258                  -269,          /* B2 = -0.008216 */
10259                  0,             /* B1 = 0.000000 */
10260                  269,           /* B0 = 0.008216 */
10261                  15310,         /* A1 = -0.934479 */
10262                  -32632,        /* A2 = 0.995880 */
10263                  10815,         /* B2 = 0.330063 */
10264                  -4962,         /* B1 = -0.302887 */
10265                  10815,         /* B0 = 0.330063 */
10266                  15924,         /* A1 = -0.971924 */
10267                  -32634,        /* A2 = 0.995941 */
10268                  18880,         /* B2 = 0.576172 */
10269                  -9364,         /* B1 = -0.571594 */
10270                  18880,         /* B0 = 0.576172 */
10271                  5,             /* Internal filter scaling */
10272                  159,           /* Minimum in-band energy threshold */
10273                  21,            /* 21/32 in-band to broad-band ratio */
10274                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10275         },
10276         {                       /* f1380 */
10277                 15247,          /* A1 = -0.930603 */
10278                  -32397,        /* A2 = 0.988708 */
10279                  -244,          /* B2 = -0.007451 */
10280                  0,             /* B1 = 0.000000 */
10281                  244,           /* B0 = 0.007451 */
10282                  14989,         /* A1 = -0.914886 */
10283                  -32627,        /* A2 = 0.995697 */
10284                  18961,         /* B2 = 0.578644 */
10285                  -8498,         /* B1 = -0.518707 */
10286                  18961,         /* B0 = 0.578644 */
10287                  15608,         /* A1 = -0.952667 */
10288                  -32628,        /* A2 = 0.995758 */
10289                  11145,         /* B2 = 0.340134 */
10290                  -5430,         /* B1 = -0.331467 */
10291                  11145,         /* B0 = 0.340134 */
10292                  5,             /* Internal filter scaling */
10293                  159,           /* Minimum in-band energy threshold */
10294                  21,            /* 21/32 in-band to broad-band ratio */
10295                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10296         },
10297         {                       /* f1400 */
10298                 14780,          /* A1 = -0.902130 */
10299                  -32393,        /* A2 = 0.988586 */
10300                  -396,          /* B2 = -0.012086 */
10301                  0,             /* B1 = 0.000000 */
10302                  396,           /* B0 = 0.012086 */
10303                  14510,         /* A1 = -0.885651 */
10304                  -32630,        /* A2 = 0.995819 */
10305                  6326,          /* B2 = 0.193069 */
10306                  -2747,         /* B1 = -0.167671 */
10307                  6326,          /* B0 = 0.193069 */
10308                  15154,         /* A1 = -0.924957 */
10309                  -32632,        /* A2 = 0.995850 */
10310                  23235,         /* B2 = 0.709076 */
10311                  -10983,        /* B1 = -0.670380 */
10312                  23235,         /* B0 = 0.709076 */
10313                  5,             /* Internal filter scaling */
10314                  159,           /* Minimum in-band energy threshold */
10315                  21,            /* 21/32 in-band to broad-band ratio */
10316                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10317         },
10318         {                       /* f1477 */
10319                 13005,          /* A1 = -0.793793 */
10320                  -32368,        /* A2 = 0.987823 */
10321                  -500,          /* B2 = -0.015265 */
10322                  0,             /* B1 = 0.000000 */
10323                  500,           /* B0 = 0.015265 */
10324                  12708,         /* A1 = -0.775665 */
10325                  -32615,        /* A2 = 0.995331 */
10326                  11420,         /* B2 = 0.348526 */
10327                  -4306,         /* B1 = -0.262833 */
10328                  11420,         /* B0 = 0.348526 */
10329                  13397,         /* A1 = -0.817688 */
10330                  -32615,        /* A2 = 0.995361 */
10331                  9454,          /* B2 = 0.288528 */
10332                  -3981,         /* B1 = -0.243027 */
10333                  9454,          /* B0 = 0.288528 */
10334                  5,             /* Internal filter scaling */
10335                  159,           /* Minimum in-band energy threshold */
10336                  21,            /* 21/32 in-band to broad-band ratio */
10337                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10338         },
10339         {                       /* f1600 */
10340                 10046,          /* A1 = -0.613190 */
10341                  -32331,        /* A2 = 0.986694 */
10342                  -455,          /* B2 = -0.013915 */
10343                  0,             /* B1 = 0.000000 */
10344                  455,           /* B0 = 0.013915 */
10345                  9694,          /* A1 = -0.591705 */
10346                  -32601,        /* A2 = 0.994934 */
10347                  6023,          /* B2 = 0.183815 */
10348                  -1708,         /* B1 = -0.104279 */
10349                  6023,          /* B0 = 0.183815 */
10350                  10478,         /* A1 = -0.639587 */
10351                  -32603,        /* A2 = 0.994965 */
10352                  22031,         /* B2 = 0.672333 */
10353                  -7342,         /* B1 = -0.448151 */
10354                  22031,         /* B0 = 0.672333 */
10355                  5,             /* Internal filter scaling */
10356                  159,           /* Minimum in-band energy threshold */
10357                  21,            /* 21/32 in-band to broad-band ratio */
10358                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10359         },
10360         {                       /* f1633_1638[] */
10361                 9181,           /* A1 = 0.560394 */
10362                  -32256,        /* A2 = -0.984375 */
10363                  -556,          /* B2 = -0.016975 */
10364                  0,             /* B1 = 0 */
10365                  556,           /* B0 = 0.016975 */
10366                  8757,          /* A1 = 0.534515 */
10367                  -32574,        /* A2 = -0.99408 */
10368                  8443,          /* B2 = 0.25769 */
10369                  -2135,         /* B1 = -0.130341 */
10370                  8443,          /* B0 = 0.25769 */
10371                  9691,          /* A1 = 0.591522 */
10372                  -32574,        /* A2 = -0.99411 */
10373                  15446,         /* B2 = 0.471375 */
10374                  -4809,         /* B1 = -0.293579 */
10375                  15446,         /* B0 = 0.471375 */
10376                  7,             /* Internal filter scaling */
10377                  159,           /* Minimum in-band energy threshold */
10378                  21,            /* 21/32 in-band to broad-band ratio */
10379                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10380         },
10381         {                       /* f1800 */
10382                 5076,           /* A1 = -0.309875 */
10383                  -32304,        /* A2 = 0.985840 */
10384                  -508,          /* B2 = -0.015503 */
10385                  0,             /* B1 = 0.000000 */
10386                  508,           /* B0 = 0.015503 */
10387                  4646,          /* A1 = -0.283600 */
10388                  -32605,        /* A2 = 0.995026 */
10389                  6742,          /* B2 = 0.205780 */
10390                  -878,          /* B1 = -0.053635 */
10391                  6742,          /* B0 = 0.205780 */
10392                  5552,          /* A1 = -0.338928 */
10393                  -32605,        /* A2 = 0.995056 */
10394                  23667,         /* B2 = 0.722260 */
10395                  -4297,         /* B1 = -0.262329 */
10396                  23667,         /* B0 = 0.722260 */
10397                  5,             /* Internal filter scaling */
10398                  159,           /* Minimum in-band energy threshold */
10399                  21,            /* 21/32 in-band to broad-band ratio */
10400                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10401         },
10402         {                       /* f1860 */
10403                 3569,           /* A1 = -0.217865 */
10404                  -32292,        /* A2 = 0.985504 */
10405                  -239,          /* B2 = -0.007322 */
10406                  0,             /* B1 = 0.000000 */
10407                  239,           /* B0 = 0.007322 */
10408                  3117,          /* A1 = -0.190277 */
10409                  -32603,        /* A2 = 0.994965 */
10410                  18658,         /* B2 = 0.569427 */
10411                  -1557,         /* B1 = -0.095032 */
10412                  18658,         /* B0 = 0.569427 */
10413                  4054,          /* A1 = -0.247437 */
10414                  -32603,        /* A2 = 0.994965 */
10415                  18886,         /* B2 = 0.576385 */
10416                  -2566,         /* B1 = -0.156647 */
10417                  18886,         /* B0 = 0.576385 */
10418                  5,             /* Internal filter scaling */
10419                  159,           /* Minimum in-band energy threshold */
10420                  21,            /* 21/32 in-band to broad-band ratio */
10421                  0x0FF5         /* shift-mask 0x0FF (look at 16 half-frames) bit count = 5 */
10422         },
10423 };
10424 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf)
10425 {
10426         unsigned short cmd;
10427         int cnt, max;
10428
10429         if (jf->filter > 3) {
10430                 return -1;
10431         }
10432         if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))        /* Select Filter */
10433
10434                 return -1;
10435         if (!jf->enable) {
10436                 if (ixj_WriteDSPCommand(0x5152, j))             /* Disable Filter */
10437
10438                         return -1;
10439                 else
10440                         return 0;
10441         } else {
10442                 if (ixj_WriteDSPCommand(0x5153, j))             /* Enable Filter */
10443
10444                         return -1;
10445                 /* Select the filter (f0 - f3) to use. */
10446                 if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))
10447                         return -1;
10448         }
10449         if (jf->freq < 12 && jf->freq > 3) {
10450                 /* Select the frequency for the selected filter. */
10451                 if (ixj_WriteDSPCommand(0x5170 + jf->freq, j))
10452                         return -1;
10453         } else if (jf->freq > 11) {
10454                 /* We need to load a programmable filter set for undefined */
10455                 /* frequencies.  So we will point the filter to a programmable set. */
10456                 /* Since there are only 4 filters and 4 programmable sets, we will */
10457                 /* just point the filter to the same number set and program it for the */
10458                 /* frequency we want. */
10459                 if (ixj_WriteDSPCommand(0x5170 + jf->filter, j))
10460                         return -1;
10461                 if (j->ver.low != 0x12) {
10462                         cmd = 0x515B;
10463                         max = 19;
10464                 } else {
10465                         cmd = 0x515E;
10466                         max = 15;
10467                 }
10468                 if (ixj_WriteDSPCommand(cmd, j))
10469                         return -1;
10470                 for (cnt = 0; cnt < max; cnt++) {
10471                         if (ixj_WriteDSPCommand(tone_table[jf->freq - 12][cnt], j))
10472                                 return -1;
10473                 }
10474         }
10475         j->filter_en[jf->filter] = jf->enable;
10476         return 0;
10477 }
10478
10479 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr)
10480 {
10481         unsigned short cmd;
10482         int cnt, max;
10483         if (jfr->filter > 3) {
10484                 return -1;
10485         }
10486         if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))       /* Select Filter */
10487                 return -1;
10488
10489         if (!jfr->enable) {
10490                 if (ixj_WriteDSPCommand(0x5152, j))             /* Disable Filter */
10491                         return -1;
10492                 else
10493                         return 0;
10494         } else {
10495                 if (ixj_WriteDSPCommand(0x5153, j))             /* Enable Filter */
10496                         return -1;
10497                 /* Select the filter (f0 - f3) to use. */
10498                 if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))
10499                         return -1;
10500         }
10501         /* We need to load a programmable filter set for undefined */
10502         /* frequencies.  So we will point the filter to a programmable set. */
10503         /* Since there are only 4 filters and 4 programmable sets, we will */
10504         /* just point the filter to the same number set and program it for the */
10505         /* frequency we want. */
10506         if (ixj_WriteDSPCommand(0x5170 + jfr->filter, j))
10507                 return -1;
10508         if (j->ver.low != 0x12) {
10509                 cmd = 0x515B;
10510                 max = 19;
10511         } else {
10512                 cmd = 0x515E;
10513                 max = 15;
10514         }
10515         if (ixj_WriteDSPCommand(cmd, j))
10516                 return -1;
10517         for (cnt = 0; cnt < max; cnt++) {
10518                 if (ixj_WriteDSPCommand(jfr->coeff[cnt], j))
10519                         return -1;
10520         }
10521         j->filter_en[jfr->filter] = jfr->enable;
10522         return 0;
10523 }
10524
10525 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti)
10526 {
10527         int freq0, freq1;
10528         unsigned short data;
10529         if (ti->freq0) {
10530                 freq0 = ti->freq0;
10531         } else {
10532                 freq0 = 0x7FFF;
10533         }
10534
10535         if (ti->freq1) {
10536                 freq1 = ti->freq1;
10537         } else {
10538                 freq1 = 0x7FFF;
10539         }
10540
10541         if(ti->tone_index > 12 && ti->tone_index < 28)
10542         {
10543                 if (ixj_WriteDSPCommand(0x6800 + ti->tone_index, j))
10544                         return -1;
10545                 if (ixj_WriteDSPCommand(0x6000 + (ti->gain1 << 4) + ti->gain0, j))
10546                         return -1;
10547                 data = freq0;
10548                 if (ixj_WriteDSPCommand(data, j))
10549                         return -1;
10550                 data = freq1;
10551                 if (ixj_WriteDSPCommand(data, j))
10552                         return -1;
10553         }
10554         return freq0;
10555 }
10556