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 ***************************************************************************/
45 * Revision 4.8 2003/07/09 19:39:00 Daniele Bellucci
46 * Audit some copy_*_user and minor cleanup.
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
52 * Revision 4.6 2001/08/13 01:05:05 craigs
53 * Really fixed PHONE_QUERY_CODEC problem this time
55 * Revision 4.5 2001/08/13 00:11:03 craigs
56 * Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson
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
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
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 *
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
74 * Revision 4.0 2001/08/04 12:33:12 craigs
75 * New version using GNU autoconf
77 * Revision 3.105 2001/07/20 23:14:32 eokerson
78 * More work on CallerID generation when using ring cadences.
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.
83 * Revision 3.103 2001/07/05 19:20:16 eokerson
85 * Changed mic gain to 30dB on Internet LineJACK mic/speaker port.
87 * Revision 3.102 2001/07/03 23:51:21 eokerson
88 * Un-mute mic on Internet LineJACK when in speakerphone mode.
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
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.
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>.
101 * Revision 3.98 2001/05/08 19:55:33 eokerson
102 * Fixed POTS hookstate detection while it is connected to PSTN port.
104 * Revision 3.97 2001/05/08 00:01:04 eokerson
105 * Fixed kernel oops when sending caller ID data.
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.
110 * Revision 3.95 2001/04/25 22:06:47 eokerson
111 * Fixed squawking at beginning of some G.723.1 calls.
113 * Revision 3.94 2001/04/03 23:42:00 eokerson
114 * Added linear volume ioctls
115 * Added raw filter load ioctl
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.
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.
126 * Revision 3.91 2001/02/13 00:55:44 eokerson
127 * Turn AEC back on after changing frame sizes.
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.
132 * Revision 3.89 2001/02/12 15:41:16 eokerson
133 * Fix from Artis Kugevics - Tone gains were not being set correctly.
135 * Revision 3.88 2001/02/05 23:25:42 eokerson
136 * Fixed lockup bugs with deregister.
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.
142 * Revision 3.86 2001/01/23 23:53:46 eokerson
143 * Fixes to G.729 compatibility.
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.
149 * Revision 3.84 2001/01/22 23:32:10 eokerson
150 * Some bugfixes from David Huggins-Daines, <dhd@cepstral.com> and other cleanups.
152 * Revision 3.83 2001/01/19 14:51:41 eokerson
153 * Fixed ixj_WriteDSPCommand to decrement usage counter when command fails.
155 * Revision 3.82 2001/01/19 00:34:49 eokerson
156 * Added verbosity to write overlap errors.
158 * Revision 3.81 2001/01/18 23:56:54 eokerson
159 * Fixed PSTN line test functions.
161 * Revision 3.80 2001/01/18 22:29:27 eokerson
162 * Updated AEC/AGC values for different cards.
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.
168 * Revision 3.78 2001/01/16 19:43:09 eokerson
169 * Added support for Linux 2.4.x kernels.
171 * Revision 3.77 2001/01/09 04:00:52 eokerson
172 * Linetest will now test the line, even if it has previously succeeded.
174 * Revision 3.76 2001/01/08 19:27:00 eokerson
175 * Fixed problem with standard cable on Internet PhoneCARD.
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.
180 * Revision 3.74 2000/12/08 22:41:50 eokerson
181 * Added capability for G729B.
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.
187 * Revision 3.72 2000/12/06 19:31:31 eokerson
188 * Modified signal behavior to only send one signal per event.
190 * Revision 3.71 2000/12/06 03:23:08 eokerson
191 * Fixed CallerID on Call Waiting.
193 * Revision 3.70 2000/12/04 21:29:37 eokerson
194 * Added checking to Smart Cable gain functions.
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.
200 * Revision 3.68 2000/12/04 00:17:21 craigs
201 * Changed mixer voice gain to +6dB rather than 0dB
203 * Revision 3.67 2000/11/30 21:25:51 eokerson
204 * Fixed write signal errors.
206 * Revision 3.66 2000/11/29 22:42:44 eokerson
207 * Fixed PSTN ring detect problems.
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
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
217 * Revision 3.63 2000/11/28 11:38:41 craigs
218 * Added display of AEC modes in AUTO and AGC mode
220 * Revision 3.62 2000/11/28 04:05:44 eokerson
221 * Improved PSTN ring detection routine.
223 * Revision 3.61 2000/11/27 21:53:12 eokerson
224 * Fixed flash detection.
226 * Revision 3.60 2000/11/27 15:57:29 eokerson
227 * More work on G.729 load routines.
229 * Revision 3.59 2000/11/25 21:55:12 eokerson
230 * Fixed errors in G.729 load routine.
232 * Revision 3.58 2000/11/25 04:08:29 eokerson
233 * Added board locks around G.729 and TS85 load routines.
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
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.
248 #define PERFMON_STATS
252 #include <linux/module.h>
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/mutex.h>
261 #include <linux/mm.h>
262 #include <linux/ioport.h>
263 #include <linux/interrupt.h>
264 #include <linux/proc_fs.h>
265 #include <linux/poll.h>
266 #include <linux/timer.h>
267 #include <linux/delay.h>
268 #include <linux/pci.h>
271 #include <asm/uaccess.h>
273 #include <linux/isapnp.h>
277 #define TYPE(inode) (iminor(inode) >> 4)
278 #define NUM(inode) (iminor(inode) & 0xf)
280 static DEFINE_MUTEX(ixj_mutex);
282 static int hertz = HZ;
283 static int samplerate = 100;
285 module_param(ixjdebug, int, 0);
287 static DEFINE_PCI_DEVICE_TABLE(ixj_pci_tbl) = {
288 { PCI_VENDOR_ID_QUICKNET, PCI_DEVICE_ID_QUICKNET_XJ,
289 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
292 MODULE_DEVICE_TABLE(pci, ixj_pci_tbl);
294 /************************************************************************
296 * ixjdebug meanings are now bit mapped instead of level based
297 * Values can be or'ed together to turn on multiple messages
299 * bit 0 (0x0001) = any failure
300 * bit 1 (0x0002) = general messages
301 * bit 2 (0x0004) = POTS ringing related
302 * bit 3 (0x0008) = PSTN events
303 * bit 4 (0x0010) = PSTN Cadence state details
304 * bit 5 (0x0020) = Tone detection triggers
305 * bit 6 (0x0040) = Tone detection cadence details
306 * bit 7 (0x0080) = ioctl tracking
307 * bit 8 (0x0100) = signal tracking
308 * bit 9 (0x0200) = CallerID generation details
310 ************************************************************************/
314 static IXJ *ixj[IXJMAX];
315 #define get_ixj(b) ixj[(b)]
318 * Allocate a free IXJ device
321 static IXJ *ixj_alloc()
323 for(cnt=0; cnt<IXJMAX; cnt++)
325 if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
327 j = kmalloc(sizeof(IXJ), GFP_KERNEL);
337 static void ixj_fsk_free(IXJ *j)
343 static void ixj_fsk_alloc(IXJ *j)
346 j->fskdata = kmalloc(8000, GFP_KERNEL);
348 if(ixjdebug & 0x0200) {
349 printk("IXJ phone%d - allocate failed\n", j->board);
354 if(ixjdebug & 0x0200) {
355 printk("IXJ phone%d - allocate succeeded\n", j->board);
363 static IXJ ixj[IXJMAX];
364 #define get_ixj(b) (&ixj[(b)])
367 * Allocate a free IXJ device
370 static IXJ *ixj_alloc(void)
373 for(cnt=0; cnt<IXJMAX; cnt++) {
374 if(!ixj[cnt].DSPbase)
380 static inline void ixj_fsk_free(IXJ *j) {;}
382 static inline void ixj_fsk_alloc(IXJ *j)
390 #define ixj_perfmon(x) ((x)++)
392 #define ixj_perfmon(x) do { } while(0)
395 static int ixj_convert_loaded;
397 static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
399 /************************************************************************
401 * These are function definitions to allow external modules to register
402 * enhanced functionality call backs.
404 ************************************************************************/
406 static int Stub(IXJ * J, unsigned long arg)
411 static IXJ_REGFUNC ixj_PreRead = &Stub;
412 static IXJ_REGFUNC ixj_PostRead = &Stub;
413 static IXJ_REGFUNC ixj_PreWrite = &Stub;
414 static IXJ_REGFUNC ixj_PostWrite = &Stub;
416 static void ixj_read_frame(IXJ *j);
417 static void ixj_write_frame(IXJ *j);
418 static void ixj_init_timer(IXJ *j);
419 static void ixj_add_timer(IXJ * j);
420 static void ixj_timeout(unsigned long ptr);
421 static int read_filters(IXJ *j);
422 static int LineMonitor(IXJ *j);
423 static int ixj_fasync(int fd, struct file *, int mode);
424 static int ixj_set_port(IXJ *j, int arg);
425 static int ixj_set_pots(IXJ *j, int arg);
426 static int ixj_hookstate(IXJ *j);
427 static int ixj_record_start(IXJ *j);
428 static void ixj_record_stop(IXJ *j);
429 static void set_rec_volume(IXJ *j, int volume);
430 static int get_rec_volume(IXJ *j);
431 static int set_rec_codec(IXJ *j, int rate);
432 static void ixj_vad(IXJ *j, int arg);
433 static int ixj_play_start(IXJ *j);
434 static void ixj_play_stop(IXJ *j);
435 static int ixj_set_tone_on(unsigned short arg, IXJ *j);
436 static int ixj_set_tone_off(unsigned short, IXJ *j);
437 static int ixj_play_tone(IXJ *j, char tone);
438 static void ixj_aec_start(IXJ *j, int level);
439 static int idle(IXJ *j);
440 static void ixj_ring_on(IXJ *j);
441 static void ixj_ring_off(IXJ *j);
442 static void aec_stop(IXJ *j);
443 static void ixj_ringback(IXJ *j);
444 static void ixj_busytone(IXJ *j);
445 static void ixj_dialtone(IXJ *j);
446 static void ixj_cpt_stop(IXJ *j);
447 static char daa_int_read(IXJ *j);
448 static char daa_CR_read(IXJ *j, int cr);
449 static int daa_set_mode(IXJ *j, int mode);
450 static int ixj_linetest(IXJ *j);
451 static int ixj_daa_write(IXJ *j);
452 static int ixj_daa_cid_read(IXJ *j);
453 static void DAA_Coeff_US(IXJ *j);
454 static void DAA_Coeff_UK(IXJ *j);
455 static void DAA_Coeff_France(IXJ *j);
456 static void DAA_Coeff_Germany(IXJ *j);
457 static void DAA_Coeff_Australia(IXJ *j);
458 static void DAA_Coeff_Japan(IXJ *j);
459 static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
460 static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
461 static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
462 static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
463 static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
464 /* Serial Control Interface funtions */
465 static int SCI_Control(IXJ *j, int control);
466 static int SCI_Prepare(IXJ *j);
467 static int SCI_WaitHighSCI(IXJ *j);
468 static int SCI_WaitLowSCI(IXJ *j);
469 static DWORD PCIEE_GetSerialNumber(WORD wAddress);
470 static int ixj_PCcontrol_wait(IXJ *j);
471 static void ixj_pre_cid(IXJ *j);
472 static void ixj_write_cid(IXJ *j);
473 static void ixj_write_cid_bit(IXJ *j, int bit);
474 static int set_base_frame(IXJ *j, int size);
475 static int set_play_codec(IXJ *j, int rate);
476 static void set_rec_depth(IXJ *j, int depth);
477 static int ixj_mixer(long val, IXJ *j);
479 /************************************************************************
480 CT8020/CT8021 Host Programmers Model
481 Host address Function Access
483 0-1 Aux Software Status Register (reserved) Read Only
484 2-3 Software Status Register Read Only
485 4-5 Aux Software Control Register (reserved) Read Write
486 6-7 Software Control Register Read Write
487 8-9 Hardware Status Register Read Only
488 A-B Hardware Control Register Read Write
489 C-D Host Transmit (Write) Data Buffer Access Port (buffer input)Write Only
490 E-F Host Receive (Read) Data Buffer Access Port (buffer input) Read Only
491 ************************************************************************/
493 static inline void ixj_read_HSR(IXJ *j)
495 j->hsr.bytes.low = inb_p(j->DSPbase + 8);
496 j->hsr.bytes.high = inb_p(j->DSPbase + 9);
499 static inline int IsControlReady(IXJ *j)
502 return j->hsr.bits.controlrdy ? 1 : 0;
505 static inline int IsPCControlReady(IXJ *j)
507 j->pccr1.byte = inb_p(j->XILINXbase + 3);
508 return j->pccr1.bits.crr ? 1 : 0;
511 static inline int IsStatusReady(IXJ *j)
514 return j->hsr.bits.statusrdy ? 1 : 0;
517 static inline int IsRxReady(IXJ *j)
520 ixj_perfmon(j->rxreadycheck);
521 return j->hsr.bits.rxrdy ? 1 : 0;
524 static inline int IsTxReady(IXJ *j)
527 ixj_perfmon(j->txreadycheck);
528 return j->hsr.bits.txrdy ? 1 : 0;
531 static inline void set_play_volume(IXJ *j, int volume)
533 if (ixjdebug & 0x0002)
534 printk(KERN_INFO "IXJ: /dev/phone%d Setting Play Volume to 0x%4.4x\n", j->board, volume);
535 ixj_WriteDSPCommand(0xCF02, j);
536 ixj_WriteDSPCommand(volume, j);
539 static int set_play_volume_linear(IXJ *j, int volume)
541 int newvolume, dspplaymax;
543 if (ixjdebug & 0x0002)
544 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Play Volume to 0x%4.4x\n", j->board, volume);
545 if(volume > 100 || volume < 0) {
549 /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
550 switch (j->cardtype) {
555 if(j->port == PORT_PSTN) {
561 case QTI_PHONEJACK_LITE:
564 case QTI_PHONEJACK_PCI:
573 newvolume = (dspplaymax * volume) / 100;
574 set_play_volume(j, newvolume);
578 static inline void set_play_depth(IXJ *j, int depth)
584 ixj_WriteDSPCommand(0x5280 + depth, j);
587 static inline int get_play_volume(IXJ *j)
589 ixj_WriteDSPCommand(0xCF00, j);
590 return j->ssr.high << 8 | j->ssr.low;
593 static int get_play_volume_linear(IXJ *j)
595 int volume, newvolume, dspplaymax;
597 /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
598 switch (j->cardtype) {
603 if(j->port == PORT_PSTN) {
609 case QTI_PHONEJACK_LITE:
612 case QTI_PHONEJACK_PCI:
621 volume = get_play_volume(j);
622 newvolume = (volume * 100) / dspplaymax;
628 static inline BYTE SLIC_GetState(IXJ *j)
630 if (j->cardtype == QTI_PHONECARD) {
632 j->psccr.bits.dev = 3;
633 j->psccr.bits.rw = 1;
634 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
635 ixj_PCcontrol_wait(j);
636 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
637 ixj_PCcontrol_wait(j);
638 if (j->pslic.bits.powerdown)
639 return PLD_SLIC_STATE_OC;
640 else if (!j->pslic.bits.ring0 && !j->pslic.bits.ring1)
641 return PLD_SLIC_STATE_ACTIVE;
643 return PLD_SLIC_STATE_RINGING;
645 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
647 return j->pld_slicr.bits.state;
650 static bool SLIC_SetState(BYTE byState, IXJ *j)
652 bool fRetVal = false;
654 if (j->cardtype == QTI_PHONECARD) {
655 if (j->flags.pcmciasct) {
657 case PLD_SLIC_STATE_TIPOPEN:
658 case PLD_SLIC_STATE_OC:
659 j->pslic.bits.powerdown = 1;
660 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
663 case PLD_SLIC_STATE_RINGING:
664 if (j->readers || j->writers) {
665 j->pslic.bits.powerdown = 0;
666 j->pslic.bits.ring0 = 1;
667 j->pslic.bits.ring1 = 0;
671 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
673 case PLD_SLIC_STATE_STANDBY:
674 case PLD_SLIC_STATE_ACTIVE:
675 if (j->readers || j->writers) {
676 j->pslic.bits.powerdown = 0;
678 j->pslic.bits.powerdown = 1;
680 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
683 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
685 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
691 j->psccr.bits.dev = 3;
692 j->psccr.bits.rw = 0;
693 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
694 ixj_PCcontrol_wait(j);
697 /* Set the C1, C2, C3 & B2EN signals. */
699 case PLD_SLIC_STATE_OC:
700 j->pld_slicw.bits.c1 = 0;
701 j->pld_slicw.bits.c2 = 0;
702 j->pld_slicw.bits.c3 = 0;
703 j->pld_slicw.bits.b2en = 0;
704 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
707 case PLD_SLIC_STATE_RINGING:
708 j->pld_slicw.bits.c1 = 1;
709 j->pld_slicw.bits.c2 = 0;
710 j->pld_slicw.bits.c3 = 0;
711 j->pld_slicw.bits.b2en = 1;
712 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
715 case PLD_SLIC_STATE_ACTIVE:
716 j->pld_slicw.bits.c1 = 0;
717 j->pld_slicw.bits.c2 = 1;
718 j->pld_slicw.bits.c3 = 0;
719 j->pld_slicw.bits.b2en = 0;
720 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
723 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
725 j->pld_slicw.bits.c1 = 1;
726 j->pld_slicw.bits.c2 = 1;
727 j->pld_slicw.bits.c3 = 0;
728 j->pld_slicw.bits.b2en = 0;
729 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
732 case PLD_SLIC_STATE_TIPOPEN:
733 j->pld_slicw.bits.c1 = 0;
734 j->pld_slicw.bits.c2 = 0;
735 j->pld_slicw.bits.c3 = 1;
736 j->pld_slicw.bits.b2en = 0;
737 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
740 case PLD_SLIC_STATE_STANDBY:
741 j->pld_slicw.bits.c1 = 1;
742 j->pld_slicw.bits.c2 = 0;
743 j->pld_slicw.bits.c3 = 1;
744 j->pld_slicw.bits.b2en = 1;
745 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
748 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
750 j->pld_slicw.bits.c1 = 0;
751 j->pld_slicw.bits.c2 = 1;
752 j->pld_slicw.bits.c3 = 1;
753 j->pld_slicw.bits.b2en = 0;
754 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
757 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
759 j->pld_slicw.bits.c1 = 1;
760 j->pld_slicw.bits.c2 = 1;
761 j->pld_slicw.bits.c3 = 1;
762 j->pld_slicw.bits.b2en = 0;
763 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
775 static int ixj_wink(IXJ *j)
779 slicnow = SLIC_GetState(j);
781 j->pots_winkstart = jiffies;
782 SLIC_SetState(PLD_SLIC_STATE_OC, j);
784 msleep(jiffies_to_msecs(j->winktime));
786 SLIC_SetState(slicnow, j);
790 static void ixj_init_timer(IXJ *j)
792 init_timer(&j->timer);
793 j->timer.function = ixj_timeout;
794 j->timer.data = (unsigned long)j;
797 static void ixj_add_timer(IXJ *j)
799 j->timer.expires = jiffies + (hertz / samplerate);
800 add_timer(&j->timer);
803 static void ixj_tone_timeout(IXJ *j)
808 if (j->tone_state == 3) {
811 j->tone_cadence_state++;
812 if (j->tone_cadence_state >= j->cadence_t->elements_used) {
813 switch (j->cadence_t->termination) {
817 case REPEAT_LAST_ELEMENT:
818 j->tone_cadence_state--;
819 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
822 j->tone_cadence_state = 0;
823 if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
824 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
825 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
826 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
827 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
828 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
829 ixj_init_tone(j, &ti);
831 ixj_set_tone_on(j->cadence_t->ce[0].tone_on_time, j);
832 ixj_set_tone_off(j->cadence_t->ce[0].tone_off_time, j);
833 ixj_play_tone(j, j->cadence_t->ce[0].index);
837 if (j->cadence_t->ce[j->tone_cadence_state].gain0) {
838 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
839 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
840 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
841 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
842 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
843 ixj_init_tone(j, &ti);
845 ixj_set_tone_on(j->cadence_t->ce[j->tone_cadence_state].tone_on_time, j);
846 ixj_set_tone_off(j->cadence_t->ce[j->tone_cadence_state].tone_off_time, j);
847 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
853 static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
855 if(j->ixj_signals[event]) {
856 if(ixjdebug & 0x0100)
857 printk("Sending signal for event %d\n", event);
858 /* Send apps notice of change */
859 /* see config.h for macro definition */
860 kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
864 static void ixj_pstn_state(IXJ *j)
867 union XOPXR0 XR0, daaint;
871 XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
873 XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
875 j->pld_scrr.byte = inb_p(j->XILINXbase);
876 if (j->pld_scrr.bits.daaflag) {
878 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.RING) {
879 if(time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
880 daaint.bitreg.RING = 1;
881 if(ixjdebug & 0x0008) {
882 printk(KERN_INFO "IXJ DAA Ring Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
885 daa_set_mode(j, SOP_PU_RESET);
888 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Caller_ID) {
889 daaint.bitreg.Caller_ID = 1;
890 j->pstn_cid_intr = 1;
891 j->pstn_cid_received = jiffies;
892 if(ixjdebug & 0x0008) {
893 printk(KERN_INFO "IXJ DAA Caller_ID Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
896 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Cadence) {
897 daaint.bitreg.Cadence = 1;
898 if(ixjdebug & 0x0008) {
899 printk(KERN_INFO "IXJ DAA Cadence Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
902 if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK != XR0.bitreg.VDD_OK) {
903 daaint.bitreg.VDD_OK = 1;
904 daaint.bitreg.SI_0 = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK;
908 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)) {
909 daaint.bitreg.RMR = 1;
910 daaint.bitreg.SI_1 = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
911 if(ixjdebug & 0x0008) {
912 printk(KERN_INFO "IXJ DAA RMR /dev/phone%d was %s for %ld\n", j->board, XR0.bitreg.RMR?"on":"off", jiffies - j->pstn_last_rmr);
914 j->pstn_prev_rmr = j->pstn_last_rmr;
915 j->pstn_last_rmr = jiffies;
917 switch(j->daa_mode) {
919 if (daaint.bitreg.RING) {
920 if (!j->flags.pstn_ringing) {
921 if (j->daa_mode != SOP_PU_RINGING) {
922 j->pstn_ring_int = jiffies;
923 daa_set_mode(j, SOP_PU_RINGING);
929 if (daaint.bitreg.RMR) {
930 if (ixjdebug & 0x0008) {
931 printk(KERN_INFO "IXJ Ring Cadence a state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
933 if (daaint.bitreg.SI_1) { /* Rising edge of RMR */
934 j->flags.pstn_rmr = 1;
935 j->pstn_ring_start = jiffies;
936 j->pstn_ring_stop = 0;
937 j->ex.bits.pstn_ring = 0;
938 if (j->cadence_f[4].state == 0) {
939 j->cadence_f[4].state = 1;
940 j->cadence_f[4].on1min = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 - var)) / 10000);
941 j->cadence_f[4].on1dot = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100)) / 10000);
942 j->cadence_f[4].on1max = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 + var)) / 10000);
943 } else if (j->cadence_f[4].state == 2) {
944 if((time_after(jiffies, j->cadence_f[4].off1min) &&
945 time_before(jiffies, j->cadence_f[4].off1max))) {
946 if (j->cadence_f[4].on2) {
947 j->cadence_f[4].state = 3;
948 j->cadence_f[4].on2min = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 - var)) / 10000));
949 j->cadence_f[4].on2dot = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100)) / 10000));
950 j->cadence_f[4].on2max = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 + var)) / 10000));
952 j->cadence_f[4].state = 7;
955 if (ixjdebug & 0x0008) {
956 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
957 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
958 j->cadence_f[4].off1);
960 j->cadence_f[4].state = 0;
962 } else if (j->cadence_f[4].state == 4) {
963 if((time_after(jiffies, j->cadence_f[4].off2min) &&
964 time_before(jiffies, j->cadence_f[4].off2max))) {
965 if (j->cadence_f[4].on3) {
966 j->cadence_f[4].state = 5;
967 j->cadence_f[4].on3min = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 - var)) / 10000));
968 j->cadence_f[4].on3dot = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100)) / 10000));
969 j->cadence_f[4].on3max = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 + var)) / 10000));
971 j->cadence_f[4].state = 7;
974 if (ixjdebug & 0x0008) {
975 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
976 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
977 j->cadence_f[4].off2);
979 j->cadence_f[4].state = 0;
981 } else if (j->cadence_f[4].state == 6) {
982 if((time_after(jiffies, j->cadence_f[4].off3min) &&
983 time_before(jiffies, j->cadence_f[4].off3max))) {
984 j->cadence_f[4].state = 7;
986 if (ixjdebug & 0x0008) {
987 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
988 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
989 j->cadence_f[4].off3);
991 j->cadence_f[4].state = 0;
994 j->cadence_f[4].state = 0;
996 } else { /* Falling edge of RMR */
997 j->pstn_ring_start = 0;
998 j->pstn_ring_stop = jiffies;
999 if (j->cadence_f[4].state == 1) {
1000 if(!j->cadence_f[4].on1) {
1001 j->cadence_f[4].state = 7;
1002 } else if((time_after(jiffies, j->cadence_f[4].on1min) &&
1003 time_before(jiffies, j->cadence_f[4].on1max))) {
1004 if (j->cadence_f[4].off1) {
1005 j->cadence_f[4].state = 2;
1006 j->cadence_f[4].off1min = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 - var)) / 10000));
1007 j->cadence_f[4].off1dot = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100)) / 10000));
1008 j->cadence_f[4].off1max = jiffies + (long)((j->cadence_f[4].off1 * (hertz * (100 + var)) / 10000));
1010 j->cadence_f[4].state = 7;
1013 if (ixjdebug & 0x0008) {
1014 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1015 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1016 j->cadence_f[4].on1);
1018 j->cadence_f[4].state = 0;
1020 } else if (j->cadence_f[4].state == 3) {
1021 if((time_after(jiffies, j->cadence_f[4].on2min) &&
1022 time_before(jiffies, j->cadence_f[4].on2max))) {
1023 if (j->cadence_f[4].off2) {
1024 j->cadence_f[4].state = 4;
1025 j->cadence_f[4].off2min = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 - var)) / 10000));
1026 j->cadence_f[4].off2dot = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100)) / 10000));
1027 j->cadence_f[4].off2max = jiffies + (long)((j->cadence_f[4].off2 * (hertz * (100 + var)) / 10000));
1029 j->cadence_f[4].state = 7;
1032 if (ixjdebug & 0x0008) {
1033 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1034 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1035 j->cadence_f[4].on2);
1037 j->cadence_f[4].state = 0;
1039 } else if (j->cadence_f[4].state == 5) {
1040 if((time_after(jiffies, j->cadence_f[4].on3min) &&
1041 time_before(jiffies, j->cadence_f[4].on3max))) {
1042 if (j->cadence_f[4].off3) {
1043 j->cadence_f[4].state = 6;
1044 j->cadence_f[4].off3min = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 - var)) / 10000));
1045 j->cadence_f[4].off3dot = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100)) / 10000));
1046 j->cadence_f[4].off3max = jiffies + (long)((j->cadence_f[4].off3 * (hertz * (100 + var)) / 10000));
1048 j->cadence_f[4].state = 7;
1051 j->cadence_f[4].state = 0;
1054 if (ixjdebug & 0x0008) {
1055 printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
1056 j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
1057 j->cadence_f[4].on3);
1059 j->cadence_f[4].state = 0;
1062 if (ixjdebug & 0x0010) {
1063 printk(KERN_INFO "IXJ Ring Cadence b state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
1065 if (ixjdebug & 0x0010) {
1066 switch(j->cadence_f[4].state) {
1068 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1069 j->cadence_f[4].on1, j->cadence_f[4].on1min, j->cadence_f[4].on1dot, j->cadence_f[4].on1max);
1072 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1073 j->cadence_f[4].off1, j->cadence_f[4].off1min, j->cadence_f[4].off1dot, j->cadence_f[4].off1max);
1076 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1077 j->cadence_f[4].on2, j->cadence_f[4].on2min, j->cadence_f[4].on2dot, j->cadence_f[4].on2max);
1080 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1081 j->cadence_f[4].off2, j->cadence_f[4].off2min, j->cadence_f[4].off2dot, j->cadence_f[4].off2max);
1084 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1085 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max);
1088 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1089 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max);
1094 if (j->cadence_f[4].state == 7) {
1095 j->cadence_f[4].state = 0;
1096 j->pstn_ring_stop = jiffies;
1097 j->ex.bits.pstn_ring = 1;
1098 ixj_kill_fasync(j, SIG_PSTN_RING, POLL_IN);
1099 if(ixjdebug & 0x0008) {
1100 printk(KERN_INFO "IXJ Ring int set /dev/phone%d at %ld\n", j->board, jiffies);
1103 if((j->pstn_ring_int != 0 && time_after(jiffies, j->pstn_ring_int + (hertz * 5)) && !j->flags.pstn_rmr) ||
1104 (j->pstn_ring_stop != 0 && time_after(jiffies, j->pstn_ring_stop + (hertz * 5)))) {
1105 if(ixjdebug & 0x0008) {
1106 printk("IXJ DAA no ring in 5 seconds /dev/phone%d at %ld\n", j->board, jiffies);
1107 printk("IXJ DAA pstn ring int /dev/phone%d at %ld\n", j->board, j->pstn_ring_int);
1108 printk("IXJ DAA pstn ring stop /dev/phone%d at %ld\n", j->board, j->pstn_ring_stop);
1110 j->pstn_ring_stop = j->pstn_ring_int = 0;
1111 daa_set_mode(j, SOP_PU_SLEEP);
1113 outb_p(j->pld_scrw.byte, j->XILINXbase);
1114 if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) {
1115 ixj_daa_cid_read(j);
1116 j->ex.bits.caller_id = 1;
1117 ixj_kill_fasync(j, SIG_CALLER_ID, POLL_IN);
1118 j->pstn_cid_intr = 0;
1120 if (daaint.bitreg.Cadence) {
1121 if(ixjdebug & 0x0008) {
1122 printk("IXJ DAA Cadence interrupt going to sleep /dev/phone%d\n", j->board);
1124 daa_set_mode(j, SOP_PU_SLEEP);
1125 j->ex.bits.pstn_ring = 0;
1128 case SOP_PU_CONVERSATION:
1129 if (daaint.bitreg.VDD_OK) {
1130 if(!daaint.bitreg.SI_0) {
1131 if (!j->pstn_winkstart) {
1132 if(ixjdebug & 0x0008) {
1133 printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies);
1135 j->pstn_winkstart = jiffies;
1138 if (j->pstn_winkstart) {
1139 if(ixjdebug & 0x0008) {
1140 printk("IXJ DAA possible wink end /dev/phone%d %ld\n", j->board, jiffies);
1142 j->pstn_winkstart = 0;
1146 if (j->pstn_winkstart && time_after(jiffies, j->pstn_winkstart + ((hertz * j->winktime) / 1000))) {
1147 if(ixjdebug & 0x0008) {
1148 printk("IXJ DAA wink detected going to sleep /dev/phone%d %ld\n", j->board, jiffies);
1150 daa_set_mode(j, SOP_PU_SLEEP);
1151 j->pstn_winkstart = 0;
1152 j->ex.bits.pstn_wink = 1;
1153 ixj_kill_fasync(j, SIG_PSTN_WINK, POLL_IN);
1159 static void ixj_timeout(unsigned long ptr)
1162 unsigned long jifon;
1163 IXJ *j = (IXJ *)ptr;
1166 if (j->DSPbase && atomic_read(&j->DSPWrite) == 0 && test_and_set_bit(board, (void *)&j->busyflags) == 0) {
1167 ixj_perfmon(j->timerchecks);
1168 j->hookstate = ixj_hookstate(j);
1169 if (j->tone_state) {
1170 if (!(j->hookstate)) {
1174 j->ex.bits.hookstate = 1;
1175 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1177 clear_bit(board, &j->busyflags);
1181 if (j->tone_state == 1)
1182 jifon = ((hertz * j->tone_on_time) * 25 / 100000);
1184 jifon = ((hertz * j->tone_on_time) * 25 / 100000) + ((hertz * j->tone_off_time) * 25 / 100000);
1185 if (time_before(jiffies, j->tone_start_jif + jifon)) {
1186 if (j->tone_state == 1) {
1187 ixj_play_tone(j, j->tone_index);
1188 if (j->dsp.low == 0x20) {
1189 clear_bit(board, &j->busyflags);
1194 ixj_play_tone(j, 0);
1195 if (j->dsp.low == 0x20) {
1196 clear_bit(board, &j->busyflags);
1202 ixj_tone_timeout(j);
1203 if (j->flags.dialtone) {
1206 if (j->flags.busytone) {
1208 if (j->dsp.low == 0x20) {
1209 clear_bit(board, &j->busyflags);
1214 if (j->flags.ringback) {
1216 if (j->dsp.low == 0x20) {
1217 clear_bit(board, &j->busyflags);
1222 if (!j->tone_state) {
1227 if (!(j->tone_state && j->dsp.low == 0x20)) {
1235 if (j->flags.cringing) {
1236 if (j->hookstate & 1) {
1237 j->flags.cringing = 0;
1239 } else if(j->cadence_f[5].enable && ((!j->cadence_f[5].en_filter) || (j->cadence_f[5].en_filter && j->flags.firstring))) {
1240 switch(j->cadence_f[5].state) {
1242 j->cadence_f[5].on1dot = jiffies + (long)((j->cadence_f[5].on1 * (hertz * 100) / 10000));
1243 if (time_before(jiffies, j->cadence_f[5].on1dot)) {
1244 if(ixjdebug & 0x0004) {
1245 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1249 j->cadence_f[5].state = 1;
1252 if (time_after(jiffies, j->cadence_f[5].on1dot)) {
1253 j->cadence_f[5].off1dot = jiffies + (long)((j->cadence_f[5].off1 * (hertz * 100) / 10000));
1254 if(ixjdebug & 0x0004) {
1255 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1258 j->cadence_f[5].state = 2;
1262 if (time_after(jiffies, j->cadence_f[5].off1dot)) {
1263 if(ixjdebug & 0x0004) {
1264 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1267 if (j->cadence_f[5].on2) {
1268 j->cadence_f[5].on2dot = jiffies + (long)((j->cadence_f[5].on2 * (hertz * 100) / 10000));
1269 j->cadence_f[5].state = 3;
1271 j->cadence_f[5].state = 7;
1276 if (time_after(jiffies, j->cadence_f[5].on2dot)) {
1277 if(ixjdebug & 0x0004) {
1278 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1281 if (j->cadence_f[5].off2) {
1282 j->cadence_f[5].off2dot = jiffies + (long)((j->cadence_f[5].off2 * (hertz * 100) / 10000));
1283 j->cadence_f[5].state = 4;
1285 j->cadence_f[5].state = 7;
1290 if (time_after(jiffies, j->cadence_f[5].off2dot)) {
1291 if(ixjdebug & 0x0004) {
1292 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1295 if (j->cadence_f[5].on3) {
1296 j->cadence_f[5].on3dot = jiffies + (long)((j->cadence_f[5].on3 * (hertz * 100) / 10000));
1297 j->cadence_f[5].state = 5;
1299 j->cadence_f[5].state = 7;
1304 if (time_after(jiffies, j->cadence_f[5].on3dot)) {
1305 if(ixjdebug & 0x0004) {
1306 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1309 if (j->cadence_f[5].off3) {
1310 j->cadence_f[5].off3dot = jiffies + (long)((j->cadence_f[5].off3 * (hertz * 100) / 10000));
1311 j->cadence_f[5].state = 6;
1313 j->cadence_f[5].state = 7;
1318 if (time_after(jiffies, j->cadence_f[5].off3dot)) {
1319 if(ixjdebug & 0x0004) {
1320 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1322 j->cadence_f[5].state = 7;
1326 if(ixjdebug & 0x0004) {
1327 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1329 j->flags.cidring = 1;
1330 j->cadence_f[5].state = 0;
1333 if (j->flags.cidring && !j->flags.cidsent) {
1334 j->flags.cidsent = 1;
1336 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1339 j->flags.cidring = 0;
1341 clear_bit(board, &j->busyflags);
1345 if (time_after(jiffies, j->ring_cadence_jif + (hertz / 2))) {
1346 if (j->flags.cidring && !j->flags.cidsent) {
1347 j->flags.cidsent = 1;
1349 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1352 j->flags.cidring = 0;
1354 j->ring_cadence_t--;
1355 if (j->ring_cadence_t == -1)
1356 j->ring_cadence_t = 15;
1357 j->ring_cadence_jif = jiffies;
1359 if (j->ring_cadence & 1 << j->ring_cadence_t) {
1360 if(j->flags.cidsent && j->cadence_f[5].en_filter)
1361 j->flags.firstring = 1;
1366 if(!j->flags.cidsent)
1367 j->flags.cidring = 1;
1370 clear_bit(board, &j->busyflags);
1375 if (!j->flags.ringing) {
1376 if (j->hookstate) { /* & 1) { */
1377 if (j->dsp.low != 0x20 &&
1378 SLIC_GetState(j) != PLD_SLIC_STATE_ACTIVE) {
1379 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1383 ixj_WriteDSPCommand(0x511B, j);
1384 j->proc_load = j->ssr.high << 8 | j->ssr.low;
1385 if (!j->m_hook && (j->hookstate & 1)) {
1386 j->m_hook = j->ex.bits.hookstate = 1;
1387 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1390 if (j->ex.bits.dtmf_ready) {
1391 j->dtmf_wp = j->dtmf_rp = j->ex.bits.dtmf_ready = 0;
1395 j->ex.bits.hookstate = 1;
1396 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1400 if (j->cardtype == QTI_LINEJACK && !j->flags.pstncheck && j->flags.pstn_present) {
1404 wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
1406 clear_bit(board, &j->busyflags);
1411 static int ixj_status_wait(IXJ *j)
1415 jif = jiffies + ((60 * hertz) / 100);
1416 while (!IsStatusReady(j)) {
1417 ixj_perfmon(j->statuswait);
1418 if (time_after(jiffies, jif)) {
1419 ixj_perfmon(j->statuswaitfail);
1426 static int ixj_PCcontrol_wait(IXJ *j)
1430 jif = jiffies + ((60 * hertz) / 100);
1431 while (!IsPCControlReady(j)) {
1432 ixj_perfmon(j->pcontrolwait);
1433 if (time_after(jiffies, jif)) {
1434 ixj_perfmon(j->pcontrolwaitfail);
1441 static int ixj_WriteDSPCommand(unsigned short cmd, IXJ *j)
1446 atomic_inc(&j->DSPWrite);
1447 if(atomic_read(&j->DSPWrite) > 1) {
1448 printk("IXJ %d DSP write overlap attempting command 0x%4.4x\n", j->board, cmd);
1451 bytes.high = (cmd & 0xFF00) >> 8;
1452 bytes.low = cmd & 0x00FF;
1453 jif = jiffies + ((60 * hertz) / 100);
1454 while (!IsControlReady(j)) {
1455 ixj_perfmon(j->iscontrolready);
1456 if (time_after(jiffies, jif)) {
1457 ixj_perfmon(j->iscontrolreadyfail);
1458 atomic_dec(&j->DSPWrite);
1459 if(atomic_read(&j->DSPWrite) > 0) {
1460 printk("IXJ %d DSP overlaped command 0x%4.4x during control ready failure.\n", j->board, cmd);
1461 while(atomic_read(&j->DSPWrite) > 0) {
1462 atomic_dec(&j->DSPWrite);
1468 outb(bytes.low, j->DSPbase + 6);
1469 outb(bytes.high, j->DSPbase + 7);
1471 if (ixj_status_wait(j)) {
1474 atomic_dec(&j->DSPWrite);
1475 if(atomic_read(&j->DSPWrite) > 0) {
1476 printk("IXJ %d DSP overlaped command 0x%4.4x during status wait failure.\n", j->board, cmd);
1477 while(atomic_read(&j->DSPWrite) > 0) {
1478 atomic_dec(&j->DSPWrite);
1483 /* Read Software Status Register */
1484 j->ssr.low = inb_p(j->DSPbase + 2);
1485 j->ssr.high = inb_p(j->DSPbase + 3);
1486 atomic_dec(&j->DSPWrite);
1487 if(atomic_read(&j->DSPWrite) > 0) {
1488 printk("IXJ %d DSP overlaped command 0x%4.4x\n", j->board, cmd);
1489 while(atomic_read(&j->DSPWrite) > 0) {
1490 atomic_dec(&j->DSPWrite);
1496 /***************************************************************************
1498 * General Purpose IO Register read routine
1500 ***************************************************************************/
1501 static inline int ixj_gpio_read(IXJ *j)
1503 if (ixj_WriteDSPCommand(0x5143, j))
1506 j->gpio.bytes.low = j->ssr.low;
1507 j->gpio.bytes.high = j->ssr.high;
1512 static inline void LED_SetState(int state, IXJ *j)
1514 if (j->cardtype == QTI_LINEJACK) {
1515 j->pld_scrw.bits.led1 = state & 0x1 ? 1 : 0;
1516 j->pld_scrw.bits.led2 = state & 0x2 ? 1 : 0;
1517 j->pld_scrw.bits.led3 = state & 0x4 ? 1 : 0;
1518 j->pld_scrw.bits.led4 = state & 0x8 ? 1 : 0;
1520 outb(j->pld_scrw.byte, j->XILINXbase);
1524 /*********************************************************************
1525 * GPIO Pins are configured as follows on the Quicknet Internet
1526 * PhoneJACK Telephony Cards
1528 * POTS Select GPIO_6=0 GPIO_7=0
1529 * Mic/Speaker Select GPIO_6=0 GPIO_7=1
1530 * Handset Select GPIO_6=1 GPIO_7=0
1532 * SLIC Active GPIO_1=0 GPIO_2=1 GPIO_5=0
1533 * SLIC Ringing GPIO_1=1 GPIO_2=1 GPIO_5=0
1534 * SLIC Open Circuit GPIO_1=0 GPIO_2=0 GPIO_5=0
1536 * Hook Switch changes reported on GPIO_3
1537 *********************************************************************/
1538 static int ixj_set_port(IXJ *j, int arg)
1540 if (j->cardtype == QTI_PHONEJACK_LITE) {
1541 if (arg != PORT_POTS)
1548 j->port = PORT_POTS;
1549 switch (j->cardtype) {
1551 if (j->flags.pcmciasct == 1)
1552 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1556 case QTI_PHONEJACK_PCI:
1557 j->pld_slicw.pcib.mic = 0;
1558 j->pld_slicw.pcib.spk = 0;
1559 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1562 ixj_set_pots(j, 0); /* Disconnect POTS/PSTN relay */
1563 if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to
1564 Software Control Register */
1566 j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
1568 outb(j->pld_scrw.byte, j->XILINXbase);
1569 j->pld_clock.byte = 0;
1570 outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1571 j->pld_slicw.bits.rly1 = 1;
1572 j->pld_slicw.bits.spken = 0;
1573 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1574 ixj_mixer(0x1200, j); /* Turn Off MIC switch on mixer left */
1575 ixj_mixer(0x1401, j); /* Turn On Mono1 switch on mixer left */
1576 ixj_mixer(0x1300, j); /* Turn Off MIC switch on mixer right */
1577 ixj_mixer(0x1501, j); /* Turn On Mono1 switch on mixer right */
1578 ixj_mixer(0x0E80, j); /*Mic mute */
1579 ixj_mixer(0x0F00, j); /* Set mono out (SLIC) to 0dB */
1580 ixj_mixer(0x0080, j); /* Mute Master Left volume */
1581 ixj_mixer(0x0180, j); /* Mute Master Right volume */
1582 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
1583 /* SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
1586 j->gpio.bytes.high = 0x0B;
1587 j->gpio.bits.gpio6 = 0;
1588 j->gpio.bits.gpio7 = 0;
1589 ixj_WriteDSPCommand(j->gpio.word, j);
1594 if (j->cardtype == QTI_LINEJACK) {
1595 ixj_WriteDSPCommand(0xC534, j); /* Write CODEC config to Software Control Register */
1597 j->pld_slicw.bits.rly3 = 0;
1598 j->pld_slicw.bits.rly1 = 1;
1599 j->pld_slicw.bits.spken = 0;
1600 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1601 j->port = PORT_PSTN;
1607 j->port = PORT_SPEAKER;
1608 switch (j->cardtype) {
1610 if (j->flags.pcmciasct) {
1611 SLIC_SetState(PLD_SLIC_STATE_OC, j);
1614 case QTI_PHONEJACK_PCI:
1615 j->pld_slicw.pcib.mic = 1;
1616 j->pld_slicw.pcib.spk = 1;
1617 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1620 ixj_set_pots(j, 0); /* Disconnect POTS/PSTN relay */
1621 if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to
1622 Software Control Register */
1624 j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
1626 outb(j->pld_scrw.byte, j->XILINXbase);
1627 j->pld_clock.byte = 0;
1628 outb(j->pld_clock.byte, j->XILINXbase + 0x04);
1629 j->pld_slicw.bits.rly1 = 1;
1630 j->pld_slicw.bits.spken = 1;
1631 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1632 ixj_mixer(0x1201, j); /* Turn On MIC switch on mixer left */
1633 ixj_mixer(0x1400, j); /* Turn Off Mono1 switch on mixer left */
1634 ixj_mixer(0x1301, j); /* Turn On MIC switch on mixer right */
1635 ixj_mixer(0x1500, j); /* Turn Off Mono1 switch on mixer right */
1636 ixj_mixer(0x0E06, j); /*Mic un-mute 0dB */
1637 ixj_mixer(0x0F80, j); /* Mute mono out (SLIC) */
1638 ixj_mixer(0x0000, j); /* Set Master Left volume to 0dB */
1639 ixj_mixer(0x0100, j); /* Set Master Right volume to 0dB */
1642 j->gpio.bytes.high = 0x0B;
1643 j->gpio.bits.gpio6 = 0;
1644 j->gpio.bits.gpio7 = 1;
1645 ixj_WriteDSPCommand(j->gpio.word, j);
1650 if (j->cardtype != QTI_PHONEJACK) {
1653 j->gpio.bytes.high = 0x0B;
1654 j->gpio.bits.gpio6 = 1;
1655 j->gpio.bits.gpio7 = 0;
1656 ixj_WriteDSPCommand(j->gpio.word, j);
1657 j->port = PORT_HANDSET;
1667 static int ixj_set_pots(IXJ *j, int arg)
1669 if (j->cardtype == QTI_LINEJACK) {
1671 if (j->port == PORT_PSTN) {
1672 j->pld_slicw.bits.rly1 = 0;
1673 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1674 j->flags.pots_pstn = 1;
1677 j->flags.pots_pstn = 0;
1681 j->pld_slicw.bits.rly1 = 1;
1682 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1683 j->flags.pots_pstn = 0;
1691 static void ixj_ring_on(IXJ *j)
1693 if (j->dsp.low == 0x20) /* Internet PhoneJACK */
1695 if (ixjdebug & 0x0004)
1696 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1698 j->gpio.bytes.high = 0x0B;
1699 j->gpio.bytes.low = 0x00;
1700 j->gpio.bits.gpio1 = 1;
1701 j->gpio.bits.gpio2 = 1;
1702 j->gpio.bits.gpio5 = 0;
1703 ixj_WriteDSPCommand(j->gpio.word, j); /* send the ring signal */
1704 } else /* Internet LineJACK, Internet PhoneJACK Lite or Internet PhoneJACK PCI */
1706 if (ixjdebug & 0x0004)
1707 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1709 SLIC_SetState(PLD_SLIC_STATE_RINGING, j);
1713 static int ixj_siadc(IXJ *j, int val)
1715 if(j->cardtype == QTI_PHONECARD){
1716 if(j->flags.pcmciascp){
1718 return j->siadc.bits.rxg;
1720 if(val < 0 || val > 0x1F)
1723 j->siadc.bits.hom = 0; /* Handset Out Mute */
1724 j->siadc.bits.lom = 0; /* Line Out Mute */
1725 j->siadc.bits.rxg = val; /*(0xC000 - 0x41C8) / 0x4EF; RX PGA Gain */
1726 j->psccr.bits.addr = 6; /* R/W Smart Cable Register Address */
1727 j->psccr.bits.rw = 0; /* Read / Write flag */
1728 j->psccr.bits.dev = 0;
1729 outb(j->siadc.byte, j->XILINXbase + 0x00);
1730 outb(j->psccr.byte, j->XILINXbase + 0x01);
1731 ixj_PCcontrol_wait(j);
1732 return j->siadc.bits.rxg;
1738 static int ixj_sidac(IXJ *j, int val)
1740 if(j->cardtype == QTI_PHONECARD){
1741 if(j->flags.pcmciascp){
1743 return j->sidac.bits.txg;
1745 if(val < 0 || val > 0x1F)
1748 j->sidac.bits.srm = 1; /* Speaker Right Mute */
1749 j->sidac.bits.slm = 1; /* Speaker Left Mute */
1750 j->sidac.bits.txg = val; /* (0xC000 - 0x45E4) / 0x5D3; TX PGA Gain */
1751 j->psccr.bits.addr = 7; /* R/W Smart Cable Register Address */
1752 j->psccr.bits.rw = 0; /* Read / Write flag */
1753 j->psccr.bits.dev = 0;
1754 outb(j->sidac.byte, j->XILINXbase + 0x00);
1755 outb(j->psccr.byte, j->XILINXbase + 0x01);
1756 ixj_PCcontrol_wait(j);
1757 return j->sidac.bits.txg;
1763 static int ixj_pcmcia_cable_check(IXJ *j)
1765 j->pccr1.byte = inb_p(j->XILINXbase + 0x03);
1766 if (!j->flags.pcmciastate) {
1767 j->pccr2.byte = inb_p(j->XILINXbase + 0x02);
1768 if (j->pccr1.bits.drf || j->pccr2.bits.rstc) {
1769 j->flags.pcmciastate = 4;
1772 if (j->pccr1.bits.ed) {
1773 j->pccr1.bits.ed = 0;
1774 j->psccr.bits.dev = 3;
1775 j->psccr.bits.rw = 1;
1776 outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
1777 ixj_PCcontrol_wait(j);
1778 j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
1779 j->pslic.bits.led2 = j->pslic.bits.det ? 1 : 0;
1780 j->psccr.bits.dev = 3;
1781 j->psccr.bits.rw = 0;
1782 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1783 ixj_PCcontrol_wait(j);
1784 return j->pslic.bits.led2 ? 1 : 0;
1785 } else if (j->flags.pcmciasct) {
1790 } else if (j->flags.pcmciastate == 4) {
1791 if (!j->pccr1.bits.drf) {
1792 j->flags.pcmciastate = 3;
1795 } else if (j->flags.pcmciastate == 3) {
1796 j->pccr2.bits.pwr = 0;
1797 j->pccr2.bits.rstc = 1;
1798 outb(j->pccr2.byte, j->XILINXbase + 0x02);
1799 j->checkwait = jiffies + (hertz * 2);
1800 j->flags.incheck = 1;
1801 j->flags.pcmciastate = 2;
1803 } else if (j->flags.pcmciastate == 2) {
1804 if (j->flags.incheck) {
1805 if (time_before(jiffies, j->checkwait)) {
1808 j->flags.incheck = 0;
1811 j->pccr2.bits.pwr = 0;
1812 j->pccr2.bits.rstc = 0;
1813 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1814 j->flags.pcmciastate = 1;
1816 } else if (j->flags.pcmciastate == 1) {
1817 j->flags.pcmciastate = 0;
1818 if (!j->pccr1.bits.drf) {
1819 j->psccr.bits.dev = 3;
1820 j->psccr.bits.rw = 1;
1821 outb_p(j->psccr.byte, j->XILINXbase + 0x01);
1822 ixj_PCcontrol_wait(j);
1823 j->flags.pcmciascp = 1; /* Set Cable Present Flag */
1825 j->flags.pcmciasct = (inw_p(j->XILINXbase + 0x00) >> 8) & 0x03; /* Get Cable Type */
1827 if (j->flags.pcmciasct == 3) {
1828 j->flags.pcmciastate = 4;
1830 } else if (j->flags.pcmciasct == 0) {
1831 j->pccr2.bits.pwr = 1;
1832 j->pccr2.bits.rstc = 0;
1833 outb_p(j->pccr2.byte, j->XILINXbase + 0x02);
1834 j->port = PORT_SPEAKER;
1836 j->port = PORT_POTS;
1838 j->sic1.bits.cpd = 0; /* Chip Power Down */
1839 j->sic1.bits.mpd = 0; /* MIC Bias Power Down */
1840 j->sic1.bits.hpd = 0; /* Handset Bias Power Down */
1841 j->sic1.bits.lpd = 0; /* Line Bias Power Down */
1842 j->sic1.bits.spd = 1; /* Speaker Drive Power Down */
1843 j->psccr.bits.addr = 1; /* R/W Smart Cable Register Address */
1844 j->psccr.bits.rw = 0; /* Read / Write flag */
1845 j->psccr.bits.dev = 0;
1846 outb(j->sic1.byte, j->XILINXbase + 0x00);
1847 outb(j->psccr.byte, j->XILINXbase + 0x01);
1848 ixj_PCcontrol_wait(j);
1850 j->sic2.bits.al = 0; /* Analog Loopback DAC analog -> ADC analog */
1851 j->sic2.bits.dl2 = 0; /* Digital Loopback DAC -> ADC one bit */
1852 j->sic2.bits.dl1 = 0; /* Digital Loopback ADC -> DAC one bit */
1853 j->sic2.bits.pll = 0; /* 1 = div 10, 0 = div 5 */
1854 j->sic2.bits.hpd = 0; /* HPF disable */
1855 j->psccr.bits.addr = 2; /* R/W Smart Cable Register Address */
1856 j->psccr.bits.rw = 0; /* Read / Write flag */
1857 j->psccr.bits.dev = 0;
1858 outb(j->sic2.byte, j->XILINXbase + 0x00);
1859 outb(j->psccr.byte, j->XILINXbase + 0x01);
1860 ixj_PCcontrol_wait(j);
1862 j->psccr.bits.addr = 3; /* R/W Smart Cable Register Address */
1863 j->psccr.bits.rw = 0; /* Read / Write flag */
1864 j->psccr.bits.dev = 0;
1865 outb(0x00, j->XILINXbase + 0x00); /* PLL Divide N1 */
1866 outb(j->psccr.byte, j->XILINXbase + 0x01);
1867 ixj_PCcontrol_wait(j);
1869 j->psccr.bits.addr = 4; /* R/W Smart Cable Register Address */
1870 j->psccr.bits.rw = 0; /* Read / Write flag */
1871 j->psccr.bits.dev = 0;
1872 outb(0x09, j->XILINXbase + 0x00); /* PLL Multiply M1 */
1873 outb(j->psccr.byte, j->XILINXbase + 0x01);
1874 ixj_PCcontrol_wait(j);
1876 j->sirxg.bits.lig = 1; /* Line In Gain */
1877 j->sirxg.bits.lim = 1; /* Line In Mute */
1878 j->sirxg.bits.mcg = 0; /* MIC In Gain was 3 */
1879 j->sirxg.bits.mcm = 0; /* MIC In Mute */
1880 j->sirxg.bits.him = 0; /* Handset In Mute */
1881 j->sirxg.bits.iir = 1; /* IIR */
1882 j->psccr.bits.addr = 5; /* R/W Smart Cable Register Address */
1883 j->psccr.bits.rw = 0; /* Read / Write flag */
1884 j->psccr.bits.dev = 0;
1885 outb(j->sirxg.byte, j->XILINXbase + 0x00);
1886 outb(j->psccr.byte, j->XILINXbase + 0x01);
1887 ixj_PCcontrol_wait(j);
1892 j->siaatt.bits.sot = 0;
1893 j->psccr.bits.addr = 9; /* R/W Smart Cable Register Address */
1894 j->psccr.bits.rw = 0; /* Read / Write flag */
1895 j->psccr.bits.dev = 0;
1896 outb(j->siaatt.byte, j->XILINXbase + 0x00);
1897 outb(j->psccr.byte, j->XILINXbase + 0x01);
1898 ixj_PCcontrol_wait(j);
1900 if (j->flags.pcmciasct == 1 && !j->readers && !j->writers) {
1901 j->psccr.byte = j->pslic.byte = 0;
1902 j->pslic.bits.powerdown = 1;
1903 j->psccr.bits.dev = 3;
1904 j->psccr.bits.rw = 0;
1905 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
1906 ixj_PCcontrol_wait(j);
1911 j->flags.pcmciascp = 0;
1917 static int ixj_hookstate(IXJ *j)
1921 switch (j->cardtype) {
1924 fOffHook = j->gpio.bits.gpio3read ? 1 : 0;
1927 case QTI_PHONEJACK_LITE:
1928 case QTI_PHONEJACK_PCI:
1930 if(j->cardtype == QTI_LINEJACK && j->flags.pots_pstn == 1 && (j->readers || j->writers)) {
1931 fOffHook = j->pld_slicr.bits.potspstn ? 1 : 0;
1932 if(fOffHook != j->p_hook) {
1934 j->checkwait = jiffies;
1936 if(time_before(jiffies, j->checkwait + 2)) {
1941 j->p_hook = fOffHook;
1942 printk("IXJ : /dev/phone%d pots-pstn hookstate check %d at %ld\n", j->board, fOffHook, jiffies);
1945 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_ACTIVE ||
1946 j->pld_slicr.bits.state == PLD_SLIC_STATE_STANDBY) {
1947 if (j->flags.ringing || j->flags.cringing) {
1948 if (!in_interrupt()) {
1952 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
1956 if (j->cardtype == QTI_PHONEJACK_PCI) {
1957 j->pld_scrr.byte = inb_p(j->XILINXbase);
1958 fOffHook = j->pld_scrr.pcib.det ? 1 : 0;
1960 fOffHook = j->pld_slicr.bits.det ? 1 : 0;
1965 fOffHook = ixj_pcmcia_cable_check(j);
1968 if (j->r_hook != fOffHook) {
1969 j->r_hook = fOffHook;
1970 if (j->port == PORT_SPEAKER || j->port == PORT_HANDSET) { // || (j->port == PORT_PSTN && j->flags.pots_pstn == 0)) {
1971 j->ex.bits.hookstate = 1;
1972 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1973 } else if (!fOffHook) {
1974 j->flash_end = jiffies + ((60 * hertz) / 100);
1978 if(time_before(jiffies, j->flash_end)) {
1979 j->ex.bits.flash = 1;
1981 ixj_kill_fasync(j, SIG_FLASH, POLL_IN);
1984 if(time_before(jiffies, j->flash_end)) {
1989 if (j->port == PORT_PSTN && j->daa_mode == SOP_PU_CONVERSATION)
1992 if (j->port == PORT_SPEAKER) {
1993 if(j->cardtype == QTI_PHONECARD) {
1994 if(j->flags.pcmciascp && j->flags.pcmciasct) {
2002 if (j->port == PORT_HANDSET)
2008 static void ixj_ring_off(IXJ *j)
2010 if (j->dsp.low == 0x20) /* Internet PhoneJACK */
2012 if (ixjdebug & 0x0004)
2013 printk(KERN_INFO "IXJ Ring Off\n");
2014 j->gpio.bytes.high = 0x0B;
2015 j->gpio.bytes.low = 0x00;
2016 j->gpio.bits.gpio1 = 0;
2017 j->gpio.bits.gpio2 = 1;
2018 j->gpio.bits.gpio5 = 0;
2019 ixj_WriteDSPCommand(j->gpio.word, j);
2020 } else /* Internet LineJACK */
2022 if (ixjdebug & 0x0004)
2023 printk(KERN_INFO "IXJ Ring Off\n");
2025 if(!j->flags.cidplay)
2026 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
2032 static void ixj_ring_start(IXJ *j)
2034 j->flags.cringing = 1;
2035 if (ixjdebug & 0x0004)
2036 printk(KERN_INFO "IXJ Cadence Ringing Start /dev/phone%d\n", j->board);
2037 if (ixj_hookstate(j) & 1) {
2038 if (j->port == PORT_POTS)
2040 j->flags.cringing = 0;
2041 if (ixjdebug & 0x0004)
2042 printk(KERN_INFO "IXJ Cadence Ringing Stopped /dev/phone%d off hook\n", j->board);
2043 } else if(j->cadence_f[5].enable && (!j->cadence_f[5].en_filter)) {
2044 j->ring_cadence_jif = jiffies;
2045 j->flags.cidsent = j->flags.cidring = 0;
2046 j->cadence_f[5].state = 0;
2047 if(j->cadence_f[5].on1)
2050 j->ring_cadence_jif = jiffies;
2051 j->ring_cadence_t = 15;
2052 if (j->ring_cadence & 1 << j->ring_cadence_t) {
2057 j->flags.cidsent = j->flags.cidring = j->flags.firstring = 0;
2061 static int ixj_ring(IXJ *j)
2066 j->flags.ringing = 1;
2067 if (ixj_hookstate(j) & 1) {
2069 j->flags.ringing = 0;
2072 for (cntr = 0; cntr < j->maxrings; cntr++) {
2073 jif = jiffies + (1 * hertz);
2075 while (time_before(jiffies, jif)) {
2076 if (ixj_hookstate(j) & 1) {
2078 j->flags.ringing = 0;
2081 schedule_timeout_interruptible(1);
2082 if (signal_pending(current))
2085 jif = jiffies + (3 * hertz);
2087 while (time_before(jiffies, jif)) {
2088 if (ixj_hookstate(j) & 1) {
2090 if (ixj_hookstate(j) & 1) {
2091 j->flags.ringing = 0;
2095 schedule_timeout_interruptible(1);
2096 if (signal_pending(current))
2101 j->flags.ringing = 0;
2105 static int ixj_open(struct phone_device *p, struct file *file_p)
2107 IXJ *j = get_ixj(p->board);
2108 file_p->private_data = j;
2113 if (file_p->f_mode & FMODE_READ) {
2121 if (file_p->f_mode & FMODE_WRITE) {
2125 if (file_p->f_mode & FMODE_READ){
2132 if (j->cardtype == QTI_PHONECARD) {
2133 j->pslic.bits.powerdown = 0;
2134 j->psccr.bits.dev = 3;
2135 j->psccr.bits.rw = 0;
2136 outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
2137 ixj_PCcontrol_wait(j);
2140 j->flags.cidplay = 0;
2141 j->flags.cidcw_ack = 0;
2143 if (ixjdebug & 0x0002)
2144 printk(KERN_INFO "Opening board %d\n", p->board);
2146 j->framesread = j->frameswritten = 0;
2150 static int ixj_release(struct inode *inode, struct file *file_p)
2154 IXJ *j = file_p->private_data;
2155 int board = j->p.board;
2158 * Set up locks to ensure that only one process is talking to the DSP at a time.
2159 * This is necessary to keep the DSP from locking up.
2161 while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
2162 schedule_timeout_interruptible(1);
2163 if (ixjdebug & 0x0002)
2164 printk(KERN_INFO "Closing board %d\n", NUM(inode));
2166 if (j->cardtype == QTI_PHONECARD)
2167 ixj_set_port(j, PORT_SPEAKER);
2169 ixj_set_port(j, PORT_POTS);
2174 set_play_volume(j, 0x100);
2175 set_rec_volume(j, 0x100);
2178 /* Restore the tone table to default settings. */
2184 ixj_init_tone(j, &ti);
2190 ixj_init_tone(j, &ti);
2196 ixj_init_tone(j, &ti);
2202 ixj_init_tone(j, &ti);
2208 ixj_init_tone(j, &ti);
2214 ixj_init_tone(j, &ti);
2220 ixj_init_tone(j, &ti);
2226 ixj_init_tone(j, &ti);
2232 ixj_init_tone(j, &ti);
2238 ixj_init_tone(j, &ti);
2244 ixj_init_tone(j, &ti);
2250 ixj_init_tone(j, &ti);
2256 ixj_init_tone(j, &ti);
2262 ixj_init_tone(j, &ti);
2268 ixj_init_tone(j, &ti);
2274 ixj_init_tone(j, &ti);
2280 ixj_init_tone(j, &ti);
2286 ixj_init_tone(j, &ti);
2288 set_rec_depth(j, 2); /* Set Record Channel Limit to 2 frames */
2290 set_play_depth(j, 2); /* Set Playback Channel Limit to 2 frames */
2292 j->ex.bits.dtmf_ready = 0;
2294 j->dtmf_wp = j->dtmf_rp = 0;
2295 j->rec_mode = j->play_mode = -1;
2296 j->flags.ringing = 0;
2297 j->maxrings = MAXRINGS;
2298 j->ring_cadence = USA_RING_CADENCE;
2299 if(j->cadence_f[5].enable) {
2300 j->cadence_f[5].enable = j->cadence_f[5].en_filter = j->cadence_f[5].state = 0;
2304 j->flags.dtmf_oob = 0;
2305 for (cnt = 0; cnt < 4; cnt++)
2306 j->cadence_f[cnt].enable = 0;
2310 if(j->cardtype == QTI_PHONECARD) {
2311 SLIC_SetState(PLD_SLIC_STATE_OC, j);
2314 if (file_p->f_mode & FMODE_READ)
2316 if (file_p->f_mode & FMODE_WRITE)
2319 if (j->read_buffer && !j->readers) {
2320 kfree(j->read_buffer);
2321 j->read_buffer = NULL;
2322 j->read_buffer_size = 0;
2324 if (j->write_buffer && !j->writers) {
2325 kfree(j->write_buffer);
2326 j->write_buffer = NULL;
2327 j->write_buffer_size = 0;
2329 j->rec_codec = j->play_codec = 0;
2330 j->rec_frame_size = j->play_frame_size = 0;
2331 j->flags.cidsent = j->flags.cidring = 0;
2333 if(j->cardtype == QTI_LINEJACK && !j->readers && !j->writers) {
2334 ixj_set_port(j, PORT_PSTN);
2335 daa_set_mode(j, SOP_PU_SLEEP);
2338 ixj_WriteDSPCommand(0x0FE3, j); /* Put the DSP in 1/5 power mode. */
2340 /* Set up the default signals for events */
2341 for (cnt = 0; cnt < 35; cnt++)
2342 j->ixj_signals[cnt] = SIGIO;
2344 /* Set the excetion signal enable flags */
2345 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring =
2346 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 =
2347 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;
2349 file_p->private_data = NULL;
2350 clear_bit(board, &j->busyflags);
2354 static int read_filters(IXJ *j)
2356 unsigned short fc, cnt, trg;
2360 if (ixj_WriteDSPCommand(0x5144, j)) {
2361 if(ixjdebug & 0x0001) {
2362 printk(KERN_INFO "Read Frame Counter failed!\n");
2366 fc = j->ssr.high << 8 | j->ssr.low;
2367 if (fc == j->frame_count)
2370 j->frame_count = fc;
2377 for (cnt = 0; cnt < 4; cnt++) {
2378 if (ixj_WriteDSPCommand(0x5154 + cnt, j)) {
2379 if(ixjdebug & 0x0001) {
2380 printk(KERN_INFO "Select Filter %d failed!\n", cnt);
2384 if (ixj_WriteDSPCommand(0x515C, j)) {
2385 if(ixjdebug & 0x0001) {
2386 printk(KERN_INFO "Read Filter History %d failed!\n", cnt);
2390 j->filter_hist[cnt] = j->ssr.high << 8 | j->ssr.low;
2392 if (j->cadence_f[cnt].enable) {
2393 if (j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) {
2394 if (j->cadence_f[cnt].state == 0) {
2395 j->cadence_f[cnt].state = 1;
2396 j->cadence_f[cnt].on1min = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 - var)) / 10000));
2397 j->cadence_f[cnt].on1dot = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100)) / 10000));
2398 j->cadence_f[cnt].on1max = jiffies + (long)((j->cadence_f[cnt].on1 * (hertz * (100 + var)) / 10000));
2399 } else if (j->cadence_f[cnt].state == 2 &&
2400 (time_after(jiffies, j->cadence_f[cnt].off1min) &&
2401 time_before(jiffies, j->cadence_f[cnt].off1max))) {
2402 if (j->cadence_f[cnt].on2) {
2403 j->cadence_f[cnt].state = 3;
2404 j->cadence_f[cnt].on2min = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 - var)) / 10000));
2405 j->cadence_f[cnt].on2dot = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100)) / 10000));
2406 j->cadence_f[cnt].on2max = jiffies + (long)((j->cadence_f[cnt].on2 * (hertz * (100 + var)) / 10000));
2408 j->cadence_f[cnt].state = 7;
2410 } else if (j->cadence_f[cnt].state == 4 &&
2411 (time_after(jiffies, j->cadence_f[cnt].off2min) &&
2412 time_before(jiffies, j->cadence_f[cnt].off2max))) {
2413 if (j->cadence_f[cnt].on3) {
2414 j->cadence_f[cnt].state = 5;
2415 j->cadence_f[cnt].on3min = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 - var)) / 10000));
2416 j->cadence_f[cnt].on3dot = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100)) / 10000));
2417 j->cadence_f[cnt].on3max = jiffies + (long)((j->cadence_f[cnt].on3 * (hertz * (100 + var)) / 10000));
2419 j->cadence_f[cnt].state = 7;
2422 j->cadence_f[cnt].state = 0;
2424 } else if (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)) {
2425 if (j->cadence_f[cnt].state == 1) {
2426 if(!j->cadence_f[cnt].on1) {
2427 j->cadence_f[cnt].state = 7;
2428 } else if((time_after(jiffies, j->cadence_f[cnt].on1min) &&
2429 time_before(jiffies, j->cadence_f[cnt].on1max))) {
2430 if(j->cadence_f[cnt].off1) {
2431 j->cadence_f[cnt].state = 2;
2432 j->cadence_f[cnt].off1min = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 - var)) / 10000));
2433 j->cadence_f[cnt].off1dot = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100)) / 10000));
2434 j->cadence_f[cnt].off1max = jiffies + (long)((j->cadence_f[cnt].off1 * (hertz * (100 + var)) / 10000));
2436 j->cadence_f[cnt].state = 7;
2439 j->cadence_f[cnt].state = 0;
2441 } else if (j->cadence_f[cnt].state == 3) {
2442 if((time_after(jiffies, j->cadence_f[cnt].on2min) &&
2443 time_before(jiffies, j->cadence_f[cnt].on2max))) {
2444 if(j->cadence_f[cnt].off2) {
2445 j->cadence_f[cnt].state = 4;
2446 j->cadence_f[cnt].off2min = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 - var)) / 10000));
2447 j->cadence_f[cnt].off2dot = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100)) / 10000));
2448 j->cadence_f[cnt].off2max = jiffies + (long)((j->cadence_f[cnt].off2 * (hertz * (100 + var)) / 10000));
2450 j->cadence_f[cnt].state = 7;
2453 j->cadence_f[cnt].state = 0;
2455 } else if (j->cadence_f[cnt].state == 5) {
2456 if ((time_after(jiffies, j->cadence_f[cnt].on3min) &&
2457 time_before(jiffies, j->cadence_f[cnt].on3max))) {
2458 if(j->cadence_f[cnt].off3) {
2459 j->cadence_f[cnt].state = 6;
2460 j->cadence_f[cnt].off3min = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 - var)) / 10000));
2461 j->cadence_f[cnt].off3dot = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100)) / 10000));
2462 j->cadence_f[cnt].off3max = jiffies + (long)((j->cadence_f[cnt].off3 * (hertz * (100 + var)) / 10000));
2464 j->cadence_f[cnt].state = 7;
2467 j->cadence_f[cnt].state = 0;
2470 j->cadence_f[cnt].state = 0;
2473 switch(j->cadence_f[cnt].state) {
2475 if(time_after(jiffies, j->cadence_f[cnt].on1dot) &&
2476 !j->cadence_f[cnt].off1 &&
2477 !j->cadence_f[cnt].on2 && !j->cadence_f[cnt].off2 &&
2478 !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2479 j->cadence_f[cnt].state = 7;
2483 if(time_after(jiffies, j->cadence_f[cnt].on2dot) &&
2484 !j->cadence_f[cnt].off2 &&
2485 !j->cadence_f[cnt].on3 && !j->cadence_f[cnt].off3) {
2486 j->cadence_f[cnt].state = 7;
2490 if(time_after(jiffies, j->cadence_f[cnt].on3dot) &&
2491 !j->cadence_f[cnt].off3) {
2492 j->cadence_f[cnt].state = 7;
2498 if (ixjdebug & 0x0040) {
2499 printk(KERN_INFO "IXJ Tone Cadence state = %d /dev/phone%d at %ld\n", j->cadence_f[cnt].state, j->board, jiffies);
2500 switch(j->cadence_f[cnt].state) {
2502 printk(KERN_INFO "IXJ /dev/phone%d No Tone detected\n", j->board);
2505 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %u %ld - %ld - %ld\n", j->board,
2506 j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max);
2509 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min,
2510 j->cadence_f[cnt].off1max);
2513 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on2min,
2514 j->cadence_f[cnt].on2max);
2517 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off2min,
2518 j->cadence_f[cnt].off2max);
2521 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min,
2522 j->cadence_f[cnt].on3max);
2525 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min,
2526 j->cadence_f[cnt].off3max);
2531 if (j->cadence_f[cnt].state == 7) {
2532 j->cadence_f[cnt].state = 0;
2533 if (j->cadence_f[cnt].enable == 1)
2534 j->cadence_f[cnt].enable = 0;
2537 if(ixjdebug & 0x0020) {
2538 printk(KERN_INFO "Filter Cadence 0 triggered %ld\n", jiffies);
2541 ixj_kill_fasync(j, SIG_FC0, POLL_IN);
2544 if(ixjdebug & 0x0020) {
2545 printk(KERN_INFO "Filter Cadence 1 triggered %ld\n", jiffies);
2548 ixj_kill_fasync(j, SIG_FC1, POLL_IN);
2551 if(ixjdebug & 0x0020) {
2552 printk(KERN_INFO "Filter Cadence 2 triggered %ld\n", jiffies);
2555 ixj_kill_fasync(j, SIG_FC2, POLL_IN);
2558 if(ixjdebug & 0x0020) {
2559 printk(KERN_INFO "Filter Cadence 3 triggered %ld\n", jiffies);
2562 ixj_kill_fasync(j, SIG_FC3, POLL_IN);
2566 if (j->filter_en[cnt] && ((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12)) ||
2567 (j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3)))) {
2568 if((j->filter_hist[cnt] & 3 && !(j->filter_hist[cnt] & 12))) {
2570 } else if((j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3))) {
2575 if(ixjdebug & 0x0020) {
2576 printk(KERN_INFO "Filter 0 triggered %d at %ld\n", trg, jiffies);
2579 ixj_kill_fasync(j, SIG_F0, POLL_IN);
2582 if(ixjdebug & 0x0020) {
2583 printk(KERN_INFO "Filter 1 triggered %d at %ld\n", trg, jiffies);
2586 ixj_kill_fasync(j, SIG_F1, POLL_IN);
2589 if(ixjdebug & 0x0020) {
2590 printk(KERN_INFO "Filter 2 triggered %d at %ld\n", trg, jiffies);
2593 ixj_kill_fasync(j, SIG_F2, POLL_IN);
2596 if(ixjdebug & 0x0020) {
2597 printk(KERN_INFO "Filter 3 triggered %d at %ld\n", trg, jiffies);
2600 ixj_kill_fasync(j, SIG_F3, POLL_IN);
2608 static int LineMonitor(IXJ *j)
2615 if (ixj_WriteDSPCommand(0x7000, j)) /* Line Monitor */
2618 j->dtmf.bytes.high = j->ssr.high;
2619 j->dtmf.bytes.low = j->ssr.low;
2620 if (!j->dtmf_state && j->dtmf.bits.dtmf_valid) {
2622 j->dtmf_current = j->dtmf.bits.digit;
2624 if (j->dtmf_state && !j->dtmf.bits.dtmf_valid) /* && j->dtmf_wp != j->dtmf_rp) */
2626 if(!j->cidcw_wait) {
2627 j->dtmfbuffer[j->dtmf_wp] = j->dtmf_current;
2629 if (j->dtmf_wp == 79)
2631 j->ex.bits.dtmf_ready = 1;
2632 if(j->ex_sig.bits.dtmf_ready) {
2633 ixj_kill_fasync(j, SIG_DTMF_READY, POLL_IN);
2636 else if(j->dtmf_current == 0x00 || j->dtmf_current == 0x0D) {
2637 if(ixjdebug & 0x0020) {
2638 printk("IXJ phone%d saw CIDCW Ack DTMF %d from display at %ld\n", j->board, j->dtmf_current, jiffies);
2640 j->flags.cidcw_ack = 1;
2649 /************************************************************************
2651 * Functions to allow alaw <-> ulaw conversions.
2653 ************************************************************************/
2655 static void ulaw2alaw(unsigned char *buff, unsigned long len)
2657 static unsigned char table_ulaw2alaw[] =
2659 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D,
2660 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25,
2661 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D,
2662 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35,
2663 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02,
2664 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A,
2665 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12,
2666 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B,
2667 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63,
2668 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79,
2669 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71,
2670 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D,
2671 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45,
2672 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D,
2673 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51,
2674 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5,
2675 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD,
2676 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5,
2677 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD,
2678 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5,
2679 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82,
2680 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A,
2681 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92,
2682 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB,
2683 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3,
2684 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9,
2685 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1,
2686 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD,
2687 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5,
2688 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD,
2689 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1,
2690 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5
2695 *buff = table_ulaw2alaw[*(unsigned char *)buff];
2700 static void alaw2ulaw(unsigned char *buff, unsigned long len)
2702 static unsigned char table_alaw2ulaw[] =
2704 0x29, 0x2A, 0x27, 0x28, 0x2D, 0x2E, 0x2B, 0x2C,
2705 0x21, 0x22, 0x1F, 0x20, 0x25, 0x26, 0x23, 0x24,
2706 0x39, 0x3A, 0x37, 0x38, 0x3D, 0x3E, 0x3B, 0x3C,
2707 0x31, 0x32, 0x2F, 0x30, 0x35, 0x36, 0x33, 0x34,
2708 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D,
2709 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
2710 0x1A, 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D,
2711 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15,
2712 0x62, 0x63, 0x60, 0x61, 0x66, 0x67, 0x64, 0x65,
2713 0x5D, 0x5D, 0x5C, 0x5C, 0x5F, 0x5F, 0x5E, 0x5E,
2714 0x74, 0x76, 0x70, 0x72, 0x7C, 0x7E, 0x78, 0x7A,
2715 0x6A, 0x6B, 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D,
2716 0x48, 0x49, 0x46, 0x47, 0x4C, 0x4D, 0x4A, 0x4B,
2717 0x40, 0x41, 0x3F, 0x3F, 0x44, 0x45, 0x42, 0x43,
2718 0x56, 0x57, 0x54, 0x55, 0x5A, 0x5B, 0x58, 0x59,
2719 0x4F, 0x4F, 0x4E, 0x4E, 0x52, 0x53, 0x50, 0x51,
2720 0xA9, 0xAA, 0xA7, 0xA8, 0xAD, 0xAE, 0xAB, 0xAC,
2721 0xA1, 0xA2, 0x9F, 0xA0, 0xA5, 0xA6, 0xA3, 0xA4,
2722 0xB9, 0xBA, 0xB7, 0xB8, 0xBD, 0xBE, 0xBB, 0xBC,
2723 0xB1, 0xB2, 0xAF, 0xB0, 0xB5, 0xB6, 0xB3, 0xB4,
2724 0x8A, 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D,
2725 0x82, 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85,
2726 0x9A, 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D,
2727 0x92, 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95,
2728 0xE2, 0xE3, 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5,
2729 0xDD, 0xDD, 0xDC, 0xDC, 0xDF, 0xDF, 0xDE, 0xDE,
2730 0xF4, 0xF6, 0xF0, 0xF2, 0xFC, 0xFE, 0xF8, 0xFA,
2731 0xEA, 0xEB, 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED,
2732 0xC8, 0xC9, 0xC6, 0xC7, 0xCC, 0xCD, 0xCA, 0xCB,
2733 0xC0, 0xC1, 0xBF, 0xBF, 0xC4, 0xC5, 0xC2, 0xC3,
2734 0xD6, 0xD7, 0xD4, 0xD5, 0xDA, 0xDB, 0xD8, 0xD9,
2735 0xCF, 0xCF, 0xCE, 0xCE, 0xD2, 0xD3, 0xD0, 0xD1
2740 *buff = table_alaw2ulaw[*(unsigned char *)buff];
2745 static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos)
2747 unsigned long i = *ppos;
2748 IXJ * j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2750 DECLARE_WAITQUEUE(wait, current);
2752 if (j->flags.inread)
2755 j->flags.inread = 1;
2757 add_wait_queue(&j->read_q, &wait);
2758 set_current_state(TASK_INTERRUPTIBLE);
2761 while (!j->read_buffer_ready || (j->dtmf_state && j->flags.dtmf_oob)) {
2763 if (file_p->f_flags & O_NONBLOCK) {
2764 set_current_state(TASK_RUNNING);
2765 remove_wait_queue(&j->read_q, &wait);
2766 j->flags.inread = 0;
2769 if (!ixj_hookstate(j)) {
2770 set_current_state(TASK_RUNNING);
2771 remove_wait_queue(&j->read_q, &wait);
2772 j->flags.inread = 0;
2775 interruptible_sleep_on(&j->read_q);
2776 if (signal_pending(current)) {
2777 set_current_state(TASK_RUNNING);
2778 remove_wait_queue(&j->read_q, &wait);
2779 j->flags.inread = 0;
2784 remove_wait_queue(&j->read_q, &wait);
2785 set_current_state(TASK_RUNNING);
2786 /* Don't ever copy more than the user asks */
2787 if(j->rec_codec == ALAW)
2788 ulaw2alaw(j->read_buffer, min(length, j->read_buffer_size));
2789 i = copy_to_user(buf, j->read_buffer, min(length, j->read_buffer_size));
2790 j->read_buffer_ready = 0;
2792 j->flags.inread = 0;
2795 j->flags.inread = 0;
2796 return min(length, j->read_buffer_size);
2800 static ssize_t ixj_enhanced_read(struct file * file_p, char __user *buf, size_t length,
2804 ssize_t read_retval = 0;
2805 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2807 pre_retval = ixj_PreRead(j, 0L);
2808 switch (pre_retval) {
2810 read_retval = ixj_read(file_p, buf, length, ppos);
2811 ixj_PostRead(j, 0L);
2814 read_retval = ixj_read(file_p, buf, length, ppos);
2817 ixj_PostRead(j, 0L);
2820 read_retval = pre_retval;
2825 static ssize_t ixj_write(struct file *file_p, const char __user *buf, size_t count, loff_t * ppos)
2827 unsigned long i = *ppos;
2828 IXJ *j = file_p->private_data;
2830 DECLARE_WAITQUEUE(wait, current);
2832 if (j->flags.inwrite)
2835 j->flags.inwrite = 1;
2837 add_wait_queue(&j->write_q, &wait);
2838 set_current_state(TASK_INTERRUPTIBLE);
2842 while (!j->write_buffers_empty) {
2844 if (file_p->f_flags & O_NONBLOCK) {
2845 set_current_state(TASK_RUNNING);
2846 remove_wait_queue(&j->write_q, &wait);
2847 j->flags.inwrite = 0;
2850 if (!ixj_hookstate(j)) {
2851 set_current_state(TASK_RUNNING);
2852 remove_wait_queue(&j->write_q, &wait);
2853 j->flags.inwrite = 0;
2856 interruptible_sleep_on(&j->write_q);
2857 if (signal_pending(current)) {
2858 set_current_state(TASK_RUNNING);
2859 remove_wait_queue(&j->write_q, &wait);
2860 j->flags.inwrite = 0;
2864 set_current_state(TASK_RUNNING);
2865 remove_wait_queue(&j->write_q, &wait);
2866 if (j->write_buffer_wp + count >= j->write_buffer_end)
2867 j->write_buffer_wp = j->write_buffer;
2868 i = copy_from_user(j->write_buffer_wp, buf, min(count, j->write_buffer_size));
2870 j->flags.inwrite = 0;
2873 if(j->play_codec == ALAW)
2874 alaw2ulaw(j->write_buffer_wp, min(count, j->write_buffer_size));
2875 j->flags.inwrite = 0;
2876 return min(count, j->write_buffer_size);
2879 static ssize_t ixj_enhanced_write(struct file * file_p, const char __user *buf, size_t count, loff_t * ppos)
2882 ssize_t write_retval = 0;
2884 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2886 pre_retval = ixj_PreWrite(j, 0L);
2887 switch (pre_retval) {
2889 write_retval = ixj_write(file_p, buf, count, ppos);
2890 if (write_retval > 0) {
2891 ixj_PostWrite(j, 0L);
2892 j->write_buffer_wp += write_retval;
2893 j->write_buffers_empty--;
2897 write_retval = ixj_write(file_p, buf, count, ppos);
2898 if (write_retval > 0) {
2899 j->write_buffer_wp += write_retval;
2900 j->write_buffers_empty--;
2904 ixj_PostWrite(j, 0L);
2907 write_retval = pre_retval;
2909 return write_retval;
2912 static void ixj_read_frame(IXJ *j)
2916 if (j->read_buffer) {
2917 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2918 if (!(cnt % 16) && !IsRxReady(j)) {
2920 while (!IsRxReady(j)) {
2928 /* Throw away word 0 of the 8021 compressed format to get standard G.729. */
2929 if (j->rec_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
2930 inb_p(j->DSPbase + 0x0E);
2931 inb_p(j->DSPbase + 0x0F);
2933 *(j->read_buffer + cnt) = inb_p(j->DSPbase + 0x0E);
2934 *(j->read_buffer + cnt + 1) = inb_p(j->DSPbase + 0x0F);
2937 if (j->intercom != -1) {
2938 if (IsTxReady(get_ixj(j->intercom))) {
2939 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2940 if (!(cnt % 16) && !IsTxReady(j)) {
2942 while (!IsTxReady(j)) {
2950 outb_p(*(j->read_buffer + cnt), get_ixj(j->intercom)->DSPbase + 0x0C);
2951 outb_p(*(j->read_buffer + cnt + 1), get_ixj(j->intercom)->DSPbase + 0x0D);
2953 get_ixj(j->intercom)->frameswritten++;
2956 j->read_buffer_ready = 1;
2957 wake_up_interruptible(&j->read_q); /* Wake any blocked readers */
2959 wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
2961 if(j->ixj_signals[SIG_READ_READY])
2962 ixj_kill_fasync(j, SIG_READ_READY, POLL_OUT);
2967 static short fsk[][6][20] =