1 /****************************************************************************
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
9 * (c) Copyright 1999-2001 Quicknet Technologies, Inc.
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.
16 * Author: Ed Okerson, <eokerson@quicknet.net>
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>
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>
28 * More information about the hardware related to this driver can be found
29 * at our website: http://www.quicknet.net
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.
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.
42 ***************************************************************************/
47 * Revision 4.8 2003/07/09 19:39:00 Daniele Bellucci
48 * Audit some copy_*_user and minor cleanup.
50 * Revision 4.7 2001/08/13 06:19:33 craigs
51 * Added additional changes from Alan Cox and John Anderson for
52 * 2.2 to 2.4 cleanup and bounds checking
54 * Revision 4.6 2001/08/13 01:05:05 craigs
55 * Really fixed PHONE_QUERY_CODEC problem this time
57 * Revision 4.5 2001/08/13 00:11:03 craigs
58 * Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson
60 * Revision 4.4 2001/08/07 07:58:12 craigs
61 * Changed back to three digit version numbers
62 * Added tagbuild target to allow automatic and easy tagging of versions
64 * Revision 4.3 2001/08/07 07:24:47 craigs
65 * Added ixj-ver.h to allow easy configuration management of driver
66 * Added display of version number in /prox/ixj
68 * Revision 4.2 2001/08/06 07:07:19 craigs
69 * Reverted IXJCTL_DSP_TYPE and IXJCTL_DSP_VERSION files to original
70 * behaviour of returning int rather than short *
72 * Revision 4.1 2001/08/05 00:17:37 craigs
73 * More changes for correct PCMCIA installation
74 * Start of changes for backward Linux compatibility
76 * Revision 4.0 2001/08/04 12:33:12 craigs
77 * New version using GNU autoconf
79 * Revision 3.105 2001/07/20 23:14:32 eokerson
80 * More work on CallerID generation when using ring cadences.
82 * Revision 3.104 2001/07/06 01:33:55 eokerson
83 * Some bugfixes from Robert Vojta <vojta@ipex.cz> and a few mods to the Makefile.
85 * Revision 3.103 2001/07/05 19:20:16 eokerson
87 * Changed mic gain to 30dB on Internet LineJACK mic/speaker port.
89 * Revision 3.102 2001/07/03 23:51:21 eokerson
90 * Un-mute mic on Internet LineJACK when in speakerphone mode.
92 * Revision 3.101 2001/07/02 19:26:56 eokerson
93 * Removed initialiazation of ixjdebug and ixj_convert_loaded so they will go in the .bss instead of the .data
95 * Revision 3.100 2001/07/02 19:18:27 eokerson
96 * Changed driver to make dynamic allocation possible. We now pass IXJ * between functions instead of array indexes.
97 * Fixed the way the POTS and PSTN ports interact during a PSTN call to allow local answering.
98 * Fixed speaker mode on Internet LineJACK.
100 * Revision 3.99 2001/05/09 14:11:16 eokerson
101 * Fixed kmalloc error in ixj_build_filter_cadence. Thanks David Chan <cat@waulogy.stanford.edu>.
103 * Revision 3.98 2001/05/08 19:55:33 eokerson
104 * Fixed POTS hookstate detection while it is connected to PSTN port.
106 * Revision 3.97 2001/05/08 00:01:04 eokerson
107 * Fixed kernel oops when sending caller ID data.
109 * Revision 3.96 2001/05/04 23:09:30 eokerson
110 * Now uses one kernel timer for each card, instead of one for the entire driver.
112 * Revision 3.95 2001/04/25 22:06:47 eokerson
113 * Fixed squawking at beginning of some G.723.1 calls.
115 * Revision 3.94 2001/04/03 23:42:00 eokerson
116 * Added linear volume ioctls
117 * Added raw filter load ioctl
119 * Revision 3.93 2001/02/27 01:00:06 eokerson
120 * Fixed blocking in CallerID.
121 * Reduced size of ixj structure for smaller driver footprint.
123 * Revision 3.92 2001/02/20 22:02:59 eokerson
124 * Fixed isapnp and pcmcia module compatibility for 2.4.x kernels.
125 * Improved PSTN ring detection.
126 * Fixed wink generation on POTS ports.
128 * Revision 3.91 2001/02/13 00:55:44 eokerson
129 * Turn AEC back on after changing frame sizes.
131 * Revision 3.90 2001/02/12 16:42:00 eokerson
132 * Added ALAW codec, thanks to Fabio Ferrari for the table based converters to make ALAW from ULAW.
134 * Revision 3.89 2001/02/12 15:41:16 eokerson
135 * Fix from Artis Kugevics - Tone gains were not being set correctly.
137 * Revision 3.88 2001/02/05 23:25:42 eokerson
138 * Fixed lockup bugs with deregister.
140 * Revision 3.87 2001/01/29 21:00:39 eokerson
141 * Fix from Fabio Ferrari <fabio.ferrari@digitro.com.br> to properly handle EAGAIN and EINTR during non-blocking write.
142 * Updated copyright date.
144 * Revision 3.86 2001/01/23 23:53:46 eokerson
145 * Fixes to G.729 compatibility.
147 * Revision 3.85 2001/01/23 21:30:36 eokerson
148 * Added verbage about cards supported.
149 * Removed commands that put the card in low power mode at some times that it should not be in low power mode.
151 * Revision 3.84 2001/01/22 23:32:10 eokerson
152 * Some bugfixes from David Huggins-Daines, <dhd@cepstral.com> and other cleanups.
154 * Revision 3.83 2001/01/19 14:51:41 eokerson
155 * Fixed ixj_WriteDSPCommand to decrement usage counter when command fails.
157 * Revision 3.82 2001/01/19 00:34:49 eokerson
158 * Added verbosity to write overlap errors.
160 * Revision 3.81 2001/01/18 23:56:54 eokerson
161 * Fixed PSTN line test functions.
163 * Revision 3.80 2001/01/18 22:29:27 eokerson
164 * Updated AEC/AGC values for different cards.
166 * Revision 3.79 2001/01/17 02:58:54 eokerson
167 * Fixed AEC reset after Caller ID.
168 * Fixed Codec lockup after Caller ID on Call Waiting when not using 30ms frames.
170 * Revision 3.78 2001/01/16 19:43:09 eokerson
171 * Added support for Linux 2.4.x kernels.
173 * Revision 3.77 2001/01/09 04:00:52 eokerson
174 * Linetest will now test the line, even if it has previously succeded.
176 * Revision 3.76 2001/01/08 19:27:00 eokerson
177 * Fixed problem with standard cable on Internet PhoneCARD.
179 * Revision 3.75 2000/12/22 16:52:14 eokerson
180 * Modified to allow hookstate detection on the POTS port when the PSTN port is selected.
182 * Revision 3.74 2000/12/08 22:41:50 eokerson
183 * Added capability for G729B.
185 * Revision 3.73 2000/12/07 23:35:16 eokerson
186 * Added capability to have different ring pattern before CallerID data.
187 * Added hookstate checks in CallerID routines to stop FSK.
189 * Revision 3.72 2000/12/06 19:31:31 eokerson
190 * Modified signal behavior to only send one signal per event.
192 * Revision 3.71 2000/12/06 03:23:08 eokerson
193 * Fixed CallerID on Call Waiting.
195 * Revision 3.70 2000/12/04 21:29:37 eokerson
196 * Added checking to Smart Cable gain functions.
198 * Revision 3.69 2000/12/04 21:05:20 eokerson
199 * Changed ixjdebug levels.
200 * Added ioctls to change gains in Internet Phone CARD Smart Cable.
202 * Revision 3.68 2000/12/04 00:17:21 craigs
203 * Changed mixer voice gain to +6dB rather than 0dB
205 * Revision 3.67 2000/11/30 21:25:51 eokerson
206 * Fixed write signal errors.
208 * Revision 3.66 2000/11/29 22:42:44 eokerson
209 * Fixed PSTN ring detect problems.
211 * Revision 3.65 2000/11/29 07:31:55 craigs
212 * Added new 425Hz filter co-efficients
213 * Added card-specific DTMF prescaler initialisation
215 * Revision 3.64 2000/11/28 14:03:32 craigs
216 * Changed certain mixer initialisations to be 0dB rather than 12dB
217 * Added additional information to /proc/ixj
219 * Revision 3.63 2000/11/28 11:38:41 craigs
220 * Added display of AEC modes in AUTO and AGC mode
222 * Revision 3.62 2000/11/28 04:05:44 eokerson
223 * Improved PSTN ring detection routine.
225 * Revision 3.61 2000/11/27 21:53:12 eokerson
226 * Fixed flash detection.
228 * Revision 3.60 2000/11/27 15:57:29 eokerson
229 * More work on G.729 load routines.
231 * Revision 3.59 2000/11/25 21:55:12 eokerson
232 * Fixed errors in G.729 load routine.
234 * Revision 3.58 2000/11/25 04:08:29 eokerson
235 * Added board locks around G.729 and TS85 load routines.
237 * Revision 3.57 2000/11/24 05:35:17 craigs
238 * Added ability to retrieve mixer values on LineJACK
239 * Added complete initialisation of all mixer values at startup
240 * Fixed spelling mistake
242 * Revision 3.56 2000/11/23 02:52:11 robertj
243 * Added cvs change log keyword.
244 * Fixed bug in capabilities list when using G.729 module.
250 #define PERFMON_STATS
254 #include <linux/module.h>
256 #include <linux/init.h>
257 #include <linux/sched.h>
258 #include <linux/kernel.h> /* printk() */
259 #include <linux/fs.h> /* everything... */
260 #include <linux/errno.h> /* error codes */
261 #include <linux/slab.h>
262 #include <linux/mm.h>
263 #include <linux/ioport.h>
264 #include <linux/interrupt.h>
265 #include <linux/proc_fs.h>
266 #include <linux/poll.h>
267 #include <linux/timer.h>
268 #include <linux/delay.h>
269 #include <linux/pci.h>
272 #include <asm/uaccess.h>
274 #include <linux/isapnp.h>
278 #define TYPE(inode) (iminor(inode) >> 4)
279 #define NUM(inode) (iminor(inode) & 0xf)
282 static int hertz = HZ;
283 static int samplerate = 100;
285 module_param(ixjdebug, int, 0);
287 /************************************************************************
289 * ixjdebug meanings are now bit mapped instead of level based
290 * Values can be or'ed together to turn on multiple messages
292 * bit 0 (0x0001) = any failure
293 * bit 1 (0x0002) = general messages
294 * bit 2 (0x0004) = POTS ringing related
295 * bit 3 (0x0008) = PSTN events
296 * bit 4 (0x0010) = PSTN Cadence state details
297 * bit 5 (0x0020) = Tone detection triggers
298 * bit 6 (0x0040) = Tone detection cadence details
299 * bit 7 (0x0080) = ioctl tracking
300 * bit 8 (0x0100) = signal tracking
301 * bit 9 (0x0200) = CallerID generation details
303 ************************************************************************/
307 static IXJ *ixj[IXJMAX];
308 #define get_ixj(b) ixj[(b)]
311 * Allocate a free IXJ device
314 static IXJ *ixj_alloc()
316 for(cnt=0; cnt<IXJMAX; cnt++)
318 if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
320 j = kmalloc(sizeof(IXJ), GFP_KERNEL);
330 static void ixj_fsk_free(IXJ *j)
332 if(j->fskdata != NULL) {
338 static void ixj_fsk_alloc(IXJ *j)
341 j->fskdata = kmalloc(8000, GFP_KERNEL);
343 if(ixjdebug & 0x0200) {
344 printk("IXJ phone%d - allocate failed\n", j->board);
349 if(ixjdebug & 0x0200) {
350 printk("IXJ phone%d - allocate succeded\n", j->board);
358 static IXJ ixj[IXJMAX];
359 #define get_ixj(b) (&ixj[(b)])
362 * Allocate a free IXJ device
365 static IXJ *ixj_alloc(void)
368 for(cnt=0; cnt<IXJMAX; cnt++) {
369 if(!ixj[cnt].DSPbase)
375 static inline void ixj_fsk_free(IXJ *j) {;}
377 static inline void ixj_fsk_alloc(IXJ *j)
385 #define ixj_perfmon(x) ((x)++)
387 #define ixj_perfmon(x) do { } while(0)
390 static int ixj_convert_loaded;
392 static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
394 /************************************************************************
396 * These are function definitions to allow external modules to register
397 * enhanced functionality call backs.
399 ************************************************************************/
401 static int Stub(IXJ * J, unsigned long arg)
406 static IXJ_REGFUNC ixj_PreRead = &Stub;
407 static IXJ_REGFUNC ixj_PostRead = &Stub;
408 static IXJ_REGFUNC ixj_PreWrite = &Stub;
409 static IXJ_REGFUNC ixj_PostWrite = &Stub;
411 static void ixj_read_frame(IXJ *j);
412 static void ixj_write_frame(IXJ *j);
413 static void ixj_init_timer(IXJ *j);
414 static void ixj_add_timer(IXJ * j);
415 static void ixj_timeout(unsigned long ptr);
416 static int read_filters(IXJ *j);
417 static int LineMonitor(IXJ *j);
418 static int ixj_fasync(int fd, struct file *, int mode);
419 static int ixj_set_port(IXJ *j, int arg);
420 static int ixj_set_pots(IXJ *j, int arg);
421 static int ixj_hookstate(IXJ *j);
422 static int ixj_record_start(IXJ *j);
423 static void ixj_record_stop(IXJ *j);
424 static void set_rec_volume(IXJ *j, int volume);
425 static int get_rec_volume(IXJ *j);
426 static int set_rec_codec(IXJ *j, int rate);
427 static void ixj_vad(IXJ *j, int arg);
428 static int ixj_play_start(IXJ *j);
429 static void ixj_play_stop(IXJ *j);
430 static int ixj_set_tone_on(unsigned short arg, IXJ *j);
431 static int ixj_set_tone_off(unsigned short, IXJ *j);
432 static int ixj_play_tone(IXJ *j, char tone);
433 static void ixj_aec_start(IXJ *j, int level);
434 static int idle(IXJ *j);
435 static void ixj_ring_on(IXJ *j);
436 static void ixj_ring_off(IXJ *j);
437 static void aec_stop(IXJ *j);
438 static void ixj_ringback(IXJ *j);
439 static void ixj_busytone(IXJ *j);
440 static void ixj_dialtone(IXJ *j);
441 static void ixj_cpt_stop(IXJ *j);
442 static char daa_int_read(IXJ *j);
443 static char daa_CR_read(IXJ *j, int cr);
444 static int daa_set_mode(IXJ *j, int mode);
445 static int ixj_linetest(IXJ *j);
446 static int ixj_daa_write(IXJ *j);
447 static int ixj_daa_cid_read(IXJ *j);
448 static void DAA_Coeff_US(IXJ *j);
449 static void DAA_Coeff_UK(IXJ *j);
450 static void DAA_Coeff_France(IXJ *j);
451 static void DAA_Coeff_Germany(IXJ *j);
452 static void DAA_Coeff_Australia(IXJ *j);
453 static void DAA_Coeff_Japan(IXJ *j);
454 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
455 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
456 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
457 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
458 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
459 /* Serial Control Interface funtions */
460 static int SCI_Control(IXJ *j, int control);
461 static int SCI_Prepare(IXJ *j);
462 static int SCI_WaitHighSCI(IXJ *j);
463 static int SCI_WaitLowSCI(IXJ *j);
464 static DWORD PCIEE_GetSerialNumber(WORD wAddress);
465 static int ixj_PCcontrol_wait(IXJ *j);
466 static void ixj_pre_cid(IXJ *j);
467 static void ixj_write_cid(IXJ *j);
468 static void ixj_write_cid_bit(IXJ *j, int bit);
469 static int set_base_frame(IXJ *j, int size);
470 static int set_play_codec(IXJ *j, int rate);
471 static void set_rec_depth(IXJ *j, int depth);
472 static int ixj_mixer(long val, IXJ *j);
474 /************************************************************************
475 CT8020/CT8021 Host Programmers Model
476 Host address Function Access
478 0-1 Aux Software Status Register (reserved) Read Only
479 2-3 Software Status Register Read Only
480 4-5 Aux Software Control Register (reserved) Read Write
481 6-7 Software Control Register Read Write
482 8-9 Hardware Status Register Read Only
483 A-B Hardware Control Register Read Write
484 C-D Host Transmit (Write) Data Buffer Access Port (buffer input)Write Only
485 E-F Host Recieve (Read) Data Buffer Access Port (buffer input) Read Only
486 ************************************************************************/
488 static inline void ixj_read_HSR(IXJ *j)
490 j->hsr.bytes.low = inb_p(j->DSPbase + 8);
491 j->hsr.bytes.high = inb_p(j->DSPbase + 9);
494 static inline int IsControlReady(IXJ *j)
497 return j->hsr.bits.controlrdy ? 1 : 0;
500 static inline int IsPCControlReady(IXJ *j)
502 j->pccr1.byte = inb_p(j->XILINXbase + 3);
503 return j->pccr1.bits.crr ? 1 : 0;
506 static inline int IsStatusReady(IXJ *j)
509 return j->hsr.bits.statusrdy ? 1 : 0;
512 static inline int IsRxReady(IXJ *j)
515 ixj_perfmon(j->rxreadycheck);
516 return j->hsr.bits.rxrdy ? 1 : 0;
519 static inline int IsTxReady(IXJ *j)
522 ixj_perfmon(j->txreadycheck);
523 return j->hsr.bits.txrdy ? 1 : 0;
526 static inline void set_play_volume(IXJ *j, int volume)
528 if (ixjdebug & 0x0002)
529 printk(KERN_INFO "IXJ: /dev/phone%d Setting Play Volume to 0x%4.4x\n", j->board, volume);
530 ixj_WriteDSPCommand(0xCF02, j);
531 ixj_WriteDSPCommand(volume, j);
534 static int set_play_volume_linear(IXJ *j, int volume)
536 int newvolume, dspplaymax;
538 if (ixjdebug & 0x0002)
539 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Play Volume to 0x%4.4x\n", j->board, volume);
540 if(volume > 100 || volume < 0) {
544 /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
545 switch (j->cardtype) {
550 if(j->port == PORT_PSTN) {
556 case QTI_PHONEJACK_LITE:
559 case QTI_PHONEJACK_PCI:
568 newvolume = (dspplaymax * volume) / 100;
569 set_play_volume(j, newvolume);
573 static inline void set_play_depth(IXJ *j, int depth)
579 ixj_WriteDSPCommand(0x5280 + depth, j);
582 static inline int get_play_volume(IXJ *j)
584 ixj_WriteDSPCommand(0xCF00, j);
585 return j->ssr.high << 8 | j->ssr.low;
588 static int get_play_volume_linear(IXJ *j)
590 int volume, newvolume, dspplaymax;
592 /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
593 switch (j->cardtype) {
598 if(j->port == PORT_PSTN) {
604 case QTI_PHONEJACK_LITE:
607 case QTI_PHONEJACK_PCI:
616 volume = get_play_volume(j);
617 newvolume = (volume * 100) / dspplaymax;
623 static inline BYTE SLIC_GetState(IXJ *j)
625 if (j->cardtype == QTI_PHONECARD) {
627 j->psccr.bits.dev = 3;
628 j->psccr.bits.rw = 1;
629 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
630 ixj_PCcontrol_wait(j);
631 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
632 ixj_PCcontrol_wait(j);
633 if (j->pslic.bits.powerdown)
634 return PLD_SLIC_STATE_OC;
635 else if (!j->pslic.bits.ring0 && !j->pslic.bits.ring1)
636 return PLD_SLIC_STATE_ACTIVE;
638 return PLD_SLIC_STATE_RINGING;
640 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
642 return j->pld_slicr.bits.state;
645 static BOOL SLIC_SetState(BYTE byState, IXJ *j)
647 BOOL fRetVal = FALSE;
649 if (j->cardtype == QTI_PHONECARD) {
650 if (j->flags.pcmciasct) {
652 case PLD_SLIC_STATE_TIPOPEN:
653 case PLD_SLIC_STATE_OC:
654 j->pslic.bits.powerdown = 1;
655 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
658 case PLD_SLIC_STATE_RINGING:
659 if (j->readers || j->writers) {
660 j->pslic.bits.powerdown = 0;
661 j->pslic.bits.ring0 = 1;
662 j->pslic.bits.ring1 = 0;
666 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
668 case PLD_SLIC_STATE_STANDBY:
669 case PLD_SLIC_STATE_ACTIVE:
670 if (j->readers || j->writers) {
671 j->pslic.bits.powerdown = 0;
673 j->pslic.bits.powerdown = 1;
675 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
678 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
680 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
686 j->psccr.bits.dev = 3;
687 j->psccr.bits.rw = 0;
688 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
689 ixj_PCcontrol_wait(j);
692 /* Set the C1, C2, C3 & B2EN signals. */
694 case PLD_SLIC_STATE_OC:
695 j->pld_slicw.bits.c1 = 0;
696 j->pld_slicw.bits.c2 = 0;
697 j->pld_slicw.bits.c3 = 0;
698 j->pld_slicw.bits.b2en = 0;
699 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
702 case PLD_SLIC_STATE_RINGING:
703 j->pld_slicw.bits.c1 = 1;
704 j->pld_slicw.bits.c2 = 0;
705 j->pld_slicw.bits.c3 = 0;
706 j->pld_slicw.bits.b2en = 1;
707 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
710 case PLD_SLIC_STATE_ACTIVE:
711 j->pld_slicw.bits.c1 = 0;
712 j->pld_slicw.bits.c2 = 1;
713 j->pld_slicw.bits.c3 = 0;
714 j->pld_slicw.bits.b2en = 0;
715 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
718 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
720 j->pld_slicw.bits.c1 = 1;
721 j->pld_slicw.bits.c2 = 1;
722 j->pld_slicw.bits.c3 = 0;
723 j->pld_slicw.bits.b2en = 0;
724 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
727 case PLD_SLIC_STATE_TIPOPEN:
728 j->pld_slicw.bits.c1 = 0;
729 j->pld_slicw.bits.c2 = 0;
730 j->pld_slicw.bits.c3 = 1;
731 j->pld_slicw.bits.b2en = 0;
732 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
735 case PLD_SLIC_STATE_STANDBY:
736 j->pld_slicw.bits.c1 = 1;
737 j->pld_slicw.bits.c2 = 0;
738 j->pld_slicw.bits.c3 = 1;
739 j->pld_slicw.bits.b2en = 1;
740 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
743 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
745 j->pld_slicw.bits.c1 = 0;
746 j->pld_slicw.bits.c2 = 1;
747 j->pld_slicw.bits.c3 = 1;
748 j->pld_slicw.bits.b2en = 0;
749 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
752 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
754 j->pld_slicw.bits.c1 = 1;
755 j->pld_slicw.bits.c2 = 1;
756 j->pld_slicw.bits.c3 = 1;
757 j->pld_slicw.bits.b2en = 0;
758 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
770 static int ixj_wink(IXJ *j)
774 slicnow = SLIC_GetState(j);
776 j->pots_winkstart = jiffies;
777 SLIC_SetState(PLD_SLIC_STATE_OC, j);
779 while (time_before(jiffies, j->pots_winkstart + j->winktime)) {
780 set_current_state(TASK_INTERRUPTIBLE);
784 SLIC_SetState(slicnow, j);
788 static void ixj_init_timer(IXJ *j)
790 init_timer(&j->timer);
791 j->timer.function = ixj_timeout;
792 j->timer.data = (unsigned long)j;
795 static void ixj_add_timer(IXJ *j)
797 j->timer.expires = jiffies + (hertz / samplerate);
798 add_timer(&j->timer);
801 static void ixj_tone_timeout(IXJ *j)
806 if (j->tone_state == 3) {
809 j->tone_cadence_state++;
810 if (j->tone_cadence_state >= j->cadence_t->elements_used) {
811 switch (j->cadence_t->termination) {
815 case REPEAT_LAST_ELEMENT:
816 j->tone_cadence_state--;
817 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
820 j->tone_cadence_state = 0;
821 if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
822 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
823 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
824 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
825 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
826 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
827 ixj_init_tone(j, &ti);
829 ixj_set_tone_on(j->cadence_t->ce[0].tone_on_time, j);
830 ixj_set_tone_off(j->cadence_t->ce[0].tone_off_time, j);
831 ixj_play_tone(j, j->cadence_t->ce[0].index);
835 if (j->cadence_t->ce[j->tone_cadence_state].gain0) {
836 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
837 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
838 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
839 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
840 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
841 ixj_init_tone(j, &ti);
843 ixj_set_tone_on(j->cadence_t->ce[j->tone_cadence_state].tone_on_time, j);
844 ixj_set_tone_off(j->cadence_t->ce[j->tone_cadence_state].tone_off_time, j);
845 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
851 static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
853 if(j->ixj_signals[event]) {
854 if(ixjdebug & 0x0100)
855 printk("Sending signal for event %d\n", event);
856 /* Send apps notice of change */
857 /* see config.h for macro definition */
858 kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
862 static void ixj_pstn_state(IXJ *j)
865 union XOPXR0 XR0, daaint;
869 XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
871 XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
873 j->pld_scrr.byte = inb_p(j->XILINXbase);
874 if (j->pld_scrr.bits.daaflag) {
876 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.RING) {
877 if(time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
878 daaint.bitreg.RING = 1;
879 if(ixjdebug & 0x0008) {
880 printk(KERN_INFO "IXJ DAA Ring Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
883 daa_set_mode(j, SOP_PU_RESET);
886 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Caller_ID) {
887 daaint.bitreg.Caller_ID = 1;
888 j->pstn_cid_intr = 1;
889 j->pstn_cid_received = jiffies;
890 if(ixjdebug & 0x0008) {
891 printk(KERN_INFO "IXJ DAA Caller_ID Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
894 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Cadence) {
895 daaint.bitreg.Cadence = 1;
896 if(ixjdebug & 0x0008) {
897 printk(KERN_INFO "IXJ DAA Cadence Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
900 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK != XR0.bitreg.VDD_OK) {
901 daaint.bitreg.VDD_OK = 1;
902 daaint.bitreg.SI_0 = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK;
906 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)) {
907 daaint.bitreg.RMR = 1;
908 daaint.bitreg.SI_1 = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
909 if(ixjdebug & 0x0008) {
910 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 j->pstn_prev_rmr = j->pstn_last_rmr;
913 j->pstn_last_rmr = jiffies;
915 switch(j->daa_mode) {
917 if (daaint.bitreg.RING) {
918 if (!j->flags.pstn_ringing) {
919 if (j->daa_mode != SOP_PU_RINGING) {
920 j->pstn_ring_int = jiffies;
921 daa_set_mode(j, SOP_PU_RINGING);
927 if (daaint.bitreg.RMR) {
928 if (ixjdebug & 0x0008) {
929 printk(KERN_INFO "IXJ Ring Cadence a state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
931 if (daaint.bitreg.SI_1) { /* Rising edge of RMR */
932 j->flags.pstn_rmr = 1;
933 j->pstn_ring_start = jiffies;
934 j->pstn_ring_stop = 0;
935 j->ex.bits.pstn_ring = 0;
936 if (j->cadence_f[4].state == 0) {
937 j->cadence_f[4].state = 1;
938 j->cadence_f[4].on1min = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 - var)) / 10000);
939 j->cadence_f[4].on1dot = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100)) / 10000);
940 j->cadence_f[4].on1max = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 + var)) / 10000);
941 } else if (j->cadence_f[4].state == 2) {
942 if((time_after(jiffies, j->cadence_f[4].off1min) &&
943 time_before(jiffies, j->cadence_f[4].off1max))) {
944 if (j->cadence_f[4].on2) {
945 j->cadence_f[4].state = 3;
946 j->cadence_f[4].on2min = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 - var)) / 10000));
947 j->cadence_f[4].on2dot = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100)) / 10000));
948 j->cadence_f[4].on2max = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 + var)) / 10000));
950 j->cadence_f[4].state = 7;
953 if (ixjdebug & 0x0008) {
954 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
955 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
956 j->cadence_f[4].off1);
958 j->cadence_f[4].state = 0;
960 } else if (j->cadence_f[4].state == 4) {
961 if((time_after(jiffies, j->cadence_f[4].off2min) &&
962 time_before(jiffies, j->cadence_f[4].off2max))) {
963 if (j->cadence_f[4].on3) {
964 j->cadence_f[4].state = 5;
965 j->cadence_f[4].on3min = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 - var)) / 10000));
966 j->cadence_f[4].on3dot = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100)) / 10000));
967 j->cadence_f[4].on3max = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 + var)) / 10000));
969 j->cadence_f[4].state = 7;
972 if (ixjdebug & 0x0008) {
973 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
974 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
975 j->cadence_f[4].off2);
977 j->cadence_f[4].state = 0;
979 } else if (j->cadence_f[4].state == 6) {
980 if((time_after(jiffies, j->cadence_f[4].off3min) &&
981 time_before(jiffies, j->cadence_f[4].off3max))) {
982 j->cadence_f[4].state = 7;
984 if (ixjdebug & 0x0008) {
985 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
986 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
987 j->cadence_f[4].off3);
989 j->cadence_f[4].state = 0;
992 j->cadence_f[4].state = 0;
994 } else { /* Falling edge of RMR */
995 j->pstn_ring_start = 0;
996 j->pstn_ring_stop = jiffies;
997 if (j->cadence_f[4].state == 1) {
998 if(!j->cadence_f[4].on1) {
999 j->cadence_f[4].state = 7;
1000 } else if((time_after(jiffies, j->cadence_f[4].on1min) &&
1001 time_before(jiffies, j->cadence_f[4].on1max))) {
1002 if (j->cadence_f[4].off1) {
1003 j->cadence_f[4].state = 2;
1004 j->cadence_f[4].off1min = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 - var)) / 10000));
1005 j->cadence_f[4].off1dot = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100)) / 10000));
1006 j->cadence_f[4].off1max = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 + var)) / 10000));
1008 j->cadence_f[4].state = 7;
1011 if (ixjdebug & 0x0008) {
1012 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1013 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1014 j->cadence_f[4].on1);
1016 j->cadence_f[4].state = 0;
1018 } else if (j->cadence_f[4].state == 3) {
1019 if((time_after(jiffies, j->cadence_f[4].on2min) &&
1020 time_before(jiffies, j->cadence_f[4].on2max))) {
1021 if (j->cadence_f[4].off2) {
1022 j->cadence_f[4].state = 4;
1023 j->cadence_f[4].off2min = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 - var)) / 10000));
1024 j->cadence_f[4].off2dot = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100)) / 10000));
1025 j->cadence_f[4].off2max = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 + var)) / 10000));
1027 j->cadence_f[4].state = 7;
1030 if (ixjdebug & 0x0008) {
1031 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1032 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1033 j->cadence_f[4].on2);
1035 j->cadence_f[4].state = 0;
1037 } else if (j->cadence_f[4].state == 5) {
1038 if((time_after(jiffies, j->cadence_f[4].on3min) &&
1039 time_before(jiffies, j->cadence_f[4].on3max))) {
1040 if (j->cadence_f[4].off3) {
1041 j->cadence_f[4].state = 6;
1042 j->cadence_f[4].off3min = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 - var)) / 10000));
1043 j->cadence_f[4].off3dot = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100)) / 10000));
1044 j->cadence_f[4].off3max = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 + var)) / 10000));
1046 j->cadence_f[4].state = 7;
1049 j->cadence_f[4].state = 0;
1052 if (ixjdebug & 0x0008) {
1053 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1054 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1055 j->cadence_f[4].on3);
1057 j->cadence_f[4].state = 0;
1060 if (ixjdebug & 0x0010) {
1061 printk(KERN_INFO "IXJ Ring Cadence b state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
1063 if (ixjdebug & 0x0010) {
1064 switch(j->cadence_f[4].state) {
1066 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1067 j->cadence_f[4].on1, j->cadence_f[4].on1min, j->cadence_f[4].on1dot, j->cadence_f[4].on1max);
1070 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1071 j->cadence_f[4].off1, j->cadence_f[4].off1min, j->cadence_f[4].off1dot, j->cadence_f[4].off1max);
1074 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1075 j->cadence_f[4].on2, j->cadence_f[4].on2min, j->cadence_f[4].on2dot, j->cadence_f[4].on2max);
1078 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1079 j->cadence_f[4].off2, j->cadence_f[4].off2min, j->cadence_f[4].off2dot, j->cadence_f[4].off2max);
1082 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1083 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max);
1086 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1087 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max);
1092 if (j->cadence_f[4].state == 7) {
1093 j->cadence_f[4].state = 0;
1094 j->pstn_ring_stop = jiffies;
1095 j->ex.bits.pstn_ring = 1;
1096 ixj_kill_fasync(j, SIG_PSTN_RING, POLL_IN);
1097 if(ixjdebug & 0x0008) {
1098 printk(KERN_INFO "IXJ Ring int set /dev/phone%d at %ld\n", j->board, jiffies);
1101 if((j->pstn_ring_int != 0 && time_after(jiffies, j->pstn_ring_int + (hertz * 5)) && !j->flags.pstn_rmr) ||
1102 (j->pstn_ring_stop != 0 && time_after(jiffies, j->pstn_ring_stop + (hertz * 5)))) {
1103 if(ixjdebug & 0x0008) {
1104 printk("IXJ DAA no ring in 5 seconds /dev/phone%d at %ld\n", j->board, jiffies);
1105 printk("IXJ DAA pstn ring int /dev/phone%d at %ld\n", j->board, j->pstn_ring_int);
1106 printk("IXJ DAA pstn ring stop /dev/phone%d at %ld\n", j->board, j->pstn_ring_stop);
1108 j->pstn_ring_stop = j->pstn_ring_int = 0;
1109 daa_set_mode(j, SOP_PU_SLEEP);
1111 outb_p(j->pld_scrw.byte, j->XILINXbase);
1112 if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) {
1113 ixj_daa_cid_read(j);
1114 j->ex.bits.caller_id = 1;
1115 ixj_kill_fasync(j, SIG_CALLER_ID, POLL_IN);
1116 j->pstn_cid_intr = 0;
1118 if (daaint.bitreg.Cadence) {
1119 if(ixjdebug & 0x0008) {
1120 printk("IXJ DAA Cadence interrupt going to sleep /dev/phone%d\n", j->board);
1122 daa_set_mode(j, SOP_PU_SLEEP);
1123 j->ex.bits.pstn_ring = 0;
1126 case SOP_PU_CONVERSATION:
1127 if (daaint.bitreg.VDD_OK) {
1128 if(!daaint.bitreg.SI_0) {
1129 if (!j->pstn_winkstart) {
1130 if(ixjdebug & 0x0008) {
1131 printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies);
1133 j->pstn_winkstart = jiffies;
1136 if (j->pstn_winkstart) {
1137 if(ixjdebug & 0x0008) {
1138 printk("IXJ DAA possible wink end /dev/phone%d %ld\n", j->board, jiffies);
1140 j->pstn_winkstart = 0;
1144 if (j->pstn_winkstart && time_after(jiffies, j->pstn_winkstart + ((hertz * j->winktime) / 1000))) {
1145 if(ixjdebug & 0x0008) {
1146 printk("IXJ DAA wink detected going to sleep /dev/phone%d %ld\n", j->board, jiffies);
1148 daa_set_mode(j, SOP_PU_SLEEP);
1149 j->pstn_winkstart = 0;
1150 j->ex.bits.pstn_wink = 1;
1151 ixj_kill_fasync(j, SIG_PSTN_WINK, POLL_IN);
1157 static void ixj_timeout(unsigned long ptr)
1160 unsigned long jifon;
1161 IXJ *j = (IXJ *)ptr;
1164 if (j->DSPbase && atomic_read(&j->DSPWrite) == 0 && test_and_set_bit(board, (void *)&j->busyflags) == 0) {
1165 ixj_perfmon(j->timerchecks);
1166 j->hookstate = ixj_hookstate(j);
1167 if (j->tone_state) {
1168 if (!(j->hookstate)) {
1172 j->ex.bits.hookstate = 1;
1173 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1175 clear_bit(board, &j->busyflags);
1179 if (j->tone_state == 1)
1180 jifon = ((hertz * j->tone_on_time) * 25 / 100000);
1182 jifon = ((hertz * j->tone_on_time) * 25 / 100000) + ((hertz * j->tone_off_time) * 25 / 100000);
1183 if (time_before(jiffies, j->tone_start_jif + jifon)) {
1184 if (j->tone_state == 1) {
1185 ixj_play_tone(j, j->tone_index);
1186 if (j->dsp.low == 0x20) {
1187 clear_bit(board, &j->busyflags);
1192 ixj_play_tone(j, 0);
1193 if (j->dsp.low == 0x20) {
1194 clear_bit(board, &j->busyflags);
1200 ixj_tone_timeout(j);
1201 if (j->flags.dialtone) {
1204 if (j->flags.busytone) {
1206 if (j->dsp.low == 0x20) {
1207 clear_bit(board, &j->busyflags);
1212 if (j->flags.ringback) {
1214 if (j->dsp.low == 0x20) {
1215 clear_bit(board, &j->busyflags);
1220 if (!j->tone_state) {
1225 if (!(j->tone_state && j->dsp.low == 0x20)) {
1233 if (j->flags.cringing) {
1234 if (j->hookstate & 1) {
1235 j->flags.cringing = 0;
1237 } else if(j->cadence_f[5].enable && ((!j->cadence_f[5].en_filter) || (j->cadence_f[5].en_filter && j->flags.firstring))) {
1238 switch(j->cadence_f[5].state) {
1240 j->cadence_f[5].on1dot = jiffies + (long)((j->cadence_f[5].on1 * (hertz * 100) / 10000));
1241 if (time_before(jiffies, j->cadence_f[5].on1dot)) {
1242 if(ixjdebug & 0x0004) {
1243 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1247 j->cadence_f[5].state = 1;
1250 if (time_after(jiffies, j->cadence_f[5].on1dot)) {
1251 j->cadence_f[5].off1dot = jiffies + (long)((j->cadence_f[5].off1 * (hertz * 100) / 10000));
1252 if(ixjdebug & 0x0004) {
1253 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1256 j->cadence_f[5].state = 2;
1260 if (time_after(jiffies, j->cadence_f[5].off1dot)) {
1261 if(ixjdebug & 0x0004) {
1262 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1265 if (j->cadence_f[5].on2) {
1266 j->cadence_f[5].on2dot = jiffies + (long)((j->cadence_f[5].on2 * (hertz * 100) / 10000));
1267 j->cadence_f[5].state = 3;
1269 j->cadence_f[5].state = 7;
1274 if (time_after(jiffies, j->cadence_f[5].on2dot)) {
1275 if(ixjdebug & 0x0004) {
1276 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1279 if (j->cadence_f[5].off2) {
1280 j->cadence_f[5].off2dot = jiffies + (long)((j->cadence_f[5].off2 * (hertz * 100) / 10000));
1281 j->cadence_f[5].state = 4;
1283 j->cadence_f[5].state = 7;
1288 if (time_after(jiffies, j->cadence_f[5].off2dot)) {
1289 if(ixjdebug & 0x0004) {
1290 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1293 if (j->cadence_f[5].on3) {
1294 j->cadence_f[5].on3dot = jiffies + (long)((j->cadence_f[5].on3 * (hertz * 100) / 10000));
1295 j->cadence_f[5].state = 5;
1297 j->cadence_f[5].state = 7;
1302 if (time_after(jiffies, j->cadence_f[5].on3dot)) {
1303 if(ixjdebug & 0x0004) {
1304 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1307 if (j->cadence_f[5].off3) {
1308 j->cadence_f[5].off3dot = jiffies + (long)((j->cadence_f[5].off3 * (hertz * 100) / 10000));
1309 j->cadence_f[5].state = 6;
1311 j->cadence_f[5].state = 7;
1316 if (time_after(jiffies, j->cadence_f[5].off3dot)) {
1317 if(ixjdebug & 0x0004) {
1318 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1320 j->cadence_f[5].state = 7;
1324 if(ixjdebug & 0x0004) {
1325 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1327 j->flags.cidring = 1;
1328 j->cadence_f[5].state = 0;
1331 if (j->flags.cidring && !j->flags.cidsent) {
1332 j->flags.cidsent = 1;
1334 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1337 j->flags.cidring = 0;
1339 clear_bit(board, &j->busyflags);
1343 if (time_after(jiffies, j->ring_cadence_jif + (hertz / 2))) {
1344 if (j->flags.cidring && !j->flags.cidsent) {
1345 j->flags.cidsent = 1;
1347 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1350 j->flags.cidring = 0;
1352 j->ring_cadence_t--;
1353 if (j->ring_cadence_t == -1)
1354 j->ring_cadence_t = 15;
1355 j->ring_cadence_jif = jiffies;
1357 if (j->ring_cadence & 1 << j->ring_cadence_t) {
1358 if(j->flags.cidsent && j->cadence_f[5].en_filter)
1359 j->flags.firstring = 1;
1364 if(!j->flags.cidsent)
1365 j->flags.cidring = 1;
1368 clear_bit(board, &j->busyflags);
1373 if (!j->flags.ringing) {
1374 if (j->hookstate) { /* & 1) { */
1375 if (j->dsp.low != 0x20 &&
1376 SLIC_GetState(j) != PLD_SLIC_STATE_ACTIVE) {
1377 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1381 ixj_WriteDSPCommand(0x511B, j);
1382 j->proc_load = j->ssr.high << 8 | j->ssr.low;
1383 if (!j->m_hook && (j->hookstate & 1)) {
1384 j->m_hook = j->ex.bits.hookstate = 1;
1385 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1388 if (j->ex.bits.dtmf_ready) {
1389 j->dtmf_wp = j->dtmf_rp = j->ex.bits.dtmf_ready = 0;
1393 j->ex.bits.hookstate = 1;
1394 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1398 if (j->cardtype == QTI_LINEJACK && !j->flags.pstncheck && j->flags.pstn_present) {
1402 wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
1404 clear_bit(board, &j->busyflags);
1409 static int ixj_status_wait(IXJ *j)
1413 jif = jiffies + ((60 * hertz) / 100);
1414 while (!IsStatusReady(j)) {
1415 ixj_perfmon(j->statuswait);
1416 if (time_after(jiffies, jif)) {
1417 ixj_perfmon(j->statuswaitfail);
1424 static int ixj_PCcontrol_wait(IXJ *j)
1428 jif = jiffies + ((60 * hertz) / 100);
1429 while (!IsPCControlReady(j)) {
1430 ixj_perfmon(j->pcontrolwait);
1431 if (time_after(jiffies, jif)) {
1432 ixj_perfmon(j->pcontrolwaitfail);
1439 static int ixj_WriteDSPCommand(unsigned short cmd, IXJ *j)
1444 atomic_inc(&j->DSPWrite);
1445 if(atomic_read(&j->DSPWrite) > 1) {
1446 printk("IXJ %d DSP write overlap attempting command 0x%4.4x\n", j->board, cmd);
1449 bytes.high = (cmd & 0xFF00) >> 8;
1450 bytes.low = cmd & 0x00FF;
1451 jif = jiffies + ((60 * hertz) / 100);
1452 while (!IsControlReady(j)) {
1453 ixj_perfmon(j->iscontrolready);
1454 if (time_after(jiffies, jif)) {
1455 ixj_perfmon(j->iscontrolreadyfail);
1456 atomic_dec(&j->DSPWrite);
1457 if(atomic_read(&j->DSPWrite) > 0) {
1458 printk("IXJ %d DSP overlaped command 0x%4.4x during control ready failure.\n", j->board, cmd);
1459 while(atomic_read(&j->DSPWrite) > 0) {
1460 atomic_dec(&j->DSPWrite);
1466 outb(bytes.low, j->DSPbase + 6);
1467 outb(bytes.high, j->DSPbase + 7);
1469 if (ixj_status_wait(j)) {
1472 atomic_dec(&j->DSPWrite);
1473 if(atomic_read(&j->DSPWrite) > 0) {
1474 printk("IXJ %d DSP overlaped command 0x%4.4x during status wait failure.\n", j->board, cmd);
1475 while(atomic_read(&j->DSPWrite) > 0) {
1476 atomic_dec(&j->DSPWrite);
1481 /* Read Software Status Register */
1482 j->ssr.low = inb_p(j->DSPbase + 2);
1483 j->ssr.high = inb_p(j->DSPbase + 3);
1484 atomic_dec(&j->DSPWrite);
1485 if(atomic_read(&j->DSPWrite) > 0) {
1486 printk("IXJ %d DSP overlaped command 0x%4.4x\n", j->board, cmd);
1487 while(atomic_read(&j->DSPWrite) > 0) {
1488 atomic_dec(&j->DSPWrite);
1494 /***************************************************************************
1496 * General Purpose IO Register read routine
1498 ***************************************************************************/
1499 static inline int ixj_gpio_read(IXJ *j)
1501 if (ixj_WriteDSPCommand(0x5143, j))
1504 j->gpio.bytes.low = j->ssr.low;
1505 j->gpio.bytes.high = j->ssr.high;
1510 static inline void LED_SetState(int state, IXJ *j)
1512 if (j->cardtype == QTI_LINEJACK) {
1513 j->pld_scrw.bits.led1 = state & 0x1 ? 1 : 0;
1514 j->pld_scrw.bits.led2 = state & 0x2 ? 1 : 0;
1515 j->pld_scrw.bits.led3 = state & 0x4 ? 1 : 0;
1516 j->pld_scrw.bits.led4 = state & 0x8 ? 1 : 0;
1518 outb(j->pld_scrw.byte, j->XILINXbase);
1522 /*********************************************************************
1523 * GPIO Pins are configured as follows on the Quicknet Internet
1524 * PhoneJACK Telephony Cards
1526 * POTS Select GPIO_6=0 GPIO_7=0
1527 * Mic/Speaker Select GPIO_6=0 GPIO_7=1
1528 * Handset Select GPIO_6=1 GPIO_7=0
1530 * SLIC Active GPIO_1=0 GPIO_2=1 GPIO_5=0
1531 * SLIC Ringing GPIO_1=1 GPIO_2=1 GPIO_5=0
1532 * SLIC Open Circuit GPIO_1=0 GPIO_2=0 GPIO_5=0
1534 * Hook Switch changes reported on GPIO_3
1535 *********************************************************************/
1536 static int ixj_set_port(IXJ *j, int arg)
1538 if (j->cardtype == QTI_PHONEJACK_LITE) {
1539 if (arg != PORT_POTS)
1546 j->port = PORT_POTS;
1547 switch (j->cardtype) {
1549 if (j->flags.pcmciasct == 1)
1550 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1554 case QTI_PHONEJACK_PCI:
1555 j->pld_slicw.pcib.mic = 0;
1556 j->pld_slicw.pcib.spk = 0;
1557 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1560 ixj_set_pots(j, 0); /* Disconnect POTS/PSTN relay */
1561 if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to
1562 Software Control Register */
1564 j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
1566 outb(j->pld_scrw.byte, j->XILINXbase);
1567 j->pld_clock.byte = 0;
1568 outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1569 j->pld_slicw.bits.rly1 = 1;
1570 j->pld_slicw.bits.spken = 0;
1571 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1572 ixj_mixer(0x1200, j); /* Turn Off MIC switch on mixer left */
1573 ixj_mixer(0x1401, j); /* Turn On Mono1 switch on mixer left */
1574 ixj_mixer(0x1300, j); /* Turn Off MIC switch on mixer right */
1575 ixj_mixer(0x1501, j); /* Turn On Mono1 switch on mixer right */
1576 ixj_mixer(0x0E80, j); /*Mic mute */
1577 ixj_mixer(0x0F00, j); /* Set mono out (SLIC) to 0dB */
1578 ixj_mixer(0x0080, j); /* Mute Master Left volume */
1579 ixj_mixer(0x0180, j); /* Mute Master Right volume */
1580 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
1581 /* SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
1584 j->gpio.bytes.high = 0x0B;
1585 j->gpio.bits.gpio6 = 0;
1586 j->gpio.bits.gpio7 = 0;
1587 ixj_WriteDSPCommand(j->gpio.word, j);
1592 if (j->cardtype == QTI_LINEJACK) {
1593 ixj_WriteDSPCommand(0xC534, j); /* Write CODEC config to Software Control Register */
1595 j->pld_slicw.bits.rly3 = 0;
1596 j->pld_slicw.bits.rly1 = 1;
1597 j->pld_slicw.bits.spken = 0;
1598 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1599 j->port = PORT_PSTN;
1605 j->port = PORT_SPEAKER;
1606 switch (j->cardtype) {
1608 if (j->flags.pcmciasct) {
1609 SLIC_SetState(PLD_SLIC_STATE_OC, j);
1612 case QTI_PHONEJACK_PCI:
1613 j->pld_slicw.pcib.mic = 1;
1614 j->pld_slicw.pcib.spk = 1;
1615 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1618 ixj_set_pots(j, 0); /* Disconnect POTS/PSTN relay */
1619 if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to
1620 Software Control Register */
1622 j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
1624 outb(j->pld_scrw.byte, j->XILINXbase);
1625 j->pld_clock.byte = 0;
1626 outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1627 j->pld_slicw.bits.rly1 = 1;
1628 j->pld_slicw.bits.spken = 1;
1629 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1630 ixj_mixer(0x1201, j); /* Turn On MIC switch on mixer left */
1631 ixj_mixer(0x1400, j); /* Turn Off Mono1 switch on mixer left */
1632 ixj_mixer(0x1301, j); /* Turn On MIC switch on mixer right */
1633 ixj_mixer(0x1500, j); /* Turn Off Mono1 switch on mixer right */
1634 ixj_mixer(0x0E06, j); /*Mic un-mute 0dB */
1635 ixj_mixer(0x0F80, j); /* Mute mono out (SLIC) */
1636 ixj_mixer(0x0000, j); /* Set Master Left volume to 0dB */
1637 ixj_mixer(0x0100, j); /* Set Master Right volume to 0dB */
1640 j->gpio.bytes.high = 0x0B;
1641 j->gpio.bits.gpio6 = 0;
1642 j->gpio.bits.gpio7 = 1;
1643 ixj_WriteDSPCommand(j->gpio.word, j);
1648 if (j->cardtype != QTI_PHONEJACK) {
1651 j->gpio.bytes.high = 0x0B;
1652 j->gpio.bits.gpio6 = 1;
1653 j->gpio.bits.gpio7 = 0;
1654 ixj_WriteDSPCommand(j->gpio.word, j);
1655 j->port = PORT_HANDSET;
1665 static int ixj_set_pots(IXJ *j, int arg)
1667 if (j->cardtype == QTI_LINEJACK) {
1669 if (j->port == PORT_PSTN) {
1670 j->pld_slicw.bits.rly1 = 0;
1671 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1672 j->flags.pots_pstn = 1;
1675 j->flags.pots_pstn = 0;
1679 j->pld_slicw.bits.rly1 = 1;
1680 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1681 j->flags.pots_pstn = 0;
1689 static void ixj_ring_on(IXJ *j)
1691 if (j->dsp.low == 0x20) /* Internet PhoneJACK */
1693 if (ixjdebug & 0x0004)
1694 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1696 j->gpio.bytes.high = 0x0B;
1697 j->gpio.bytes.low = 0x00;
1698 j->gpio.bits.gpio1 = 1;
1699 j->gpio.bits.gpio2 = 1;
1700 j->gpio.bits.gpio5 = 0;
1701 ixj_WriteDSPCommand(j->gpio.word, j); /* send the ring signal */
1702 } else /* Internet LineJACK, Internet PhoneJACK Lite or Internet PhoneJACK PCI */
1704 if (ixjdebug & 0x0004)
1705 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1707 SLIC_SetState(PLD_SLIC_STATE_RINGING, j);
1711 static int ixj_siadc(IXJ *j, int val)
1713 if(j->cardtype == QTI_PHONECARD){
1714 if(j->flags.pcmciascp){
1716 return j->siadc.bits.rxg;
1718 if(val < 0 || val > 0x1F)
1721 j->siadc.bits.hom = 0; /* Handset Out Mute */
1722 j->siadc.bits.lom = 0; /* Line Out Mute */
1723 j->siadc.bits.rxg = val; /*(0xC000 - 0x41C8) / 0x4EF; RX PGA Gain */
1724 j->psccr.bits.addr = 6; /* R/W Smart Cable Register Address */
1725 j->psccr.bits.rw = 0; /* Read / Write flag */
1726 j->psccr.bits.dev = 0;
1727 outb(j->siadc.byte, j->XILINXbase + 0x00);
1728 outb(j->psccr.byte, j->XILINXbase + 0x01);
1729 ixj_PCcontrol_wait(j);
1730 return j->siadc.bits.rxg;
1736 static int ixj_sidac(IXJ *j, int val)
1738 if(j->cardtype == QTI_PHONECARD){
1739 if(j->flags.pcmciascp){
1741 return j->sidac.bits.txg;
1743 if(val < 0 || val > 0x1F)
1746 j->sidac.bits.srm = 1; /* Speaker Right Mute */
1747 j->sidac.bits.slm = 1; /* Speaker Left Mute */
1748 j->sidac.bits.txg = val; /* (0xC000 - 0x45E4) / 0x5D3; TX PGA Gain */
1749 j->psccr.bits.addr = 7; /* R/W Smart Cable Register Address */
1750 j->psccr.bits.rw = 0; /* Read / Write flag */
1751 j->psccr.bits.dev = 0;
1752 outb(j->sidac.byte, j->XILINXbase + 0x00);
1753 outb(j->psccr.byte, j->XILINXbase + 0x01);
1754 ixj_PCcontrol_wait(j);
1755 return j->sidac.bits.txg;
1761 static int ixj_pcmcia_cable_check(IXJ *j)
1763 j->pccr1.byte = inb_p(j->XILINXbase + 0x03);
1764 if (!j->flags.pcmciastate) {
1765 j->pccr2.byte = inb_p(j->XILINXbase + 0x02);
1766 if (j->pccr1.bits.drf || j->pccr2.bits.rstc) {
1767 j->flags.pcmciastate = 4;
1770 if (j->pccr1.bits.ed) {
1771 j->pccr1.bits.ed = 0;
1772 j->psccr.bits.dev = 3;
1773 j->psccr.bits.rw = 1;
1774 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
1775 ixj_PCcontrol_wait(j);
1776 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
1777 j->pslic.bits.led2 = j->pslic.bits.det ? 1 : 0;
1778 j->psccr.bits.dev = 3;
1779 j->psccr.bits.rw = 0;
1780 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1781 ixj_PCcontrol_wait(j);
1782 return j->pslic.bits.led2 ? 1 : 0;
1783 } else if (j->flags.pcmciasct) {
1788 } else if (j->flags.pcmciastate == 4) {
1789 if (!j->pccr1.bits.drf) {
1790 j->flags.pcmciastate = 3;
1793 } else if (j->flags.pcmciastate == 3) {
1794 j->pccr2.bits.pwr = 0;
1795 j->pccr2.bits.rstc = 1;
1796 outb(j->pccr2.byte, j->XILINXbase + 0x02);
1797 j->checkwait = jiffies + (hertz * 2);
1798 j->flags.incheck = 1;
1799 j->flags.pcmciastate = 2;
1801 } else if (j->flags.pcmciastate == 2) {
1802 if (j->flags.incheck) {
1803 if (time_before(jiffies, j->checkwait)) {
1806 j->flags.incheck = 0;
1809 j->pccr2.bits.pwr = 0;
1810 j->pccr2.bits.rstc = 0;
1811 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1812 j->flags.pcmciastate = 1;
1814 } else if (j->flags.pcmciastate == 1) {
1815 j->flags.pcmciastate = 0;
1816 if (!j->pccr1.bits.drf) {
1817 j->psccr.bits.dev = 3;
1818 j->psccr.bits.rw = 1;
1819 outb_p(j->psccr.byte, j->XILINXbase + 0x01);
1820 ixj_PCcontrol_wait(j);
1821 j->flags.pcmciascp = 1; /* Set Cable Present Flag */
1823 j->flags.pcmciasct = (inw_p(j->XILINXbase + 0x00) >> 8) & 0x03; /* Get Cable Type */
1825 if (j->flags.pcmciasct == 3) {
1826 j->flags.pcmciastate = 4;
1828 } else if (j->flags.pcmciasct == 0) {
1829 j->pccr2.bits.pwr = 1;
1830 j->pccr2.bits.rstc = 0;
1831 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1832 j->port = PORT_SPEAKER;
1834 j->port = PORT_POTS;
1836 j->sic1.bits.cpd = 0; /* Chip Power Down */
1837 j->sic1.bits.mpd = 0; /* MIC Bias Power Down */
1838 j->sic1.bits.hpd = 0; /* Handset Bias Power Down */
1839 j->sic1.bits.lpd = 0; /* Line Bias Power Down */
1840 j->sic1.bits.spd = 1; /* Speaker Drive Power Down */
1841 j->psccr.bits.addr = 1; /* R/W Smart Cable Register Address */
1842 j->psccr.bits.rw = 0; /* Read / Write flag */
1843 j->psccr.bits.dev = 0;
1844 outb(j->sic1.byte, j->XILINXbase + 0x00);
1845 outb(j->psccr.byte, j->XILINXbase + 0x01);
1846 ixj_PCcontrol_wait(j);
1848 j->sic2.bits.al = 0; /* Analog Loopback DAC analog -> ADC analog */
1849 j->sic2.bits.dl2 = 0; /* Digital Loopback DAC -> ADC one bit */
1850 j->sic2.bits.dl1 = 0; /* Digital Loopback ADC -> DAC one bit */
1851 j->sic2.bits.pll = 0; /* 1 = div 10, 0 = div 5 */
1852 j->sic2.bits.hpd = 0; /* HPF disable */
1853 j->psccr.bits.addr = 2; /* R/W Smart Cable Register Address */
1854 j->psccr.bits.rw = 0; /* Read / Write flag */
1855 j->psccr.bits.dev = 0;
1856 outb(j->sic2.byte, j->XILINXbase + 0x00);
1857 outb(j->psccr.byte, j->XILINXbase + 0x01);
1858 ixj_PCcontrol_wait(j);
1860 j->psccr.bits.addr = 3; /* R/W Smart Cable Register Address */
1861 j->psccr.bits.rw = 0; /* Read / Write flag */
1862 j->psccr.bits.dev = 0;
1863 outb(0x00, j->XILINXbase + 0x00); /* PLL Divide N1 */
1864 outb(j->psccr.byte, j->XILINXbase + 0x01);
1865 ixj_PCcontrol_wait(j);
1867 j->psccr.bits.addr = 4; /* R/W Smart Cable Register Address */
1868 j->psccr.bits.rw = 0; /* Read / Write flag */
1869 j->psccr.bits.dev = 0;
1870 outb(0x09, j->XILINXbase + 0x00); /* PLL Multiply M1 */
1871 outb(j->psccr.byte, j->XILINXbase + 0x01);
1872 ixj_PCcontrol_wait(j);
1874 j->sirxg.bits.lig = 1; /* Line In Gain */
1875 j->sirxg.bits.lim = 1; /* Line In Mute */
1876 j->sirxg.bits.mcg = 0; /* MIC In Gain was 3 */
1877 j->sirxg.bits.mcm = 0; /* MIC In Mute */
1878 j->sirxg.bits.him = 0; /* Handset In Mute */
1879 j->sirxg.bits.iir = 1; /* IIR */
1880 j->psccr.bits.addr = 5; /* R/W Smart Cable Register Address */
1881 j->psccr.bits.rw = 0; /* Read / Write flag */
1882 j->psccr.bits.dev = 0;
1883 outb(j->sirxg.byte, j->XILINXbase + 0x00);
1884 outb(j->psccr.byte, j->XILINXbase + 0x01);
1885 ixj_PCcontrol_wait(j);
1890 j->siaatt.bits.sot = 0;
1891 j->psccr.bits.addr = 9; /* R/W Smart Cable Register Address */
1892 j->psccr.bits.rw = 0; /* Read / Write flag */
1893 j->psccr.bits.dev = 0;
1894 outb(j->siaatt.byte, j->XILINXbase + 0x00);
1895 outb(j->psccr.byte, j->XILINXbase + 0x01);
1896 ixj_PCcontrol_wait(j);
1898 if (j->flags.pcmciasct == 1 && !j->readers && !j->writers) {
1899 j->psccr.byte = j->pslic.byte = 0;
1900 j->pslic.bits.powerdown = 1;
1901 j->psccr.bits.dev = 3;
1902 j->psccr.bits.rw = 0;
1903 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1904 ixj_PCcontrol_wait(j);
1909 j->flags.pcmciascp = 0;
1915 static int ixj_hookstate(IXJ *j)
1920 switch (j->cardtype) {
1923 fOffHook = j->gpio.bits.gpio3read ? 1 : 0;
1926 case QTI_PHONEJACK_LITE:
1927 case QTI_PHONEJACK_PCI:
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) {
1933 j->checkwait = jiffies;
1935 if(time_before(jiffies, j->checkwait + 2)) {
1940 j->p_hook = fOffHook;
1941 printk("IXJ : /dev/phone%d pots-pstn hookstate check %d at %ld\n", j->board, fOffHook, jiffies);
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 det = jiffies + (hertz / 50);
1949 while (time_before(jiffies, det)) {
1950 set_current_state(TASK_INTERRUPTIBLE);
1951 schedule_timeout(1);
1955 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
1959 if (j->cardtype == QTI_PHONEJACK_PCI) {
1960 j->pld_scrr.byte = inb_p(j->XILINXbase);
1961 fOffHook = j->pld_scrr.pcib.det ? 1 : 0;
1963 fOffHook = j->pld_slicr.bits.det ? 1 : 0;
1968 fOffHook = ixj_pcmcia_cable_check(j);
1971 if (j->r_hook != fOffHook) {
1972 j->r_hook = fOffHook;
1973 if (j->port == PORT_SPEAKER || j->port == PORT_HANDSET) { // || (j->port == PORT_PSTN && j->flags.pots_pstn == 0)) {
1974 j->ex.bits.hookstate = 1;
1975 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1976 } else if (!fOffHook) {
1977 j->flash_end = jiffies + ((60 * hertz) / 100);
1981 if(time_before(jiffies, j->flash_end)) {
1982 j->ex.bits.flash = 1;
1984 ixj_kill_fasync(j, SIG_FLASH, POLL_IN);
1987 if(time_before(jiffies, j->flash_end)) {
1992 if (j->port == PORT_PSTN && j->daa_mode == SOP_PU_CONVERSATION)
1995 if (j->port == PORT_SPEAKER) {
1996 if(j->cardtype == QTI_PHONECARD) {
1997 if(j->flags.pcmciascp && j->flags.pcmciasct) {
2005 if (j->port == PORT_HANDSET)
2011 static void ixj_ring_off(IXJ *j)
2013 if (j->dsp.low == 0x20) /* Internet PhoneJACK */
2015 if (ixjdebug & 0x0004)
2016 printk(KERN_INFO "IXJ Ring Off\n");
2017 j->gpio.bytes.high = 0x0B;
2018 j->gpio.bytes.low = 0x00;
2019 j->gpio.bits.gpio1 = 0;
2020 j->gpio.bits.gpio2 = 1;
2021 j->gpio.bits.gpio5 = 0;
2022 ixj_WriteDSPCommand(j->gpio.word, j);
2023 } else /* Internet LineJACK */
2025 if (ixjdebug & 0x0004)
2026 printk(KERN_INFO "IXJ Ring Off\n");
2028 if(!j->flags.cidplay)
2029 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
2035 static void ixj_ring_start(IXJ *j)
2037 j->flags.cringing = 1;
2038 if (ixjdebug & 0x0004)
2039 printk(KERN_INFO "IXJ Cadence Ringing Start /dev/phone%d\n", j->board);
2040 if (ixj_hookstate(j) & 1) {
2041 if (j->port == PORT_POTS)
2043 j->flags.cringing = 0;
2044 if (ixjdebug & 0x0004)
2045 printk(KERN_INFO "IXJ Cadence Ringing Stopped /dev/phone%d off hook\n", j->board);
2046 } else if(j->cadence_f[5].enable && (!j->cadence_f[5].en_filter)) {
2047 j->ring_cadence_jif = jiffies;
2048 j->flags.cidsent = j->flags.cidring = 0;
2049 j->cadence_f[5].state = 0;
2050 if(j->cadence_f[5].on1)
2053 j->ring_cadence_jif = jiffies;
2054 j->ring_cadence_t = 15;
2055 if (j->ring_cadence & 1 << j->ring_cadence_t) {
2060 j->flags.cidsent = j->flags.cidring = j->flags.firstring = 0;
2064 static int ixj_ring(IXJ *j)
2067 unsigned long jif, det;
2069 j->flags.ringing = 1;
2070 if (ixj_hookstate(j) & 1) {
2072 j->flags.ringing = 0;
2076 for (cntr = 0; cntr < j->maxrings; cntr++) {
2077 jif = jiffies + (1 * hertz);
2079 while (time_before(jiffies, jif)) {
2080 if (ixj_hookstate(j) & 1) {
2082 j->flags.ringing = 0;
2085 set_current_state(TASK_INTERRUPTIBLE);
2086 schedule_timeout(1);
2087 if (signal_pending(current))
2090 jif = jiffies + (3 * hertz);
2092 while (time_before(jiffies, jif)) {
2093 if (ixj_hookstate(j) & 1) {
2094 det = jiffies + (hertz / 100);
2095 while (time_before(jiffies, det)) {
2096 set_current_state(TASK_INTERRUPTIBLE);
2097 schedule_timeout(1);
2098 if (signal_pending(current))
2101 if (ixj_hookstate(j) & 1) {
2102 j->flags.ringing = 0;
2106 set_current_state(TASK_INTERRUPTIBLE);
2107 schedule_timeout(1);
2108 if (signal_pending(current))
2113 j->flags.ringing = 0;
2117 static int ixj_open(struct phone_device *p, struct file *file_p)
2119 IXJ *j = get_ixj(p->board);
2120 file_p->private_data = j;
2125 if (file_p->f_mode & FMODE_READ) {
2133 if (file_p->f_mode & FMODE_WRITE) {
2137 if (file_p->f_mode & FMODE_READ){
2144 if (j->cardtype == QTI_PHONECARD) {
2145 j->pslic.bits.powerdown = 0;
2146 j->psccr.bits.dev = 3;
2147 j->psccr.bits.rw = 0;
2148 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
2149 ixj_PCcontrol_wait(j);
2152 j->flags.cidplay = 0;
2153 j->flags.cidcw_ack = 0;
2155 if (ixjdebug & 0x0002)
2156 printk(KERN_INFO "Opening board %d\n", p->board);
2158 j->framesread = j->frameswritten = 0;
2162 static int ixj_release(struct inode *inode, struct file *file_p)
2166 IXJ *j = file_p->private_data;
2167 int board = j->p.board;
2170 * Set up locks to ensure that only one process is talking to the DSP at a time.
2171 * This is necessary to keep the DSP from locking up.
2173 while(test_and_set_bit(board, (void *)&j->busyflags) != 0) {
2174 set_current_state(TASK_INTERRUPTIBLE);
2175 schedule_timeout(1);
2177 if (ixjdebug & 0x0002)
2178 printk(KERN_INFO "Closing board %d\n", NUM(inode));
2180 if (j->cardtype == QTI_PHONECARD)
2181 ixj_set_port(j, PORT_SPEAKER);
2183 ixj_set_port(j, PORT_POTS);
2188 set_play_volume(j, 0x100);
2189 set_rec_volume(j, 0x100);
2192 /* Restore the tone table to default settings. */
2198 ixj_init_tone(j, &ti);
2204 ixj_init_tone(j, &ti);
2210 ixj_init_tone(j, &ti);
2216 ixj_init_tone(j, &ti);
2222 ixj_init_tone(j, &ti);
2228 ixj_init_tone(j, &ti);
2234 ixj_init_tone(j, &ti);
2240 ixj_init_tone(j, &ti);
2246 ixj_init_tone(j, &ti);
2252 ixj_init_tone(j, &ti);
2258 ixj_init_tone(j, &ti);
2264 ixj_init_tone(j, &ti);
2270 ixj_init_tone(j, &ti);
2276 ixj_init_tone(j, &ti);
2282 ixj_init_tone(j, &ti);
2288 ixj_init_tone(j, &ti);
2294 ixj_init_tone(j, &ti);
2300 ixj_init_tone(j, &ti);
2302 set_rec_depth(j, 2); /* Set Record Channel Limit to 2 frames */
2304 set_play_depth(j, 2); /* Set Playback Channel Limit to 2 frames */
2306 j->ex.bits.dtmf_ready = 0;
2308 j->dtmf_wp = j->dtmf_rp = 0;
2309 j->rec_mode = j->play_mode = -1;
2310 j->flags.ringing = 0;
2311 j->maxrings = MAXRINGS;
2312 j->ring_cadence = USA_RING_CADENCE;
2313 if(j->cadence_f[5].enable) {
2314 j->cadence_f[5].enable = j->cadence_f[5].en_filter = j->cadence_f[5].state = 0;
2318 j->flags.dtmf_oob = 0;
2319 for (cnt = 0; cnt < 4; cnt++)
2320 j->cadence_f[cnt].enable = 0;
2324 if(j->cardtype == QTI_PHONECARD) {
2325 SLIC_SetState(PLD_SLIC_STATE_OC, j);
2328 if (file_p->f_mode & FMODE_READ)
2330 if (file_p->f_mode & FMODE_WRITE)
2333 if (j->read_buffer && !j->readers) {
2334 kfree(j->read_buffer);
2335 j->read_buffer = NULL;
2336 j->read_buffer_size = 0;
2338 if (j->write_buffer && !j->writers) {
2339 kfree(j->write_buffer);
2340 j->write_buffer = NULL;
2341 j->write_buffer_size = 0;
2343 j->rec_codec = j->play_codec = 0;
2344 j->rec_frame_size = j->play_frame_size = 0;
2345 j->flags.cidsent = j->flags.cidring = 0;
2346 ixj_fasync(-1, file_p, 0); /* remove from list of async notification */
2348 if(j->cardtype == QTI_LINEJACK && !j->readers && !j->writers) {
2349 ixj_set_port(j, PORT_PSTN);
2350 daa_set_mode(j, SOP_PU_SLEEP);
2353 ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
2355 /* Set up the default signals for events */
2356 for (cnt = 0; cnt < 35; cnt++)
2357 j->ixj_signals[cnt] = SIGIO;
2359 /* Set the excetion signal enable flags */
2360 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring =
2361 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 =
2362 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;
2364 file_p->private_data = NULL;
2365 clear_bit(board, &j->busyflags);
2369 static int read_filters(IXJ *j)
2371 unsigned short fc, cnt, trg;
2375 if (ixj_WriteDSPCommand(0x5144, j)) {
2376 if(ixjdebug & 0x0001) {
2377 printk(KERN_INFO "Read Frame Counter failed!\n");
2381 fc = j->ssr.high << 8 | j->ssr.low;
2382 if (fc == j->frame_count)
2385 j->frame_count = fc;
2392 for (cnt = 0; cnt < 4; cnt++) {
2393 if (ixj_WriteDSPCommand(0x5154 + cnt, j)) {
2394 if(ixjdebug & 0x0001) {
2395 printk(KERN_INFO "Select Filter %d failed!\n", cnt);
2399 if (ixj_WriteDSPCommand(0x515C, j)) {
2400 if(ixjdebug & 0x0001) {
2401 printk(KERN_INFO "Read Filter History %d failed!\n", cnt);
2405 j->filter_hist[cnt] = j->ssr.high << 8 | j->ssr.low;
2407 if (j->cadence_f[cnt].enable) {
2408 if (j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) {
2409 if (j->cadence_f[cnt].state == 0) {
2410 j->cadence_f[cnt].state = 1;
2411 j->cadence_f[cnt].on1min = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 - var)) / 10000));
2412 j->cadence_f[cnt].on1dot = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100)) / 10000));
2413 j->cadence_f[cnt].on1max = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 + var)) / 10000));
2414 } else if (j->cadence_f[cnt].state == 2 &&
2415 (time_after(jiffies, j->cadence_f[cnt].off1min) &&
2416 time_before(jiffies, j->cadence_f[cnt].off1max))) {
2417 if (j->cadence_f[cnt].on2) {
2418 j->cadence_f[cnt].state = 3;
2419 j->cadence_f[cnt].on2min = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 - var)) / 10000));
2420 j->cadence_f[cnt].on2dot = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100)) / 10000));
2421 j->cadence_f[cnt].on2max = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 + var)) / 10000));
2423 j->cadence_f[cnt].state = 7;
2425 } else if (j->cadence_f[cnt].state == 4 &&
2426 (time_after(jiffies, j->cadence_f[cnt].off2min) &&
2427 time_before(jiffies, j->cadence_f[cnt].off2max))) {
2428 if (j->cadence_f[cnt].on3) {
2429 j->cadence_f[cnt].state = 5;
2430 j->cadence_f[cnt].on3min = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 - var)) / 10000));
2431 j->cadence_f[cnt].on3dot = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100)) / 10000));
2432 j->cadence_f[cnt].on3max = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 + var)) / 10000));
2434 j->cadence_f[cnt].state = 7;
2437 j->cadence_f[cnt].state = 0;
2439 } else if (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)) {
2440 if (j->cadence_f[cnt].state == 1) {
2441 if(!j->cadence_f[cnt].on1) {
2442 j->cadence_f[cnt].state = 7;
2443 } else if((time_after(jiffies, j->cadence_f[cnt].on1min) &&
2444 time_before(jiffies, j->cadence_f[cnt].on1max))) {
2445 if(j->cadence_f[cnt].off1) {
2446 j->cadence_f[cnt].state = 2;
2447 j->cadence_f[cnt].off1min = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 - var)) / 10000));
2448 j->cadence_f[cnt].off1dot = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100)) / 10000));
2449 j->cadence_f[cnt].off1max = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 + var)) / 10000));
2451 j->cadence_f[cnt].state = 7;
2454 j->cadence_f[cnt].state = 0;
2456 } else if (j->cadence_f[cnt].state == 3) {
2457 if((time_after(jiffies, j->cadence_f[cnt].on2min) &&
2458 time_before(jiffies, j->cadence_f[cnt].on2max))) {
2459 if(j->cadence_f[cnt].off2) {
2460 j->cadence_f[cnt].state = 4;
2461 j->cadence_f[cnt].off2min = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 - var)) / 10000));
2462 j->cadence_f[cnt].off2dot = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100)) / 10000));
2463 j->cadence_f[cnt].off2max = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 + var)) / 10000));
2465 j->cadence_f[cnt].state = 7;
2468 j->cadence_f[cnt].state = 0;
2470 } else if (j->cadence_f[cnt].state == 5) {
2471 if ((time_after(jiffies, j->cadence_f[cnt].on3min) &&
2472 time_before(jiffies, j->cadence_f[cnt].on3max))) {
2473 if(j->cadence_f[cnt].off3) {
2474 j->cadence_f[cnt].state = 6;
2475 j->cadence_f[cnt].off3min = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 - var)) / 10000));
2476 j->cadence_f[cnt].off3dot = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100)) / 10000));
2477 j->cadence_f[cnt].off3max = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 + var)) / 10000));
2479 j->cadence_f[cnt].state = 7;
2482 j->cadence_f[cnt].state = 0;
2485 j->cadence_f[cnt].state = 0;
2488 switch(j->cadence_f[cnt].state) {
2490 if(time_after(jiffies, j->cadence_f[cnt].on1dot) &&
2491 !j->cadence_f[cnt].off1 &&
2492 !j->cadence_f[cnt].on2 && !j->cadence_f[cnt].off2 &&
2493 !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2494 j->cadence_f[cnt].state = 7;
2498 if(time_after(jiffies, j->cadence_f[cnt].on2dot) &&
2499 !j->cadence_f[cnt].off2 &&
2500 !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2501 j->cadence_f[cnt].state = 7;
2505 if(time_after(jiffies, j->cadence_f[cnt].on3dot) &&
2506 !j->cadence_f[cnt].off3) {
2507 j->cadence_f[cnt].state = 7;
2513 if (ixjdebug & 0x0040) {
2514 printk(KERN_INFO "IXJ Tone Cadence state = %d /dev/phone%d at %ld\n", j->cadence_f[cnt].state, j->board, jiffies);
2515 switch(j->cadence_f[cnt].state) {
2517 printk(KERN_INFO "IXJ /dev/phone%d No Tone detected\n", j->board);
2520 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %u %ld - %ld - %ld\n", j->board,
2521 j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max);
2524 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min,
2525 j->cadence_f[cnt].off1max);
2528 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on2min,
2529 j->cadence_f[cnt].on2max);
2532 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off2min,
2533 j->cadence_f[cnt].off2max);
2536 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min,
2537 j->cadence_f[cnt].on3max);
2540 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min,
2541 j->cadence_f[cnt].off3max);
2546 if (j->cadence_f[cnt].state == 7) {
2547 j->cadence_f[cnt].state = 0;
2548 if (j->cadence_f[cnt].enable == 1)
2549 j->cadence_f[cnt].enable = 0;
2552 if(ixjdebug & 0x0020) {
2553 printk(KERN_INFO "Filter Cadence 0 triggered %ld\n", jiffies);
2556 ixj_kill_fasync(j, SIG_FC0, POLL_IN);
2559 if(ixjdebug & 0x0020) {
2560 printk(KERN_INFO "Filter Cadence 1 triggered %ld\n", jiffies);
2563 ixj_kill_fasync(j, SIG_FC1, POLL_IN);
2566 if(ixjdebug & 0x0020) {
2567 printk(KERN_INFO "Filter Cadence 2 triggered %ld\n", jiffies);
2570 ixj_kill_fasync(j, SIG_FC2, POLL_IN);
2573 if(ixjdebug & 0x0020) {
2574 printk(KERN_INFO "Filter Cadence 3 triggered %ld\n", jiffies);
2577 ixj_kill_fasync(j, SIG_FC3, POLL_IN);
2581 if (j->filter_en[cnt] && ((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) ||
2582 (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)))) {
2583 if((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12))) {
2585 } else if((j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3))) {
2590 if(ixjdebug & 0x0020) {
2591 printk(KERN_INFO "Filter 0 triggered %d at %ld\n", trg, jiffies);
2594 ixj_kill_fasync(j, SIG_F0, POLL_IN);
2597 if(ixjdebug & 0x0020) {
2598 printk(KERN_INFO "Filter 1 triggered %d at %ld\n", trg, jiffies);
2601 ixj_kill_fasync(j, SIG_F1, POLL_IN);
2604 if(ixjdebug & 0x0020) {
2605 printk(KERN_INFO "Filter 2 triggered %d at %ld\n", trg, jiffies);
2608 ixj_kill_fasync(j, SIG_F2, POLL_IN);
2611 if(ixjdebug & 0x0020) {
2612 printk(KERN_INFO "Filter 3 triggered %d at %ld\n", trg, jiffies);
2615 ixj_kill_fasync(j, SIG_F3, POLL_IN);
2623 static int LineMonitor(IXJ *j)
2630 if (ixj_WriteDSPCommand(0x7000, j)) /* Line Monitor */
2633 j->dtmf.bytes.high = j->ssr.high;
2634 j->dtmf.bytes.low = j->ssr.low;
2635 if (!j->dtmf_state && j->dtmf.bits.dtmf_valid) {
2637 j->dtmf_current = j->dtmf.bits.digit;
2639 if (j->dtmf_state && !j->dtmf.bits.dtmf_valid) /* && j->dtmf_wp != j->dtmf_rp) */
2641 if(!j->cidcw_wait) {
2642 j->dtmfbuffer[j->dtmf_wp] = j->dtmf_current;
2644 if (j->dtmf_wp == 79)
2646 j->ex.bits.dtmf_ready = 1;
2647 if(j->ex_sig.bits.dtmf_ready) {
2648 ixj_kill_fasync(j, SIG_DTMF_READY, POLL_IN);
2651 else if(j->dtmf_current == 0x00 || j->dtmf_current == 0x0D) {
2652 if(ixjdebug & 0x0020) {
2653 printk("IXJ phone%d saw CIDCW Ack DTMF %d from display at %ld\n", j->board, j->dtmf_current, jiffies);
2655 j->flags.cidcw_ack = 1;
2664 /************************************************************************
2666 * Functions to allow alaw <-> ulaw conversions.
2668 ************************************************************************/
2670 static void ulaw2alaw(unsigned char *buff, unsigned long len)
2672 static unsigned char table_ulaw2alaw[] =
2674 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D,
2675 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25,
2676 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D,
2677 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35,
2678 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02,
2679 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A,
2680 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12,
2681 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B,
2682 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63,
2683 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79,
2684 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71,
2685 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D,
2686 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45,
2687 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D,
2688 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51,
2689 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5,
2690 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD,
2691 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5,
2692 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD,
2693 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5,
2694 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82,
2695 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A,
2696 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92,
2697 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB,
2698 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3,
2699 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9,
2700 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1,
2701 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD,
2702 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5,
2703 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD,
2704 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1,
2705 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5