forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathixj.c
10550 lines (9736 loc) · 312 KB
/
ixj.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
* ixj.c
*
* Device Driver for Quicknet Technologies, Inc.'s Telephony cards
* including the Internet PhoneJACK, Internet PhoneJACK Lite,
* Internet PhoneJACK PCI, Internet LineJACK, Internet PhoneCARD and
* SmartCABLE
*
* (c) Copyright 1999-2001 Quicknet Technologies, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Author: Ed Okerson, <[email protected]>
*
* Contributors: Greg Herlein, <[email protected]>
* David W. Erhart, <[email protected]>
* John Sellers, <[email protected]>
* Mike Preston, <[email protected]>
*
* Fixes: David Huggins-Daines, <[email protected]>
* Fabio Ferrari, <[email protected]>
* Artis Kugevics, <[email protected]>
* Daniele Bellucci, <[email protected]>
*
* More information about the hardware related to this driver can be found
* at our website: http://www.quicknet.net
*
* IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET
* TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND QUICKNET TECHNOLOGIES, INC. HAS NO OBLIGATION
* TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
***************************************************************************/
/*
* Revision 4.8 2003/07/09 19:39:00 Daniele Bellucci
* Audit some copy_*_user and minor cleanup.
*
* Revision 4.7 2001/08/13 06:19:33 craigs
* Added additional changes from Alan Cox and John Anderson for
* 2.2 to 2.4 cleanup and bounds checking
*
* Revision 4.6 2001/08/13 01:05:05 craigs
* Really fixed PHONE_QUERY_CODEC problem this time
*
* Revision 4.5 2001/08/13 00:11:03 craigs
* Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson
*
* Revision 4.4 2001/08/07 07:58:12 craigs
* Changed back to three digit version numbers
* Added tagbuild target to allow automatic and easy tagging of versions
*
* Revision 4.3 2001/08/07 07:24:47 craigs
* Added ixj-ver.h to allow easy configuration management of driver
* Added display of version number in /prox/ixj
*
* Revision 4.2 2001/08/06 07:07:19 craigs
* Reverted IXJCTL_DSP_TYPE and IXJCTL_DSP_VERSION files to original
* behaviour of returning int rather than short *
*
* Revision 4.1 2001/08/05 00:17:37 craigs
* More changes for correct PCMCIA installation
* Start of changes for backward Linux compatibility
*
* Revision 4.0 2001/08/04 12:33:12 craigs
* New version using GNU autoconf
*
* Revision 3.105 2001/07/20 23:14:32 eokerson
* More work on CallerID generation when using ring cadences.
*
* Revision 3.104 2001/07/06 01:33:55 eokerson
* Some bugfixes from Robert Vojta <[email protected]> and a few mods to the Makefile.
*
* Revision 3.103 2001/07/05 19:20:16 eokerson
* Updated HOWTO
* Changed mic gain to 30dB on Internet LineJACK mic/speaker port.
*
* Revision 3.102 2001/07/03 23:51:21 eokerson
* Un-mute mic on Internet LineJACK when in speakerphone mode.
*
* Revision 3.101 2001/07/02 19:26:56 eokerson
* Removed initialiazation of ixjdebug and ixj_convert_loaded so they will go in the .bss instead of the .data
*
* Revision 3.100 2001/07/02 19:18:27 eokerson
* Changed driver to make dynamic allocation possible. We now pass IXJ * between functions instead of array indexes.
* Fixed the way the POTS and PSTN ports interact during a PSTN call to allow local answering.
* Fixed speaker mode on Internet LineJACK.
*
* Revision 3.99 2001/05/09 14:11:16 eokerson
* Fixed kmalloc error in ixj_build_filter_cadence. Thanks David Chan <[email protected]>.
*
* Revision 3.98 2001/05/08 19:55:33 eokerson
* Fixed POTS hookstate detection while it is connected to PSTN port.
*
* Revision 3.97 2001/05/08 00:01:04 eokerson
* Fixed kernel oops when sending caller ID data.
*
* Revision 3.96 2001/05/04 23:09:30 eokerson
* Now uses one kernel timer for each card, instead of one for the entire driver.
*
* Revision 3.95 2001/04/25 22:06:47 eokerson
* Fixed squawking at beginning of some G.723.1 calls.
*
* Revision 3.94 2001/04/03 23:42:00 eokerson
* Added linear volume ioctls
* Added raw filter load ioctl
*
* Revision 3.93 2001/02/27 01:00:06 eokerson
* Fixed blocking in CallerID.
* Reduced size of ixj structure for smaller driver footprint.
*
* Revision 3.92 2001/02/20 22:02:59 eokerson
* Fixed isapnp and pcmcia module compatibility for 2.4.x kernels.
* Improved PSTN ring detection.
* Fixed wink generation on POTS ports.
*
* Revision 3.91 2001/02/13 00:55:44 eokerson
* Turn AEC back on after changing frame sizes.
*
* Revision 3.90 2001/02/12 16:42:00 eokerson
* Added ALAW codec, thanks to Fabio Ferrari for the table based converters to make ALAW from ULAW.
*
* Revision 3.89 2001/02/12 15:41:16 eokerson
* Fix from Artis Kugevics - Tone gains were not being set correctly.
*
* Revision 3.88 2001/02/05 23:25:42 eokerson
* Fixed lockup bugs with deregister.
*
* Revision 3.87 2001/01/29 21:00:39 eokerson
* Fix from Fabio Ferrari <[email protected]> to properly handle EAGAIN and EINTR during non-blocking write.
* Updated copyright date.
*
* Revision 3.86 2001/01/23 23:53:46 eokerson
* Fixes to G.729 compatibility.
*
* Revision 3.85 2001/01/23 21:30:36 eokerson
* Added verbage about cards supported.
* Removed commands that put the card in low power mode at some times that it should not be in low power mode.
*
* Revision 3.84 2001/01/22 23:32:10 eokerson
* Some bugfixes from David Huggins-Daines, <[email protected]> and other cleanups.
*
* Revision 3.83 2001/01/19 14:51:41 eokerson
* Fixed ixj_WriteDSPCommand to decrement usage counter when command fails.
*
* Revision 3.82 2001/01/19 00:34:49 eokerson
* Added verbosity to write overlap errors.
*
* Revision 3.81 2001/01/18 23:56:54 eokerson
* Fixed PSTN line test functions.
*
* Revision 3.80 2001/01/18 22:29:27 eokerson
* Updated AEC/AGC values for different cards.
*
* Revision 3.79 2001/01/17 02:58:54 eokerson
* Fixed AEC reset after Caller ID.
* Fixed Codec lockup after Caller ID on Call Waiting when not using 30ms frames.
*
* Revision 3.78 2001/01/16 19:43:09 eokerson
* Added support for Linux 2.4.x kernels.
*
* Revision 3.77 2001/01/09 04:00:52 eokerson
* Linetest will now test the line, even if it has previously succeded.
*
* Revision 3.76 2001/01/08 19:27:00 eokerson
* Fixed problem with standard cable on Internet PhoneCARD.
*
* Revision 3.75 2000/12/22 16:52:14 eokerson
* Modified to allow hookstate detection on the POTS port when the PSTN port is selected.
*
* Revision 3.74 2000/12/08 22:41:50 eokerson
* Added capability for G729B.
*
* Revision 3.73 2000/12/07 23:35:16 eokerson
* Added capability to have different ring pattern before CallerID data.
* Added hookstate checks in CallerID routines to stop FSK.
*
* Revision 3.72 2000/12/06 19:31:31 eokerson
* Modified signal behavior to only send one signal per event.
*
* Revision 3.71 2000/12/06 03:23:08 eokerson
* Fixed CallerID on Call Waiting.
*
* Revision 3.70 2000/12/04 21:29:37 eokerson
* Added checking to Smart Cable gain functions.
*
* Revision 3.69 2000/12/04 21:05:20 eokerson
* Changed ixjdebug levels.
* Added ioctls to change gains in Internet Phone CARD Smart Cable.
*
* Revision 3.68 2000/12/04 00:17:21 craigs
* Changed mixer voice gain to +6dB rather than 0dB
*
* Revision 3.67 2000/11/30 21:25:51 eokerson
* Fixed write signal errors.
*
* Revision 3.66 2000/11/29 22:42:44 eokerson
* Fixed PSTN ring detect problems.
*
* Revision 3.65 2000/11/29 07:31:55 craigs
* Added new 425Hz filter co-efficients
* Added card-specific DTMF prescaler initialisation
*
* Revision 3.64 2000/11/28 14:03:32 craigs
* Changed certain mixer initialisations to be 0dB rather than 12dB
* Added additional information to /proc/ixj
*
* Revision 3.63 2000/11/28 11:38:41 craigs
* Added display of AEC modes in AUTO and AGC mode
*
* Revision 3.62 2000/11/28 04:05:44 eokerson
* Improved PSTN ring detection routine.
*
* Revision 3.61 2000/11/27 21:53:12 eokerson
* Fixed flash detection.
*
* Revision 3.60 2000/11/27 15:57:29 eokerson
* More work on G.729 load routines.
*
* Revision 3.59 2000/11/25 21:55:12 eokerson
* Fixed errors in G.729 load routine.
*
* Revision 3.58 2000/11/25 04:08:29 eokerson
* Added board locks around G.729 and TS85 load routines.
*
* Revision 3.57 2000/11/24 05:35:17 craigs
* Added ability to retrieve mixer values on LineJACK
* Added complete initialisation of all mixer values at startup
* Fixed spelling mistake
*
* Revision 3.56 2000/11/23 02:52:11 robertj
* Added cvs change log keyword.
* Fixed bug in capabilities list when using G.729 module.
*
*/
#include "ixj-ver.h"
#define PERFMON_STATS
#define IXJDEBUG 0
#define MAXRINGS 5
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/mm.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/pci.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/isapnp.h>
#include "ixj.h"
#define TYPE(inode) (iminor(inode) >> 4)
#define NUM(inode) (iminor(inode) & 0xf)
static int ixjdebug;
static int hertz = HZ;
static int samplerate = 100;
module_param(ixjdebug, int, 0);
static struct pci_device_id ixj_pci_tbl[] __devinitdata = {
{ PCI_VENDOR_ID_QUICKNET, PCI_DEVICE_ID_QUICKNET_XJ,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{ }
};
MODULE_DEVICE_TABLE(pci, ixj_pci_tbl);
/************************************************************************
*
* ixjdebug meanings are now bit mapped instead of level based
* Values can be or'ed together to turn on multiple messages
*
* bit 0 (0x0001) = any failure
* bit 1 (0x0002) = general messages
* bit 2 (0x0004) = POTS ringing related
* bit 3 (0x0008) = PSTN events
* bit 4 (0x0010) = PSTN Cadence state details
* bit 5 (0x0020) = Tone detection triggers
* bit 6 (0x0040) = Tone detection cadence details
* bit 7 (0x0080) = ioctl tracking
* bit 8 (0x0100) = signal tracking
* bit 9 (0x0200) = CallerID generation details
*
************************************************************************/
#ifdef IXJ_DYN_ALLOC
static IXJ *ixj[IXJMAX];
#define get_ixj(b) ixj[(b)]
/*
* Allocate a free IXJ device
*/
static IXJ *ixj_alloc()
{
for(cnt=0; cnt<IXJMAX; cnt++)
{
if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
{
j = kmalloc(sizeof(IXJ), GFP_KERNEL);
if (j == NULL)
return NULL;
ixj[cnt] = j;
return j;
}
}
return NULL;
}
static void ixj_fsk_free(IXJ *j)
{
kfree(j->fskdata);
j->fskdata = NULL;
}
static void ixj_fsk_alloc(IXJ *j)
{
if(!j->fskdata) {
j->fskdata = kmalloc(8000, GFP_KERNEL);
if (!j->fskdata) {
if(ixjdebug & 0x0200) {
printk("IXJ phone%d - allocate failed\n", j->board);
}
return;
} else {
j->fsksize = 8000;
if(ixjdebug & 0x0200) {
printk("IXJ phone%d - allocate succeded\n", j->board);
}
}
}
}
#else
static IXJ ixj[IXJMAX];
#define get_ixj(b) (&ixj[(b)])
/*
* Allocate a free IXJ device
*/
static IXJ *ixj_alloc(void)
{
int cnt;
for(cnt=0; cnt<IXJMAX; cnt++) {
if(!ixj[cnt].DSPbase)
return &ixj[cnt];
}
return NULL;
}
static inline void ixj_fsk_free(IXJ *j) {;}
static inline void ixj_fsk_alloc(IXJ *j)
{
j->fsksize = 8000;
}
#endif
#ifdef PERFMON_STATS
#define ixj_perfmon(x) ((x)++)
#else
#define ixj_perfmon(x) do { } while(0)
#endif
static int ixj_convert_loaded;
static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
/************************************************************************
*
* These are function definitions to allow external modules to register
* enhanced functionality call backs.
*
************************************************************************/
static int Stub(IXJ * J, unsigned long arg)
{
return 0;
}
static IXJ_REGFUNC ixj_PreRead = &Stub;
static IXJ_REGFUNC ixj_PostRead = &Stub;
static IXJ_REGFUNC ixj_PreWrite = &Stub;
static IXJ_REGFUNC ixj_PostWrite = &Stub;
static void ixj_read_frame(IXJ *j);
static void ixj_write_frame(IXJ *j);
static void ixj_init_timer(IXJ *j);
static void ixj_add_timer(IXJ * j);
static void ixj_timeout(unsigned long ptr);
static int read_filters(IXJ *j);
static int LineMonitor(IXJ *j);
static int ixj_fasync(int fd, struct file *, int mode);
static int ixj_set_port(IXJ *j, int arg);
static int ixj_set_pots(IXJ *j, int arg);
static int ixj_hookstate(IXJ *j);
static int ixj_record_start(IXJ *j);
static void ixj_record_stop(IXJ *j);
static void set_rec_volume(IXJ *j, int volume);
static int get_rec_volume(IXJ *j);
static int set_rec_codec(IXJ *j, int rate);
static void ixj_vad(IXJ *j, int arg);
static int ixj_play_start(IXJ *j);
static void ixj_play_stop(IXJ *j);
static int ixj_set_tone_on(unsigned short arg, IXJ *j);
static int ixj_set_tone_off(unsigned short, IXJ *j);
static int ixj_play_tone(IXJ *j, char tone);
static void ixj_aec_start(IXJ *j, int level);
static int idle(IXJ *j);
static void ixj_ring_on(IXJ *j);
static void ixj_ring_off(IXJ *j);
static void aec_stop(IXJ *j);
static void ixj_ringback(IXJ *j);
static void ixj_busytone(IXJ *j);
static void ixj_dialtone(IXJ *j);
static void ixj_cpt_stop(IXJ *j);
static char daa_int_read(IXJ *j);
static char daa_CR_read(IXJ *j, int cr);
static int daa_set_mode(IXJ *j, int mode);
static int ixj_linetest(IXJ *j);
static int ixj_daa_write(IXJ *j);
static int ixj_daa_cid_read(IXJ *j);
static void DAA_Coeff_US(IXJ *j);
static void DAA_Coeff_UK(IXJ *j);
static void DAA_Coeff_France(IXJ *j);
static void DAA_Coeff_Germany(IXJ *j);
static void DAA_Coeff_Australia(IXJ *j);
static void DAA_Coeff_Japan(IXJ *j);
static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
/* Serial Control Interface funtions */
static int SCI_Control(IXJ *j, int control);
static int SCI_Prepare(IXJ *j);
static int SCI_WaitHighSCI(IXJ *j);
static int SCI_WaitLowSCI(IXJ *j);
static DWORD PCIEE_GetSerialNumber(WORD wAddress);
static int ixj_PCcontrol_wait(IXJ *j);
static void ixj_pre_cid(IXJ *j);
static void ixj_write_cid(IXJ *j);
static void ixj_write_cid_bit(IXJ *j, int bit);
static int set_base_frame(IXJ *j, int size);
static int set_play_codec(IXJ *j, int rate);
static void set_rec_depth(IXJ *j, int depth);
static int ixj_mixer(long val, IXJ *j);
/************************************************************************
CT8020/CT8021 Host Programmers Model
Host address Function Access
DSPbase +
0-1 Aux Software Status Register (reserved) Read Only
2-3 Software Status Register Read Only
4-5 Aux Software Control Register (reserved) Read Write
6-7 Software Control Register Read Write
8-9 Hardware Status Register Read Only
A-B Hardware Control Register Read Write
C-D Host Transmit (Write) Data Buffer Access Port (buffer input)Write Only
E-F Host Recieve (Read) Data Buffer Access Port (buffer input) Read Only
************************************************************************/
static inline void ixj_read_HSR(IXJ *j)
{
j->hsr.bytes.low = inb_p(j->DSPbase + 8);
j->hsr.bytes.high = inb_p(j->DSPbase + 9);
}
static inline int IsControlReady(IXJ *j)
{
ixj_read_HSR(j);
return j->hsr.bits.controlrdy ? 1 : 0;
}
static inline int IsPCControlReady(IXJ *j)
{
j->pccr1.byte = inb_p(j->XILINXbase + 3);
return j->pccr1.bits.crr ? 1 : 0;
}
static inline int IsStatusReady(IXJ *j)
{
ixj_read_HSR(j);
return j->hsr.bits.statusrdy ? 1 : 0;
}
static inline int IsRxReady(IXJ *j)
{
ixj_read_HSR(j);
ixj_perfmon(j->rxreadycheck);
return j->hsr.bits.rxrdy ? 1 : 0;
}
static inline int IsTxReady(IXJ *j)
{
ixj_read_HSR(j);
ixj_perfmon(j->txreadycheck);
return j->hsr.bits.txrdy ? 1 : 0;
}
static inline void set_play_volume(IXJ *j, int volume)
{
if (ixjdebug & 0x0002)
printk(KERN_INFO "IXJ: /dev/phone%d Setting Play Volume to 0x%4.4x\n", j->board, volume);
ixj_WriteDSPCommand(0xCF02, j);
ixj_WriteDSPCommand(volume, j);
}
static int set_play_volume_linear(IXJ *j, int volume)
{
int newvolume, dspplaymax;
if (ixjdebug & 0x0002)
printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Play Volume to 0x%4.4x\n", j->board, volume);
if(volume > 100 || volume < 0) {
return -1;
}
/* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
switch (j->cardtype) {
case QTI_PHONEJACK:
dspplaymax = 0x380;
break;
case QTI_LINEJACK:
if(j->port == PORT_PSTN) {
dspplaymax = 0x48;
} else {
dspplaymax = 0x100;
}
break;
case QTI_PHONEJACK_LITE:
dspplaymax = 0x380;
break;
case QTI_PHONEJACK_PCI:
dspplaymax = 0x6C;
break;
case QTI_PHONECARD:
dspplaymax = 0x50;
break;
default:
return -1;
}
newvolume = (dspplaymax * volume) / 100;
set_play_volume(j, newvolume);
return 0;
}
static inline void set_play_depth(IXJ *j, int depth)
{
if (depth > 60)
depth = 60;
if (depth < 0)
depth = 0;
ixj_WriteDSPCommand(0x5280 + depth, j);
}
static inline int get_play_volume(IXJ *j)
{
ixj_WriteDSPCommand(0xCF00, j);
return j->ssr.high << 8 | j->ssr.low;
}
static int get_play_volume_linear(IXJ *j)
{
int volume, newvolume, dspplaymax;
/* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
switch (j->cardtype) {
case QTI_PHONEJACK:
dspplaymax = 0x380;
break;
case QTI_LINEJACK:
if(j->port == PORT_PSTN) {
dspplaymax = 0x48;
} else {
dspplaymax = 0x100;
}
break;
case QTI_PHONEJACK_LITE:
dspplaymax = 0x380;
break;
case QTI_PHONEJACK_PCI:
dspplaymax = 0x6C;
break;
case QTI_PHONECARD:
dspplaymax = 100;
break;
default:
return -1;
}
volume = get_play_volume(j);
newvolume = (volume * 100) / dspplaymax;
if(newvolume > 100)
newvolume = 100;
return newvolume;
}
static inline BYTE SLIC_GetState(IXJ *j)
{
if (j->cardtype == QTI_PHONECARD) {
j->pccr1.byte = 0;
j->psccr.bits.dev = 3;
j->psccr.bits.rw = 1;
outw_p(j->psccr.byte << 8, j->XILINXbase + 0x00);
ixj_PCcontrol_wait(j);
j->pslic.byte = inw_p(j->XILINXbase + 0x00) & 0xFF;
ixj_PCcontrol_wait(j);
if (j->pslic.bits.powerdown)
return PLD_SLIC_STATE_OC;
else if (!j->pslic.bits.ring0 && !j->pslic.bits.ring1)
return PLD_SLIC_STATE_ACTIVE;
else
return PLD_SLIC_STATE_RINGING;
} else {
j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
}
return j->pld_slicr.bits.state;
}
static bool SLIC_SetState(BYTE byState, IXJ *j)
{
bool fRetVal = false;
if (j->cardtype == QTI_PHONECARD) {
if (j->flags.pcmciasct) {
switch (byState) {
case PLD_SLIC_STATE_TIPOPEN:
case PLD_SLIC_STATE_OC:
j->pslic.bits.powerdown = 1;
j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
fRetVal = true;
break;
case PLD_SLIC_STATE_RINGING:
if (j->readers || j->writers) {
j->pslic.bits.powerdown = 0;
j->pslic.bits.ring0 = 1;
j->pslic.bits.ring1 = 0;
fRetVal = true;
}
break;
case PLD_SLIC_STATE_OHT: /* On-hook transmit */
case PLD_SLIC_STATE_STANDBY:
case PLD_SLIC_STATE_ACTIVE:
if (j->readers || j->writers) {
j->pslic.bits.powerdown = 0;
} else {
j->pslic.bits.powerdown = 1;
}
j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
fRetVal = true;
break;
case PLD_SLIC_STATE_APR: /* Active polarity reversal */
case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
default:
fRetVal = false;
break;
}
j->psccr.bits.dev = 3;
j->psccr.bits.rw = 0;
outw_p(j->psccr.byte << 8 | j->pslic.byte, j->XILINXbase + 0x00);
ixj_PCcontrol_wait(j);
}
} else {
/* Set the C1, C2, C3 & B2EN signals. */
switch (byState) {
case PLD_SLIC_STATE_OC:
j->pld_slicw.bits.c1 = 0;
j->pld_slicw.bits.c2 = 0;
j->pld_slicw.bits.c3 = 0;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_RINGING:
j->pld_slicw.bits.c1 = 1;
j->pld_slicw.bits.c2 = 0;
j->pld_slicw.bits.c3 = 0;
j->pld_slicw.bits.b2en = 1;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_ACTIVE:
j->pld_slicw.bits.c1 = 0;
j->pld_slicw.bits.c2 = 1;
j->pld_slicw.bits.c3 = 0;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_OHT: /* On-hook transmit */
j->pld_slicw.bits.c1 = 1;
j->pld_slicw.bits.c2 = 1;
j->pld_slicw.bits.c3 = 0;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_TIPOPEN:
j->pld_slicw.bits.c1 = 0;
j->pld_slicw.bits.c2 = 0;
j->pld_slicw.bits.c3 = 1;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_STANDBY:
j->pld_slicw.bits.c1 = 1;
j->pld_slicw.bits.c2 = 0;
j->pld_slicw.bits.c3 = 1;
j->pld_slicw.bits.b2en = 1;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_APR: /* Active polarity reversal */
j->pld_slicw.bits.c1 = 0;
j->pld_slicw.bits.c2 = 1;
j->pld_slicw.bits.c3 = 1;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
j->pld_slicw.bits.c1 = 1;
j->pld_slicw.bits.c2 = 1;
j->pld_slicw.bits.c3 = 1;
j->pld_slicw.bits.b2en = 0;
outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
fRetVal = true;
break;
default:
fRetVal = false;
break;
}
}
return fRetVal;
}
static int ixj_wink(IXJ *j)
{
BYTE slicnow;
slicnow = SLIC_GetState(j);
j->pots_winkstart = jiffies;
SLIC_SetState(PLD_SLIC_STATE_OC, j);
msleep(jiffies_to_msecs(j->winktime));
SLIC_SetState(slicnow, j);
return 0;
}
static void ixj_init_timer(IXJ *j)
{
init_timer(&j->timer);
j->timer.function = ixj_timeout;
j->timer.data = (unsigned long)j;
}
static void ixj_add_timer(IXJ *j)
{
j->timer.expires = jiffies + (hertz / samplerate);
add_timer(&j->timer);
}
static void ixj_tone_timeout(IXJ *j)
{
IXJ_TONE ti;
j->tone_state++;
if (j->tone_state == 3) {
j->tone_state = 0;
if (j->cadence_t) {
j->tone_cadence_state++;
if (j->tone_cadence_state >= j->cadence_t->elements_used) {
switch (j->cadence_t->termination) {
case PLAY_ONCE:
ixj_cpt_stop(j);
break;
case REPEAT_LAST_ELEMENT:
j->tone_cadence_state--;
ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
break;
case REPEAT_ALL:
j->tone_cadence_state = 0;
if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
ixj_init_tone(j, &ti);
}
ixj_set_tone_on(j->cadence_t->ce[0].tone_on_time, j);
ixj_set_tone_off(j->cadence_t->ce[0].tone_off_time, j);
ixj_play_tone(j, j->cadence_t->ce[0].index);
break;
}
} else {
if (j->cadence_t->ce[j->tone_cadence_state].gain0) {
ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
ixj_init_tone(j, &ti);
}
ixj_set_tone_on(j->cadence_t->ce[j->tone_cadence_state].tone_on_time, j);
ixj_set_tone_off(j->cadence_t->ce[j->tone_cadence_state].tone_off_time, j);
ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
}
}
}
}
static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
{
if(j->ixj_signals[event]) {
if(ixjdebug & 0x0100)
printk("Sending signal for event %d\n", event);
/* Send apps notice of change */
/* see config.h for macro definition */
kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
}
}
static void ixj_pstn_state(IXJ *j)
{
int var;
union XOPXR0 XR0, daaint;
var = 10;
XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
daaint.reg = 0;
XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
j->pld_scrr.byte = inb_p(j->XILINXbase);
if (j->pld_scrr.bits.daaflag) {
daa_int_read(j);
if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.RING) {
if(time_after(jiffies, j->pstn_sleeptil) && !(j->flags.pots_pstn && j->hookstate)) {
daaint.bitreg.RING = 1;
if(ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ DAA Ring Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
}
} else {
daa_set_mode(j, SOP_PU_RESET);
}
}
if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Caller_ID) {
daaint.bitreg.Caller_ID = 1;
j->pstn_cid_intr = 1;
j->pstn_cid_received = jiffies;
if(ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ DAA Caller_ID Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
}
}
if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.Cadence) {
daaint.bitreg.Cadence = 1;
if(ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ DAA Cadence Interrupt /dev/phone%d at %ld\n", j->board, jiffies);
}
}
if(j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK != XR0.bitreg.VDD_OK) {
daaint.bitreg.VDD_OK = 1;
daaint.bitreg.SI_0 = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK;
}
}
daa_CR_read(j, 1);
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)) {
daaint.bitreg.RMR = 1;
daaint.bitreg.SI_1 = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
if(ixjdebug & 0x0008) {
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);
}
j->pstn_prev_rmr = j->pstn_last_rmr;
j->pstn_last_rmr = jiffies;
}
switch(j->daa_mode) {
case SOP_PU_SLEEP:
if (daaint.bitreg.RING) {
if (!j->flags.pstn_ringing) {
if (j->daa_mode != SOP_PU_RINGING) {
j->pstn_ring_int = jiffies;
daa_set_mode(j, SOP_PU_RINGING);
}
}
}
break;
case SOP_PU_RINGING:
if (daaint.bitreg.RMR) {
if (ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ Ring Cadence a state = %d /dev/phone%d at %ld\n", j->cadence_f[4].state, j->board, jiffies);
}
if (daaint.bitreg.SI_1) { /* Rising edge of RMR */
j->flags.pstn_rmr = 1;
j->pstn_ring_start = jiffies;
j->pstn_ring_stop = 0;
j->ex.bits.pstn_ring = 0;
if (j->cadence_f[4].state == 0) {
j->cadence_f[4].state = 1;
j->cadence_f[4].on1min = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 - var)) / 10000);
j->cadence_f[4].on1dot = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100)) / 10000);
j->cadence_f[4].on1max = jiffies + (long)((j->cadence_f[4].on1 * hertz * (100 + var)) / 10000);
} else if (j->cadence_f[4].state == 2) {
if((time_after(jiffies, j->cadence_f[4].off1min) &&
time_before(jiffies, j->cadence_f[4].off1max))) {
if (j->cadence_f[4].on2) {
j->cadence_f[4].state = 3;
j->cadence_f[4].on2min = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 - var)) / 10000));
j->cadence_f[4].on2dot = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100)) / 10000));
j->cadence_f[4].on2max = jiffies + (long)((j->cadence_f[4].on2 * (hertz * (100 + var)) / 10000));
} else {
j->cadence_f[4].state = 7;
}
} else {
if (ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
j->cadence_f[4].off1);
}
j->cadence_f[4].state = 0;
}
} else if (j->cadence_f[4].state == 4) {
if((time_after(jiffies, j->cadence_f[4].off2min) &&
time_before(jiffies, j->cadence_f[4].off2max))) {
if (j->cadence_f[4].on3) {
j->cadence_f[4].state = 5;
j->cadence_f[4].on3min = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 - var)) / 10000));
j->cadence_f[4].on3dot = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100)) / 10000));
j->cadence_f[4].on3max = jiffies + (long)((j->cadence_f[4].on3 * (hertz * (100 + var)) / 10000));
} else {
j->cadence_f[4].state = 7;
}
} else {
if (ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
j->cadence_f[4].off2);
}
j->cadence_f[4].state = 0;
}
} else if (j->cadence_f[4].state == 6) {
if((time_after(jiffies, j->cadence_f[4].off3min) &&
time_before(jiffies, j->cadence_f[4].off3max))) {
j->cadence_f[4].state = 7;
} else {
if (ixjdebug & 0x0008) {
printk(KERN_INFO "IXJ Ring Cadence fail state = %d /dev/phone%d at %ld should be %d\n",
j->cadence_f[4].state, j->board, jiffies - j->pstn_prev_rmr,
j->cadence_f[4].off3);
}
j->cadence_f[4].state = 0;
}
} else {
j->cadence_f[4].state = 0;
}
} else { /* Falling edge of RMR */
j->pstn_ring_start = 0;
j->pstn_ring_stop = jiffies;
if (j->cadence_f[4].state == 1) {
if(!j->cadence_f[4].on1) {