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#include "ixj-ver.h"
247
248#define PERFMON_STATS
249#define IXJDEBUG 0
250#define MAXRINGS 5
251
252#include <linux/module.h>
253
254#include <linux/init.h>
255#include <linux/sched.h>
256#include <linux/kernel.h>
257#include <linux/fs.h>
258#include <linux/errno.h>
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>
269
270#include <asm/io.h>
271#include <asm/uaccess.h>
272
273#include <linux/isapnp.h>
274
275#include "ixj.h"
276
277#define TYPE(inode) (iminor(inode) >> 4)
278#define NUM(inode) (iminor(inode) & 0xf)
279
280static DEFINE_MUTEX(ixj_mutex);
281static int ixjdebug;
282static int hertz = HZ;
283static int samplerate = 100;
284
285module_param(ixjdebug, int, 0);
286
287static 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},
290 { }
291};
292MODULE_DEVICE_TABLE(pci, ixj_pci_tbl);
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312#ifdef IXJ_DYN_ALLOC
313
314static IXJ *ixj[IXJMAX];
315#define get_ixj(b) ixj[(b)]
316
317
318
319
320
321static IXJ *ixj_alloc()
322{
323 for(cnt=0; cnt<IXJMAX; cnt++)
324 {
325 if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase)
326 {
327 j = kmalloc(sizeof(IXJ), GFP_KERNEL);
328 if (j == NULL)
329 return NULL;
330 ixj[cnt] = j;
331 return j;
332 }
333 }
334 return NULL;
335}
336
337static void ixj_fsk_free(IXJ *j)
338{
339 kfree(j->fskdata);
340 j->fskdata = NULL;
341}
342
343static void ixj_fsk_alloc(IXJ *j)
344{
345 if(!j->fskdata) {
346 j->fskdata = kmalloc(8000, GFP_KERNEL);
347 if (!j->fskdata) {
348 if(ixjdebug & 0x0200) {
349 printk("IXJ phone%d - allocate failed\n", j->board);
350 }
351 return;
352 } else {
353 j->fsksize = 8000;
354 if(ixjdebug & 0x0200) {
355 printk("IXJ phone%d - allocate succeeded\n", j->board);
356 }
357 }
358 }
359}
360
361#else
362
363static IXJ ixj[IXJMAX];
364#define get_ixj(b) (&ixj[(b)])
365
366
367
368
369
370static IXJ *ixj_alloc(void)
371{
372 int cnt;
373 for(cnt=0; cnt<IXJMAX; cnt++) {
374 if(!ixj[cnt].DSPbase)
375 return &ixj[cnt];
376 }
377 return NULL;
378}
379
380static inline void ixj_fsk_free(IXJ *j) {;}
381
382static inline void ixj_fsk_alloc(IXJ *j)
383{
384 j->fsksize = 8000;
385}
386
387#endif
388
389#ifdef PERFMON_STATS
390#define ixj_perfmon(x) ((x)++)
391#else
392#define ixj_perfmon(x) do { } while(0)
393#endif
394
395static int ixj_convert_loaded;
396
397static int ixj_WriteDSPCommand(unsigned short, IXJ *j);
398
399
400
401
402
403
404
405
406static int Stub(IXJ * J, unsigned long arg)
407{
408 return 0;
409}
410
411static IXJ_REGFUNC ixj_PreRead = &Stub;
412static IXJ_REGFUNC ixj_PostRead = &Stub;
413static IXJ_REGFUNC ixj_PreWrite = &Stub;
414static IXJ_REGFUNC ixj_PostWrite = &Stub;
415
416static void ixj_read_frame(IXJ *j);
417static void ixj_write_frame(IXJ *j);
418static void ixj_init_timer(IXJ *j);
419static void ixj_add_timer(IXJ * j);
420static void ixj_timeout(unsigned long ptr);
421static int read_filters(IXJ *j);
422static int LineMonitor(IXJ *j);
423static int ixj_fasync(int fd, struct file *, int mode);
424static int ixj_set_port(IXJ *j, int arg);
425static int ixj_set_pots(IXJ *j, int arg);
426static int ixj_hookstate(IXJ *j);
427static int ixj_record_start(IXJ *j);
428static void ixj_record_stop(IXJ *j);
429static void set_rec_volume(IXJ *j, int volume);
430static int get_rec_volume(IXJ *j);
431static int set_rec_codec(IXJ *j, int rate);
432static void ixj_vad(IXJ *j, int arg);
433static int ixj_play_start(IXJ *j);
434static void ixj_play_stop(IXJ *j);
435static int ixj_set_tone_on(unsigned short arg, IXJ *j);
436static int ixj_set_tone_off(unsigned short, IXJ *j);
437static int ixj_play_tone(IXJ *j, char tone);
438static void ixj_aec_start(IXJ *j, int level);
439static int idle(IXJ *j);
440static void ixj_ring_on(IXJ *j);
441static void ixj_ring_off(IXJ *j);
442static void aec_stop(IXJ *j);
443static void ixj_ringback(IXJ *j);
444static void ixj_busytone(IXJ *j);
445static void ixj_dialtone(IXJ *j);
446static void ixj_cpt_stop(IXJ *j);
447static char daa_int_read(IXJ *j);
448static char daa_CR_read(IXJ *j, int cr);
449static int daa_set_mode(IXJ *j, int mode);
450static int ixj_linetest(IXJ *j);
451static int ixj_daa_write(IXJ *j);
452static int ixj_daa_cid_read(IXJ *j);
453static void DAA_Coeff_US(IXJ *j);
454static void DAA_Coeff_UK(IXJ *j);
455static void DAA_Coeff_France(IXJ *j);
456static void DAA_Coeff_Germany(IXJ *j);
457static void DAA_Coeff_Australia(IXJ *j);
458static void DAA_Coeff_Japan(IXJ *j);
459static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf);
460static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr);
461static int ixj_init_tone(IXJ *j, IXJ_TONE * ti);
462static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp);
463static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp);
464
465static int SCI_Control(IXJ *j, int control);
466static int SCI_Prepare(IXJ *j);
467static int SCI_WaitHighSCI(IXJ *j);
468static int SCI_WaitLowSCI(IXJ *j);
469static DWORD PCIEE_GetSerialNumber(WORD wAddress);
470static int ixj_PCcontrol_wait(IXJ *j);
471static void ixj_pre_cid(IXJ *j);
472static void ixj_write_cid(IXJ *j);
473static void ixj_write_cid_bit(IXJ *j, int bit);
474static int set_base_frame(IXJ *j, int size);
475static int set_play_codec(IXJ *j, int rate);
476static void set_rec_depth(IXJ *j, int depth);
477static int ixj_mixer(long val, IXJ *j);
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493static inline void ixj_read_HSR(IXJ *j)
494{
495 j->hsr.bytes.low = inb_p(j->DSPbase + 8);
496 j->hsr.bytes.high = inb_p(j->DSPbase + 9);
497}
498
499static inline int IsControlReady(IXJ *j)
500{
501 ixj_read_HSR(j);
502 return j->hsr.bits.controlrdy ? 1 : 0;
503}
504
505static inline int IsPCControlReady(IXJ *j)
506{
507 j->pccr1.byte = inb_p(j->XILINXbase + 3);
508 return j->pccr1.bits.crr ? 1 : 0;
509}
510
511static inline int IsStatusReady(IXJ *j)
512{
513 ixj_read_HSR(j);
514 return j->hsr.bits.statusrdy ? 1 : 0;
515}
516
517static inline int IsRxReady(IXJ *j)
518{
519 ixj_read_HSR(j);
520 ixj_perfmon(j->rxreadycheck);
521 return j->hsr.bits.rxrdy ? 1 : 0;
522}
523
524static inline int IsTxReady(IXJ *j)
525{
526 ixj_read_HSR(j);
527 ixj_perfmon(j->txreadycheck);
528 return j->hsr.bits.txrdy ? 1 : 0;
529}
530
531static inline void set_play_volume(IXJ *j, int volume)
532{
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);
537}
538
539static int set_play_volume_linear(IXJ *j, int volume)
540{
541 int newvolume, dspplaymax;
542
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) {
546 return -1;
547 }
548
549
550 switch (j->cardtype) {
551 case QTI_PHONEJACK:
552 dspplaymax = 0x380;
553 break;
554 case QTI_LINEJACK:
555 if(j->port == PORT_PSTN) {
556 dspplaymax = 0x48;
557 } else {
558 dspplaymax = 0x100;
559 }
560 break;
561 case QTI_PHONEJACK_LITE:
562 dspplaymax = 0x380;
563 break;
564 case QTI_PHONEJACK_PCI:
565 dspplaymax = 0x6C;
566 break;
567 case QTI_PHONECARD:
568 dspplaymax = 0x50;
569 break;
570 default:
571 return -1;
572 }
573 newvolume = (dspplaymax * volume) / 100;
574 set_play_volume(j, newvolume);
575 return 0;
576}
577
578static inline void set_play_depth(IXJ *j, int depth)
579{
580 if (depth > 60)
581 depth = 60;
582 if (depth < 0)
583 depth = 0;
584 ixj_WriteDSPCommand(0x5280 + depth, j);
585}
586
587static inline int get_play_volume(IXJ *j)
588{
589 ixj_WriteDSPCommand(0xCF00, j);
590 return j->ssr.high << 8 | j->ssr.low;
591}
592
593static int get_play_volume_linear(IXJ *j)
594{
595 int volume, newvolume, dspplaymax;
596
597
598 switch (j->cardtype) {
599 case QTI_PHONEJACK:
600 dspplaymax = 0x380;
601 break;
602 case QTI_LINEJACK:
603 if(j->port == PORT_PSTN) {
604 dspplaymax = 0x48;
605 } else {
606 dspplaymax = 0x100;
607 }
608 break;
609 case QTI_PHONEJACK_LITE:
610 dspplaymax = 0x380;
611 break;
612 case QTI_PHONEJACK_PCI:
613 dspplaymax = 0x6C;
614 break;
615 case QTI_PHONECARD:
616 dspplaymax = 100;
617 break;
618 default:
619 return -1;
620 }
621 volume = get_play_volume(j);
622 newvolume = (volume * 100) / dspplaymax;
623 if(newvolume > 100)
624 newvolume = 100;
625 return newvolume;
626}
627
628static inline BYTE SLIC_GetState(IXJ *j)
629{
630 if (j->cardtype == QTI_PHONECARD) {
631 j->pccr1.byte = 0;
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;
642 else
643 return PLD_SLIC_STATE_RINGING;
644 } else {
645 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
646 }
647 return j->pld_slicr.bits.state;
648}
649
650static bool SLIC_SetState(BYTE byState, IXJ *j)
651{
652 bool fRetVal = false;
653
654 if (j->cardtype == QTI_PHONECARD) {
655 if (j->flags.pcmciasct) {
656 switch (byState) {
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;
661 fRetVal = true;
662 break;
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;
668 fRetVal = true;
669 }
670 break;
671 case PLD_SLIC_STATE_OHT:
672
673 case PLD_SLIC_STATE_STANDBY:
674 case PLD_SLIC_STATE_ACTIVE:
675 if (j->readers || j->writers) {
676 j->pslic.bits.powerdown = 0;
677 } else {
678 j->pslic.bits.powerdown = 1;
679 }
680 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
681 fRetVal = true;
682 break;
683 case PLD_SLIC_STATE_APR:
684
685 case PLD_SLIC_STATE_OHTPR:
686
687 default:
688 fRetVal = false;
689 break;
690 }
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);
695 }
696 } else {
697
698 switch (byState) {
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);
705 fRetVal = true;
706 break;
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);
713 fRetVal = true;
714 break;
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);
721 fRetVal = true;
722 break;
723 case PLD_SLIC_STATE_OHT:
724
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);
730 fRetVal = true;
731 break;
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);
738 fRetVal = true;
739 break;
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);
746 fRetVal = true;
747 break;
748 case PLD_SLIC_STATE_APR:
749
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);
755 fRetVal = true;
756 break;
757 case PLD_SLIC_STATE_OHTPR:
758
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);
764 fRetVal = true;
765 break;
766 default:
767 fRetVal = false;
768 break;
769 }
770 }
771
772 return fRetVal;
773}
774
775static int ixj_wink(IXJ *j)
776{
777 BYTE slicnow;
778
779 slicnow = SLIC_GetState(j);
780
781 j->pots_winkstart = jiffies;
782 SLIC_SetState(PLD_SLIC_STATE_OC, j);
783
784 msleep(jiffies_to_msecs(j->winktime));
785
786 SLIC_SetState(slicnow, j);
787 return 0;
788}
789
790static void ixj_init_timer(IXJ *j)
791{
792 init_timer(&j->timer);
793 j->timer.function = ixj_timeout;
794 j->timer.data = (unsigned long)j;
795}
796
797static void ixj_add_timer(IXJ *j)
798{
799 j->timer.expires = jiffies + (hertz / samplerate);
800 add_timer(&j->timer);
801}
802
803static void ixj_tone_timeout(IXJ *j)
804{
805 IXJ_TONE ti;
806
807 j->tone_state++;
808 if (j->tone_state == 3) {
809 j->tone_state = 0;
810 if (j->cadence_t) {
811 j->tone_cadence_state++;
812 if (j->tone_cadence_state >= j->cadence_t->elements_used) {
813 switch (j->cadence_t->termination) {
814 case PLAY_ONCE:
815 ixj_cpt_stop(j);
816 break;
817 case REPEAT_LAST_ELEMENT:
818 j->tone_cadence_state--;
819 ixj_play_tone(j, j->cadence_t->ce[j->tone_cadence_state].index);
820 break;
821 case REPEAT_ALL:
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);
830 }
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);
834 break;
835 }
836 } else {
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);
844 }
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);
848 }
849 }
850 }
851}
852
853static inline void ixj_kill_fasync(IXJ *j, IXJ_SIGEVENT event, int dir)
854{
855 if(j->ixj_signals[event]) {
856 if(ixjdebug & 0x0100)
857 printk("Sending signal for event %d\n", event);
858
859
860 kill_fasync(&(j->async_queue), j->ixj_signals[event], dir);
861 }
862}
863
864static void ixj_pstn_state(IXJ *j)
865{
866 int var;
867 union XOPXR0 XR0, daaint;
868
869 var = 10;
870
871 XR0.reg = j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg;
872 daaint.reg = 0;
873 XR0.bitreg.RMR = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR;
874
875 j->pld_scrr.byte = inb_p(j->XILINXbase);
876 if (j->pld_scrr.bits.daaflag) {
877 daa_int_read(j);
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);
883 }
884 } else {
885 daa_set_mode(j, SOP_PU_RESET);
886 }
887 }
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);
894 }
895 }
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);
900 }
901 }
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;
905 }
906 }
907 daa_CR_read(j, 1);
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);
913 }
914 j->pstn_prev_rmr = j->pstn_last_rmr;
915 j->pstn_last_rmr = jiffies;
916 }
917 switch(j->daa_mode) {
918 case SOP_PU_SLEEP:
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);
924 }
925 }
926 }
927 break;
928 case 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);
932 }
933 if (daaint.bitreg.SI_1) {
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));
951 } else {
952 j->cadence_f[4].state = 7;
953 }
954 } else {
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);
959 }
960 j->cadence_f[4].state = 0;
961 }
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));
970 } else {
971 j->cadence_f[4].state = 7;
972 }
973 } else {
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);
978 }
979 j->cadence_f[4].state = 0;
980 }
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;
985 } else {
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);
990 }
991 j->cadence_f[4].state = 0;
992 }
993 } else {
994 j->cadence_f[4].state = 0;
995 }
996 } else {
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));
1009 } else {
1010 j->cadence_f[4].state = 7;
1011 }
1012 } else {
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);
1017 }
1018 j->cadence_f[4].state = 0;
1019 }
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));
1028 } else {
1029 j->cadence_f[4].state = 7;
1030 }
1031 } else {
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);
1036 }
1037 j->cadence_f[4].state = 0;
1038 }
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));
1047 } else {
1048 j->cadence_f[4].state = 7;
1049 }
1050 } else {
1051 j->cadence_f[4].state = 0;
1052 }
1053 } else {
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);
1058 }
1059 j->cadence_f[4].state = 0;
1060 }
1061 }
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);
1064 }
1065 if (ixjdebug & 0x0010) {
1066 switch(j->cadence_f[4].state) {
1067 case 1:
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);
1070 break;
1071 case 2:
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);
1074 break;
1075 case 3:
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);
1078 break;
1079 case 4:
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);
1082 break;
1083 case 5:
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);
1086 break;
1087 case 6:
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);
1090 break;
1091 }
1092 }
1093 }
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);
1101 }
1102 }
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);
1109 }
1110 j->pstn_ring_stop = j->pstn_ring_int = 0;
1111 daa_set_mode(j, SOP_PU_SLEEP);
1112 }
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;
1119 }
1120 if (daaint.bitreg.Cadence) {
1121 if(ixjdebug & 0x0008) {
1122 printk("IXJ DAA Cadence interrupt going to sleep /dev/phone%d\n", j->board);
1123 }
1124 daa_set_mode(j, SOP_PU_SLEEP);
1125 j->ex.bits.pstn_ring = 0;
1126 }
1127 break;
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);
1134 }
1135 j->pstn_winkstart = jiffies;
1136 }
1137 } else {
1138 if (j->pstn_winkstart) {
1139 if(ixjdebug & 0x0008) {
1140 printk("IXJ DAA possible wink end /dev/phone%d %ld\n", j->board, jiffies);
1141 }
1142 j->pstn_winkstart = 0;
1143 }
1144 }
1145 }
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);
1149 }
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);
1154 }
1155 break;
1156 }
1157}
1158
1159static void ixj_timeout(unsigned long ptr)
1160{
1161 int board;
1162 unsigned long jifon;
1163 IXJ *j = (IXJ *)ptr;
1164 board = j->board;
1165
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)) {
1171 ixj_cpt_stop(j);
1172 if (j->m_hook) {
1173 j->m_hook = 0;
1174 j->ex.bits.hookstate = 1;
1175 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1176 }
1177 clear_bit(board, &j->busyflags);
1178 ixj_add_timer(j);
1179 return;
1180 }
1181 if (j->tone_state == 1)
1182 jifon = ((hertz * j->tone_on_time) * 25 / 100000);
1183 else
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);
1190 ixj_add_timer(j);
1191 return;
1192 }
1193 } else {
1194 ixj_play_tone(j, 0);
1195 if (j->dsp.low == 0x20) {
1196 clear_bit(board, &j->busyflags);
1197 ixj_add_timer(j);
1198 return;
1199 }
1200 }
1201 } else {
1202 ixj_tone_timeout(j);
1203 if (j->flags.dialtone) {
1204 ixj_dialtone(j);
1205 }
1206 if (j->flags.busytone) {
1207 ixj_busytone(j);
1208 if (j->dsp.low == 0x20) {
1209 clear_bit(board, &j->busyflags);
1210 ixj_add_timer(j);
1211 return;
1212 }
1213 }
1214 if (j->flags.ringback) {
1215 ixj_ringback(j);
1216 if (j->dsp.low == 0x20) {
1217 clear_bit(board, &j->busyflags);
1218 ixj_add_timer(j);
1219 return;
1220 }
1221 }
1222 if (!j->tone_state) {
1223 ixj_cpt_stop(j);
1224 }
1225 }
1226 }
1227 if (!(j->tone_state && j->dsp.low == 0x20)) {
1228 if (IsRxReady(j)) {
1229 ixj_read_frame(j);
1230 }
1231 if (IsTxReady(j)) {
1232 ixj_write_frame(j);
1233 }
1234 }
1235 if (j->flags.cringing) {
1236 if (j->hookstate & 1) {
1237 j->flags.cringing = 0;
1238 ixj_ring_off(j);
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) {
1241 case 0:
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);
1246 }
1247 ixj_ring_on(j);
1248 }
1249 j->cadence_f[5].state = 1;
1250 break;
1251 case 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);
1256 }
1257 ixj_ring_off(j);
1258 j->cadence_f[5].state = 2;
1259 }
1260 break;
1261 case 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);
1265 }
1266 ixj_ring_on(j);
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;
1270 } else {
1271 j->cadence_f[5].state = 7;
1272 }
1273 }
1274 break;
1275 case 3:
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);
1279 }
1280 ixj_ring_off(j);
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;
1284 } else {
1285 j->cadence_f[5].state = 7;
1286 }
1287 }
1288 break;
1289 case 4:
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);
1293 }
1294 ixj_ring_on(j);
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;
1298 } else {
1299 j->cadence_f[5].state = 7;
1300 }
1301 }
1302 break;
1303 case 5:
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);
1307 }
1308 ixj_ring_off(j);
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;
1312 } else {
1313 j->cadence_f[5].state = 7;
1314 }
1315 }
1316 break;
1317 case 6:
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);
1321 }
1322 j->cadence_f[5].state = 7;
1323 }
1324 break;
1325 case 7:
1326 if(ixjdebug & 0x0004) {
1327 printk("Ringing cadence state = %d - %ld\n", j->cadence_f[5].state, jiffies);
1328 }
1329 j->flags.cidring = 1;
1330 j->cadence_f[5].state = 0;
1331 break;
1332 }
1333 if (j->flags.cidring && !j->flags.cidsent) {
1334 j->flags.cidsent = 1;
1335 if(j->fskdcnt) {
1336 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1337 ixj_pre_cid(j);
1338 }
1339 j->flags.cidring = 0;
1340 }
1341 clear_bit(board, &j->busyflags);
1342 ixj_add_timer(j);
1343 return;
1344 } else {
1345 if (time_after(jiffies, j->ring_cadence_jif + (hertz / 2))) {
1346 if (j->flags.cidring && !j->flags.cidsent) {
1347 j->flags.cidsent = 1;
1348 if(j->fskdcnt) {
1349 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
1350 ixj_pre_cid(j);
1351 }
1352 j->flags.cidring = 0;
1353 }
1354 j->ring_cadence_t--;
1355 if (j->ring_cadence_t == -1)
1356 j->ring_cadence_t = 15;
1357 j->ring_cadence_jif = jiffies;
1358
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;
1362 else
1363 ixj_ring_on(j);
1364 } else {
1365 ixj_ring_off(j);
1366 if(!j->flags.cidsent)
1367 j->flags.cidring = 1;
1368 }
1369 }
1370 clear_bit(board, &j->busyflags);
1371 ixj_add_timer(j);
1372 return;
1373 }
1374 }
1375 if (!j->flags.ringing) {
1376 if (j->hookstate) {
1377 if (j->dsp.low != 0x20 &&
1378 SLIC_GetState(j) != PLD_SLIC_STATE_ACTIVE) {
1379 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1380 }
1381 LineMonitor(j);
1382 read_filters(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);
1388 }
1389 } else {
1390 if (j->ex.bits.dtmf_ready) {
1391 j->dtmf_wp = j->dtmf_rp = j->ex.bits.dtmf_ready = 0;
1392 }
1393 if (j->m_hook) {
1394 j->m_hook = 0;
1395 j->ex.bits.hookstate = 1;
1396 ixj_kill_fasync(j, SIG_HOOKSTATE, POLL_IN);
1397 }
1398 }
1399 }
1400 if (j->cardtype == QTI_LINEJACK && !j->flags.pstncheck && j->flags.pstn_present) {
1401 ixj_pstn_state(j);
1402 }
1403 if (j->ex.bytes) {
1404 wake_up_interruptible(&j->poll_q);
1405 }
1406 clear_bit(board, &j->busyflags);
1407 }
1408 ixj_add_timer(j);
1409}
1410
1411static int ixj_status_wait(IXJ *j)
1412{
1413 unsigned long jif;
1414
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);
1420 return -1;
1421 }
1422 }
1423 return 0;
1424}
1425
1426static int ixj_PCcontrol_wait(IXJ *j)
1427{
1428 unsigned long jif;
1429
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);
1435 return -1;
1436 }
1437 }
1438 return 0;
1439}
1440
1441static int ixj_WriteDSPCommand(unsigned short cmd, IXJ *j)
1442{
1443 BYTES bytes;
1444 unsigned long jif;
1445
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);
1449 return -1;
1450 }
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);
1463 }
1464 }
1465 return -1;
1466 }
1467 }
1468 outb(bytes.low, j->DSPbase + 6);
1469 outb(bytes.high, j->DSPbase + 7);
1470
1471 if (ixj_status_wait(j)) {
1472 j->ssr.low = 0xFF;
1473 j->ssr.high = 0xFF;
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);
1479 }
1480 }
1481 return -1;
1482 }
1483
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);
1491 }
1492 }
1493 return 0;
1494}
1495
1496
1497
1498
1499
1500
1501static inline int ixj_gpio_read(IXJ *j)
1502{
1503 if (ixj_WriteDSPCommand(0x5143, j))
1504 return -1;
1505
1506 j->gpio.bytes.low = j->ssr.low;
1507 j->gpio.bytes.high = j->ssr.high;
1508
1509 return 0;
1510}
1511
1512static inline void LED_SetState(int state, IXJ *j)
1513{
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;
1519
1520 outb(j->pld_scrw.byte, j->XILINXbase);
1521 }
1522}
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538static int ixj_set_port(IXJ *j, int arg)
1539{
1540 if (j->cardtype == QTI_PHONEJACK_LITE) {
1541 if (arg != PORT_POTS)
1542 return 10;
1543 else
1544 return 0;
1545 }
1546 switch (arg) {
1547 case PORT_POTS:
1548 j->port = PORT_POTS;
1549 switch (j->cardtype) {
1550 case QTI_PHONECARD:
1551 if (j->flags.pcmciasct == 1)
1552 SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j);
1553 else
1554 return 11;
1555 break;
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);
1560 break;
1561 case QTI_LINEJACK:
1562 ixj_set_pots(j, 0);
1563 if (ixj_WriteDSPCommand(0xC528, j))
1564
1565 return 2;
1566 j->pld_scrw.bits.daafsyncen = 0;
1567
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);
1575 ixj_mixer(0x1401, j);
1576 ixj_mixer(0x1300, j);
1577 ixj_mixer(0x1501, j);
1578 ixj_mixer(0x0E80, j);
1579 ixj_mixer(0x0F00, j);
1580 ixj_mixer(0x0080, j);
1581 ixj_mixer(0x0180, j);
1582 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
1583
1584 break;
1585 case QTI_PHONEJACK:
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);
1590 break;
1591 }
1592 break;
1593 case PORT_PSTN:
1594 if (j->cardtype == QTI_LINEJACK) {
1595 ixj_WriteDSPCommand(0xC534, j);
1596
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;
1602 } else {
1603 return 4;
1604 }
1605 break;
1606 case PORT_SPEAKER:
1607 j->port = PORT_SPEAKER;
1608 switch (j->cardtype) {
1609 case QTI_PHONECARD:
1610 if (j->flags.pcmciasct) {
1611 SLIC_SetState(PLD_SLIC_STATE_OC, j);
1612 }
1613 break;
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);
1618 break;
1619 case QTI_LINEJACK:
1620 ixj_set_pots(j, 0);
1621 if (ixj_WriteDSPCommand(0xC528, j))
1622
1623 return 2;
1624 j->pld_scrw.bits.daafsyncen = 0;
1625
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);
1633 ixj_mixer(0x1400, j);
1634 ixj_mixer(0x1301, j);
1635 ixj_mixer(0x1500, j);
1636 ixj_mixer(0x0E06, j);
1637 ixj_mixer(0x0F80, j);
1638 ixj_mixer(0x0000, j);
1639 ixj_mixer(0x0100, j);
1640 break;
1641 case QTI_PHONEJACK:
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);
1646 break;
1647 }
1648 break;
1649 case PORT_HANDSET:
1650 if (j->cardtype != QTI_PHONEJACK) {
1651 return 5;
1652 } else {
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;
1658 }
1659 break;
1660 default:
1661 return 6;
1662 break;
1663 }
1664 return 0;
1665}
1666
1667static int ixj_set_pots(IXJ *j, int arg)
1668{
1669 if (j->cardtype == QTI_LINEJACK) {
1670 if (arg) {
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;
1675 return 1;
1676 } else {
1677 j->flags.pots_pstn = 0;
1678 return 0;
1679 }
1680 } else {
1681 j->pld_slicw.bits.rly1 = 1;
1682 outb(j->pld_slicw.byte, j->XILINXbase + 0x01);
1683 j->flags.pots_pstn = 0;
1684 return 1;
1685 }
1686 } else {
1687 return 0;
1688 }
1689}
1690
1691static void ixj_ring_on(IXJ *j)
1692{
1693 if (j->dsp.low == 0x20)
1694 {
1695 if (ixjdebug & 0x0004)
1696 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1697
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);
1704 } else
1705 {
1706 if (ixjdebug & 0x0004)
1707 printk(KERN_INFO "IXJ Ring On /dev/phone%d\n", j->board);
1708
1709 SLIC_SetState(PLD_SLIC_STATE_RINGING, j);
1710 }
1711}
1712
1713static int ixj_siadc(IXJ *j, int val)
1714{
1715 if(j->cardtype == QTI_PHONECARD){
1716 if(j->flags.pcmciascp){
1717 if(val == -1)
1718 return j->siadc.bits.rxg;
1719
1720 if(val < 0 || val > 0x1F)
1721 return -1;
1722
1723 j->siadc.bits.hom = 0;
1724 j->siadc.bits.lom = 0;
1725 j->siadc.bits.rxg = val;
1726 j->psccr.bits.addr = 6;
1727 j->psccr.bits.rw = 0;
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;
1733 }
1734 }
1735 return -1;
1736}
1737
1738static int ixj_sidac(IXJ *j, int val)
1739{
1740 if(j->cardtype == QTI_PHONECARD){
1741 if(j->flags.pcmciascp){
1742 if(val == -1)
1743 return j->sidac.bits.txg;
1744
1745 if(val < 0 || val > 0x1F)
1746 return -1;
1747
1748 j->sidac.bits.srm = 1;
1749 j->sidac.bits.slm = 1;
1750 j->sidac.bits.txg = val;
1751 j->psccr.bits.addr = 7;
1752 j->psccr.bits.rw = 0;
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;
1758 }
1759 }
1760 return -1;
1761}
1762
1763static int ixj_pcmcia_cable_check(IXJ *j)
1764{
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;
1770 return 0;
1771 }
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) {
1786 return j->r_hook;
1787 } else {
1788 return 1;
1789 }
1790 } else if (j->flags.pcmciastate == 4) {
1791 if (!j->pccr1.bits.drf) {
1792 j->flags.pcmciastate = 3;
1793 }
1794 return 0;
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;
1802 return 0;
1803 } else if (j->flags.pcmciastate == 2) {
1804 if (j->flags.incheck) {
1805 if (time_before(jiffies, j->checkwait)) {
1806 return 0;
1807 } else {
1808 j->flags.incheck = 0;
1809 }
1810 }
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;
1815 return 0;
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;
1824
1825 j->flags.pcmciasct = (inw_p(j->XILINXbase + 0x00) >> 8) & 0x03;
1826
1827 if (j->flags.pcmciasct == 3) {
1828 j->flags.pcmciastate = 4;
1829 return 0;
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;
1835 } else {
1836 j->port = PORT_POTS;
1837 }
1838 j->sic1.bits.cpd = 0;
1839 j->sic1.bits.mpd = 0;
1840 j->sic1.bits.hpd = 0;
1841 j->sic1.bits.lpd = 0;
1842 j->sic1.bits.spd = 1;
1843 j->psccr.bits.addr = 1;
1844 j->psccr.bits.rw = 0;
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);
1849
1850 j->sic2.bits.al = 0;
1851 j->sic2.bits.dl2 = 0;
1852 j->sic2.bits.dl1 = 0;
1853 j->sic2.bits.pll = 0;
1854 j->sic2.bits.hpd = 0;
1855 j->psccr.bits.addr = 2;
1856 j->psccr.bits.rw = 0;
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);
1861
1862 j->psccr.bits.addr = 3;
1863 j->psccr.bits.rw = 0;
1864 j->psccr.bits.dev = 0;
1865 outb(0x00, j->XILINXbase + 0x00);
1866 outb(j->psccr.byte, j->XILINXbase + 0x01);
1867 ixj_PCcontrol_wait(j);
1868
1869 j->psccr.bits.addr = 4;
1870 j->psccr.bits.rw = 0;
1871 j->psccr.bits.dev = 0;
1872 outb(0x09, j->XILINXbase + 0x00);
1873 outb(j->psccr.byte, j->XILINXbase + 0x01);
1874 ixj_PCcontrol_wait(j);
1875
1876 j->sirxg.bits.lig = 1;
1877 j->sirxg.bits.lim = 1;
1878 j->sirxg.bits.mcg = 0;
1879 j->sirxg.bits.mcm = 0;
1880 j->sirxg.bits.him = 0;
1881 j->sirxg.bits.iir = 1;
1882 j->psccr.bits.addr = 5;
1883 j->psccr.bits.rw = 0;
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);
1888
1889 ixj_siadc(j, 0x17);
1890 ixj_sidac(j, 0x1D);
1891
1892 j->siaatt.bits.sot = 0;
1893 j->psccr.bits.addr = 9;
1894 j->psccr.bits.rw = 0;
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);
1899
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);
1907 }
1908 }
1909 return 0;
1910 } else {
1911 j->flags.pcmciascp = 0;
1912 return 0;
1913 }
1914 return 0;
1915}
1916
1917static int ixj_hookstate(IXJ *j)
1918{
1919 int fOffHook = 0;
1920
1921 switch (j->cardtype) {
1922 case QTI_PHONEJACK:
1923 ixj_gpio_read(j);
1924 fOffHook = j->gpio.bits.gpio3read ? 1 : 0;
1925 break;
1926 case QTI_LINEJACK:
1927 case QTI_PHONEJACK_LITE:
1928 case QTI_PHONEJACK_PCI:
1929 SLIC_GetState(j);
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) {
1933 if(!j->checkwait) {
1934 j->checkwait = jiffies;
1935 }
1936 if(time_before(jiffies, j->checkwait + 2)) {
1937 fOffHook ^= 1;
1938 } else {
1939 j->checkwait = 0;
1940 }
1941 j->p_hook = fOffHook;
1942 printk("IXJ : /dev/phone%d pots-pstn hookstate check %d at %ld\n", j->board, fOffHook, jiffies);
1943 }
1944 } else {
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()) {
1949 msleep(20);
1950 }
1951 SLIC_GetState(j);
1952 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
1953 ixj_ring_on(j);
1954 }
1955 }
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;
1959 } else
1960 fOffHook = j->pld_slicr.bits.det ? 1 : 0;
1961 }
1962 }
1963 break;
1964 case QTI_PHONECARD:
1965 fOffHook = ixj_pcmcia_cable_check(j);
1966 break;
1967 }
1968 if (j->r_hook != fOffHook) {
1969 j->r_hook = fOffHook;
1970 if (j->port == PORT_SPEAKER || j->port == PORT_HANDSET) {
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);
1975 }
1976 }
1977 if (fOffHook) {
1978 if(time_before(jiffies, j->flash_end)) {
1979 j->ex.bits.flash = 1;
1980 j->flash_end = 0;
1981 ixj_kill_fasync(j, SIG_FLASH, POLL_IN);
1982 }
1983 } else {
1984 if(time_before(jiffies, j->flash_end)) {
1985 fOffHook = 1;
1986 }
1987 }
1988
1989 if (j->port == PORT_PSTN && j->daa_mode == SOP_PU_CONVERSATION)
1990 fOffHook |= 2;
1991
1992 if (j->port == PORT_SPEAKER) {
1993 if(j->cardtype == QTI_PHONECARD) {
1994 if(j->flags.pcmciascp && j->flags.pcmciasct) {
1995 fOffHook |= 2;
1996 }
1997 } else {
1998 fOffHook |= 2;
1999 }
2000 }
2001
2002 if (j->port == PORT_HANDSET)
2003 fOffHook |= 2;
2004
2005 return fOffHook;
2006}
2007
2008static void ixj_ring_off(IXJ *j)
2009{
2010 if (j->dsp.low == 0x20)
2011 {
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
2021 {
2022 if (ixjdebug & 0x0004)
2023 printk(KERN_INFO "IXJ Ring Off\n");
2024
2025 if(!j->flags.cidplay)
2026 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
2027
2028 SLIC_GetState(j);
2029 }
2030}
2031
2032static void ixj_ring_start(IXJ *j)
2033{
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)
2039 ixj_ring_off(j);
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)
2048 ixj_ring_on(j);
2049 } else {
2050 j->ring_cadence_jif = jiffies;
2051 j->ring_cadence_t = 15;
2052 if (j->ring_cadence & 1 << j->ring_cadence_t) {
2053 ixj_ring_on(j);
2054 } else {
2055 ixj_ring_off(j);
2056 }
2057 j->flags.cidsent = j->flags.cidring = j->flags.firstring = 0;
2058 }
2059}
2060
2061static int ixj_ring(IXJ *j)
2062{
2063 char cntr;
2064 unsigned long jif;
2065
2066 j->flags.ringing = 1;
2067 if (ixj_hookstate(j) & 1) {
2068 ixj_ring_off(j);
2069 j->flags.ringing = 0;
2070 return 1;
2071 }
2072 for (cntr = 0; cntr < j->maxrings; cntr++) {
2073 jif = jiffies + (1 * hertz);
2074 ixj_ring_on(j);
2075 while (time_before(jiffies, jif)) {
2076 if (ixj_hookstate(j) & 1) {
2077 ixj_ring_off(j);
2078 j->flags.ringing = 0;
2079 return 1;
2080 }
2081 schedule_timeout_interruptible(1);
2082 if (signal_pending(current))
2083 break;
2084 }
2085 jif = jiffies + (3 * hertz);
2086 ixj_ring_off(j);
2087 while (time_before(jiffies, jif)) {
2088 if (ixj_hookstate(j) & 1) {
2089 msleep(10);
2090 if (ixj_hookstate(j) & 1) {
2091 j->flags.ringing = 0;
2092 return 1;
2093 }
2094 }
2095 schedule_timeout_interruptible(1);
2096 if (signal_pending(current))
2097 break;
2098 }
2099 }
2100 ixj_ring_off(j);
2101 j->flags.ringing = 0;
2102 return 0;
2103}
2104
2105static int ixj_open(struct phone_device *p, struct file *file_p)
2106{
2107 IXJ *j = get_ixj(p->board);
2108 file_p->private_data = j;
2109
2110 if (!j->DSPbase)
2111 return -ENODEV;
2112
2113 if (file_p->f_mode & FMODE_READ) {
2114 if(!j->readers) {
2115 j->readers++;
2116 } else {
2117 return -EBUSY;
2118 }
2119 }
2120
2121 if (file_p->f_mode & FMODE_WRITE) {
2122 if(!j->writers) {
2123 j->writers++;
2124 } else {
2125 if (file_p->f_mode & FMODE_READ){
2126 j->readers--;
2127 }
2128 return -EBUSY;
2129 }
2130 }
2131
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);
2138 }
2139
2140 j->flags.cidplay = 0;
2141 j->flags.cidcw_ack = 0;
2142
2143 if (ixjdebug & 0x0002)
2144 printk(KERN_INFO "Opening board %d\n", p->board);
2145
2146 j->framesread = j->frameswritten = 0;
2147 return 0;
2148}
2149
2150static int ixj_release(struct inode *inode, struct file *file_p)
2151{
2152 IXJ_TONE ti;
2153 int cnt;
2154 IXJ *j = file_p->private_data;
2155 int board = j->p.board;
2156
2157
2158
2159
2160
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));
2165
2166 if (j->cardtype == QTI_PHONECARD)
2167 ixj_set_port(j, PORT_SPEAKER);
2168 else
2169 ixj_set_port(j, PORT_POTS);
2170
2171 aec_stop(j);
2172 ixj_play_stop(j);
2173 ixj_record_stop(j);
2174 set_play_volume(j, 0x100);
2175 set_rec_volume(j, 0x100);
2176 ixj_ring_off(j);
2177
2178
2179 ti.tone_index = 10;
2180 ti.gain0 = 1;
2181 ti.freq0 = hz941;
2182 ti.gain1 = 0;
2183 ti.freq1 = hz1209;
2184 ixj_init_tone(j, &ti);
2185 ti.tone_index = 11;
2186 ti.gain0 = 1;
2187 ti.freq0 = hz941;
2188 ti.gain1 = 0;
2189 ti.freq1 = hz1336;
2190 ixj_init_tone(j, &ti);
2191 ti.tone_index = 12;
2192 ti.gain0 = 1;
2193 ti.freq0 = hz941;
2194 ti.gain1 = 0;
2195 ti.freq1 = hz1477;
2196 ixj_init_tone(j, &ti);
2197 ti.tone_index = 13;
2198 ti.gain0 = 1;
2199 ti.freq0 = hz800;
2200 ti.gain1 = 0;
2201 ti.freq1 = 0;
2202 ixj_init_tone(j, &ti);
2203 ti.tone_index = 14;
2204 ti.gain0 = 1;
2205 ti.freq0 = hz1000;
2206 ti.gain1 = 0;
2207 ti.freq1 = 0;
2208 ixj_init_tone(j, &ti);
2209 ti.tone_index = 15;
2210 ti.gain0 = 1;
2211 ti.freq0 = hz1250;
2212 ti.gain1 = 0;
2213 ti.freq1 = 0;
2214 ixj_init_tone(j, &ti);
2215 ti.tone_index = 16;
2216 ti.gain0 = 1;
2217 ti.freq0 = hz950;
2218 ti.gain1 = 0;
2219 ti.freq1 = 0;
2220 ixj_init_tone(j, &ti);
2221 ti.tone_index = 17;
2222 ti.gain0 = 1;
2223 ti.freq0 = hz1100;
2224 ti.gain1 = 0;
2225 ti.freq1 = 0;
2226 ixj_init_tone(j, &ti);
2227 ti.tone_index = 18;
2228 ti.gain0 = 1;
2229 ti.freq0 = hz1400;
2230 ti.gain1 = 0;
2231 ti.freq1 = 0;
2232 ixj_init_tone(j, &ti);
2233 ti.tone_index = 19;
2234 ti.gain0 = 1;
2235 ti.freq0 = hz1500;
2236 ti.gain1 = 0;
2237 ti.freq1 = 0;
2238 ixj_init_tone(j, &ti);
2239 ti.tone_index = 20;
2240 ti.gain0 = 1;
2241 ti.freq0 = hz1600;
2242 ti.gain1 = 0;
2243 ti.freq1 = 0;
2244 ixj_init_tone(j, &ti);
2245 ti.tone_index = 21;
2246 ti.gain0 = 1;
2247 ti.freq0 = hz1800;
2248 ti.gain1 = 0;
2249 ti.freq1 = 0;
2250 ixj_init_tone(j, &ti);
2251 ti.tone_index = 22;
2252 ti.gain0 = 1;
2253 ti.freq0 = hz2100;
2254 ti.gain1 = 0;
2255 ti.freq1 = 0;
2256 ixj_init_tone(j, &ti);
2257 ti.tone_index = 23;
2258 ti.gain0 = 1;
2259 ti.freq0 = hz1300;
2260 ti.gain1 = 0;
2261 ti.freq1 = 0;
2262 ixj_init_tone(j, &ti);
2263 ti.tone_index = 24;
2264 ti.gain0 = 1;
2265 ti.freq0 = hz2450;
2266 ti.gain1 = 0;
2267 ti.freq1 = 0;
2268 ixj_init_tone(j, &ti);
2269 ti.tone_index = 25;
2270 ti.gain0 = 1;
2271 ti.freq0 = hz350;
2272 ti.gain1 = 0;
2273 ti.freq1 = hz440;
2274 ixj_init_tone(j, &ti);
2275 ti.tone_index = 26;
2276 ti.gain0 = 1;
2277 ti.freq0 = hz440;
2278 ti.gain1 = 0;
2279 ti.freq1 = hz480;
2280 ixj_init_tone(j, &ti);
2281 ti.tone_index = 27;
2282 ti.gain0 = 1;
2283 ti.freq0 = hz480;
2284 ti.gain1 = 0;
2285 ti.freq1 = hz620;
2286 ixj_init_tone(j, &ti);
2287
2288 set_rec_depth(j, 2);
2289
2290 set_play_depth(j, 2);
2291
2292 j->ex.bits.dtmf_ready = 0;
2293 j->dtmf_state = 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;
2301 }
2302 j->drybuffer = 0;
2303 j->winktime = 320;
2304 j->flags.dtmf_oob = 0;
2305 for (cnt = 0; cnt < 4; cnt++)
2306 j->cadence_f[cnt].enable = 0;
2307
2308 idle(j);
2309
2310 if(j->cardtype == QTI_PHONECARD) {
2311 SLIC_SetState(PLD_SLIC_STATE_OC, j);
2312 }
2313
2314 if (file_p->f_mode & FMODE_READ)
2315 j->readers--;
2316 if (file_p->f_mode & FMODE_WRITE)
2317 j->writers--;
2318
2319 if (j->read_buffer && !j->readers) {
2320 kfree(j->read_buffer);
2321 j->read_buffer = NULL;
2322 j->read_buffer_size = 0;
2323 }
2324 if (j->write_buffer && !j->writers) {
2325 kfree(j->write_buffer);
2326 j->write_buffer = NULL;
2327 j->write_buffer_size = 0;
2328 }
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;
2332
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);
2336 ixj_set_pots(j, 1);
2337 }
2338 ixj_WriteDSPCommand(0x0FE3, j);
2339
2340
2341 for (cnt = 0; cnt < 35; cnt++)
2342 j->ixj_signals[cnt] = SIGIO;
2343
2344
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;
2348
2349 file_p->private_data = NULL;
2350 clear_bit(board, &j->busyflags);
2351 return 0;
2352}
2353
2354static int read_filters(IXJ *j)
2355{
2356 unsigned short fc, cnt, trg;
2357 int var;
2358
2359 trg = 0;
2360 if (ixj_WriteDSPCommand(0x5144, j)) {
2361 if(ixjdebug & 0x0001) {
2362 printk(KERN_INFO "Read Frame Counter failed!\n");
2363 }
2364 return -1;
2365 }
2366 fc = j->ssr.high << 8 | j->ssr.low;
2367 if (fc == j->frame_count)
2368 return 1;
2369
2370 j->frame_count = fc;
2371
2372 if (j->dtmf_proc)
2373 return 1;
2374
2375 var = 10;
2376
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);
2381 }
2382 return -1;
2383 }
2384 if (ixj_WriteDSPCommand(0x515C, j)) {
2385 if(ixjdebug & 0x0001) {
2386 printk(KERN_INFO "Read Filter History %d failed!\n", cnt);
2387 }
2388 return -1;
2389 }
2390 j->filter_hist[cnt] = j->ssr.high << 8 | j->ssr.low;
2391
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));
2407 } else {
2408 j->cadence_f[cnt].state = 7;
2409 }
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));
2418 } else {
2419 j->cadence_f[cnt].state = 7;
2420 }
2421 } else {
2422 j->cadence_f[cnt].state = 0;
2423 }
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));
2435 } else {
2436 j->cadence_f[cnt].state = 7;
2437 }
2438 } else {
2439 j->cadence_f[cnt].state = 0;
2440 }
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));
2449 } else {
2450 j->cadence_f[cnt].state = 7;
2451 }
2452 } else {
2453 j->cadence_f[cnt].state = 0;
2454 }
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));
2463 } else {
2464 j->cadence_f[cnt].state = 7;
2465 }
2466 } else {
2467 j->cadence_f[cnt].state = 0;
2468 }
2469 } else {
2470 j->cadence_f[cnt].state = 0;
2471 }
2472 } else {
2473 switch(j->cadence_f[cnt].state) {
2474 case 1:
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;
2480 }
2481 break;
2482 case 3:
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;
2487 }
2488 break;
2489 case 5:
2490 if(time_after(jiffies, j->cadence_f[cnt].on3dot) &&
2491 !j->cadence_f[cnt].off3) {
2492 j->cadence_f[cnt].state = 7;
2493 }
2494 break;
2495 }
2496 }
2497
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) {
2501 case 0:
2502 printk(KERN_INFO "IXJ /dev/phone%d No Tone detected\n", j->board);
2503 break;
2504 case 1:
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);
2507 break;
2508 case 2:
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);
2511 break;
2512 case 3:
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);
2515 break;
2516 case 4:
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);
2519 break;
2520 case 5:
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);
2523 break;
2524 case 6:
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);
2527 break;
2528 }
2529 }
2530 }
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;
2535 switch (cnt) {
2536 case 0:
2537 if(ixjdebug & 0x0020) {
2538 printk(KERN_INFO "Filter Cadence 0 triggered %ld\n", jiffies);
2539 }
2540 j->ex.bits.fc0 = 1;
2541 ixj_kill_fasync(j, SIG_FC0, POLL_IN);
2542 break;
2543 case 1:
2544 if(ixjdebug & 0x0020) {
2545 printk(KERN_INFO "Filter Cadence 1 triggered %ld\n", jiffies);
2546 }
2547 j->ex.bits.fc1 = 1;
2548 ixj_kill_fasync(j, SIG_FC1, POLL_IN);
2549 break;
2550 case 2:
2551 if(ixjdebug & 0x0020) {
2552 printk(KERN_INFO "Filter Cadence 2 triggered %ld\n", jiffies);
2553 }
2554 j->ex.bits.fc2 = 1;
2555 ixj_kill_fasync(j, SIG_FC2, POLL_IN);
2556 break;
2557 case 3:
2558 if(ixjdebug & 0x0020) {
2559 printk(KERN_INFO "Filter Cadence 3 triggered %ld\n", jiffies);
2560 }
2561 j->ex.bits.fc3 = 1;
2562 ixj_kill_fasync(j, SIG_FC3, POLL_IN);
2563 break;
2564 }
2565 }
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))) {
2569 trg = 1;
2570 } else if((j->filter_hist[cnt] & 12 && !(j->filter_hist[cnt] & 3))) {
2571 trg = 0;
2572 }
2573 switch (cnt) {
2574 case 0:
2575 if(ixjdebug & 0x0020) {
2576 printk(KERN_INFO "Filter 0 triggered %d at %ld\n", trg, jiffies);
2577 }
2578 j->ex.bits.f0 = 1;
2579 ixj_kill_fasync(j, SIG_F0, POLL_IN);
2580 break;
2581 case 1:
2582 if(ixjdebug & 0x0020) {
2583 printk(KERN_INFO "Filter 1 triggered %d at %ld\n", trg, jiffies);
2584 }
2585 j->ex.bits.f1 = 1;
2586 ixj_kill_fasync(j, SIG_F1, POLL_IN);
2587 break;
2588 case 2:
2589 if(ixjdebug & 0x0020) {
2590 printk(KERN_INFO "Filter 2 triggered %d at %ld\n", trg, jiffies);
2591 }
2592 j->ex.bits.f2 = 1;
2593 ixj_kill_fasync(j, SIG_F2, POLL_IN);
2594 break;
2595 case 3:
2596 if(ixjdebug & 0x0020) {
2597 printk(KERN_INFO "Filter 3 triggered %d at %ld\n", trg, jiffies);
2598 }
2599 j->ex.bits.f3 = 1;
2600 ixj_kill_fasync(j, SIG_F3, POLL_IN);
2601 break;
2602 }
2603 }
2604 }
2605 return 0;
2606}
2607
2608static int LineMonitor(IXJ *j)
2609{
2610 if (j->dtmf_proc) {
2611 return -1;
2612 }
2613 j->dtmf_proc = 1;
2614
2615 if (ixj_WriteDSPCommand(0x7000, j))
2616 return -1;
2617
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) {
2621 j->dtmf_state = 1;
2622 j->dtmf_current = j->dtmf.bits.digit;
2623 }
2624 if (j->dtmf_state && !j->dtmf.bits.dtmf_valid)
2625 {
2626 if(!j->cidcw_wait) {
2627 j->dtmfbuffer[j->dtmf_wp] = j->dtmf_current;
2628 j->dtmf_wp++;
2629 if (j->dtmf_wp == 79)
2630 j->dtmf_wp = 0;
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);
2634 }
2635 }
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);
2639 }
2640 j->flags.cidcw_ack = 1;
2641 }
2642 j->dtmf_state = 0;
2643 }
2644 j->dtmf_proc = 0;
2645
2646 return 0;
2647}
2648
2649
2650
2651
2652
2653
2654
2655static void ulaw2alaw(unsigned char *buff, unsigned long len)
2656{
2657 static unsigned char table_ulaw2alaw[] =
2658 {
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
2691 };
2692
2693 while (len--)
2694 {
2695 *buff = table_ulaw2alaw[*(unsigned char *)buff];
2696 buff++;
2697 }
2698}
2699
2700static void alaw2ulaw(unsigned char *buff, unsigned long len)
2701{
2702 static unsigned char table_alaw2ulaw[] =
2703 {
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
2736 };
2737
2738 while (len--)
2739 {
2740 *buff = table_alaw2ulaw[*(unsigned char *)buff];
2741 buff++;
2742 }
2743}
2744
2745static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos)
2746{
2747 unsigned long i = *ppos;
2748 IXJ * j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2749
2750 DECLARE_WAITQUEUE(wait, current);
2751
2752 if (j->flags.inread)
2753 return -EALREADY;
2754
2755 j->flags.inread = 1;
2756
2757 add_wait_queue(&j->read_q, &wait);
2758 set_current_state(TASK_INTERRUPTIBLE);
2759 mb();
2760
2761 while (!j->read_buffer_ready || (j->dtmf_state && j->flags.dtmf_oob)) {
2762 ++j->read_wait;
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;
2767 return -EAGAIN;
2768 }
2769 if (!ixj_hookstate(j)) {
2770 set_current_state(TASK_RUNNING);
2771 remove_wait_queue(&j->read_q, &wait);
2772 j->flags.inread = 0;
2773 return 0;
2774 }
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;
2780 return -EINTR;
2781 }
2782 }
2783
2784 remove_wait_queue(&j->read_q, &wait);
2785 set_current_state(TASK_RUNNING);
2786
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;
2791 if (i) {
2792 j->flags.inread = 0;
2793 return -EFAULT;
2794 } else {
2795 j->flags.inread = 0;
2796 return min(length, j->read_buffer_size);
2797 }
2798}
2799
2800static ssize_t ixj_enhanced_read(struct file * file_p, char __user *buf, size_t length,
2801 loff_t * ppos)
2802{
2803 int pre_retval;
2804 ssize_t read_retval = 0;
2805 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2806
2807 pre_retval = ixj_PreRead(j, 0L);
2808 switch (pre_retval) {
2809 case NORMAL:
2810 read_retval = ixj_read(file_p, buf, length, ppos);
2811 ixj_PostRead(j, 0L);
2812 break;
2813 case NOPOST:
2814 read_retval = ixj_read(file_p, buf, length, ppos);
2815 break;
2816 case POSTONLY:
2817 ixj_PostRead(j, 0L);
2818 break;
2819 default:
2820 read_retval = pre_retval;
2821 }
2822 return read_retval;
2823}
2824
2825static ssize_t ixj_write(struct file *file_p, const char __user *buf, size_t count, loff_t * ppos)
2826{
2827 unsigned long i = *ppos;
2828 IXJ *j = file_p->private_data;
2829
2830 DECLARE_WAITQUEUE(wait, current);
2831
2832 if (j->flags.inwrite)
2833 return -EALREADY;
2834
2835 j->flags.inwrite = 1;
2836
2837 add_wait_queue(&j->write_q, &wait);
2838 set_current_state(TASK_INTERRUPTIBLE);
2839 mb();
2840
2841
2842 while (!j->write_buffers_empty) {
2843 ++j->write_wait;
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;
2848 return -EAGAIN;
2849 }
2850 if (!ixj_hookstate(j)) {
2851 set_current_state(TASK_RUNNING);
2852 remove_wait_queue(&j->write_q, &wait);
2853 j->flags.inwrite = 0;
2854 return 0;
2855 }
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;
2861 return -EINTR;
2862 }
2863 }
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));
2869 if (i) {
2870 j->flags.inwrite = 0;
2871 return -EFAULT;
2872 }
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);
2877}
2878
2879static ssize_t ixj_enhanced_write(struct file * file_p, const char __user *buf, size_t count, loff_t * ppos)
2880{
2881 int pre_retval;
2882 ssize_t write_retval = 0;
2883
2884 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2885
2886 pre_retval = ixj_PreWrite(j, 0L);
2887 switch (pre_retval) {
2888 case NORMAL:
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--;
2894 }
2895 break;
2896 case NOPOST:
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--;
2901 }
2902 break;
2903 case POSTONLY:
2904 ixj_PostWrite(j, 0L);
2905 break;
2906 default:
2907 write_retval = pre_retval;
2908 }
2909 return write_retval;
2910}
2911
2912static void ixj_read_frame(IXJ *j)
2913{
2914 int cnt, dly;
2915
2916 if (j->read_buffer) {
2917 for (cnt = 0; cnt < j->rec_frame_size * 2; cnt += 2) {
2918 if (!(cnt % 16) && !IsRxReady(j)) {
2919 dly = 0;
2920 while (!IsRxReady(j)) {
2921 if (dly++ > 5) {
2922 dly = 0;
2923 break;
2924 }
2925 udelay(10);
2926 }
2927 }
2928
2929 if (j->rec_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
2930 inb_p(j->DSPbase + 0x0E);
2931 inb_p(j->DSPbase + 0x0F);
2932 }
2933 *(j->read_buffer + cnt) = inb_p(j->DSPbase + 0x0E);
2934 *(j->read_buffer + cnt + 1) = inb_p(j->DSPbase + 0x0F);
2935 }
2936 ++j->framesread;
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)) {
2941 dly = 0;
2942 while (!IsTxReady(j)) {
2943 if (dly++ > 5) {
2944 dly = 0;
2945 break;
2946 }
2947 udelay(10);
2948 }
2949 }
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);
2952 }
2953 get_ixj(j->intercom)->frameswritten++;
2954 }
2955 } else {
2956 j->read_buffer_ready = 1;
2957 wake_up_interruptible(&j->read_q);
2958
2959 wake_up_interruptible(&j->poll_q);
2960
2961 if(j->ixj_signals[SIG_READ_READY])
2962 ixj_kill_fasync(j, SIG_READ_READY, POLL_OUT);
2963 }
2964 }
2965}
2966
2967static short fsk[][6][20] =
2968{
2969 {
2970 {
2971 0, 17846, 29934, 32364, 24351, 8481, -10126, -25465, -32587, -29196,
2972 -16384, 1715, 19260, 30591, 32051, 23170, 6813, -11743, -26509, -32722
2973 },
2974 {
2975 -28377, -14876, 3425, 20621, 31163, 31650, 21925, 5126, -13328, -27481,
2976 -32767, -27481, -13328, 5126, 21925, 31650, 31163, 20621, 3425, -14876
2977 },
2978 {
2979 -28377, -32722, -26509, -11743, 6813, 23170, 32051, 30591, 19260, 1715,
2980 -16384, -29196, -32587, -25465, -10126, 8481, 24351, 32364, 29934, 17846
2981 },
2982 {
2983 0, -17846, -29934, -32364, -24351, -8481, 10126, 25465, 32587, 29196,
2984 16384, -1715, -19260, -30591, -32051, -23170, -6813, 11743, 26509, 32722
2985 },
2986 {
2987 28377, 14876, -3425, -20621, -31163, -31650, -21925, -5126, 13328, 27481,
2988 32767, 27481, 13328, -5126, -21925, -31650, -31163, -20621, -3425, 14876
2989 },
2990 {
2991 28377, 32722, 26509, 11743, -6813, -23170, -32051, -30591, -19260, -1715,
2992 16384, 29196, 32587, 25465, 10126, -8481, -24351, -32364, -29934, -17846
2993 }
2994 },
2995 {
2996 {
2997 0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126,
2998 0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126
2999 },
3000 {
3001 -28377, -21925, -13328, -3425, 6813, 16384, 24351, 29934, 32587, 32051,
3002 28377, 21925, 13328, 3425, -6813, -16384, -24351, -29934, -32587, -32051
3003 },
3004 {
3005 -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925,
3006 28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925
3007 },
3008 {
3009 0, -10126, -19260, -26509, -31163, -32767, -31163, -26509, -19260, -10126,
3010 0, 10126, 19260, 26509, 31163, 32767, 31163, 26509, 19260, 10126
3011 },
3012 {
3013 28377, 21925, 13328, 3425, -6813, -16383, -24351, -29934, -32587, -32051,
3014 -28377, -21925, -13328, -3425, 6813, 16383, 24351, 29934, 32587, 32051
3015 },
3016 {
3017 28377, 32051, 32587, 29934, 24351, 16384, 6813, -3425, -13328, -21925,
3018 -28377, -32051, -32587, -29934, -24351, -16384, -6813, 3425, 13328, 21925
3019 }
3020 }
3021};
3022
3023
3024static void ixj_write_cid_bit(IXJ *j, int bit)
3025{
3026 while (j->fskcnt < 20) {
3027 if(j->fskdcnt < (j->fsksize - 1))
3028 j->fskdata[j->fskdcnt++] = fsk[bit][j->fskz][j->fskcnt];
3029
3030 j->fskcnt += 3;
3031 }
3032 j->fskcnt %= 20;
3033
3034 if (!bit)
3035 j->fskz++;
3036 if (j->fskz >= 6)
3037 j->fskz = 0;
3038
3039}
3040
3041static void ixj_write_cid_byte(IXJ *j, char byte)
3042{
3043 IXJ_CBYTE cb;
3044
3045 cb.cbyte = byte;
3046 ixj_write_cid_bit(j, 0);
3047 ixj_write_cid_bit(j, cb.cbits.b0 ? 1 : 0);
3048 ixj_write_cid_bit(j, cb.cbits.b1 ? 1 : 0);
3049 ixj_write_cid_bit(j, cb.cbits.b2 ? 1 : 0);
3050 ixj_write_cid_bit(j, cb.cbits.b3 ? 1 : 0);
3051 ixj_write_cid_bit(j, cb.cbits.b4 ? 1 : 0);
3052 ixj_write_cid_bit(j, cb.cbits.b5 ? 1 : 0);
3053 ixj_write_cid_bit(j, cb.cbits.b6 ? 1 : 0);
3054 ixj_write_cid_bit(j, cb.cbits.b7 ? 1 : 0);
3055 ixj_write_cid_bit(j, 1);
3056}
3057
3058static void ixj_write_cid_seize(IXJ *j)
3059{
3060 int cnt;
3061
3062 for (cnt = 0; cnt < 150; cnt++) {
3063 ixj_write_cid_bit(j, 0);
3064 ixj_write_cid_bit(j, 1);
3065 }
3066 for (cnt = 0; cnt < 180; cnt++) {
3067 ixj_write_cid_bit(j, 1);
3068 }
3069}
3070
3071static void ixj_write_cidcw_seize(IXJ *j)
3072{
3073 int cnt;
3074
3075 for (cnt = 0; cnt < 80; cnt++) {
3076 ixj_write_cid_bit(j, 1);
3077 }
3078}
3079
3080static int ixj_write_cid_string(IXJ *j, char *s, int checksum)
3081{
3082 int cnt;
3083
3084 for (cnt = 0; cnt < strlen(s); cnt++) {
3085 ixj_write_cid_byte(j, s[cnt]);
3086 checksum = (checksum + s[cnt]);
3087 }
3088 return checksum;
3089}
3090
3091static void ixj_pad_fsk(IXJ *j, int pad)
3092{
3093 int cnt;
3094
3095 for (cnt = 0; cnt < pad; cnt++) {
3096 if(j->fskdcnt < (j->fsksize - 1))
3097 j->fskdata[j->fskdcnt++] = 0x0000;
3098 }
3099 for (cnt = 0; cnt < 720; cnt++) {
3100 if(j->fskdcnt < (j->fsksize - 1))
3101 j->fskdata[j->fskdcnt++] = 0x0000;
3102 }
3103}
3104
3105static void ixj_pre_cid(IXJ *j)
3106{
3107 j->cid_play_codec = j->play_codec;
3108 j->cid_play_frame_size = j->play_frame_size;
3109 j->cid_play_volume = get_play_volume(j);
3110 j->cid_play_flag = j->flags.playing;
3111
3112 j->cid_rec_codec = j->rec_codec;
3113 j->cid_rec_volume = get_rec_volume(j);
3114 j->cid_rec_flag = j->flags.recording;
3115
3116 j->cid_play_aec_level = j->aec_level;
3117
3118 switch(j->baseframe.low) {
3119 case 0xA0:
3120 j->cid_base_frame_size = 20;
3121 break;
3122 case 0x50:
3123 j->cid_base_frame_size = 10;
3124 break;
3125 case 0xF0:
3126 j->cid_base_frame_size = 30;
3127 break;
3128 }
3129
3130 ixj_play_stop(j);
3131 ixj_cpt_stop(j);
3132
3133 j->flags.cidplay = 1;
3134
3135 set_base_frame(j, 30);
3136 set_play_codec(j, LINEAR16);
3137 set_play_volume(j, 0x1B);
3138 ixj_play_start(j);
3139}
3140
3141static void ixj_post_cid(IXJ *j)
3142{
3143 ixj_play_stop(j);
3144
3145 if(j->cidsize > 5000) {
3146 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
3147 }
3148 j->flags.cidplay = 0;
3149 if(ixjdebug & 0x0200) {
3150 printk("IXJ phone%d Finished Playing CallerID data %ld\n", j->board, jiffies);
3151 }
3152
3153 ixj_fsk_free(j);
3154
3155 j->fskdcnt = 0;
3156 set_base_frame(j, j->cid_base_frame_size);
3157 set_play_codec(j, j->cid_play_codec);
3158 ixj_aec_start(j, j->cid_play_aec_level);
3159 set_play_volume(j, j->cid_play_volume);
3160
3161 set_rec_codec(j, j->cid_rec_codec);
3162 set_rec_volume(j, j->cid_rec_volume);
3163
3164 if(j->cid_rec_flag)
3165 ixj_record_start(j);
3166
3167 if(j->cid_play_flag)
3168 ixj_play_start(j);
3169
3170 if(j->cid_play_flag) {
3171 wake_up_interruptible(&j->write_q);
3172 }
3173}
3174
3175static void ixj_write_cid(IXJ *j)
3176{
3177 char sdmf1[50];
3178 char sdmf2[50];
3179 char sdmf3[80];
3180 char mdmflen, len1, len2, len3;
3181 int pad;
3182
3183 int checksum = 0;
3184
3185 if (j->dsp.low == 0x20 || j->flags.cidplay)
3186 return;
3187
3188 j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3189 j->cidsize = j->cidcnt = 0;
3190
3191 ixj_fsk_alloc(j);
3192
3193 strcpy(sdmf1, j->cid_send.month);
3194 strcat(sdmf1, j->cid_send.day);
3195 strcat(sdmf1, j->cid_send.hour);
3196 strcat(sdmf1, j->cid_send.min);
3197 strcpy(sdmf2, j->cid_send.number);
3198 strcpy(sdmf3, j->cid_send.name);
3199
3200 len1 = strlen(sdmf1);
3201 len2 = strlen(sdmf2);
3202 len3 = strlen(sdmf3);
3203 mdmflen = len1 + len2 + len3 + 6;
3204
3205 while(1){
3206 ixj_write_cid_seize(j);
3207
3208 ixj_write_cid_byte(j, 0x80);
3209 checksum = 0x80;
3210 ixj_write_cid_byte(j, mdmflen);
3211 checksum = checksum + mdmflen;
3212
3213 ixj_write_cid_byte(j, 0x01);
3214 checksum = checksum + 0x01;
3215 ixj_write_cid_byte(j, len1);
3216 checksum = checksum + len1;
3217 checksum = ixj_write_cid_string(j, sdmf1, checksum);
3218 if(ixj_hookstate(j) & 1)
3219 break;
3220
3221 ixj_write_cid_byte(j, 0x02);
3222 checksum = checksum + 0x02;
3223 ixj_write_cid_byte(j, len2);
3224 checksum = checksum + len2;
3225 checksum = ixj_write_cid_string(j, sdmf2, checksum);
3226 if(ixj_hookstate(j) & 1)
3227 break;
3228
3229 ixj_write_cid_byte(j, 0x07);
3230 checksum = checksum + 0x07;
3231 ixj_write_cid_byte(j, len3);
3232 checksum = checksum + len3;
3233 checksum = ixj_write_cid_string(j, sdmf3, checksum);
3234 if(ixj_hookstate(j) & 1)
3235 break;
3236
3237 checksum %= 256;
3238 checksum ^= 0xFF;
3239 checksum += 1;
3240
3241 ixj_write_cid_byte(j, (char) checksum);
3242
3243 pad = j->fskdcnt % 240;
3244 if (pad) {
3245 pad = 240 - pad;
3246 }
3247 ixj_pad_fsk(j, pad);
3248 break;
3249 }
3250
3251 ixj_write_frame(j);
3252}
3253
3254static void ixj_write_cidcw(IXJ *j)
3255{
3256 IXJ_TONE ti;
3257
3258 char sdmf1[50];
3259 char sdmf2[50];
3260 char sdmf3[80];
3261 char mdmflen, len1, len2, len3;
3262 int pad;
3263
3264 int checksum = 0;
3265
3266 if (j->dsp.low == 0x20 || j->flags.cidplay)
3267 return;
3268
3269 j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3270 j->cidsize = j->cidcnt = 0;
3271
3272 ixj_fsk_alloc(j);
3273
3274 j->flags.cidcw_ack = 0;
3275
3276 ti.tone_index = 23;
3277 ti.gain0 = 1;
3278 ti.freq0 = hz440;
3279 ti.gain1 = 0;
3280 ti.freq1 = 0;
3281 ixj_init_tone(j, &ti);
3282
3283 ixj_set_tone_on(1500, j);
3284 ixj_set_tone_off(32, j);
3285 if(ixjdebug & 0x0200) {
3286 printk("IXJ cidcw phone%d first tone start at %ld\n", j->board, jiffies);
3287 }
3288 ixj_play_tone(j, 23);
3289
3290 clear_bit(j->board, &j->busyflags);
3291 while(j->tone_state)
3292 schedule_timeout_interruptible(1);
3293 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3294 schedule_timeout_interruptible(1);
3295 if(ixjdebug & 0x0200) {
3296 printk("IXJ cidcw phone%d first tone end at %ld\n", j->board, jiffies);
3297 }
3298
3299 ti.tone_index = 24;
3300 ti.gain0 = 1;
3301 ti.freq0 = hz2130;
3302 ti.gain1 = 0;
3303 ti.freq1 = hz2750;
3304 ixj_init_tone(j, &ti);
3305
3306 ixj_set_tone_off(10, j);
3307 ixj_set_tone_on(600, j);
3308 if(ixjdebug & 0x0200) {
3309 printk("IXJ cidcw phone%d second tone start at %ld\n", j->board, jiffies);
3310 }
3311 ixj_play_tone(j, 24);
3312
3313 clear_bit(j->board, &j->busyflags);
3314 while(j->tone_state)
3315 schedule_timeout_interruptible(1);
3316 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3317 schedule_timeout_interruptible(1);
3318 if(ixjdebug & 0x0200) {
3319 printk("IXJ cidcw phone%d sent second tone at %ld\n", j->board, jiffies);
3320 }
3321
3322 j->cidcw_wait = jiffies + ((50 * hertz) / 100);
3323
3324 clear_bit(j->board, &j->busyflags);
3325 while(!j->flags.cidcw_ack && time_before(jiffies, j->cidcw_wait))
3326 schedule_timeout_interruptible(1);
3327 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3328 schedule_timeout_interruptible(1);
3329 j->cidcw_wait = 0;
3330 if(!j->flags.cidcw_ack) {
3331 if(ixjdebug & 0x0200) {
3332 printk("IXJ cidcw phone%d did not receive ACK from display %ld\n", j->board, jiffies);
3333 }
3334 ixj_post_cid(j);
3335 if(j->cid_play_flag) {
3336 wake_up_interruptible(&j->write_q);
3337 }
3338 return;
3339 } else {
3340 ixj_pre_cid(j);
3341 }
3342 j->flags.cidcw_ack = 0;
3343 strcpy(sdmf1, j->cid_send.month);
3344 strcat(sdmf1, j->cid_send.day);
3345 strcat(sdmf1, j->cid_send.hour);
3346 strcat(sdmf1, j->cid_send.min);
3347 strcpy(sdmf2, j->cid_send.number);
3348 strcpy(sdmf3, j->cid_send.name);
3349
3350 len1 = strlen(sdmf1);
3351 len2 = strlen(sdmf2);
3352 len3 = strlen(sdmf3);
3353 mdmflen = len1 + len2 + len3 + 6;
3354
3355 ixj_write_cidcw_seize(j);
3356
3357 ixj_write_cid_byte(j, 0x80);
3358 checksum = 0x80;
3359 ixj_write_cid_byte(j, mdmflen);
3360 checksum = checksum + mdmflen;
3361
3362 ixj_write_cid_byte(j, 0x01);
3363 checksum = checksum + 0x01;
3364 ixj_write_cid_byte(j, len1);
3365 checksum = checksum + len1;
3366 checksum = ixj_write_cid_string(j, sdmf1, checksum);
3367
3368 ixj_write_cid_byte(j, 0x02);
3369 checksum = checksum + 0x02;
3370 ixj_write_cid_byte(j, len2);
3371 checksum = checksum + len2;
3372 checksum = ixj_write_cid_string(j, sdmf2, checksum);
3373
3374 ixj_write_cid_byte(j, 0x07);
3375 checksum = checksum + 0x07;
3376 ixj_write_cid_byte(j, len3);
3377 checksum = checksum + len3;
3378 checksum = ixj_write_cid_string(j, sdmf3, checksum);
3379
3380 checksum %= 256;
3381 checksum ^= 0xFF;
3382 checksum += 1;
3383
3384 ixj_write_cid_byte(j, (char) checksum);
3385
3386 pad = j->fskdcnt % 240;
3387 if (pad) {
3388 pad = 240 - pad;
3389 }
3390 ixj_pad_fsk(j, pad);
3391 if(ixjdebug & 0x0200) {
3392 printk("IXJ cidcw phone%d sent FSK data at %ld\n", j->board, jiffies);
3393 }
3394}
3395
3396static void ixj_write_vmwi(IXJ *j, int msg)
3397{
3398 char mdmflen;
3399 int pad;
3400
3401 int checksum = 0;
3402
3403 if (j->dsp.low == 0x20 || j->flags.cidplay)
3404 return;
3405
3406 j->fskz = j->fskphase = j->fskcnt = j->fskdcnt = 0;
3407 j->cidsize = j->cidcnt = 0;
3408
3409 ixj_fsk_alloc(j);
3410
3411 mdmflen = 3;
3412
3413 if (j->port == PORT_POTS)
3414 SLIC_SetState(PLD_SLIC_STATE_OHT, j);
3415
3416 ixj_write_cid_seize(j);
3417
3418 ixj_write_cid_byte(j, 0x82);
3419 checksum = 0x82;
3420 ixj_write_cid_byte(j, mdmflen);
3421 checksum = checksum + mdmflen;
3422
3423 ixj_write_cid_byte(j, 0x0B);
3424 checksum = checksum + 0x0B;
3425 ixj_write_cid_byte(j, 1);
3426 checksum = checksum + 1;
3427
3428 if(msg) {
3429 ixj_write_cid_byte(j, 0xFF);
3430 checksum = checksum + 0xFF;
3431 }
3432 else {
3433 ixj_write_cid_byte(j, 0x00);
3434 checksum = checksum + 0x00;
3435 }
3436
3437 checksum %= 256;
3438 checksum ^= 0xFF;
3439 checksum += 1;
3440
3441 ixj_write_cid_byte(j, (char) checksum);
3442
3443 pad = j->fskdcnt % 240;
3444 if (pad) {
3445 pad = 240 - pad;
3446 }
3447 ixj_pad_fsk(j, pad);
3448}
3449
3450static void ixj_write_frame(IXJ *j)
3451{
3452 int cnt, frame_count, dly;
3453 IXJ_WORD dat;
3454
3455 frame_count = 0;
3456 if(j->flags.cidplay) {
3457 for(cnt = 0; cnt < 480; cnt++) {
3458 if (!(cnt % 16) && !IsTxReady(j)) {
3459 dly = 0;
3460 while (!IsTxReady(j)) {
3461 if (dly++ > 5) {
3462 dly = 0;
3463 break;
3464 }
3465 udelay(10);
3466 }
3467 }
3468 dat.word = j->fskdata[j->cidcnt++];
3469 outb_p(dat.bytes.low, j->DSPbase + 0x0C);
3470 outb_p(dat.bytes.high, j->DSPbase + 0x0D);
3471 cnt++;
3472 }
3473 if(j->cidcnt >= j->fskdcnt) {
3474 ixj_post_cid(j);
3475 }
3476
3477
3478
3479 if (j->write_buffer_rp > j->write_buffer_wp) {
3480 j->write_buffer_rp += j->cid_play_frame_size * 2;
3481 if (j->write_buffer_rp >= j->write_buffer_end) {
3482 j->write_buffer_rp = j->write_buffer;
3483 }
3484 j->write_buffers_empty++;
3485 wake_up_interruptible(&j->write_q);
3486
3487 wake_up_interruptible(&j->poll_q);
3488 }
3489 } else if (j->write_buffer && j->write_buffers_empty < 1) {
3490 if (j->write_buffer_wp > j->write_buffer_rp) {
3491 frame_count =
3492 (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2);
3493 }
3494 if (j->write_buffer_rp > j->write_buffer_wp) {
3495 frame_count =
3496 (j->write_buffer_wp - j->write_buffer) / (j->play_frame_size * 2) +
3497 (j->write_buffer_end - j->write_buffer_rp) / (j->play_frame_size * 2);
3498 }
3499 if (frame_count >= 1) {
3500 if (j->ver.low == 0x12 && j->play_mode && j->flags.play_first_frame) {
3501 BYTES blankword;
3502
3503 switch (j->play_mode) {
3504 case PLAYBACK_MODE_ULAW:
3505 case PLAYBACK_MODE_ALAW:
3506 blankword.low = blankword.high = 0xFF;
3507 break;
3508 case PLAYBACK_MODE_8LINEAR:
3509 case PLAYBACK_MODE_16LINEAR:
3510 default:
3511 blankword.low = blankword.high = 0x00;
3512 break;
3513 case PLAYBACK_MODE_8LINEAR_WSS:
3514 blankword.low = blankword.high = 0x80;
3515 break;
3516 }
3517 for (cnt = 0; cnt < 16; cnt++) {
3518 if (!(cnt % 16) && !IsTxReady(j)) {
3519 dly = 0;
3520 while (!IsTxReady(j)) {
3521 if (dly++ > 5) {
3522 dly = 0;
3523 break;
3524 }
3525 udelay(10);
3526 }
3527 }
3528 outb_p((blankword.low), j->DSPbase + 0x0C);
3529 outb_p((blankword.high), j->DSPbase + 0x0D);
3530 }
3531 j->flags.play_first_frame = 0;
3532 } else if (j->play_codec == G723_63 && j->flags.play_first_frame) {
3533 for (cnt = 0; cnt < 24; cnt++) {
3534 BYTES blankword;
3535
3536 if(cnt == 12) {
3537 blankword.low = 0x02;
3538 blankword.high = 0x00;
3539 }
3540 else {
3541 blankword.low = blankword.high = 0x00;
3542 }
3543 if (!(cnt % 16) && !IsTxReady(j)) {
3544 dly = 0;
3545 while (!IsTxReady(j)) {
3546 if (dly++ > 5) {
3547 dly = 0;
3548 break;
3549 }
3550 udelay(10);
3551 }
3552 }
3553 outb_p((blankword.low), j->DSPbase + 0x0C);
3554 outb_p((blankword.high), j->DSPbase + 0x0D);
3555 }
3556 j->flags.play_first_frame = 0;
3557 }
3558 for (cnt = 0; cnt < j->play_frame_size * 2; cnt += 2) {
3559 if (!(cnt % 16) && !IsTxReady(j)) {
3560 dly = 0;
3561 while (!IsTxReady(j)) {
3562 if (dly++ > 5) {
3563 dly = 0;
3564 break;
3565 }
3566 udelay(10);
3567 }
3568 }
3569
3570 if (j->play_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
3571 if (j->write_buffer_rp[cnt] == 0 &&
3572 j->write_buffer_rp[cnt + 1] == 0 &&
3573 j->write_buffer_rp[cnt + 2] == 0 &&
3574 j->write_buffer_rp[cnt + 3] == 0 &&
3575 j->write_buffer_rp[cnt + 4] == 0 &&
3576 j->write_buffer_rp[cnt + 5] == 0 &&
3577 j->write_buffer_rp[cnt + 6] == 0 &&
3578 j->write_buffer_rp[cnt + 7] == 0 &&
3579 j->write_buffer_rp[cnt + 8] == 0 &&
3580 j->write_buffer_rp[cnt + 9] == 0) {
3581
3582 outb_p(0x00, j->DSPbase + 0x0C);
3583 outb_p(0x00, j->DSPbase + 0x0D);
3584 } else {
3585
3586 outb_p(0x01, j->DSPbase + 0x0C);
3587 outb_p(0x00, j->DSPbase + 0x0D);
3588 }
3589 }
3590 outb_p(*(j->write_buffer_rp + cnt), j->DSPbase + 0x0C);
3591 outb_p(*(j->write_buffer_rp + cnt + 1), j->DSPbase + 0x0D);
3592 *(j->write_buffer_rp + cnt) = 0;
3593 *(j->write_buffer_rp + cnt + 1) = 0;
3594 }
3595 j->write_buffer_rp += j->play_frame_size * 2;
3596 if (j->write_buffer_rp >= j->write_buffer_end) {
3597 j->write_buffer_rp = j->write_buffer;
3598 }
3599 j->write_buffers_empty++;
3600 wake_up_interruptible(&j->write_q);
3601
3602 wake_up_interruptible(&j->poll_q);
3603
3604 ++j->frameswritten;
3605 }
3606 } else {
3607 j->drybuffer++;
3608 }
3609 if(j->ixj_signals[SIG_WRITE_READY]) {
3610 ixj_kill_fasync(j, SIG_WRITE_READY, POLL_OUT);
3611 }
3612}
3613
3614static int idle(IXJ *j)
3615{
3616 if (ixj_WriteDSPCommand(0x0000, j))
3617
3618 return 0;
3619
3620 if (j->ssr.high || j->ssr.low) {
3621 return 0;
3622 } else {
3623 j->play_mode = -1;
3624 j->flags.playing = 0;
3625 j->rec_mode = -1;
3626 j->flags.recording = 0;
3627 return 1;
3628 }
3629}
3630
3631static int set_base_frame(IXJ *j, int size)
3632{
3633 unsigned short cmd;
3634 int cnt;
3635
3636 idle(j);
3637 j->cid_play_aec_level = j->aec_level;
3638 aec_stop(j);
3639 for (cnt = 0; cnt < 10; cnt++) {
3640 if (idle(j))
3641 break;
3642 }
3643 if (j->ssr.high || j->ssr.low)
3644 return -1;
3645 if (j->dsp.low != 0x20) {
3646 switch (size) {
3647 case 30:
3648 cmd = 0x07F0;
3649
3650 break;
3651 case 20:
3652 cmd = 0x07A0;
3653
3654 break;
3655 case 10:
3656 cmd = 0x0750;
3657
3658 break;
3659 default:
3660 return -1;
3661 }
3662 } else {
3663 if (size == 30)
3664 return size;
3665 else
3666 return -1;
3667 }
3668 if (ixj_WriteDSPCommand(cmd, j)) {
3669 j->baseframe.high = j->baseframe.low = 0xFF;
3670 return -1;
3671 } else {
3672 j->baseframe.high = j->ssr.high;
3673 j->baseframe.low = j->ssr.low;
3674
3675 if(j->baseframe.high == 0x00 && j->baseframe.low == 0x00) {
3676 return -1;
3677 }
3678 }
3679 ixj_aec_start(j, j->cid_play_aec_level);
3680 return size;
3681}
3682
3683static int set_rec_codec(IXJ *j, int rate)
3684{
3685 int retval = 0;
3686
3687 j->rec_codec = rate;
3688
3689 switch (rate) {
3690 case G723_63:
3691 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3692 j->rec_frame_size = 12;
3693 j->rec_mode = 0;
3694 } else {
3695 retval = 1;
3696 }
3697 break;
3698 case G723_53:
3699 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3700 j->rec_frame_size = 10;
3701 j->rec_mode = 0;
3702 } else {
3703 retval = 1;
3704 }
3705 break;
3706 case TS85:
3707 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
3708 j->rec_frame_size = 16;
3709 j->rec_mode = 0;
3710 } else {
3711 retval = 1;
3712 }
3713 break;
3714 case TS48:
3715 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3716 j->rec_frame_size = 9;
3717 j->rec_mode = 0;
3718 } else {
3719 retval = 1;
3720 }
3721 break;
3722 case TS41:
3723 if (j->ver.low != 0x12 || ixj_convert_loaded) {
3724 j->rec_frame_size = 8;
3725 j->rec_mode = 0;
3726 } else {
3727 retval = 1;
3728 }
3729 break;
3730 case G728:
3731 if (j->dsp.low != 0x20) {
3732 j->rec_frame_size = 48;
3733 j->rec_mode = 0;
3734 } else {
3735 retval = 1;
3736 }
3737 break;
3738 case G729:
3739 if (j->dsp.low != 0x20) {
3740 if (!j->flags.g729_loaded) {
3741 retval = 1;
3742 break;
3743 }
3744 switch (j->baseframe.low) {
3745 case 0xA0:
3746 j->rec_frame_size = 10;
3747 break;
3748 case 0x50:
3749 j->rec_frame_size = 5;
3750 break;
3751 default:
3752 j->rec_frame_size = 15;
3753 break;
3754 }
3755 j->rec_mode = 0;
3756 } else {
3757 retval = 1;
3758 }
3759 break;
3760 case G729B:
3761 if (j->dsp.low != 0x20) {
3762 if (!j->flags.g729_loaded) {
3763 retval = 1;
3764 break;
3765 }
3766 switch (j->baseframe.low) {
3767 case 0xA0:
3768 j->rec_frame_size = 12;
3769 break;
3770 case 0x50:
3771 j->rec_frame_size = 6;
3772 break;
3773 default:
3774 j->rec_frame_size = 18;
3775 break;
3776 }
3777 j->rec_mode = 0;
3778 } else {
3779 retval = 1;
3780 }
3781 break;
3782 case ULAW:
3783 switch (j->baseframe.low) {
3784 case 0xA0:
3785 j->rec_frame_size = 80;
3786 break;
3787 case 0x50:
3788 j->rec_frame_size = 40;
3789 break;
3790 default:
3791 j->rec_frame_size = 120;
3792 break;
3793 }
3794 j->rec_mode = 4;
3795 break;
3796 case ALAW:
3797 switch (j->baseframe.low) {
3798 case 0xA0:
3799 j->rec_frame_size = 80;
3800 break;
3801 case 0x50:
3802 j->rec_frame_size = 40;
3803 break;
3804 default:
3805 j->rec_frame_size = 120;
3806 break;
3807 }
3808 j->rec_mode = 4;
3809 break;
3810 case LINEAR16:
3811 switch (j->baseframe.low) {
3812 case 0xA0:
3813 j->rec_frame_size = 160;
3814 break;
3815 case 0x50:
3816 j->rec_frame_size = 80;
3817 break;
3818 default:
3819 j->rec_frame_size = 240;
3820 break;
3821 }
3822 j->rec_mode = 5;
3823 break;
3824 case LINEAR8:
3825 switch (j->baseframe.low) {
3826 case 0xA0:
3827 j->rec_frame_size = 80;
3828 break;
3829 case 0x50:
3830 j->rec_frame_size = 40;
3831 break;
3832 default:
3833 j->rec_frame_size = 120;
3834 break;
3835 }
3836 j->rec_mode = 6;
3837 break;
3838 case WSS:
3839 switch (j->baseframe.low) {
3840 case 0xA0:
3841 j->rec_frame_size = 80;
3842 break;
3843 case 0x50:
3844 j->rec_frame_size = 40;
3845 break;
3846 default:
3847 j->rec_frame_size = 120;
3848 break;
3849 }
3850 j->rec_mode = 7;
3851 break;
3852 default:
3853 kfree(j->read_buffer);
3854 j->rec_frame_size = 0;
3855 j->rec_mode = -1;
3856 j->read_buffer = NULL;
3857 j->read_buffer_size = 0;
3858 retval = 1;
3859 break;
3860 }
3861 return retval;
3862}
3863
3864static int ixj_record_start(IXJ *j)
3865{
3866 unsigned short cmd = 0x0000;
3867
3868 if (j->read_buffer) {
3869 ixj_record_stop(j);
3870 }
3871 j->flags.recording = 1;
3872 ixj_WriteDSPCommand(0x0FE0, j);
3873
3874 if(ixjdebug & 0x0002)
3875 printk("IXJ %d Starting Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3876
3877 if (!j->rec_mode) {
3878 switch (j->rec_codec) {
3879 case G723_63:
3880 cmd = 0x5131;
3881 break;
3882 case G723_53:
3883 cmd = 0x5132;
3884 break;
3885 case TS85:
3886 cmd = 0x5130;
3887
3888 break;
3889 case TS48:
3890 cmd = 0x5133;
3891
3892 break;
3893 case TS41:
3894 cmd = 0x5134;
3895
3896 break;
3897 case G728:
3898 cmd = 0x5135;
3899 break;
3900 case G729:
3901 case G729B:
3902 cmd = 0x5136;
3903 break;
3904 default:
3905 return 1;
3906 }
3907 if (ixj_WriteDSPCommand(cmd, j))
3908 return -1;
3909 }
3910 if (!j->read_buffer) {
3911 if (!j->read_buffer)
3912 j->read_buffer = kmalloc(j->rec_frame_size * 2, GFP_ATOMIC);
3913 if (!j->read_buffer) {
3914 printk("Read buffer allocation for ixj board %d failed!\n", j->board);
3915 return -ENOMEM;
3916 }
3917 }
3918 j->read_buffer_size = j->rec_frame_size * 2;
3919
3920 if (ixj_WriteDSPCommand(0x5102, j))
3921
3922 return -1;
3923
3924 switch (j->rec_mode) {
3925 case 0:
3926 cmd = 0x1C03;
3927
3928 break;
3929 case 4:
3930 if (j->ver.low == 0x12) {
3931 cmd = 0x1E03;
3932
3933 } else {
3934 cmd = 0x1E01;
3935
3936 }
3937 break;
3938 case 5:
3939 if (j->ver.low == 0x12) {
3940 cmd = 0x1E83;
3941
3942 } else {
3943 cmd = 0x1E81;
3944
3945 }
3946 break;
3947 case 6:
3948 if (j->ver.low == 0x12) {
3949 cmd = 0x1F03;
3950
3951 } else {
3952 cmd = 0x1F01;
3953
3954 }
3955 break;
3956 case 7:
3957 if (j->ver.low == 0x12) {
3958 cmd = 0x1F83;
3959 } else {
3960 cmd = 0x1F81;
3961 }
3962 break;
3963 }
3964 if (ixj_WriteDSPCommand(cmd, j))
3965 return -1;
3966
3967 if (j->flags.playing) {
3968 ixj_aec_start(j, j->aec_level);
3969 }
3970 return 0;
3971}
3972
3973static void ixj_record_stop(IXJ *j)
3974{
3975 if (ixjdebug & 0x0002)
3976 printk("IXJ %d Stopping Record Codec %d at %ld\n", j->board, j->rec_codec, jiffies);
3977
3978 kfree(j->read_buffer);
3979 j->read_buffer = NULL;
3980 j->read_buffer_size = 0;
3981 if (j->rec_mode > -1) {
3982 ixj_WriteDSPCommand(0x5120, j);
3983 j->rec_mode = -1;
3984 }
3985 j->flags.recording = 0;
3986}
3987static void ixj_vad(IXJ *j, int arg)
3988{
3989 if (arg)
3990 ixj_WriteDSPCommand(0x513F, j);
3991 else
3992 ixj_WriteDSPCommand(0x513E, j);
3993}
3994
3995static void set_rec_depth(IXJ *j, int depth)
3996{
3997 if (depth > 60)
3998 depth = 60;
3999 if (depth < 0)
4000 depth = 0;
4001 ixj_WriteDSPCommand(0x5180 + depth, j);
4002}
4003
4004static void set_dtmf_prescale(IXJ *j, int volume)
4005{
4006 ixj_WriteDSPCommand(0xCF07, j);
4007 ixj_WriteDSPCommand(volume, j);
4008}
4009
4010static int get_dtmf_prescale(IXJ *j)
4011{
4012 ixj_WriteDSPCommand(0xCF05, j);
4013 return j->ssr.high << 8 | j->ssr.low;
4014}
4015
4016static void set_rec_volume(IXJ *j, int volume)
4017{
4018 if(j->aec_level == AEC_AGC) {
4019 if (ixjdebug & 0x0002)
4020 printk(KERN_INFO "IXJ: /dev/phone%d Setting AGC Threshold to 0x%4.4x\n", j->board, volume);
4021 ixj_WriteDSPCommand(0xCF96, j);
4022 ixj_WriteDSPCommand(volume, j);
4023 } else {
4024 if (ixjdebug & 0x0002)
4025 printk(KERN_INFO "IXJ: /dev/phone %d Setting Record Volume to 0x%4.4x\n", j->board, volume);
4026 ixj_WriteDSPCommand(0xCF03, j);
4027 ixj_WriteDSPCommand(volume, j);
4028 }
4029}
4030
4031static int set_rec_volume_linear(IXJ *j, int volume)
4032{
4033 int newvolume, dsprecmax;
4034
4035 if (ixjdebug & 0x0002)
4036 printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Record Volume to 0x%4.4x\n", j->board, volume);
4037 if(volume > 100 || volume < 0) {
4038 return -1;
4039 }
4040
4041
4042 switch (j->cardtype) {
4043 case QTI_PHONEJACK:
4044 dsprecmax = 0x440;
4045 break;
4046 case QTI_LINEJACK:
4047 dsprecmax = 0x180;
4048 ixj_mixer(0x0203, j);
4049 ixj_mixer(0x0303, j);
4050 ixj_mixer(0x0C00, j);
4051 break;
4052 case QTI_PHONEJACK_LITE:
4053 dsprecmax = 0x4C0;
4054 break;
4055 case QTI_PHONEJACK_PCI:
4056 dsprecmax = 0x100;
4057 break;
4058 case QTI_PHONECARD:
4059 dsprecmax = 0x400;
4060 break;
4061 default:
4062 return -1;
4063 }
4064 newvolume = (dsprecmax * volume) / 100;
4065 set_rec_volume(j, newvolume);
4066 return 0;
4067}
4068
4069static int get_rec_volume(IXJ *j)
4070{
4071 if(j->aec_level == AEC_AGC) {
4072 if (ixjdebug & 0x0002)
4073 printk(KERN_INFO "Getting AGC Threshold\n");
4074 ixj_WriteDSPCommand(0xCF86, j);
4075 if (ixjdebug & 0x0002)
4076 printk(KERN_INFO "AGC Threshold is 0x%2.2x%2.2x\n", j->ssr.high, j->ssr.low);
4077 return j->ssr.high << 8 | j->ssr.low;
4078 } else {
4079 if (ixjdebug & 0x0002)
4080 printk(KERN_INFO "Getting Record Volume\n");
4081 ixj_WriteDSPCommand(0xCF01, j);
4082 return j->ssr.high << 8 | j->ssr.low;
4083 }
4084}
4085
4086static int get_rec_volume_linear(IXJ *j)
4087{
4088 int volume, newvolume, dsprecmax;
4089
4090 switch (j->cardtype) {
4091 case QTI_PHONEJACK:
4092 dsprecmax = 0x440;
4093 break;
4094 case QTI_LINEJACK:
4095 dsprecmax = 0x180;
4096 break;
4097 case QTI_PHONEJACK_LITE:
4098 dsprecmax = 0x4C0;
4099 break;
4100 case QTI_PHONEJACK_PCI:
4101 dsprecmax = 0x100;
4102 break;
4103 case QTI_PHONECARD:
4104 dsprecmax = 0x400;
4105 break;
4106 default:
4107 return -1;
4108 }
4109 volume = get_rec_volume(j);
4110 newvolume = (volume * 100) / dsprecmax;
4111 if(newvolume > 100)
4112 newvolume = 100;
4113 return newvolume;
4114}
4115
4116static int get_rec_level(IXJ *j)
4117{
4118 int retval;
4119
4120 ixj_WriteDSPCommand(0xCF88, j);
4121
4122 retval = j->ssr.high << 8 | j->ssr.low;
4123 retval = (retval * 256) / 240;
4124 return retval;
4125}
4126
4127static void ixj_aec_start(IXJ *j, int level)
4128{
4129 j->aec_level = level;
4130 if (ixjdebug & 0x0002)
4131 printk(KERN_INFO "AGC set = 0x%2.2x\n", j->aec_level);
4132 if (!level) {
4133 aec_stop(j);
4134 } else {
4135 if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4136 ixj_WriteDSPCommand(0xE022, j);
4137
4138 ixj_WriteDSPCommand(0x0300, j);
4139 }
4140 ixj_WriteDSPCommand(0xB001, j);
4141
4142 ixj_WriteDSPCommand(0xE013, j);
4143
4144 switch (level) {
4145 case AEC_LOW:
4146 ixj_WriteDSPCommand(0x0000, j);
4147
4148 ixj_WriteDSPCommand(0xE011, j);
4149 ixj_WriteDSPCommand(0xFFFF, j);
4150
4151 ixj_WriteDSPCommand(0xCF97, j);
4152 ixj_WriteDSPCommand(0x0000, j);
4153
4154 break;
4155
4156 case AEC_MED:
4157 ixj_WriteDSPCommand(0x0600, j);
4158
4159 ixj_WriteDSPCommand(0xE011, j);
4160 ixj_WriteDSPCommand(0x0080, j);
4161
4162 ixj_WriteDSPCommand(0xCF97, j);
4163 ixj_WriteDSPCommand(0x0000, j);
4164
4165 break;
4166
4167 case AEC_HIGH:
4168 ixj_WriteDSPCommand(0x0C00, j);
4169
4170 ixj_WriteDSPCommand(0xE011, j);
4171 ixj_WriteDSPCommand(0x0080, j);
4172
4173 ixj_WriteDSPCommand(0xCF97, j);
4174 ixj_WriteDSPCommand(0x0000, j);
4175
4176 break;
4177
4178 case AEC_AGC:
4179
4180 ixj_WriteDSPCommand(0x0002, j);
4181
4182 ixj_WriteDSPCommand(0xE011, j);
4183 ixj_WriteDSPCommand(0x0100, j);
4184
4185 ixj_WriteDSPCommand(0xE012, j);
4186
4187 if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4188 ixj_WriteDSPCommand(0x0224, j);
4189 else
4190 ixj_WriteDSPCommand(0x1224, j);
4191
4192 ixj_WriteDSPCommand(0xE014, j);
4193 ixj_WriteDSPCommand(0x0003, j);
4194
4195 ixj_WriteDSPCommand(0xE338, j);
4196
4197
4198 ixj_WriteDSPCommand(0xCF90, j);
4199 ixj_WriteDSPCommand(0x0020, j);
4200
4201 ixj_WriteDSPCommand(0xCF91, j);
4202 ixj_WriteDSPCommand(0x1000, j);
4203
4204 ixj_WriteDSPCommand(0xCF92, j);
4205 ixj_WriteDSPCommand(0x0800, j);
4206
4207 ixj_WriteDSPCommand(0xCF93, j);
4208 ixj_WriteDSPCommand(0x1F40, j);
4209
4210 ixj_WriteDSPCommand(0xCF94, j);
4211 ixj_WriteDSPCommand(0x0005, j);
4212
4213 ixj_WriteDSPCommand(0xCF95, j);
4214 ixj_WriteDSPCommand(0x000D, j);
4215
4216 ixj_WriteDSPCommand(0xCF96, j);
4217 ixj_WriteDSPCommand(0x1200, j);
4218
4219 ixj_WriteDSPCommand(0xCF97, j);
4220 ixj_WriteDSPCommand(0x0001, j);
4221
4222 break;
4223
4224 case AEC_AUTO:
4225 ixj_WriteDSPCommand(0x0002, j);
4226
4227 ixj_WriteDSPCommand(0xE011, j);
4228 ixj_WriteDSPCommand(0x0100, j);
4229
4230 ixj_WriteDSPCommand(0xE012, j);
4231
4232 if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
4233 ixj_WriteDSPCommand(0x0224, j);
4234 else
4235 ixj_WriteDSPCommand(0x1224, j);
4236
4237 ixj_WriteDSPCommand(0xE014, j);
4238 ixj_WriteDSPCommand(0x0003, j);
4239
4240 ixj_WriteDSPCommand(0xE338, j);
4241
4242 break;
4243 }
4244 }
4245}
4246
4247static void aec_stop(IXJ *j)
4248{
4249 j->aec_level = AEC_OFF;
4250 if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
4251 ixj_WriteDSPCommand(0xE022, j);
4252
4253 ixj_WriteDSPCommand(0x0700, j);
4254 }
4255 if (j->play_mode != -1 && j->rec_mode != -1)
4256 {
4257 ixj_WriteDSPCommand(0xB002, j);
4258 }
4259}
4260
4261static int set_play_codec(IXJ *j, int rate)
4262{
4263 int retval = 0;
4264
4265 j->play_codec = rate;
4266
4267 switch (rate) {
4268 case G723_63:
4269 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4270 j->play_frame_size = 12;
4271 j->play_mode = 0;
4272 } else {
4273 retval = 1;
4274 }
4275 break;
4276 case G723_53:
4277 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4278 j->play_frame_size = 10;
4279 j->play_mode = 0;
4280 } else {
4281 retval = 1;
4282 }
4283 break;
4284 case TS85:
4285 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
4286 j->play_frame_size = 16;
4287 j->play_mode = 0;
4288 } else {
4289 retval = 1;
4290 }
4291 break;
4292 case TS48:
4293 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4294 j->play_frame_size = 9;
4295 j->play_mode = 0;
4296 } else {
4297 retval = 1;
4298 }
4299 break;
4300 case TS41:
4301 if (j->ver.low != 0x12 || ixj_convert_loaded) {
4302 j->play_frame_size = 8;
4303 j->play_mode = 0;
4304 } else {
4305 retval = 1;
4306 }
4307 break;
4308 case G728:
4309 if (j->dsp.low != 0x20) {
4310 j->play_frame_size = 48;
4311 j->play_mode = 0;
4312 } else {
4313 retval = 1;
4314 }
4315 break;
4316 case G729:
4317 if (j->dsp.low != 0x20) {
4318 if (!j->flags.g729_loaded) {
4319 retval = 1;
4320 break;
4321 }
4322 switch (j->baseframe.low) {
4323 case 0xA0:
4324 j->play_frame_size = 10;
4325 break;
4326 case 0x50:
4327 j->play_frame_size = 5;
4328 break;
4329 default:
4330 j->play_frame_size = 15;
4331 break;
4332 }
4333 j->play_mode = 0;
4334 } else {
4335 retval = 1;
4336 }
4337 break;
4338 case G729B:
4339 if (j->dsp.low != 0x20) {
4340 if (!j->flags.g729_loaded) {
4341 retval = 1;
4342 break;
4343 }
4344 switch (j->baseframe.low) {
4345 case 0xA0:
4346 j->play_frame_size = 12;
4347 break;
4348 case 0x50:
4349 j->play_frame_size = 6;
4350 break;
4351 default:
4352 j->play_frame_size = 18;
4353 break;
4354 }
4355 j->play_mode = 0;
4356 } else {
4357 retval = 1;
4358 }
4359 break;
4360 case ULAW:
4361 switch (j->baseframe.low) {
4362 case 0xA0:
4363 j->play_frame_size = 80;
4364 break;
4365 case 0x50:
4366 j->play_frame_size = 40;
4367 break;
4368 default:
4369 j->play_frame_size = 120;
4370 break;
4371 }
4372 j->play_mode = 2;
4373 break;
4374 case ALAW:
4375 switch (j->baseframe.low) {
4376 case 0xA0:
4377 j->play_frame_size = 80;
4378 break;
4379 case 0x50:
4380 j->play_frame_size = 40;
4381 break;
4382 default:
4383 j->play_frame_size = 120;
4384 break;
4385 }
4386 j->play_mode = 2;
4387 break;
4388 case LINEAR16:
4389 switch (j->baseframe.low) {
4390 case 0xA0:
4391 j->play_frame_size = 160;
4392 break;
4393 case 0x50:
4394 j->play_frame_size = 80;
4395 break;
4396 default:
4397 j->play_frame_size = 240;
4398 break;
4399 }
4400 j->play_mode = 6;
4401 break;
4402 case LINEAR8:
4403 switch (j->baseframe.low) {
4404 case 0xA0:
4405 j->play_frame_size = 80;
4406 break;
4407 case 0x50:
4408 j->play_frame_size = 40;
4409 break;
4410 default:
4411 j->play_frame_size = 120;
4412 break;
4413 }
4414 j->play_mode = 4;
4415 break;
4416 case WSS:
4417 switch (j->baseframe.low) {
4418 case 0xA0:
4419 j->play_frame_size = 80;
4420 break;
4421 case 0x50:
4422 j->play_frame_size = 40;
4423 break;
4424 default:
4425 j->play_frame_size = 120;
4426 break;
4427 }
4428 j->play_mode = 5;
4429 break;
4430 default:
4431 kfree(j->write_buffer);
4432 j->play_frame_size = 0;
4433 j->play_mode = -1;
4434 j->write_buffer = NULL;
4435 j->write_buffer_size = 0;
4436 retval = 1;
4437 break;
4438 }
4439 return retval;
4440}
4441
4442static int ixj_play_start(IXJ *j)
4443{
4444 unsigned short cmd = 0x0000;
4445
4446 if (j->write_buffer) {
4447 ixj_play_stop(j);
4448 }
4449
4450 if(ixjdebug & 0x0002)
4451 printk("IXJ %d Starting Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4452
4453 j->flags.playing = 1;
4454 ixj_WriteDSPCommand(0x0FE0, j);
4455
4456 j->flags.play_first_frame = 1;
4457 j->drybuffer = 0;
4458
4459 if (!j->play_mode) {
4460 switch (j->play_codec) {
4461 case G723_63:
4462 cmd = 0x5231;
4463 break;
4464 case G723_53:
4465 cmd = 0x5232;
4466 break;
4467 case TS85:
4468 cmd = 0x5230;
4469
4470 break;
4471 case TS48:
4472 cmd = 0x5233;
4473
4474 break;
4475 case TS41:
4476 cmd = 0x5234;
4477
4478 break;
4479 case G728:
4480 cmd = 0x5235;
4481 break;
4482 case G729:
4483 case G729B:
4484 cmd = 0x5236;
4485 break;
4486 default:
4487 return 1;
4488 }
4489 if (ixj_WriteDSPCommand(cmd, j))
4490 return -1;
4491 }
4492 j->write_buffer = kmalloc(j->play_frame_size * 2, GFP_ATOMIC);
4493 if (!j->write_buffer) {
4494 printk("Write buffer allocation for ixj board %d failed!\n", j->board);
4495 return -ENOMEM;
4496 }
4497
4498 j->write_buffers_empty = 1;
4499 j->write_buffer_size = j->play_frame_size * 2;
4500 j->write_buffer_end = j->write_buffer + j->play_frame_size * 2;
4501 j->write_buffer_rp = j->write_buffer_wp = j->write_buffer;
4502
4503 if (ixj_WriteDSPCommand(0x5202, j))
4504
4505 return -1;
4506
4507 switch (j->play_mode) {
4508 case 0:
4509 cmd = 0x2C03;
4510 break;
4511 case 2:
4512 if (j->ver.low == 0x12) {
4513 cmd = 0x2C23;
4514 } else {
4515 cmd = 0x2C21;
4516 }
4517 break;
4518 case 4:
4519 if (j->ver.low == 0x12) {
4520 cmd = 0x2C43;
4521 } else {
4522 cmd = 0x2C41;
4523 }
4524 break;
4525 case 5:
4526 if (j->ver.low == 0x12) {
4527 cmd = 0x2C53;
4528 } else {
4529 cmd = 0x2C51;
4530 }
4531 break;
4532 case 6:
4533 if (j->ver.low == 0x12) {
4534 cmd = 0x2C63;
4535 } else {
4536 cmd = 0x2C61;
4537 }
4538 break;
4539 }
4540 if (ixj_WriteDSPCommand(cmd, j))
4541 return -1;
4542
4543 if (ixj_WriteDSPCommand(0x2000, j))
4544 return -1;
4545
4546 if (ixj_WriteDSPCommand(0x2000 + j->play_frame_size, j))
4547 return -1;
4548
4549 if (j->flags.recording) {
4550 ixj_aec_start(j, j->aec_level);
4551 }
4552
4553 return 0;
4554}
4555
4556static void ixj_play_stop(IXJ *j)
4557{
4558 if (ixjdebug & 0x0002)
4559 printk("IXJ %d Stopping Play Codec %d at %ld\n", j->board, j->play_codec, jiffies);
4560
4561 kfree(j->write_buffer);
4562 j->write_buffer = NULL;
4563 j->write_buffer_size = 0;
4564 if (j->play_mode > -1) {
4565 ixj_WriteDSPCommand(0x5221, j);
4566
4567 j->play_mode = -1;
4568 }
4569 j->flags.playing = 0;
4570}
4571
4572static inline int get_play_level(IXJ *j)
4573{
4574 int retval;
4575
4576 ixj_WriteDSPCommand(0xCF8F, j);
4577 return j->ssr.high << 8 | j->ssr.low;
4578 retval = j->ssr.high << 8 | j->ssr.low;
4579 retval = (retval * 256) / 240;
4580 return retval;
4581}
4582
4583static unsigned int ixj_poll(struct file *file_p, poll_table * wait)
4584{
4585 unsigned int mask = 0;
4586
4587 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
4588
4589 poll_wait(file_p, &(j->poll_q), wait);
4590 if (j->read_buffer_ready > 0)
4591 mask |= POLLIN | POLLRDNORM;
4592 if (j->write_buffers_empty > 0)
4593 mask |= POLLOUT | POLLWRNORM;
4594 if (j->ex.bytes)
4595 mask |= POLLPRI;
4596 return mask;
4597}
4598
4599static int ixj_play_tone(IXJ *j, char tone)
4600{
4601 if (!j->tone_state) {
4602 if(ixjdebug & 0x0002) {
4603 printk("IXJ %d starting tone %d at %ld\n", j->board, tone, jiffies);
4604 }
4605 if (j->dsp.low == 0x20) {
4606 idle(j);
4607 }
4608 j->tone_start_jif = jiffies;
4609
4610 j->tone_state = 1;
4611 }
4612
4613 j->tone_index = tone;
4614 if (ixj_WriteDSPCommand(0x6000 + j->tone_index, j))
4615 return -1;
4616
4617 return 0;
4618}
4619
4620static int ixj_set_tone_on(unsigned short arg, IXJ *j)
4621{
4622 j->tone_on_time = arg;
4623
4624 if (ixj_WriteDSPCommand(0x6E04, j))
4625
4626 return -1;
4627
4628 if (ixj_WriteDSPCommand(arg, j))
4629 return -1;
4630
4631 return 0;
4632}
4633
4634static int SCI_WaitHighSCI(IXJ *j)
4635{
4636 int cnt;
4637
4638 j->pld_scrr.byte = inb_p(j->XILINXbase);
4639 if (!j->pld_scrr.bits.sci) {
4640 for (cnt = 0; cnt < 10; cnt++) {
4641 udelay(32);
4642 j->pld_scrr.byte = inb_p(j->XILINXbase);
4643
4644 if ((j->pld_scrr.bits.sci))
4645 return 1;
4646 }
4647 if (ixjdebug & 0x0001)
4648 printk(KERN_INFO "SCI Wait High failed %x\n", j->pld_scrr.byte);
4649 return 0;
4650 } else
4651 return 1;
4652}
4653
4654static int SCI_WaitLowSCI(IXJ *j)
4655{
4656 int cnt;
4657
4658 j->pld_scrr.byte = inb_p(j->XILINXbase);
4659 if (j->pld_scrr.bits.sci) {
4660 for (cnt = 0; cnt < 10; cnt++) {
4661 udelay(32);
4662 j->pld_scrr.byte = inb_p(j->XILINXbase);
4663
4664 if (!(j->pld_scrr.bits.sci))
4665 return 1;
4666 }
4667 if (ixjdebug & 0x0001)
4668 printk(KERN_INFO "SCI Wait Low failed %x\n", j->pld_scrr.byte);
4669 return 0;
4670 } else
4671 return 1;
4672}
4673
4674static int SCI_Control(IXJ *j, int control)
4675{
4676 switch (control) {
4677 case SCI_End:
4678 j->pld_scrw.bits.c0 = 0;
4679
4680 j->pld_scrw.bits.c1 = 0;
4681
4682 break;
4683 case SCI_Enable_DAA:
4684 j->pld_scrw.bits.c0 = 1;
4685
4686 j->pld_scrw.bits.c1 = 0;
4687
4688 break;
4689 case SCI_Enable_Mixer:
4690 j->pld_scrw.bits.c0 = 0;
4691
4692 j->pld_scrw.bits.c1 = 1;
4693
4694 break;
4695 case SCI_Enable_EEPROM:
4696 j->pld_scrw.bits.c0 = 1;
4697
4698 j->pld_scrw.bits.c1 = 1;
4699
4700 break;
4701 default:
4702 return 0;
4703 break;
4704 }
4705 outb_p(j->pld_scrw.byte, j->XILINXbase);
4706
4707 switch (control) {
4708 case SCI_End:
4709 return 1;
4710 break;
4711 case SCI_Enable_DAA:
4712 case SCI_Enable_Mixer:
4713 case SCI_Enable_EEPROM:
4714 if (!SCI_WaitHighSCI(j))
4715 return 0;
4716 break;
4717 default:
4718 return 0;
4719 break;
4720 }
4721 return 1;
4722}
4723
4724static int SCI_Prepare(IXJ *j)
4725{
4726 if (!SCI_Control(j, SCI_End))
4727 return 0;
4728
4729 if (!SCI_WaitLowSCI(j))
4730 return 0;
4731
4732 return 1;
4733}
4734
4735static int ixj_get_mixer(long val, IXJ *j)
4736{
4737 int reg = (val & 0x1F00) >> 8;
4738 return j->mix.vol[reg];
4739}
4740
4741static int ixj_mixer(long val, IXJ *j)
4742{
4743 BYTES bytes;
4744
4745 bytes.high = (val & 0x1F00) >> 8;
4746 bytes.low = val & 0x00FF;
4747
4748
4749 j->mix.vol[bytes.high] = bytes.low;
4750
4751 outb_p(bytes.high & 0x1F, j->XILINXbase + 0x03);
4752
4753 outb_p(bytes.low, j->XILINXbase + 0x02);
4754
4755 SCI_Control(j, SCI_Enable_Mixer);
4756
4757 SCI_Control(j, SCI_End);
4758
4759 return 0;
4760}
4761
4762static int daa_load(BYTES * p_bytes, IXJ *j)
4763{
4764 outb_p(p_bytes->high, j->XILINXbase + 0x03);
4765 outb_p(p_bytes->low, j->XILINXbase + 0x02);
4766 if (!SCI_Control(j, SCI_Enable_DAA))
4767 return 0;
4768 else
4769 return 1;
4770}
4771
4772static int ixj_daa_cr4(IXJ *j, char reg)
4773{
4774 BYTES bytes;
4775
4776 switch (j->daa_mode) {
4777 case SOP_PU_SLEEP:
4778 bytes.high = 0x14;
4779 break;
4780 case SOP_PU_RINGING:
4781 bytes.high = 0x54;
4782 break;
4783 case SOP_PU_CONVERSATION:
4784 bytes.high = 0x94;
4785 break;
4786 case SOP_PU_PULSEDIALING:
4787 bytes.high = 0xD4;
4788 break;
4789 }
4790
4791 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = reg;
4792
4793 switch (j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGX) {
4794 case 0:
4795 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 0;
4796 break;
4797 case 1:
4798 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 2;
4799 break;
4800 case 2:
4801 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 1;
4802 break;
4803 case 3:
4804 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 3;
4805 break;
4806 }
4807
4808 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
4809
4810 if (!daa_load(&bytes, j))
4811 return 0;
4812
4813 if (!SCI_Prepare(j))
4814 return 0;
4815
4816 return 1;
4817}
4818
4819static char daa_int_read(IXJ *j)
4820{
4821 BYTES bytes;
4822
4823 if (!SCI_Prepare(j))
4824 return 0;
4825
4826 bytes.high = 0x38;
4827 bytes.low = 0x00;
4828 outb_p(bytes.high, j->XILINXbase + 0x03);
4829 outb_p(bytes.low, j->XILINXbase + 0x02);
4830
4831 if (!SCI_Control(j, SCI_Enable_DAA))
4832 return 0;
4833
4834 bytes.high = inb_p(j->XILINXbase + 0x03);
4835 bytes.low = inb_p(j->XILINXbase + 0x02);
4836 if (bytes.low != ALISDAA_ID_BYTE) {
4837 if (ixjdebug & 0x0001)
4838 printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4839 return 0;
4840 }
4841 if (!SCI_Control(j, SCI_Enable_DAA))
4842 return 0;
4843 if (!SCI_Control(j, SCI_End))
4844 return 0;
4845
4846 bytes.high = inb_p(j->XILINXbase + 0x03);
4847 bytes.low = inb_p(j->XILINXbase + 0x02);
4848
4849 j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg = bytes.high;
4850
4851 return 1;
4852}
4853
4854static char daa_CR_read(IXJ *j, int cr)
4855{
4856 IXJ_WORD wdata;
4857 BYTES bytes;
4858
4859 if (!SCI_Prepare(j))
4860 return 0;
4861
4862 switch (j->daa_mode) {
4863 case SOP_PU_SLEEP:
4864 bytes.high = 0x30 + cr;
4865 break;
4866 case SOP_PU_RINGING:
4867 bytes.high = 0x70 + cr;
4868 break;
4869 case SOP_PU_CONVERSATION:
4870 bytes.high = 0xB0 + cr;
4871 break;
4872 case SOP_PU_PULSEDIALING:
4873 default:
4874 bytes.high = 0xF0 + cr;
4875 break;
4876 }
4877
4878 bytes.low = 0x00;
4879
4880 outb_p(bytes.high, j->XILINXbase + 0x03);
4881 outb_p(bytes.low, j->XILINXbase + 0x02);
4882
4883 if (!SCI_Control(j, SCI_Enable_DAA))
4884 return 0;
4885
4886 bytes.high = inb_p(j->XILINXbase + 0x03);
4887 bytes.low = inb_p(j->XILINXbase + 0x02);
4888 if (bytes.low != ALISDAA_ID_BYTE) {
4889 if (ixjdebug & 0x0001)
4890 printk("Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4891 return 0;
4892 }
4893 if (!SCI_Control(j, SCI_Enable_DAA))
4894 return 0;
4895 if (!SCI_Control(j, SCI_End))
4896 return 0;
4897
4898 wdata.word = inw_p(j->XILINXbase + 0x02);
4899
4900 switch(cr){
4901 case 5:
4902 j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = wdata.bytes.high;
4903 break;
4904 case 4:
4905 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = wdata.bytes.high;
4906 break;
4907 case 3:
4908 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = wdata.bytes.high;
4909 break;
4910 case 2:
4911 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = wdata.bytes.high;
4912 break;
4913 case 1:
4914 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = wdata.bytes.high;
4915 break;
4916 case 0:
4917 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = wdata.bytes.high;
4918 break;
4919 default:
4920 return 0;
4921 }
4922 return 1;
4923}
4924
4925static int ixj_daa_cid_reset(IXJ *j)
4926{
4927 int i;
4928 BYTES bytes;
4929
4930 if (ixjdebug & 0x0002)
4931 printk("DAA Clearing CID ram\n");
4932
4933 if (!SCI_Prepare(j))
4934 return 0;
4935
4936 bytes.high = 0x58;
4937 bytes.low = 0x00;
4938 outb_p(bytes.high, j->XILINXbase + 0x03);
4939 outb_p(bytes.low, j->XILINXbase + 0x02);
4940
4941 if (!SCI_Control(j, SCI_Enable_DAA))
4942 return 0;
4943
4944 if (!SCI_WaitHighSCI(j))
4945 return 0;
4946
4947 for (i = 0; i < ALISDAA_CALLERID_SIZE - 1; i += 2) {
4948 bytes.high = bytes.low = 0x00;
4949 outb_p(bytes.high, j->XILINXbase + 0x03);
4950
4951 if (i < ALISDAA_CALLERID_SIZE - 1)
4952 outb_p(bytes.low, j->XILINXbase + 0x02);
4953
4954 if (!SCI_Control(j, SCI_Enable_DAA))
4955 return 0;
4956
4957 if (!SCI_WaitHighSCI(j))
4958 return 0;
4959
4960 }
4961
4962 if (!SCI_Control(j, SCI_End))
4963 return 0;
4964
4965 if (ixjdebug & 0x0002)
4966 printk("DAA CID ram cleared\n");
4967
4968 return 1;
4969}
4970
4971static int ixj_daa_cid_read(IXJ *j)
4972{
4973 int i;
4974 BYTES bytes;
4975 char CID[ALISDAA_CALLERID_SIZE];
4976 bool mContinue;
4977 char *pIn, *pOut;
4978
4979 if (!SCI_Prepare(j))
4980 return 0;
4981
4982 bytes.high = 0x78;
4983 bytes.low = 0x00;
4984 outb_p(bytes.high, j->XILINXbase + 0x03);
4985 outb_p(bytes.low, j->XILINXbase + 0x02);
4986
4987 if (!SCI_Control(j, SCI_Enable_DAA))
4988 return 0;
4989
4990 if (!SCI_WaitHighSCI(j))
4991 return 0;
4992
4993 bytes.high = inb_p(j->XILINXbase + 0x03);
4994 bytes.low = inb_p(j->XILINXbase + 0x02);
4995 if (bytes.low != ALISDAA_ID_BYTE) {
4996 if (ixjdebug & 0x0001)
4997 printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
4998 return 0;
4999 }
5000 for (i = 0; i < ALISDAA_CALLERID_SIZE; i += 2) {
5001 bytes.high = bytes.low = 0x00;
5002 outb_p(bytes.high, j->XILINXbase + 0x03);
5003 outb_p(bytes.low, j->XILINXbase + 0x02);
5004
5005 if (!SCI_Control(j, SCI_Enable_DAA))
5006 return 0;
5007
5008 if (!SCI_WaitHighSCI(j))
5009 return 0;
5010
5011 CID[i + 0] = inb_p(j->XILINXbase + 0x03);
5012 CID[i + 1] = inb_p(j->XILINXbase + 0x02);
5013 }
5014
5015 if (!SCI_Control(j, SCI_End))
5016 return 0;
5017
5018 pIn = CID;
5019 pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5020 mContinue = true;
5021 while (mContinue) {
5022 if ((pIn[1] & 0x03) == 0x01) {
5023 pOut[0] = pIn[0];
5024 }
5025 if ((pIn[2] & 0x0c) == 0x04) {
5026 pOut[1] = ((pIn[2] & 0x03) << 6) | ((pIn[1] & 0xfc) >> 2);
5027 }
5028 if ((pIn[3] & 0x30) == 0x10) {
5029 pOut[2] = ((pIn[3] & 0x0f) << 4) | ((pIn[2] & 0xf0) >> 4);
5030 }
5031 if ((pIn[4] & 0xc0) == 0x40) {
5032 pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6);
5033 } else {
5034 mContinue = false;
5035 }
5036 pIn += 5, pOut += 4;
5037 }
5038 memset(&j->cid, 0, sizeof(PHONE_CID));
5039 pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5040 pOut += 4;
5041 strncpy(j->cid.month, pOut, 2);
5042 pOut += 2;
5043 strncpy(j->cid.day, pOut, 2);
5044 pOut += 2;
5045 strncpy(j->cid.hour, pOut, 2);
5046 pOut += 2;
5047 strncpy(j->cid.min, pOut, 2);
5048 pOut += 3;
5049 j->cid.numlen = *pOut;
5050 pOut += 1;
5051 strncpy(j->cid.number, pOut, j->cid.numlen);
5052 pOut += j->cid.numlen + 1;
5053 j->cid.namelen = *pOut;
5054 pOut += 1;
5055 strncpy(j->cid.name, pOut, j->cid.namelen);
5056
5057 ixj_daa_cid_reset(j);
5058 return 1;
5059}
5060
5061static char daa_get_version(IXJ *j)
5062{
5063 BYTES bytes;
5064
5065 if (!SCI_Prepare(j))
5066 return 0;
5067
5068 bytes.high = 0x35;
5069 bytes.low = 0x00;
5070 outb_p(bytes.high, j->XILINXbase + 0x03);
5071 outb_p(bytes.low, j->XILINXbase + 0x02);
5072
5073 if (!SCI_Control(j, SCI_Enable_DAA))
5074 return 0;
5075
5076 bytes.high = inb_p(j->XILINXbase + 0x03);
5077 bytes.low = inb_p(j->XILINXbase + 0x02);
5078 if (bytes.low != ALISDAA_ID_BYTE) {
5079 if (ixjdebug & 0x0001)
5080 printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %d\n", bytes.high, bytes.low);
5081 return 0;
5082 }
5083 if (!SCI_Control(j, SCI_Enable_DAA))
5084 return 0;
5085
5086 if (!SCI_Control(j, SCI_End))
5087 return 0;
5088
5089 bytes.high = inb_p(j->XILINXbase + 0x03);
5090 bytes.low = inb_p(j->XILINXbase + 0x02);
5091 if (ixjdebug & 0x0002)
5092 printk("DAA CR5 Byte high = 0x%x low = 0x%x\n", bytes.high, bytes.low);
5093 j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = bytes.high;
5094 return bytes.high;
5095}
5096
5097static int daa_set_mode(IXJ *j, int mode)
5098{
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113 BYTES bytes;
5114
5115 j->flags.pstn_rmr = 0;
5116
5117 if (!SCI_Prepare(j))
5118 return 0;
5119
5120 switch (mode) {
5121 case SOP_PU_RESET:
5122 j->pld_scrw.bits.daafsyncen = 0;
5123
5124 outb_p(j->pld_scrw.byte, j->XILINXbase);
5125 j->pld_slicw.bits.rly2 = 0;
5126 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5127 bytes.high = 0x10;
5128 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5129 daa_load(&bytes, j);
5130 if (!SCI_Prepare(j))
5131 return 0;
5132
5133 j->daa_mode = SOP_PU_SLEEP;
5134 break;
5135 case SOP_PU_SLEEP:
5136 if(j->daa_mode == SOP_PU_SLEEP)
5137 {
5138 break;
5139 }
5140 if (ixjdebug & 0x0008)
5141 printk(KERN_INFO "phone DAA: SOP_PU_SLEEP at %ld\n", jiffies);
5142
5143 {
5144 j->pld_scrw.bits.daafsyncen = 0;
5145
5146 outb_p(j->pld_scrw.byte, j->XILINXbase);
5147 j->pld_slicw.bits.rly2 = 0;
5148 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5149 bytes.high = 0x10;
5150 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5151 daa_load(&bytes, j);
5152 if (!SCI_Prepare(j))
5153 return 0;
5154 }
5155 j->pld_scrw.bits.daafsyncen = 0;
5156
5157 outb_p(j->pld_scrw.byte, j->XILINXbase);
5158 j->pld_slicw.bits.rly2 = 0;
5159 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5160 bytes.high = 0x10;
5161 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5162 daa_load(&bytes, j);
5163 if (!SCI_Prepare(j))
5164 return 0;
5165
5166 j->daa_mode = SOP_PU_SLEEP;
5167 j->flags.pstn_ringing = 0;
5168 j->ex.bits.pstn_ring = 0;
5169 j->pstn_sleeptil = jiffies + (hertz / 4);
5170 wake_up_interruptible(&j->read_q);
5171 wake_up_interruptible(&j->write_q);
5172 wake_up_interruptible(&j->poll_q);
5173 break;
5174 case SOP_PU_RINGING:
5175 if (ixjdebug & 0x0008)
5176 printk(KERN_INFO "phone DAA: SOP_PU_RINGING at %ld\n", jiffies);
5177 j->pld_scrw.bits.daafsyncen = 0;
5178
5179 outb_p(j->pld_scrw.byte, j->XILINXbase);
5180 j->pld_slicw.bits.rly2 = 0;
5181 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5182 bytes.high = 0x50;
5183 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5184 daa_load(&bytes, j);
5185 if (!SCI_Prepare(j))
5186 return 0;
5187 j->daa_mode = SOP_PU_RINGING;
5188 break;
5189 case SOP_PU_CONVERSATION:
5190 if (ixjdebug & 0x0008)
5191 printk(KERN_INFO "phone DAA: SOP_PU_CONVERSATION at %ld\n", jiffies);
5192 bytes.high = 0x90;
5193 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5194 daa_load(&bytes, j);
5195 if (!SCI_Prepare(j))
5196 return 0;
5197 j->pld_slicw.bits.rly2 = 1;
5198 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5199 j->pld_scrw.bits.daafsyncen = 1;
5200
5201 outb_p(j->pld_scrw.byte, j->XILINXbase);
5202 j->daa_mode = SOP_PU_CONVERSATION;
5203 j->flags.pstn_ringing = 0;
5204 j->ex.bits.pstn_ring = 0;
5205 j->pstn_sleeptil = jiffies;
5206 j->pstn_ring_start = j->pstn_ring_stop = j->pstn_ring_int = 0;
5207 break;
5208 case SOP_PU_PULSEDIALING:
5209 if (ixjdebug & 0x0008)
5210 printk(KERN_INFO "phone DAA: SOP_PU_PULSEDIALING at %ld\n", jiffies);
5211 j->pld_scrw.bits.daafsyncen = 0;
5212
5213 outb_p(j->pld_scrw.byte, j->XILINXbase);
5214 j->pld_slicw.bits.rly2 = 0;
5215 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
5216 bytes.high = 0xD0;
5217 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5218 daa_load(&bytes, j);
5219 if (!SCI_Prepare(j))
5220 return 0;
5221 j->daa_mode = SOP_PU_PULSEDIALING;
5222 break;
5223 default:
5224 break;
5225 }
5226 return 1;
5227}
5228
5229static int ixj_daa_write(IXJ *j)
5230{
5231 BYTES bytes;
5232
5233 j->flags.pstncheck = 1;
5234
5235 daa_set_mode(j, SOP_PU_SLEEP);
5236
5237 if (!SCI_Prepare(j))
5238 return 0;
5239
5240 outb_p(j->pld_scrw.byte, j->XILINXbase);
5241
5242 bytes.high = 0x14;
5243 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
5244 if (!daa_load(&bytes, j))
5245 return 0;
5246
5247 bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg;
5248 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg;
5249 if (!daa_load(&bytes, j))
5250 return 0;
5251
5252 bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg;
5253 bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
5254 if (!daa_load(&bytes, j))
5255 return 0;
5256
5257 if (!SCI_Prepare(j))
5258 return 0;
5259
5260 bytes.high = 0x1F;
5261 bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg;
5262 if (!daa_load(&bytes, j))
5263 return 0;
5264
5265 bytes.high = j->m_DAAShadowRegs.XOP_xr6_W.reg;
5266 bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg;
5267 if (!daa_load(&bytes, j))
5268 return 0;
5269
5270 bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg;
5271 bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg;
5272 if (!daa_load(&bytes, j))
5273 return 0;
5274
5275 bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg;
5276 bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg;
5277 if (!daa_load(&bytes, j))
5278 return 0;
5279
5280 bytes.high = j->m_DAAShadowRegs.XOP_xr0_W.reg;
5281 bytes.low = 0x00;
5282 if (!daa_load(&bytes, j))
5283 return 0;
5284
5285 if (!SCI_Prepare(j))
5286 return 0;
5287
5288 bytes.high = 0x00;
5289 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7];
5290 if (!daa_load(&bytes, j))
5291 return 0;
5292
5293 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6];
5294 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5];
5295 if (!daa_load(&bytes, j))
5296 return 0;
5297
5298 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4];
5299 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3];
5300 if (!daa_load(&bytes, j))
5301 return 0;
5302
5303 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2];
5304 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1];
5305 if (!daa_load(&bytes, j))
5306 return 0;
5307
5308 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0];
5309 bytes.low = 0x00;
5310 if (!daa_load(&bytes, j))
5311 return 0;
5312
5313 if (!SCI_Control(j, SCI_End))
5314 return 0;
5315 if (!SCI_WaitLowSCI(j))
5316 return 0;
5317
5318 bytes.high = 0x01;
5319 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7];
5320 if (!daa_load(&bytes, j))
5321 return 0;
5322
5323 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6];
5324 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5];
5325 if (!daa_load(&bytes, j))
5326 return 0;
5327
5328 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4];
5329 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3];
5330 if (!daa_load(&bytes, j))
5331 return 0;
5332
5333 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2];
5334 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1];
5335 if (!daa_load(&bytes, j))
5336 return 0;
5337
5338 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0];
5339 bytes.low = 0x00;
5340 if (!daa_load(&bytes, j))
5341 return 0;
5342
5343 if (!SCI_Control(j, SCI_End))
5344 return 0;
5345 if (!SCI_WaitLowSCI(j))
5346 return 0;
5347
5348 bytes.high = 0x02;
5349 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7];
5350 if (!daa_load(&bytes, j))
5351 return 0;
5352
5353 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6];
5354 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5];
5355 if (!daa_load(&bytes, j))
5356 return 0;
5357
5358 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4];
5359 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3];
5360 if (!daa_load(&bytes, j))
5361 return 0;
5362
5363 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2];
5364 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1];
5365 if (!daa_load(&bytes, j))
5366 return 0;
5367
5368 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0];
5369 bytes.low = 0x00;
5370 if (!daa_load(&bytes, j))
5371 return 0;
5372
5373 if (!SCI_Control(j, SCI_End))
5374 return 0;
5375 if (!SCI_WaitLowSCI(j))
5376 return 0;
5377
5378 bytes.high = 0x03;
5379 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7];
5380 if (!daa_load(&bytes, j))
5381 return 0;
5382
5383 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6];
5384 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5];
5385 if (!daa_load(&bytes, j))
5386 return 0;
5387
5388 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4];
5389 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3];
5390 if (!daa_load(&bytes, j))
5391 return 0;
5392
5393 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2];
5394 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1];
5395 if (!daa_load(&bytes, j))
5396 return 0;
5397
5398 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0];
5399 bytes.low = 0x00;
5400 if (!daa_load(&bytes, j))
5401 return 0;
5402
5403 if (!SCI_Control(j, SCI_End))
5404 return 0;
5405 if (!SCI_WaitLowSCI(j))
5406 return 0;
5407
5408 bytes.high = 0x04;
5409 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7];
5410 if (!daa_load(&bytes, j))
5411 return 0;
5412
5413 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6];
5414 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5];
5415 if (!daa_load(&bytes, j))
5416 return 0;
5417
5418 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4];
5419 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3];
5420 if (!daa_load(&bytes, j))
5421 return 0;
5422
5423 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2];
5424 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1];
5425 if (!daa_load(&bytes, j))
5426 return 0;
5427
5428 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0];
5429 bytes.low = 0x00;
5430 if (!daa_load(&bytes, j))
5431 return 0;
5432
5433 if (!SCI_Control(j, SCI_End))
5434 return 0;
5435 if (!SCI_WaitLowSCI(j))
5436 return 0;
5437
5438 bytes.high = 0x05;
5439 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7];
5440 if (!daa_load(&bytes, j))
5441 return 0;
5442
5443 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6];
5444 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5];
5445 if (!daa_load(&bytes, j))
5446 return 0;
5447
5448 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4];
5449 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3];
5450 if (!daa_load(&bytes, j))
5451 return 0;
5452
5453 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2];
5454 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1];
5455 if (!daa_load(&bytes, j))
5456 return 0;
5457
5458 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0];
5459 bytes.low = 0x00;
5460 if (!daa_load(&bytes, j))
5461 return 0;
5462
5463 if (!SCI_Control(j, SCI_End))
5464 return 0;
5465 if (!SCI_WaitLowSCI(j))
5466 return 0;
5467
5468 bytes.high = 0x06;
5469 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7];
5470 if (!daa_load(&bytes, j))
5471 return 0;
5472
5473 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6];
5474 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5];
5475 if (!daa_load(&bytes, j))
5476 return 0;
5477
5478 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4];
5479 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3];
5480 if (!daa_load(&bytes, j))
5481 return 0;
5482
5483 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2];
5484 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1];
5485 if (!daa_load(&bytes, j))
5486 return 0;
5487
5488 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0];
5489 bytes.low = 0x00;
5490 if (!daa_load(&bytes, j))
5491 return 0;
5492
5493 if (!SCI_Control(j, SCI_End))
5494 return 0;
5495 if (!SCI_WaitLowSCI(j))
5496 return 0;
5497
5498 bytes.high = 0x07;
5499 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7];
5500 if (!daa_load(&bytes, j))
5501 return 0;
5502
5503 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6];
5504 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5];
5505 if (!daa_load(&bytes, j))
5506 return 0;
5507
5508 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4];
5509 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3];
5510 if (!daa_load(&bytes, j))
5511 return 0;
5512
5513 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2];
5514 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1];
5515 if (!daa_load(&bytes, j))
5516 return 0;
5517
5518 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0];
5519 bytes.low = 0x00;
5520 if (!daa_load(&bytes, j))
5521 return 0;
5522
5523 if (!SCI_Control(j, SCI_End))
5524 return 0;
5525 if (!SCI_WaitLowSCI(j))
5526 return 0;
5527
5528 bytes.high = 0x08;
5529 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7];
5530 if (!daa_load(&bytes, j))
5531 return 0;
5532
5533 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6];
5534 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5];
5535 if (!daa_load(&bytes, j))
5536 return 0;
5537
5538 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4];
5539 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3];
5540 if (!daa_load(&bytes, j))
5541 return 0;
5542
5543 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2];
5544 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1];
5545 if (!daa_load(&bytes, j))
5546 return 0;
5547
5548 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0];
5549 bytes.low = 0x00;
5550 if (!daa_load(&bytes, j))
5551 return 0;
5552
5553 if (!SCI_Control(j, SCI_End))
5554 return 0;
5555 if (!SCI_WaitLowSCI(j))
5556 return 0;
5557
5558 bytes.high = 0x09;
5559 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3];
5560 if (!daa_load(&bytes, j))
5561 return 0;
5562
5563 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2];
5564 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1];
5565 if (!daa_load(&bytes, j))
5566 return 0;
5567
5568 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0];
5569 bytes.low = 0x00;
5570 if (!daa_load(&bytes, j))
5571 return 0;
5572
5573 if (!SCI_Control(j, SCI_End))
5574 return 0;
5575 if (!SCI_WaitLowSCI(j))
5576 return 0;
5577
5578 bytes.high = 0x0A;
5579 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3];
5580 if (!daa_load(&bytes, j))
5581 return 0;
5582
5583 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2];
5584 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1];
5585 if (!daa_load(&bytes, j))
5586 return 0;
5587
5588 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0];
5589 bytes.low = 0x00;
5590 if (!daa_load(&bytes, j))
5591 return 0;
5592
5593 if (!SCI_Control(j, SCI_End))
5594 return 0;
5595 if (!SCI_WaitLowSCI(j))
5596 return 0;
5597
5598 bytes.high = 0x0B;
5599 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3];
5600 if (!daa_load(&bytes, j))
5601 return 0;
5602
5603 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2];
5604 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1];
5605 if (!daa_load(&bytes, j))
5606 return 0;
5607
5608 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0];
5609 bytes.low = 0x00;
5610 if (!daa_load(&bytes, j))
5611 return 0;
5612
5613 if (!SCI_Control(j, SCI_End))
5614 return 0;
5615 if (!SCI_WaitLowSCI(j))
5616 return 0;
5617
5618 bytes.high = 0x0C;
5619 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3];
5620 if (!daa_load(&bytes, j))
5621 return 0;
5622
5623 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2];
5624 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1];
5625 if (!daa_load(&bytes, j))
5626 return 0;
5627
5628 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0];
5629 bytes.low = 0x00;
5630 if (!daa_load(&bytes, j))
5631 return 0;
5632
5633 if (!SCI_Control(j, SCI_End))
5634 return 0;
5635 if (!SCI_WaitLowSCI(j))
5636 return 0;
5637
5638 bytes.high = 0x0D;
5639 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3];
5640 if (!daa_load(&bytes, j))
5641 return 0;
5642
5643 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2];
5644 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1];
5645 if (!daa_load(&bytes, j))
5646 return 0;
5647
5648 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0];
5649 bytes.low = 0x00;
5650 if (!daa_load(&bytes, j))
5651 return 0;
5652
5653 if (!SCI_Control(j, SCI_End))
5654 return 0;
5655 if (!SCI_WaitLowSCI(j))
5656 return 0;
5657
5658 bytes.high = 0x0E;
5659 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7];
5660 if (!daa_load(&bytes, j))
5661 return 0;
5662
5663 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6];
5664 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5];
5665 if (!daa_load(&bytes, j))
5666 return 0;
5667
5668 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4];
5669 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3];
5670 if (!daa_load(&bytes, j))
5671 return 0;
5672
5673 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2];
5674 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1];
5675 if (!daa_load(&bytes, j))
5676 return 0;
5677
5678 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0];
5679 bytes.low = 0x00;
5680 if (!daa_load(&bytes, j))
5681 return 0;
5682
5683 if (!SCI_Control(j, SCI_End))
5684 return 0;
5685 if (!SCI_WaitLowSCI(j))
5686 return 0;
5687
5688 bytes.high = 0x0F;
5689 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7];
5690 if (!daa_load(&bytes, j))
5691 return 0;
5692
5693 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6];
5694 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5];
5695 if (!daa_load(&bytes, j))
5696 return 0;
5697
5698 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4];
5699 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3];
5700 if (!daa_load(&bytes, j))
5701 return 0;
5702
5703 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2];
5704 bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1];
5705 if (!daa_load(&bytes, j))
5706 return 0;
5707
5708 bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0];
5709 bytes.low = 0x00;
5710 if (!daa_load(&bytes, j))
5711 return 0;
5712
5713 udelay(32);
5714 j->pld_scrr.byte = inb_p(j->XILINXbase);
5715 if (!SCI_Control(j, SCI_End))
5716 return 0;
5717
5718 outb_p(j->pld_scrw.byte, j->XILINXbase);
5719
5720 if (ixjdebug & 0x0002)
5721 printk("DAA Coefficients Loaded\n");
5722
5723 j->flags.pstncheck = 0;
5724 return 1;
5725}
5726
5727static int ixj_set_tone_off(unsigned short arg, IXJ *j)
5728{
5729 j->tone_off_time = arg;
5730 if (ixj_WriteDSPCommand(0x6E05, j))
5731
5732 return -1;
5733 if (ixj_WriteDSPCommand(arg, j))
5734 return -1;
5735 return 0;
5736}
5737
5738static int ixj_get_tone_on(IXJ *j)
5739{
5740 if (ixj_WriteDSPCommand(0x6E06, j))
5741
5742 return -1;
5743 return 0;
5744}
5745
5746static int ixj_get_tone_off(IXJ *j)
5747{
5748 if (ixj_WriteDSPCommand(0x6E07, j))
5749
5750 return -1;
5751 return 0;
5752}
5753
5754static void ixj_busytone(IXJ *j)
5755{
5756 j->flags.ringback = 0;
5757 j->flags.dialtone = 0;
5758 j->flags.busytone = 1;
5759 ixj_set_tone_on(0x07D0, j);
5760 ixj_set_tone_off(0x07D0, j);
5761 ixj_play_tone(j, 27);
5762}
5763
5764static void ixj_dialtone(IXJ *j)
5765{
5766 j->flags.ringback = 0;
5767 j->flags.dialtone = 1;
5768 j->flags.busytone = 0;
5769 if (j->dsp.low == 0x20) {
5770 return;
5771 } else {
5772 ixj_set_tone_on(0xFFFF, j);
5773 ixj_set_tone_off(0x0000, j);
5774 ixj_play_tone(j, 25);
5775 }
5776}
5777
5778static void ixj_cpt_stop(IXJ *j)
5779{
5780 if(j->tone_state || j->tone_cadence_state)
5781 {
5782 j->flags.dialtone = 0;
5783 j->flags.busytone = 0;
5784 j->flags.ringback = 0;
5785 ixj_set_tone_on(0x0001, j);
5786 ixj_set_tone_off(0x0000, j);
5787 ixj_play_tone(j, 0);
5788 j->tone_state = j->tone_cadence_state = 0;
5789 if (j->cadence_t) {
5790 kfree(j->cadence_t->ce);
5791 kfree(j->cadence_t);
5792 j->cadence_t = NULL;
5793 }
5794 }
5795 if (j->play_mode == -1 && j->rec_mode == -1)
5796 idle(j);
5797 if (j->play_mode != -1 && j->dsp.low == 0x20)
5798 ixj_play_start(j);
5799 if (j->rec_mode != -1 && j->dsp.low == 0x20)
5800 ixj_record_start(j);
5801}
5802
5803static void ixj_ringback(IXJ *j)
5804{
5805 j->flags.busytone = 0;
5806 j->flags.dialtone = 0;
5807 j->flags.ringback = 1;
5808 ixj_set_tone_on(0x0FA0, j);
5809 ixj_set_tone_off(0x2EE0, j);
5810 ixj_play_tone(j, 26);
5811}
5812
5813static void ixj_testram(IXJ *j)
5814{
5815 ixj_WriteDSPCommand(0x3001, j);
5816}
5817
5818static int ixj_build_cadence(IXJ *j, IXJ_CADENCE __user * cp)
5819{
5820 ixj_cadence *lcp;
5821 IXJ_CADENCE_ELEMENT __user *cep;
5822 IXJ_CADENCE_ELEMENT *lcep;
5823 IXJ_TONE ti;
5824 int err;
5825
5826 lcp = kmalloc(sizeof(ixj_cadence), GFP_KERNEL);
5827 if (lcp == NULL)
5828 return -ENOMEM;
5829
5830 err = -EFAULT;
5831 if (copy_from_user(&lcp->elements_used,
5832 &cp->elements_used, sizeof(int)))
5833 goto out;
5834 if (copy_from_user(&lcp->termination,
5835 &cp->termination, sizeof(IXJ_CADENCE_TERM)))
5836 goto out;
5837 if (get_user(cep, &cp->ce))
5838 goto out;
5839
5840 err = -EINVAL;
5841 if ((unsigned)lcp->elements_used >= ~0U/sizeof(IXJ_CADENCE_ELEMENT))
5842 goto out;
5843
5844 err = -ENOMEM;
5845 lcep = kmalloc(sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used, GFP_KERNEL);
5846 if (!lcep)
5847 goto out;
5848
5849 err = -EFAULT;
5850 if (copy_from_user(lcep, cep, sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used))
5851 goto out1;
5852
5853 if (j->cadence_t) {
5854 kfree(j->cadence_t->ce);
5855 kfree(j->cadence_t);
5856 }
5857 lcp->ce = (void *) lcep;
5858 j->cadence_t = lcp;
5859 j->tone_cadence_state = 0;
5860 ixj_set_tone_on(lcp->ce[0].tone_on_time, j);
5861 ixj_set_tone_off(lcp->ce[0].tone_off_time, j);
5862 if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
5863 ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
5864 ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
5865 ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
5866 ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
5867 ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
5868 ixj_init_tone(j, &ti);
5869 }
5870 ixj_play_tone(j, lcp->ce[0].index);
5871 return 1;
5872out1:
5873 kfree(lcep);
5874out:
5875 kfree(lcp);
5876 return err;
5877}
5878
5879static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE __user * cp)
5880{
5881 IXJ_FILTER_CADENCE *lcp;
5882 lcp = memdup_user(cp, sizeof(IXJ_FILTER_CADENCE));
5883 if (IS_ERR(lcp)) {
5884 if(ixjdebug & 0x0001) {
5885 printk(KERN_INFO "Could not allocate memory for cadence or could not copy cadence to kernel\n");
5886 }
5887 return PTR_ERR(lcp);
5888 }
5889 if (lcp->filter > 5) {
5890 if(ixjdebug & 0x0001) {
5891 printk(KERN_INFO "Cadence out of range\n");
5892 }
5893 kfree(lcp);
5894 return -1;
5895 }
5896 j->cadence_f[lcp->filter].state = 0;
5897 j->cadence_f[lcp->filter].enable = lcp->enable;
5898 j->filter_en[lcp->filter] = j->cadence_f[lcp->filter].en_filter = lcp->en_filter;
5899 j->cadence_f[lcp->filter].on1 = lcp->on1;
5900 j->cadence_f[lcp->filter].on1min = 0;
5901 j->cadence_f[lcp->filter].on1max = 0;
5902 j->cadence_f[lcp->filter].off1 = lcp->off1;
5903 j->cadence_f[lcp->filter].off1min = 0;
5904 j->cadence_f[lcp->filter].off1max = 0;
5905 j->cadence_f[lcp->filter].on2 = lcp->on2;
5906 j->cadence_f[lcp->filter].on2min = 0;
5907 j->cadence_f[lcp->filter].on2max = 0;
5908 j->cadence_f[lcp->filter].off2 = lcp->off2;
5909 j->cadence_f[lcp->filter].off2min = 0;
5910 j->cadence_f[lcp->filter].off2max = 0;
5911 j->cadence_f[lcp->filter].on3 = lcp->on3;
5912 j->cadence_f[lcp->filter].on3min = 0;
5913 j->cadence_f[lcp->filter].on3max = 0;
5914 j->cadence_f[lcp->filter].off3 = lcp->off3;
5915 j->cadence_f[lcp->filter].off3min = 0;
5916 j->cadence_f[lcp->filter].off3max = 0;
5917 if(ixjdebug & 0x0002) {
5918 printk(KERN_INFO "Cadence %d loaded\n", lcp->filter);
5919 }
5920 kfree(lcp);
5921 return 0;
5922}
5923
5924static void add_caps(IXJ *j)
5925{
5926 j->caps = 0;
5927 j->caplist[j->caps].cap = PHONE_VENDOR_QUICKNET;
5928 strcpy(j->caplist[j->caps].desc, "Quicknet Technologies, Inc. (www.quicknet.net)");
5929 j->caplist[j->caps].captype = vendor;
5930 j->caplist[j->caps].handle = j->caps++;
5931 j->caplist[j->caps].captype = device;
5932 switch (j->cardtype) {
5933 case QTI_PHONEJACK:
5934 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK");
5935 break;
5936 case QTI_LINEJACK:
5937 strcpy(j->caplist[j->caps].desc, "Quicknet Internet LineJACK");
5938 break;
5939 case QTI_PHONEJACK_LITE:
5940 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK Lite");
5941 break;
5942 case QTI_PHONEJACK_PCI:
5943 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK PCI");
5944 break;
5945 case QTI_PHONECARD:
5946 strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneCARD");
5947 break;
5948 }
5949 j->caplist[j->caps].cap = j->cardtype;
5950 j->caplist[j->caps].handle = j->caps++;
5951 strcpy(j->caplist[j->caps].desc, "POTS");
5952 j->caplist[j->caps].captype = port;
5953 j->caplist[j->caps].cap = pots;
5954 j->caplist[j->caps].handle = j->caps++;
5955
5956
5957 switch (j->cardtype) {
5958 case QTI_PHONEJACK:
5959 case QTI_LINEJACK:
5960 case QTI_PHONEJACK_PCI:
5961 case QTI_PHONECARD:
5962 strcpy(j->caplist[j->caps].desc, "SPEAKER");
5963 j->caplist[j->caps].captype = port;
5964 j->caplist[j->caps].cap = speaker;
5965 j->caplist[j->caps].handle = j->caps++;
5966 default:
5967 break;
5968 }
5969
5970
5971 switch (j->cardtype) {
5972 case QTI_PHONEJACK:
5973 strcpy(j->caplist[j->caps].desc, "HANDSET");
5974 j->caplist[j->caps].captype = port;
5975 j->caplist[j->caps].cap = handset;
5976 j->caplist[j->caps].handle = j->caps++;
5977 break;
5978 default:
5979 break;
5980 }
5981
5982
5983 switch (j->cardtype) {
5984 case QTI_LINEJACK:
5985 strcpy(j->caplist[j->caps].desc, "PSTN");
5986 j->caplist[j->caps].captype = port;
5987 j->caplist[j->caps].cap = pstn;
5988 j->caplist[j->caps].handle = j->caps++;
5989 break;
5990 default:
5991 break;
5992 }
5993
5994
5995 strcpy(j->caplist[j->caps].desc, "ULAW");
5996 j->caplist[j->caps].captype = codec;
5997 j->caplist[j->caps].cap = ULAW;
5998 j->caplist[j->caps].handle = j->caps++;
5999
6000 strcpy(j->caplist[j->caps].desc, "LINEAR 16 bit");
6001 j->caplist[j->caps].captype = codec;
6002 j->caplist[j->caps].cap = LINEAR16;
6003 j->caplist[j->caps].handle = j->caps++;
6004
6005 strcpy(j->caplist[j->caps].desc, "LINEAR 8 bit");
6006 j->caplist[j->caps].captype = codec;
6007 j->caplist[j->caps].cap = LINEAR8;
6008 j->caplist[j->caps].handle = j->caps++;
6009
6010 strcpy(j->caplist[j->caps].desc, "Windows Sound System");
6011 j->caplist[j->caps].captype = codec;
6012 j->caplist[j->caps].cap = WSS;
6013 j->caplist[j->caps].handle = j->caps++;
6014
6015
6016 strcpy(j->caplist[j->caps].desc, "ALAW");
6017 j->caplist[j->caps].captype = codec;
6018 j->caplist[j->caps].cap = ALAW;
6019 j->caplist[j->caps].handle = j->caps++;
6020
6021
6022 if (j->dsp.low != 0x20 || j->ver.low != 0x12) {
6023 strcpy(j->caplist[j->caps].desc, "G.723.1 6.3kbps");
6024 j->caplist[j->caps].captype = codec;
6025 j->caplist[j->caps].cap = G723_63;
6026 j->caplist[j->caps].handle = j->caps++;
6027
6028 strcpy(j->caplist[j->caps].desc, "G.723.1 5.3kbps");
6029 j->caplist[j->caps].captype = codec;
6030 j->caplist[j->caps].cap = G723_53;
6031 j->caplist[j->caps].handle = j->caps++;
6032
6033 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.8kbps");
6034 j->caplist[j->caps].captype = codec;
6035 j->caplist[j->caps].cap = TS48;
6036 j->caplist[j->caps].handle = j->caps++;
6037
6038 strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.1kbps");
6039 j->caplist[j->caps].captype = codec;
6040 j->caplist[j->caps].cap = TS41;
6041 j->caplist[j->caps].handle = j->caps++;
6042 }
6043
6044
6045 if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
6046 strcpy(j->caplist[j->caps].desc, "TrueSpeech 8.5kbps");
6047 j->caplist[j->caps].captype = codec;
6048 j->caplist[j->caps].cap = TS85;
6049 j->caplist[j->caps].handle = j->caps++;
6050 }
6051
6052
6053 if (j->dsp.low == 0x21) {
6054 strcpy(j->caplist[j->caps].desc, "G.728 16kbps");
6055 j->caplist[j->caps].captype = codec;
6056 j->caplist[j->caps].cap = G728;
6057 j->caplist[j->caps].handle = j->caps++;
6058 }
6059
6060
6061 if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6062 strcpy(j->caplist[j->caps].desc, "G.729A 8kbps");
6063 j->caplist[j->caps].captype = codec;
6064 j->caplist[j->caps].cap = G729;
6065 j->caplist[j->caps].handle = j->caps++;
6066 }
6067 if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
6068 strcpy(j->caplist[j->caps].desc, "G.729B 8kbps");
6069 j->caplist[j->caps].captype = codec;
6070 j->caplist[j->caps].cap = G729B;
6071 j->caplist[j->caps].handle = j->caps++;
6072 }
6073}
6074
6075static int capabilities_check(IXJ *j, struct phone_capability *pcreq)
6076{
6077 int cnt;
6078 int retval = 0;
6079 for (cnt = 0; cnt < j->caps; cnt++) {
6080 if (pcreq->captype == j->caplist[cnt].captype
6081 && pcreq->cap == j->caplist[cnt].cap) {
6082 retval = 1;
6083 break;
6084 }
6085 }
6086 return retval;
6087}
6088
6089static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6090{
6091 IXJ_TONE ti;
6092 IXJ_FILTER jf;
6093 IXJ_FILTER_RAW jfr;
6094 void __user *argp = (void __user *)arg;
6095 struct inode *inode = file_p->f_path.dentry->d_inode;
6096 unsigned int minor = iminor(inode);
6097 unsigned int raise, mant;
6098 int board = NUM(inode);
6099
6100 IXJ *j = get_ixj(NUM(inode));
6101
6102 int retval = 0;
6103
6104
6105
6106
6107
6108 while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
6109 schedule_timeout_interruptible(1);
6110 if (ixjdebug & 0x0040)
6111 printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6112 if (minor >= IXJMAX) {
6113 clear_bit(board, &j->busyflags);
6114 return -ENODEV;
6115 }
6116
6117
6118
6119 if (!capable(CAP_SYS_ADMIN)) {
6120 switch (cmd) {
6121 case IXJCTL_TESTRAM:
6122 case IXJCTL_HZ:
6123 retval = -EPERM;
6124 }
6125 }
6126 switch (cmd) {
6127 case IXJCTL_TESTRAM:
6128 ixj_testram(j);
6129 retval = (j->ssr.high << 8) + j->ssr.low;
6130 break;
6131 case IXJCTL_CARDTYPE:
6132 retval = j->cardtype;
6133 break;
6134 case IXJCTL_SERIAL:
6135 retval = j->serial;
6136 break;
6137 case IXJCTL_VERSION:
6138 {
6139 char arg_str[100];
6140 snprintf(arg_str, sizeof(arg_str),
6141 "\nDriver version %i.%i.%i", IXJ_VER_MAJOR,
6142 IXJ_VER_MINOR, IXJ_BLD_VER);
6143 if (copy_to_user(argp, arg_str, strlen(arg_str)))
6144 retval = -EFAULT;
6145 }
6146 break;
6147 case PHONE_RING_CADENCE:
6148 j->ring_cadence = arg;
6149 break;
6150 case IXJCTL_CIDCW:
6151 if(arg) {
6152 if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6153 retval = -EFAULT;
6154 break;
6155 }
6156 } else {
6157 memset(&j->cid_send, 0, sizeof(PHONE_CID));
6158 }
6159 ixj_write_cidcw(j);
6160 break;
6161
6162 case OLD_PHONE_RING_START:
6163 arg = 0;
6164
6165 case PHONE_RING_START:
6166 if(arg) {
6167 if (copy_from_user(&j->cid_send, argp, sizeof(PHONE_CID))) {
6168 retval = -EFAULT;
6169 break;
6170 }
6171 ixj_write_cid(j);
6172 } else {
6173 memset(&j->cid_send, 0, sizeof(PHONE_CID));
6174 }
6175 ixj_ring_start(j);
6176 break;
6177 case PHONE_RING_STOP:
6178 j->flags.cringing = 0;
6179 if(j->cadence_f[5].enable) {
6180 j->cadence_f[5].state = 0;
6181 }
6182 ixj_ring_off(j);
6183 break;
6184 case PHONE_RING:
6185 retval = ixj_ring(j);
6186 break;
6187 case PHONE_EXCEPTION:
6188 retval = j->ex.bytes;
6189 if(j->ex.bits.flash) {
6190 j->flash_end = 0;
6191 j->ex.bits.flash = 0;
6192 }
6193 j->ex.bits.pstn_ring = 0;
6194 j->ex.bits.caller_id = 0;
6195 j->ex.bits.pstn_wink = 0;
6196 j->ex.bits.f0 = 0;
6197 j->ex.bits.f1 = 0;
6198 j->ex.bits.f2 = 0;
6199 j->ex.bits.f3 = 0;
6200 j->ex.bits.fc0 = 0;
6201 j->ex.bits.fc1 = 0;
6202 j->ex.bits.fc2 = 0;
6203 j->ex.bits.fc3 = 0;
6204 j->ex.bits.reserved = 0;
6205 break;
6206 case PHONE_HOOKSTATE:
6207 j->ex.bits.hookstate = 0;
6208 retval = j->hookstate;
6209 break;
6210 case IXJCTL_SET_LED:
6211 LED_SetState(arg, j);
6212 break;
6213 case PHONE_FRAME:
6214 retval = set_base_frame(j, arg);
6215 break;
6216 case PHONE_REC_CODEC:
6217 retval = set_rec_codec(j, arg);
6218 break;
6219 case PHONE_VAD:
6220 ixj_vad(j, arg);
6221 break;
6222 case PHONE_REC_START:
6223 ixj_record_start(j);
6224 break;
6225 case PHONE_REC_STOP:
6226 ixj_record_stop(j);
6227 break;
6228 case PHONE_REC_DEPTH:
6229 set_rec_depth(j, arg);
6230 break;
6231 case PHONE_REC_VOLUME:
6232 if(arg == -1) {
6233 retval = get_rec_volume(j);
6234 }
6235 else {
6236 set_rec_volume(j, arg);
6237 retval = arg;
6238 }
6239 break;
6240 case PHONE_REC_VOLUME_LINEAR:
6241 if(arg == -1) {
6242 retval = get_rec_volume_linear(j);
6243 }
6244 else {
6245 set_rec_volume_linear(j, arg);
6246 retval = arg;
6247 }
6248 break;
6249 case IXJCTL_DTMF_PRESCALE:
6250 if(arg == -1) {
6251 retval = get_dtmf_prescale(j);
6252 }
6253 else {
6254 set_dtmf_prescale(j, arg);
6255 retval = arg;
6256 }
6257 break;
6258 case PHONE_REC_LEVEL:
6259 retval = get_rec_level(j);
6260 break;
6261 case IXJCTL_SC_RXG:
6262 retval = ixj_siadc(j, arg);
6263 break;
6264 case IXJCTL_SC_TXG:
6265 retval = ixj_sidac(j, arg);
6266 break;
6267 case IXJCTL_AEC_START:
6268 ixj_aec_start(j, arg);
6269 break;
6270 case IXJCTL_AEC_STOP:
6271 aec_stop(j);
6272 break;
6273 case IXJCTL_AEC_GET_LEVEL:
6274 retval = j->aec_level;
6275 break;
6276 case PHONE_PLAY_CODEC:
6277 retval = set_play_codec(j, arg);
6278 break;
6279 case PHONE_PLAY_START:
6280 retval = ixj_play_start(j);
6281 break;
6282 case PHONE_PLAY_STOP:
6283 ixj_play_stop(j);
6284 break;
6285 case PHONE_PLAY_DEPTH:
6286 set_play_depth(j, arg);
6287 break;
6288 case PHONE_PLAY_VOLUME:
6289 if(arg == -1) {
6290 retval = get_play_volume(j);
6291 }
6292 else {
6293 set_play_volume(j, arg);
6294 retval = arg;
6295 }
6296 break;
6297 case PHONE_PLAY_VOLUME_LINEAR:
6298 if(arg == -1) {
6299 retval = get_play_volume_linear(j);
6300 }
6301 else {
6302 set_play_volume_linear(j, arg);
6303 retval = arg;
6304 }
6305 break;
6306 case PHONE_PLAY_LEVEL:
6307 retval = get_play_level(j);
6308 break;
6309 case IXJCTL_DSP_TYPE:
6310 retval = (j->dsp.high << 8) + j->dsp.low;
6311 break;
6312 case IXJCTL_DSP_VERSION:
6313 retval = (j->ver.high << 8) + j->ver.low;
6314 break;
6315 case IXJCTL_HZ:
6316 hertz = arg;
6317 break;
6318 case IXJCTL_RATE:
6319 if (arg > hertz)
6320 retval = -1;
6321 else
6322 samplerate = arg;
6323 break;
6324 case IXJCTL_DRYBUFFER_READ:
6325 put_user(j->drybuffer, (unsigned long __user *) argp);
6326 break;
6327 case IXJCTL_DRYBUFFER_CLEAR:
6328 j->drybuffer = 0;
6329 break;
6330 case IXJCTL_FRAMES_READ:
6331 put_user(j->framesread, (unsigned long __user *) argp);
6332 break;
6333 case IXJCTL_FRAMES_WRITTEN:
6334 put_user(j->frameswritten, (unsigned long __user *) argp);
6335 break;
6336 case IXJCTL_READ_WAIT:
6337 put_user(j->read_wait, (unsigned long __user *) argp);
6338 break;
6339 case IXJCTL_WRITE_WAIT:
6340 put_user(j->write_wait, (unsigned long __user *) argp);
6341 break;
6342 case PHONE_MAXRINGS:
6343 j->maxrings = arg;
6344 break;
6345 case PHONE_SET_TONE_ON_TIME:
6346 ixj_set_tone_on(arg, j);
6347 break;
6348 case PHONE_SET_TONE_OFF_TIME:
6349 ixj_set_tone_off(arg, j);
6350 break;
6351 case PHONE_GET_TONE_ON_TIME:
6352 if (ixj_get_tone_on(j)) {
6353 retval = -1;
6354 } else {
6355 retval = (j->ssr.high << 8) + j->ssr.low;
6356 }
6357 break;
6358 case PHONE_GET_TONE_OFF_TIME:
6359 if (ixj_get_tone_off(j)) {
6360 retval = -1;
6361 } else {
6362 retval = (j->ssr.high << 8) + j->ssr.low;
6363 }
6364 break;
6365 case PHONE_PLAY_TONE:
6366 if (!j->tone_state)
6367 retval = ixj_play_tone(j, arg);
6368 else
6369 retval = -1;
6370 break;
6371 case PHONE_GET_TONE_STATE:
6372 retval = j->tone_state;
6373 break;
6374 case PHONE_DTMF_READY:
6375 retval = j->ex.bits.dtmf_ready;
6376 break;
6377 case PHONE_GET_DTMF:
6378 if (ixj_hookstate(j)) {
6379 if (j->dtmf_rp != j->dtmf_wp) {
6380 retval = j->dtmfbuffer[j->dtmf_rp];
6381 j->dtmf_rp++;
6382 if (j->dtmf_rp == 79)
6383 j->dtmf_rp = 0;
6384 if (j->dtmf_rp == j->dtmf_wp) {
6385 j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6386 }
6387 }
6388 }
6389 break;
6390 case PHONE_GET_DTMF_ASCII:
6391 if (ixj_hookstate(j)) {
6392 if (j->dtmf_rp != j->dtmf_wp) {
6393 switch (j->dtmfbuffer[j->dtmf_rp]) {
6394 case 10:
6395 retval = 42;
6396
6397 break;
6398 case 11:
6399 retval = 48;
6400
6401 break;
6402 case 12:
6403 retval = 35;
6404
6405 break;
6406 case 28:
6407 retval = 65;
6408
6409 break;
6410 case 29:
6411 retval = 66;
6412
6413 break;
6414 case 30:
6415 retval = 67;
6416
6417 break;
6418 case 31:
6419 retval = 68;
6420
6421 break;
6422 default:
6423 retval = 48 + j->dtmfbuffer[j->dtmf_rp];
6424 break;
6425 }
6426 j->dtmf_rp++;
6427 if (j->dtmf_rp == 79)
6428 j->dtmf_rp = 0;
6429 if(j->dtmf_rp == j->dtmf_wp)
6430 {
6431 j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
6432 }
6433 }
6434 }
6435 break;
6436 case PHONE_DTMF_OOB:
6437 j->flags.dtmf_oob = arg;
6438 break;
6439 case PHONE_DIALTONE:
6440 ixj_dialtone(j);
6441 break;
6442 case PHONE_BUSY:
6443 ixj_busytone(j);
6444 break;
6445 case PHONE_RINGBACK:
6446 ixj_ringback(j);
6447 break;
6448 case PHONE_WINK:
6449 if(j->cardtype == QTI_PHONEJACK)
6450 retval = -1;
6451 else
6452 retval = ixj_wink(j);
6453 break;
6454 case PHONE_CPT_STOP:
6455 ixj_cpt_stop(j);
6456 break;
6457 case PHONE_QUERY_CODEC:
6458 {
6459 struct phone_codec_data pd;
6460 int val;
6461 int proto_size[] = {
6462 -1,
6463 12, 10, 16, 9, 8, 48, 5,
6464 40, 40, 80, 40, 40, 6
6465 };
6466 if(copy_from_user(&pd, argp, sizeof(pd))) {
6467 retval = -EFAULT;
6468 break;
6469 }
6470 if(pd.type<1 || pd.type>13) {
6471 retval = -EPROTONOSUPPORT;
6472 break;
6473 }
6474 if(pd.type<G729)
6475 val=proto_size[pd.type];
6476 else switch(j->baseframe.low)
6477 {
6478 case 0xA0:val=2*proto_size[pd.type];break;
6479 case 0x50:val=proto_size[pd.type];break;
6480 default:val=proto_size[pd.type]*3;break;
6481 }
6482 pd.buf_min=pd.buf_max=pd.buf_opt=val;
6483 if(copy_to_user(argp, &pd, sizeof(pd)))
6484 retval = -EFAULT;
6485 break;
6486 }
6487 case IXJCTL_DSP_IDLE:
6488 idle(j);
6489 break;
6490 case IXJCTL_MIXER:
6491 if ((arg & 0xff) == 0xff)
6492 retval = ixj_get_mixer(arg, j);
6493 else
6494 ixj_mixer(arg, j);
6495 break;
6496 case IXJCTL_DAA_COEFF_SET:
6497 switch (arg) {
6498 case DAA_US:
6499 DAA_Coeff_US(j);
6500 retval = ixj_daa_write(j);
6501 break;
6502 case DAA_UK:
6503 DAA_Coeff_UK(j);
6504 retval = ixj_daa_write(j);
6505 break;
6506 case DAA_FRANCE:
6507 DAA_Coeff_France(j);
6508 retval = ixj_daa_write(j);
6509 break;
6510 case DAA_GERMANY:
6511 DAA_Coeff_Germany(j);
6512 retval = ixj_daa_write(j);
6513 break;
6514 case DAA_AUSTRALIA:
6515 DAA_Coeff_Australia(j);
6516 retval = ixj_daa_write(j);
6517 break;
6518 case DAA_JAPAN:
6519 DAA_Coeff_Japan(j);
6520 retval = ixj_daa_write(j);
6521 break;
6522 default:
6523 retval = 1;
6524 break;
6525 }
6526 break;
6527 case IXJCTL_DAA_AGAIN:
6528 ixj_daa_cr4(j, arg | 0x02);
6529 break;
6530 case IXJCTL_PSTN_LINETEST:
6531 retval = ixj_linetest(j);
6532 break;
6533 case IXJCTL_VMWI:
6534 ixj_write_vmwi(j, arg);
6535 break;
6536 case IXJCTL_CID:
6537 if (copy_to_user(argp, &j->cid, sizeof(PHONE_CID)))
6538 retval = -EFAULT;
6539 j->ex.bits.caller_id = 0;
6540 break;
6541 case IXJCTL_WINK_DURATION:
6542 j->winktime = arg;
6543 break;
6544 case IXJCTL_PORT:
6545 if (arg)
6546 retval = ixj_set_port(j, arg);
6547 else
6548 retval = j->port;
6549 break;
6550 case IXJCTL_POTS_PSTN:
6551 retval = ixj_set_pots(j, arg);
6552 break;
6553 case PHONE_CAPABILITIES:
6554 add_caps(j);
6555 retval = j->caps;
6556 break;
6557 case PHONE_CAPABILITIES_LIST:
6558 add_caps(j);
6559 if (copy_to_user(argp, j->caplist, sizeof(struct phone_capability) * j->caps))
6560 retval = -EFAULT;
6561 break;
6562 case PHONE_CAPABILITIES_CHECK:
6563 {
6564 struct phone_capability cap;
6565 if (copy_from_user(&cap, argp, sizeof(cap)))
6566 retval = -EFAULT;
6567 else {
6568 add_caps(j);
6569 retval = capabilities_check(j, &cap);
6570 }
6571 }
6572 break;
6573 case PHONE_PSTN_SET_STATE:
6574 daa_set_mode(j, arg);
6575 break;
6576 case PHONE_PSTN_GET_STATE:
6577 retval = j->daa_mode;
6578 j->ex.bits.pstn_ring = 0;
6579 break;
6580 case IXJCTL_SET_FILTER:
6581 if (copy_from_user(&jf, argp, sizeof(jf)))
6582 retval = -EFAULT;
6583 else
6584 retval = ixj_init_filter(j, &jf);
6585 break;
6586 case IXJCTL_SET_FILTER_RAW:
6587 if (copy_from_user(&jfr, argp, sizeof(jfr)))
6588 retval = -EFAULT;
6589 else
6590 retval = ixj_init_filter_raw(j, &jfr);
6591 break;
6592 case IXJCTL_GET_FILTER_HIST:
6593 if(arg<0||arg>3)
6594 retval = -EINVAL;
6595 else
6596 retval = j->filter_hist[arg];
6597 break;
6598 case IXJCTL_INIT_TONE:
6599 if (copy_from_user(&ti, argp, sizeof(ti)))
6600 retval = -EFAULT;
6601 else
6602 retval = ixj_init_tone(j, &ti);
6603 break;
6604 case IXJCTL_TONE_CADENCE:
6605 retval = ixj_build_cadence(j, argp);
6606 break;
6607 case IXJCTL_FILTER_CADENCE:
6608 retval = ixj_build_filter_cadence(j, argp);
6609 break;
6610 case IXJCTL_SIGCTL:
6611 if (copy_from_user(&j->sigdef, argp, sizeof(IXJ_SIGDEF))) {
6612 retval = -EFAULT;
6613 break;
6614 }
6615 j->ixj_signals[j->sigdef.event] = j->sigdef.signal;
6616 if(j->sigdef.event < 33) {
6617 raise = 1;
6618 for(mant = 0; mant < j->sigdef.event; mant++){
6619 raise *= 2;
6620 }
6621 if(j->sigdef.signal)
6622 j->ex_sig.bytes |= raise;
6623 else
6624 j->ex_sig.bytes &= (raise^0xffff);
6625 }
6626 break;
6627 case IXJCTL_INTERCOM_STOP:
6628 if(arg < 0 || arg >= IXJMAX)
6629 return -EINVAL;
6630 j->intercom = -1;
6631 ixj_record_stop(j);
6632 ixj_play_stop(j);
6633 idle(j);
6634 get_ixj(arg)->intercom = -1;
6635 ixj_record_stop(get_ixj(arg));
6636 ixj_play_stop(get_ixj(arg));
6637 idle(get_ixj(arg));
6638 break;
6639 case IXJCTL_INTERCOM_START:
6640 if(arg < 0 || arg >= IXJMAX)
6641 return -EINVAL;
6642 j->intercom = arg;
6643 ixj_record_start(j);
6644 ixj_play_start(j);
6645 get_ixj(arg)->intercom = board;
6646 ixj_play_start(get_ixj(arg));
6647 ixj_record_start(get_ixj(arg));
6648 break;
6649 }
6650 if (ixjdebug & 0x0040)
6651 printk("phone%d ioctl end, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6652 clear_bit(board, &j->busyflags);
6653 return retval;
6654}
6655
6656static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6657{
6658 long ret;
6659 mutex_lock(&ixj_mutex);
6660 ret = do_ixj_ioctl(file_p, cmd, arg);
6661 mutex_unlock(&ixj_mutex);
6662 return ret;
6663}
6664
6665static int ixj_fasync(int fd, struct file *file_p, int mode)
6666{
6667 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
6668
6669 return fasync_helper(fd, file_p, mode, &j->async_queue);
6670}
6671
6672static const struct file_operations ixj_fops =
6673{
6674 .owner = THIS_MODULE,
6675 .read = ixj_enhanced_read,
6676 .write = ixj_enhanced_write,
6677 .poll = ixj_poll,
6678 .unlocked_ioctl = ixj_ioctl,
6679 .release = ixj_release,
6680 .fasync = ixj_fasync,
6681 .llseek = default_llseek,
6682};
6683
6684static int ixj_linetest(IXJ *j)
6685{
6686 j->flags.pstncheck = 1;
6687 j->flags.pstn_present = 0;
6688
6689 daa_int_read(j);
6690
6691
6692
6693
6694 j->pld_slicw.bits.rly1 = 0;
6695 j->pld_slicw.bits.rly2 = 0;
6696 j->pld_slicw.bits.rly3 = 0;
6697 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6698 j->pld_scrw.bits.daafsyncen = 0;
6699
6700 outb_p(j->pld_scrw.byte, j->XILINXbase);
6701 j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
6702 if (j->pld_slicr.bits.potspstn) {
6703 j->flags.pots_pstn = 1;
6704 j->flags.pots_correct = 0;
6705 LED_SetState(0x4, j);
6706 } else {
6707 j->flags.pots_pstn = 0;
6708 j->pld_slicw.bits.rly1 = 0;
6709 j->pld_slicw.bits.rly2 = 0;
6710 j->pld_slicw.bits.rly3 = 1;
6711 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6712 j->pld_scrw.bits.daafsyncen = 0;
6713
6714 outb_p(j->pld_scrw.byte, j->XILINXbase);
6715 daa_set_mode(j, SOP_PU_CONVERSATION);
6716 msleep(1000);
6717 daa_int_read(j);
6718 daa_set_mode(j, SOP_PU_RESET);
6719 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6720 j->flags.pots_correct = 0;
6721 LED_SetState(0x4, j);
6722 j->pld_slicw.bits.rly3 = 0;
6723 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6724 } else {
6725 j->flags.pots_correct = 1;
6726 LED_SetState(0x8, j);
6727 j->pld_slicw.bits.rly1 = 1;
6728 j->pld_slicw.bits.rly2 = 0;
6729 j->pld_slicw.bits.rly3 = 0;
6730 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6731 }
6732 }
6733 j->pld_slicw.bits.rly3 = 0;
6734 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6735 daa_set_mode(j, SOP_PU_CONVERSATION);
6736 msleep(1000);
6737 daa_int_read(j);
6738 daa_set_mode(j, SOP_PU_RESET);
6739 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
6740 j->pstn_sleeptil = jiffies + (hertz / 4);
6741 j->flags.pstn_present = 1;
6742 } else {
6743 j->flags.pstn_present = 0;
6744 }
6745 if (j->flags.pstn_present) {
6746 if (j->flags.pots_correct) {
6747 LED_SetState(0xA, j);
6748 } else {
6749 LED_SetState(0x6, j);
6750 }
6751 } else {
6752 if (j->flags.pots_correct) {
6753 LED_SetState(0x9, j);
6754 } else {
6755 LED_SetState(0x5, j);
6756 }
6757 }
6758 j->flags.pstncheck = 0;
6759 return j->flags.pstn_present;
6760}
6761
6762static int ixj_selfprobe(IXJ *j)
6763{
6764 unsigned short cmd;
6765 int cnt;
6766 BYTES bytes;
6767
6768 init_waitqueue_head(&j->poll_q);
6769 init_waitqueue_head(&j->read_q);
6770 init_waitqueue_head(&j->write_q);
6771
6772 while(atomic_read(&j->DSPWrite) > 0)
6773 atomic_dec(&j->DSPWrite);
6774 if (ixjdebug & 0x0002)
6775 printk(KERN_INFO "Write IDLE to Software Control Register\n");
6776 ixj_WriteDSPCommand(0x0FE0, j);
6777
6778 if (ixj_WriteDSPCommand(0x0000, j))
6779 return -1;
6780
6781 if (j->ssr.low || j->ssr.high)
6782 return -1;
6783 if (ixjdebug & 0x0002)
6784 printk(KERN_INFO "Get Device ID Code\n");
6785 if (ixj_WriteDSPCommand(0x3400, j))
6786 return -1;
6787 j->dsp.low = j->ssr.low;
6788 j->dsp.high = j->ssr.high;
6789 if (ixjdebug & 0x0002)
6790 printk(KERN_INFO "Get Device Version Code\n");
6791 if (ixj_WriteDSPCommand(0x3800, j))
6792 return -1;
6793 j->ver.low = j->ssr.low;
6794 j->ver.high = j->ssr.high;
6795 if (!j->cardtype) {
6796 if (j->dsp.low == 0x21) {
6797 bytes.high = bytes.low = inb_p(j->XILINXbase + 0x02);
6798 outb_p(bytes.low ^ 0xFF, j->XILINXbase + 0x02);
6799
6800 bytes.low = inb_p(j->XILINXbase + 0x02);
6801 if (bytes.low == bytes.high)
6802
6803 {
6804 j->cardtype = QTI_PHONEJACK_LITE;
6805 if (!request_region(j->XILINXbase, 4, "ixj control")) {
6806 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6807 return -1;
6808 }
6809 j->pld_slicw.pcib.e1 = 1;
6810 outb_p(j->pld_slicw.byte, j->XILINXbase);
6811 } else {
6812 j->cardtype = QTI_LINEJACK;
6813
6814 if (!request_region(j->XILINXbase, 8, "ixj control")) {
6815 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6816 return -1;
6817 }
6818 }
6819 } else if (j->dsp.low == 0x22) {
6820 j->cardtype = QTI_PHONEJACK_PCI;
6821 request_region(j->XILINXbase, 4, "ixj control");
6822 j->pld_slicw.pcib.e1 = 1;
6823 outb_p(j->pld_slicw.byte, j->XILINXbase);
6824 } else
6825 j->cardtype = QTI_PHONEJACK;
6826 } else {
6827 switch (j->cardtype) {
6828 case QTI_PHONEJACK:
6829 if (!j->dsp.low != 0x20) {
6830 j->dsp.high = 0x80;
6831 j->dsp.low = 0x20;
6832 ixj_WriteDSPCommand(0x3800, j);
6833 j->ver.low = j->ssr.low;
6834 j->ver.high = j->ssr.high;
6835 }
6836 break;
6837 case QTI_LINEJACK:
6838 if (!request_region(j->XILINXbase, 8, "ixj control")) {
6839 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6840 return -1;
6841 }
6842 break;
6843 case QTI_PHONEJACK_LITE:
6844 case QTI_PHONEJACK_PCI:
6845 if (!request_region(j->XILINXbase, 4, "ixj control")) {
6846 printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);
6847 return -1;
6848 }
6849 j->pld_slicw.pcib.e1 = 1;
6850 outb_p(j->pld_slicw.byte, j->XILINXbase);
6851 break;
6852 case QTI_PHONECARD:
6853 break;
6854 }
6855 }
6856 if (j->dsp.low == 0x20 || j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
6857 if (ixjdebug & 0x0002)
6858 printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6859 if (ixj_WriteDSPCommand(0xC462, j))
6860 return -1;
6861 if (ixjdebug & 0x0002)
6862 printk(KERN_INFO "Write CODEC timing to Software Control Register\n");
6863 if (j->cardtype == QTI_PHONEJACK) {
6864 cmd = 0x9FF2;
6865 } else {
6866 cmd = 0x9FF5;
6867 }
6868 if (ixj_WriteDSPCommand(cmd, j))
6869 return -1;
6870 } else {
6871 if (set_base_frame(j, 30) != 30)
6872 return -1;
6873 if (ixjdebug & 0x0002)
6874 printk(KERN_INFO "Write CODEC config to Software Control Register\n");
6875 if (j->cardtype == QTI_PHONECARD) {
6876 if (ixj_WriteDSPCommand(0xC528, j))
6877 return -1;
6878 }
6879 if (j->cardtype == QTI_LINEJACK) {
6880 if (ixj_WriteDSPCommand(0xC528, j))
6881 return -1;
6882 if (ixjdebug & 0x0002)
6883 printk(KERN_INFO "Turn on the PLD Clock at 8Khz\n");
6884 j->pld_clock.byte = 0;
6885 outb_p(j->pld_clock.byte, j->XILINXbase + 0x04);
6886 }
6887 }
6888
6889 if (j->dsp.low == 0x20) {
6890 if (ixjdebug & 0x0002)
6891 printk(KERN_INFO "Configure GPIO pins\n");
6892 j->gpio.bytes.high = 0x09;
6893
6894 j->gpio.bits.gpio1 = 1;
6895 j->gpio.bits.gpio2 = 1;
6896 j->gpio.bits.gpio3 = 0;
6897 j->gpio.bits.gpio4 = 1;
6898 j->gpio.bits.gpio5 = 1;
6899 j->gpio.bits.gpio6 = 1;
6900 j->gpio.bits.gpio7 = 1;
6901 ixj_WriteDSPCommand(j->gpio.word, j);
6902 if (ixjdebug & 0x0002)
6903 printk(KERN_INFO "Enable SLIC\n");
6904 j->gpio.bytes.high = 0x0B;
6905 j->gpio.bytes.low = 0x00;
6906 j->gpio.bits.gpio1 = 0;
6907 j->gpio.bits.gpio2 = 1;
6908 j->gpio.bits.gpio5 = 0;
6909 ixj_WriteDSPCommand(j->gpio.word, j);
6910 j->port = PORT_POTS;
6911 } else {
6912 if (j->cardtype == QTI_LINEJACK) {
6913 LED_SetState(0x1, j);
6914 msleep(100);
6915 LED_SetState(0x2, j);
6916 msleep(100);
6917 LED_SetState(0x4, j);
6918 msleep(100);
6919 LED_SetState(0x8, j);
6920 msleep(100);
6921 LED_SetState(0x0, j);
6922 daa_get_version(j);
6923 if (ixjdebug & 0x0002)
6924 printk("Loading DAA Coefficients\n");
6925 DAA_Coeff_US(j);
6926 if (!ixj_daa_write(j)) {
6927 printk("DAA write failed on board %d\n", j->board);
6928 return -1;
6929 }
6930 if(!ixj_daa_cid_reset(j)) {
6931 printk("DAA CID reset failed on board %d\n", j->board);
6932 return -1;
6933 }
6934 j->flags.pots_correct = 0;
6935 j->flags.pstn_present = 0;
6936 ixj_linetest(j);
6937 if (j->flags.pots_correct) {
6938 j->pld_scrw.bits.daafsyncen = 0;
6939
6940 outb_p(j->pld_scrw.byte, j->XILINXbase);
6941 j->pld_slicw.bits.rly1 = 1;
6942 j->pld_slicw.bits.spken = 1;
6943 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6944 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
6945
6946 j->port = PORT_POTS;
6947 }
6948 ixj_set_port(j, PORT_PSTN);
6949 ixj_set_pots(j, 1);
6950 if (ixjdebug & 0x0002)
6951 printk(KERN_INFO "Enable Mixer\n");
6952 ixj_mixer(0x0000, j);
6953 ixj_mixer(0x0100, j);
6954
6955 ixj_mixer(0x0203, j);
6956 ixj_mixer(0x0303, j);
6957
6958 ixj_mixer(0x0480, j);
6959 ixj_mixer(0x0580, j);
6960
6961 ixj_mixer(0x0680, j);
6962 ixj_mixer(0x0780, j);
6963
6964 ixj_mixer(0x0880, j);
6965 ixj_mixer(0x0980, j);
6966
6967 ixj_mixer(0x0A80, j);
6968 ixj_mixer(0x0B80, j);
6969
6970 ixj_mixer(0x0C00, j);
6971 ixj_mixer(0x0D80, j);
6972
6973 ixj_mixer(0x0E80, j);
6974
6975 ixj_mixer(0x0F00, j);
6976
6977 ixj_mixer(0x1000, j);
6978 ixj_mixer(0x110C, j);
6979
6980
6981 ixj_mixer(0x1200, j);
6982 ixj_mixer(0x1401, j);
6983
6984 ixj_mixer(0x1300, j);
6985 ixj_mixer(0x1501, j);
6986
6987 ixj_mixer(0x1700, j);
6988
6989 ixj_mixer(0x1800, j);
6990
6991 ixj_mixer(0x1901, j);
6992
6993 if (ixjdebug & 0x0002)
6994 printk(KERN_INFO "Setting Default US Ring Cadence Detection\n");
6995 j->cadence_f[4].state = 0;
6996 j->cadence_f[4].on1 = 0;
6997 j->cadence_f[4].off1 = 0;
6998 j->cadence_f[4].on2 = 0;
6999 j->cadence_f[4].off2 = 0;
7000 j->cadence_f[4].on3 = 0;
7001 j->cadence_f[4].off3 = 0;
7002 j->pstn_last_rmr = jiffies;
7003
7004 } else {
7005 if (j->cardtype == QTI_PHONECARD) {
7006 ixj_WriteDSPCommand(0xCF07, j);
7007 ixj_WriteDSPCommand(0x00B0, j);
7008 ixj_set_port(j, PORT_SPEAKER);
7009 } else {
7010 ixj_set_port(j, PORT_POTS);
7011 SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
7012
7013 }
7014 }
7015 }
7016
7017 j->intercom = -1;
7018 j->framesread = j->frameswritten = 0;
7019 j->read_wait = j->write_wait = 0;
7020 j->rxreadycheck = j->txreadycheck = 0;
7021
7022
7023 if (j->cardtype == QTI_LINEJACK) {
7024 set_dtmf_prescale(j, 0x10);
7025 } else {
7026 set_dtmf_prescale(j, 0x40);
7027 }
7028 set_play_volume(j, 0x100);
7029 set_rec_volume(j, 0x100);
7030
7031 if (ixj_WriteDSPCommand(0x0000, j))
7032 return -1;
7033
7034 if (j->ssr.low || j->ssr.high)
7035 return -1;
7036
7037 if (ixjdebug & 0x0002)
7038 printk(KERN_INFO "Enable Line Monitor\n");
7039
7040 if (ixjdebug & 0x0002)
7041 printk(KERN_INFO "Set Line Monitor to Asyncronous Mode\n");
7042
7043 if (ixj_WriteDSPCommand(0x7E01, j))
7044 return -1;
7045
7046 if (ixjdebug & 0x002)
7047 printk(KERN_INFO "Enable DTMF Detectors\n");
7048
7049 if (ixj_WriteDSPCommand(0x5151, j))
7050 return -1;
7051
7052 if (ixj_WriteDSPCommand(0x6E01, j))
7053 return -1;
7054
7055 set_rec_depth(j, 2);
7056
7057 set_play_depth(j, 2);
7058
7059 j->ex.bits.dtmf_ready = 0;
7060 j->dtmf_state = 0;
7061 j->dtmf_wp = j->dtmf_rp = 0;
7062 j->rec_mode = j->play_mode = -1;
7063 j->flags.ringing = 0;
7064 j->maxrings = MAXRINGS;
7065 j->ring_cadence = USA_RING_CADENCE;
7066 j->drybuffer = 0;
7067 j->winktime = 320;
7068 j->flags.dtmf_oob = 0;
7069 for (cnt = 0; cnt < 4; cnt++)
7070 j->cadence_f[cnt].enable = 0;
7071
7072 ixj_WriteDSPCommand(0x0FE3, j);
7073
7074
7075 for (cnt = 0; cnt < 35; cnt++)
7076 j->ixj_signals[cnt] = SIGIO;
7077
7078
7079 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring =
7080 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 =
7081 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;
7082#ifdef IXJ_DYN_ALLOC
7083 j->fskdata = NULL;
7084#endif
7085 j->fskdcnt = 0;
7086 j->cidcw_wait = 0;
7087
7088
7089 j->p.f_op = &ixj_fops;
7090 j->p.open = ixj_open;
7091 j->p.board = j->board;
7092 phone_register_device(&j->p, PHONE_UNIT_ANY);
7093
7094 ixj_init_timer(j);
7095 ixj_add_timer(j);
7096 return 0;
7097}
7098
7099
7100
7101
7102
7103IXJ *ixj_pcmcia_probe(unsigned long dsp, unsigned long xilinx)
7104{
7105 IXJ *j = ixj_alloc();
7106
7107 j->board = 0;
7108
7109 j->DSPbase = dsp;
7110 j->XILINXbase = xilinx;
7111 j->cardtype = QTI_PHONECARD;
7112 ixj_selfprobe(j);
7113 return j;
7114}
7115
7116EXPORT_SYMBOL(ixj_pcmcia_probe);
7117
7118static int ixj_get_status_proc(char *buf)
7119{
7120 int len;
7121 int cnt;
7122 IXJ *j;
7123 len = 0;
7124 len += sprintf(buf + len, "\nDriver version %i.%i.%i", IXJ_VER_MAJOR, IXJ_VER_MINOR, IXJ_BLD_VER);
7125 len += sprintf(buf + len, "\nsizeof IXJ struct %Zd bytes", sizeof(IXJ));
7126 len += sprintf(buf + len, "\nsizeof DAA struct %Zd bytes", sizeof(DAA_REGS));
7127 len += sprintf(buf + len, "\nUsing old telephony API");
7128 len += sprintf(buf + len, "\nDebug Level %d\n", ixjdebug);
7129
7130 for (cnt = 0; cnt < IXJMAX; cnt++) {
7131 j = get_ixj(cnt);
7132 if(j==NULL)
7133 continue;
7134 if (j->DSPbase) {
7135 len += sprintf(buf + len, "\nCard Num %d", cnt);
7136 len += sprintf(buf + len, "\nDSP Base Address 0x%4.4x", j->DSPbase);
7137 if (j->cardtype != QTI_PHONEJACK)
7138 len += sprintf(buf + len, "\nXILINX Base Address 0x%4.4x", j->XILINXbase);
7139 len += sprintf(buf + len, "\nDSP Type %2.2x%2.2x", j->dsp.high, j->dsp.low);
7140 len += sprintf(buf + len, "\nDSP Version %2.2x.%2.2x", j->ver.high, j->ver.low);
7141 len += sprintf(buf + len, "\nSerial Number %8.8x", j->serial);
7142 switch (j->cardtype) {
7143 case (QTI_PHONEJACK):
7144 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK");
7145 break;
7146 case (QTI_LINEJACK):
7147 len += sprintf(buf + len, "\nCard Type = Internet LineJACK");
7148 if (j->flags.g729_loaded)
7149 len += sprintf(buf + len, " w/G.729 A/B");
7150 len += sprintf(buf + len, " Country = %d", j->daa_country);
7151 break;
7152 case (QTI_PHONEJACK_LITE):
7153 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK Lite");
7154 if (j->flags.g729_loaded)
7155 len += sprintf(buf + len, " w/G.729 A/B");
7156 break;
7157 case (QTI_PHONEJACK_PCI):
7158 len += sprintf(buf + len, "\nCard Type = Internet PhoneJACK PCI");
7159 if (j->flags.g729_loaded)
7160 len += sprintf(buf + len, " w/G.729 A/B");
7161 break;
7162 case (QTI_PHONECARD):
7163 len += sprintf(buf + len, "\nCard Type = Internet PhoneCARD");
7164 if (j->flags.g729_loaded)
7165 len += sprintf(buf + len, " w/G.729 A/B");
7166 len += sprintf(buf + len, "\nSmart Cable %spresent", j->pccr1.bits.drf ? "not " : "");
7167 if (!j->pccr1.bits.drf)
7168 len += sprintf(buf + len, "\nSmart Cable type %d", j->flags.pcmciasct);
7169 len += sprintf(buf + len, "\nSmart Cable state %d", j->flags.pcmciastate);
7170 break;
7171 default:
7172 len += sprintf(buf + len, "\nCard Type = %d", j->cardtype);
7173 break;
7174 }
7175 len += sprintf(buf + len, "\nReaders %d", j->readers);
7176 len += sprintf(buf + len, "\nWriters %d", j->writers);
7177 add_caps(j);
7178 len += sprintf(buf + len, "\nCapabilities %d", j->caps);
7179 if (j->dsp.low != 0x20)
7180 len += sprintf(buf + len, "\nDSP Processor load %d", j->proc_load);
7181 if (j->flags.cidsent)
7182 len += sprintf(buf + len, "\nCaller ID data sent");
7183 else
7184 len += sprintf(buf + len, "\nCaller ID data not sent");
7185
7186 len += sprintf(buf + len, "\nPlay CODEC ");
7187 switch (j->play_codec) {
7188 case G723_63:
7189 len += sprintf(buf + len, "G.723.1 6.3");
7190 break;
7191 case G723_53:
7192 len += sprintf(buf + len, "G.723.1 5.3");
7193 break;
7194 case TS85:
7195 len += sprintf(buf + len, "TrueSpeech 8.5");
7196 break;
7197 case TS48:
7198 len += sprintf(buf + len, "TrueSpeech 4.8");
7199 break;
7200 case TS41:
7201 len += sprintf(buf + len, "TrueSpeech 4.1");
7202 break;
7203 case G728:
7204 len += sprintf(buf + len, "G.728");
7205 break;
7206 case G729:
7207 len += sprintf(buf + len, "G.729");
7208 break;
7209 case G729B:
7210 len += sprintf(buf + len, "G.729B");
7211 break;
7212 case ULAW:
7213 len += sprintf(buf + len, "uLaw");
7214 break;
7215 case ALAW:
7216 len += sprintf(buf + len, "aLaw");
7217 break;
7218 case LINEAR16:
7219 len += sprintf(buf + len, "16 bit Linear");
7220 break;
7221 case LINEAR8:
7222 len += sprintf(buf + len, "8 bit Linear");
7223 break;
7224 case WSS:
7225 len += sprintf(buf + len, "Windows Sound System");
7226 break;
7227 default:
7228 len += sprintf(buf + len, "NO CODEC CHOSEN");
7229 break;
7230 }
7231 len += sprintf(buf + len, "\nRecord CODEC ");
7232 switch (j->rec_codec) {
7233 case G723_63:
7234 len += sprintf(buf + len, "G.723.1 6.3");
7235 break;
7236 case G723_53:
7237 len += sprintf(buf + len, "G.723.1 5.3");
7238 break;
7239 case TS85:
7240 len += sprintf(buf + len, "TrueSpeech 8.5");
7241 break;
7242 case TS48:
7243 len += sprintf(buf + len, "TrueSpeech 4.8");
7244 break;
7245 case TS41:
7246 len += sprintf(buf + len, "TrueSpeech 4.1");
7247 break;
7248 case G728:
7249 len += sprintf(buf + len, "G.728");
7250 break;
7251 case G729:
7252 len += sprintf(buf + len, "G.729");
7253 break;
7254 case G729B:
7255 len += sprintf(buf + len, "G.729B");
7256 break;
7257 case ULAW:
7258 len += sprintf(buf + len, "uLaw");
7259 break;
7260 case ALAW:
7261 len += sprintf(buf + len, "aLaw");
7262 break;
7263 case LINEAR16:
7264 len += sprintf(buf + len, "16 bit Linear");
7265 break;
7266 case LINEAR8:
7267 len += sprintf(buf + len, "8 bit Linear");
7268 break;
7269 case WSS:
7270 len += sprintf(buf + len, "Windows Sound System");
7271 break;
7272 default:
7273 len += sprintf(buf + len, "NO CODEC CHOSEN");
7274 break;
7275 }
7276 len += sprintf(buf + len, "\nAEC ");
7277 switch (j->aec_level) {
7278 case AEC_OFF:
7279 len += sprintf(buf + len, "Off");
7280 break;
7281 case AEC_LOW:
7282 len += sprintf(buf + len, "Low");
7283 break;
7284 case AEC_MED:
7285 len += sprintf(buf + len, "Med");
7286 break;
7287 case AEC_HIGH:
7288 len += sprintf(buf + len, "High");
7289 break;
7290 case AEC_AUTO:
7291 len += sprintf(buf + len, "Auto");
7292 break;
7293 case AEC_AGC:
7294 len += sprintf(buf + len, "AEC/AGC");
7295 break;
7296 default:
7297 len += sprintf(buf + len, "unknown(%i)", j->aec_level);
7298 break;
7299 }
7300
7301 len += sprintf(buf + len, "\nRec volume 0x%x", get_rec_volume(j));
7302 len += sprintf(buf + len, "\nPlay volume 0x%x", get_play_volume(j));
7303 len += sprintf(buf + len, "\nDTMF prescale 0x%x", get_dtmf_prescale(j));
7304
7305 len += sprintf(buf + len, "\nHook state %d", j->hookstate);
7306
7307 if (j->cardtype == QTI_LINEJACK) {
7308 len += sprintf(buf + len, "\nPOTS Correct %d", j->flags.pots_correct);
7309 len += sprintf(buf + len, "\nPSTN Present %d", j->flags.pstn_present);
7310 len += sprintf(buf + len, "\nPSTN Check %d", j->flags.pstncheck);
7311 len += sprintf(buf + len, "\nPOTS to PSTN %d", j->flags.pots_pstn);
7312 switch (j->daa_mode) {
7313 case SOP_PU_SLEEP:
7314 len += sprintf(buf + len, "\nDAA PSTN On Hook");
7315 break;
7316 case SOP_PU_RINGING:
7317 len += sprintf(buf + len, "\nDAA PSTN Ringing");
7318 len += sprintf(buf + len, "\nRinging state = %d", j->cadence_f[4].state);
7319 break;
7320 case SOP_PU_CONVERSATION:
7321 len += sprintf(buf + len, "\nDAA PSTN Off Hook");
7322 break;
7323 case SOP_PU_PULSEDIALING:
7324 len += sprintf(buf + len, "\nDAA PSTN Pulse Dialing");
7325 break;
7326 }
7327 len += sprintf(buf + len, "\nDAA RMR = %d", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.bitreg.RMR);
7328 len += sprintf(buf + len, "\nDAA VDD OK = %d", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK);
7329 len += sprintf(buf + len, "\nDAA CR0 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg);
7330 len += sprintf(buf + len, "\nDAA CR1 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg);
7331 len += sprintf(buf + len, "\nDAA CR2 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg);
7332 len += sprintf(buf + len, "\nDAA CR3 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg);
7333 len += sprintf(buf + len, "\nDAA CR4 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg);
7334 len += sprintf(buf + len, "\nDAA CR5 = 0x%02x", j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg);
7335 len += sprintf(buf + len, "\nDAA XR0 = 0x%02x", j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg);
7336 len += sprintf(buf + len, "\nDAA ringstop %ld - jiffies %ld", j->pstn_ring_stop, jiffies);
7337 }
7338 switch (j->port) {
7339 case PORT_POTS:
7340 len += sprintf(buf + len, "\nPort POTS");
7341 break;
7342 case PORT_PSTN:
7343 len += sprintf(buf + len, "\nPort PSTN");
7344 break;
7345 case PORT_SPEAKER:
7346 len += sprintf(buf + len, "\nPort SPEAKER/MIC");
7347 break;
7348 case PORT_HANDSET:
7349 len += sprintf(buf + len, "\nPort HANDSET");
7350 break;
7351 }
7352 if (j->dsp.low == 0x21 || j->dsp.low == 0x22) {
7353 len += sprintf(buf + len, "\nSLIC state ");
7354 switch (SLIC_GetState(j)) {
7355 case PLD_SLIC_STATE_OC:
7356 len += sprintf(buf + len, "OC");
7357 break;
7358 case PLD_SLIC_STATE_RINGING:
7359 len += sprintf(buf + len, "RINGING");
7360 break;
7361 case PLD_SLIC_STATE_ACTIVE:
7362 len += sprintf(buf + len, "ACTIVE");
7363 break;
7364 case PLD_SLIC_STATE_OHT:
7365 len += sprintf(buf + len, "OHT");
7366 break;
7367 case PLD_SLIC_STATE_TIPOPEN:
7368 len += sprintf(buf + len, "TIPOPEN");
7369 break;
7370 case PLD_SLIC_STATE_STANDBY:
7371 len += sprintf(buf + len, "STANDBY");
7372 break;
7373 case PLD_SLIC_STATE_APR:
7374 len += sprintf(buf + len, "APR");
7375 break;
7376 case PLD_SLIC_STATE_OHTPR:
7377 len += sprintf(buf + len, "OHTPR");
7378 break;
7379 default:
7380 len += sprintf(buf + len, "%d", SLIC_GetState(j));
7381 break;
7382 }
7383 }
7384 len += sprintf(buf + len, "\nBase Frame %2.2x.%2.2x", j->baseframe.high, j->baseframe.low);
7385 len += sprintf(buf + len, "\nCID Base Frame %2d", j->cid_base_frame_size);
7386#ifdef PERFMON_STATS
7387 len += sprintf(buf + len, "\nTimer Checks %ld", j->timerchecks);
7388 len += sprintf(buf + len, "\nRX Ready Checks %ld", j->rxreadycheck);
7389 len += sprintf(buf + len, "\nTX Ready Checks %ld", j->txreadycheck);
7390 len += sprintf(buf + len, "\nFrames Read %ld", j->framesread);
7391 len += sprintf(buf + len, "\nFrames Written %ld", j->frameswritten);
7392 len += sprintf(buf + len, "\nDry Buffer %ld", j->drybuffer);
7393 len += sprintf(buf + len, "\nRead Waits %ld", j->read_wait);
7394 len += sprintf(buf + len, "\nWrite Waits %ld", j->write_wait);
7395 len += sprintf(buf + len, "\nStatus Waits %ld", j->statuswait);
7396 len += sprintf(buf + len, "\nStatus Wait Fails %ld", j->statuswaitfail);
7397 len += sprintf(buf + len, "\nPControl Waits %ld", j->pcontrolwait);
7398 len += sprintf(buf + len, "\nPControl Wait Fails %ld", j->pcontrolwaitfail);
7399 len += sprintf(buf + len, "\nIs Control Ready Checks %ld", j->iscontrolready);
7400 len += sprintf(buf + len, "\nIs Control Ready Check failures %ld", j->iscontrolreadyfail);
7401
7402#endif
7403 len += sprintf(buf + len, "\n");
7404 }
7405 }
7406 return len;
7407}
7408
7409static int ixj_read_proc(char *page, char **start, off_t off,
7410 int count, int *eof, void *data)
7411{
7412 int len = ixj_get_status_proc(page);
7413 if (len <= off+count) *eof = 1;
7414 *start = page + off;
7415 len -= off;
7416 if (len>count) len = count;
7417 if (len<0) len = 0;
7418 return len;
7419}
7420
7421
7422static void cleanup(void)
7423{
7424 int cnt;
7425 IXJ *j;
7426
7427 for (cnt = 0; cnt < IXJMAX; cnt++) {
7428 j = get_ixj(cnt);
7429 if(j != NULL && j->DSPbase) {
7430 if (ixjdebug & 0x0002)
7431 printk(KERN_INFO "IXJ: Deleting timer for /dev/phone%d\n", cnt);
7432 del_timer(&j->timer);
7433 if (j->cardtype == QTI_LINEJACK) {
7434 j->pld_scrw.bits.daafsyncen = 0;
7435
7436 outb_p(j->pld_scrw.byte, j->XILINXbase);
7437 j->pld_slicw.bits.rly1 = 0;
7438 j->pld_slicw.bits.rly2 = 0;
7439 j->pld_slicw.bits.rly3 = 0;
7440 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
7441 LED_SetState(0x0, j);
7442 if (ixjdebug & 0x0002)
7443 printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7444 release_region(j->XILINXbase, 8);
7445 } else if (j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
7446 if (ixjdebug & 0x0002)
7447 printk(KERN_INFO "IXJ: Releasing XILINX address for /dev/phone%d\n", cnt);
7448 release_region(j->XILINXbase, 4);
7449 }
7450 kfree(j->read_buffer);
7451 kfree(j->write_buffer);
7452 if (j->dev)
7453 pnp_device_detach(j->dev);
7454 if (ixjdebug & 0x0002)
7455 printk(KERN_INFO "IXJ: Unregistering /dev/phone%d from LTAPI\n", cnt);
7456 phone_unregister_device(&j->p);
7457 if (ixjdebug & 0x0002)
7458 printk(KERN_INFO "IXJ: Releasing DSP address for /dev/phone%d\n", cnt);
7459 release_region(j->DSPbase, 16);
7460#ifdef IXJ_DYN_ALLOC
7461 if (ixjdebug & 0x0002)
7462 printk(KERN_INFO "IXJ: Freeing memory for /dev/phone%d\n", cnt);
7463 kfree(j);
7464 ixj[cnt] = NULL;
7465#endif
7466 }
7467 }
7468 if (ixjdebug & 0x0002)
7469 printk(KERN_INFO "IXJ: Removing /proc/ixj\n");
7470 remove_proc_entry ("ixj", NULL);
7471}
7472
7473
7474typedef struct {
7475 BYTE length;
7476 DWORD bits;
7477} DATABLOCK;
7478
7479static void PCIEE_WriteBit(WORD wEEPROMAddress, BYTE lastLCC, BYTE byData)
7480{
7481 lastLCC = lastLCC & 0xfb;
7482 lastLCC = lastLCC | (byData ? 4 : 0);
7483 outb(lastLCC, wEEPROMAddress);
7484
7485 mdelay(1);
7486 lastLCC = lastLCC | 0x01;
7487 outb(lastLCC, wEEPROMAddress);
7488
7489 byData = byData << 1;
7490 lastLCC = lastLCC & 0xfe;
7491 mdelay(1);
7492 outb(lastLCC, wEEPROMAddress);
7493
7494}
7495
7496static BYTE PCIEE_ReadBit(WORD wEEPROMAddress, BYTE lastLCC)
7497{
7498 mdelay(1);
7499 lastLCC = lastLCC | 0x01;
7500 outb(lastLCC, wEEPROMAddress);
7501
7502 lastLCC = lastLCC & 0xfe;
7503 mdelay(1);
7504 outb(lastLCC, wEEPROMAddress);
7505
7506 return ((inb(wEEPROMAddress) >> 3) & 1);
7507}
7508
7509static bool PCIEE_ReadWord(WORD wAddress, WORD wLoc, WORD * pwResult)
7510{
7511 BYTE lastLCC;
7512 WORD wEEPROMAddress = wAddress + 3;
7513 DWORD i;
7514 BYTE byResult;
7515 *pwResult = 0;
7516 lastLCC = inb(wEEPROMAddress);
7517 lastLCC = lastLCC | 0x02;
7518 lastLCC = lastLCC & 0xfe;
7519 outb(lastLCC, wEEPROMAddress);
7520
7521 mdelay(1);
7522
7523 PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7524 PCIEE_WriteBit(wEEPROMAddress, lastLCC, 1);
7525 PCIEE_WriteBit(wEEPROMAddress, lastLCC, 0);
7526 for (i = 0; i < 8; i++) {
7527 PCIEE_WriteBit(wEEPROMAddress, lastLCC, wLoc & 0x80 ? 1 : 0);
7528 wLoc <<= 1;
7529 }
7530
7531 for (i = 0; i < 16; i++) {
7532 byResult = PCIEE_ReadBit(wEEPROMAddress, lastLCC);
7533 *pwResult = (*pwResult << 1) | byResult;
7534 }
7535
7536 mdelay(1);
7537
7538 lastLCC = lastLCC & 0xfd;
7539 outb(lastLCC, wEEPROMAddress);
7540
7541 return 0;
7542}
7543
7544static DWORD PCIEE_GetSerialNumber(WORD wAddress)
7545{
7546 WORD wLo, wHi;
7547 if (PCIEE_ReadWord(wAddress, 62, &wLo))
7548 return 0;
7549 if (PCIEE_ReadWord(wAddress, 63, &wHi))
7550 return 0;
7551 return (((DWORD) wHi << 16) | wLo);
7552}
7553
7554static int dspio[IXJMAX + 1] =
7555{
7556 0,
7557};
7558static int xio[IXJMAX + 1] =
7559{
7560 0,
7561};
7562
7563module_param_array(dspio, int, NULL, 0);
7564module_param_array(xio, int, NULL, 0);
7565MODULE_DESCRIPTION("Quicknet VoIP Telephony card module - www.quicknet.net");
7566MODULE_AUTHOR("Ed Okerson <eokerson@quicknet.net>");
7567MODULE_LICENSE("GPL");
7568
7569static void __exit ixj_exit(void)
7570{
7571 cleanup();
7572}
7573
7574static IXJ *new_ixj(unsigned long port)
7575{
7576 IXJ *res;
7577 if (!request_region(port, 16, "ixj DSP")) {
7578 printk(KERN_INFO "ixj: can't get I/O address 0x%lx\n", port);
7579 return NULL;
7580 }
7581 res = ixj_alloc();
7582 if (!res) {
7583 release_region(port, 16);
7584 printk(KERN_INFO "ixj: out of memory\n");
7585 return NULL;
7586 }
7587 res->DSPbase = port;
7588 return res;
7589}
7590
7591static int __init ixj_probe_isapnp(int *cnt)
7592{
7593 int probe = 0;
7594 int func = 0x110;
7595 struct pnp_dev *dev = NULL, *old_dev = NULL;
7596
7597 while (1) {
7598 do {
7599 IXJ *j;
7600 int result;
7601
7602 old_dev = dev;
7603 dev = pnp_find_dev(NULL, ISAPNP_VENDOR('Q', 'T', 'I'),
7604 ISAPNP_FUNCTION(func), old_dev);
7605 if (!dev || !dev->card)
7606 break;
7607 result = pnp_device_attach(dev);
7608 if (result < 0) {
7609 printk("pnp attach failed %d \n", result);
7610 break;
7611 }
7612 if (pnp_activate_dev(dev) < 0) {
7613 printk("pnp activate failed (out of resources?)\n");
7614 pnp_device_detach(dev);
7615 return -ENOMEM;
7616 }
7617
7618 if (!pnp_port_valid(dev, 0)) {
7619 pnp_device_detach(dev);
7620 return -ENODEV;
7621 }
7622
7623 j = new_ixj(pnp_port_start(dev, 0));
7624 if (!j)
7625 break;
7626
7627 if (func != 0x110)
7628 j->XILINXbase = pnp_port_start(dev, 1);
7629
7630 switch (func) {
7631 case (0x110):
7632 j->cardtype = QTI_PHONEJACK;
7633 break;
7634 case (0x310):
7635 j->cardtype = QTI_LINEJACK;
7636 break;
7637 case (0x410):
7638 j->cardtype = QTI_PHONEJACK_LITE;
7639 break;
7640 }
7641 j->board = *cnt;
7642 probe = ixj_selfprobe(j);
7643 if(!probe) {
7644 j->serial = dev->card->serial;
7645 j->dev = dev;
7646 switch (func) {
7647 case 0x110:
7648 printk(KERN_INFO "ixj: found Internet PhoneJACK at 0x%x\n", j->DSPbase);
7649 break;
7650 case 0x310:
7651 printk(KERN_INFO "ixj: found Internet LineJACK at 0x%x\n", j->DSPbase);
7652 break;
7653 case 0x410:
7654 printk(KERN_INFO "ixj: found Internet PhoneJACK Lite at 0x%x\n", j->DSPbase);
7655 break;
7656 }
7657 }
7658 ++*cnt;
7659 } while (dev);
7660 if (func == 0x410)
7661 break;
7662 if (func == 0x310)
7663 func = 0x410;
7664 if (func == 0x110)
7665 func = 0x310;
7666 dev = NULL;
7667 }
7668 return probe;
7669}
7670
7671static int __init ixj_probe_isa(int *cnt)
7672{
7673 int i, probe;
7674
7675
7676 for (i = 0; i < IXJMAX; i++) {
7677 if (dspio[i]) {
7678 IXJ *j = new_ixj(dspio[i]);
7679
7680 if (!j)
7681 break;
7682
7683 j->XILINXbase = xio[i];
7684 j->cardtype = 0;
7685
7686 j->board = *cnt;
7687 probe = ixj_selfprobe(j);
7688 j->dev = NULL;
7689 ++*cnt;
7690 }
7691 }
7692 return 0;
7693}
7694
7695static int __init ixj_probe_pci(int *cnt)
7696{
7697 struct pci_dev *pci = NULL;
7698 int i, probe = 0;
7699 IXJ *j = NULL;
7700
7701 for (i = 0; i < IXJMAX - *cnt; i++) {
7702 pci = pci_get_device(PCI_VENDOR_ID_QUICKNET,
7703 PCI_DEVICE_ID_QUICKNET_XJ, pci);
7704 if (!pci)
7705 break;
7706
7707 if (pci_enable_device(pci))
7708 break;
7709 j = new_ixj(pci_resource_start(pci, 0));
7710 if (!j)
7711 break;
7712
7713 j->serial = (PCIEE_GetSerialNumber)pci_resource_start(pci, 2);
7714 j->XILINXbase = j->DSPbase + 0x10;
7715 j->cardtype = QTI_PHONEJACK_PCI;
7716 j->board = *cnt;
7717 probe = ixj_selfprobe(j);
7718 if (!probe)
7719 printk(KERN_INFO "ixj: found Internet PhoneJACK PCI at 0x%x\n", j->DSPbase);
7720 ++*cnt;
7721 }
7722 pci_dev_put(pci);
7723 return probe;
7724}
7725
7726static int __init ixj_init(void)
7727{
7728 int cnt = 0;
7729 int probe = 0;
7730
7731 cnt = 0;
7732
7733
7734 if ((probe = ixj_probe_isapnp(&cnt)) < 0) {
7735 return probe;
7736 }
7737 if ((probe = ixj_probe_isa(&cnt)) < 0) {
7738 return probe;
7739 }
7740 if ((probe = ixj_probe_pci(&cnt)) < 0) {
7741 return probe;
7742 }
7743 printk(KERN_INFO "ixj driver initialized.\n");
7744 create_proc_read_entry ("ixj", 0, NULL, ixj_read_proc, NULL);
7745 return probe;
7746}
7747
7748module_init(ixj_init);
7749module_exit(ixj_exit);
7750
7751static void DAA_Coeff_US(IXJ *j)
7752{
7753 int i;
7754
7755 j->daa_country = DAA_US;
7756
7757
7758 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
7759 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
7760 }
7761
7762
7763 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x03;
7764 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0x4B;
7765 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x5D;
7766 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xCD;
7767 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x24;
7768 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xC5;
7769 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
7770 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
7771
7772 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x71;
7773 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x1A;
7774 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
7775 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
7776 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xB5;
7777 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
7778 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
7779 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
7780
7781 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x05;
7782 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xA3;
7783 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x72;
7784 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
7785 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x3F;
7786 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x3B;
7787 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
7788 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
7789
7790 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x05;
7791 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
7792 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
7793 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x3E;
7794 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x32;
7795 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xDA;
7796 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
7797 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
7798
7799 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x41;
7800 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
7801 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
7802 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
7803
7804 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
7805 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
7806 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
7807 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
7808
7809 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
7810 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
7811 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
7812 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
7813 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA5;
7814 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
7815 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
7816 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
7817
7818 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
7819 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xA2;
7820 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2B;
7821 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
7822 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
7823 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAB;
7824 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
7825 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xCC;
7826
7827 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
7828 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
7829 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xD2;
7830 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x24;
7831 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBA;
7832 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xA9;
7833 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x3B;
7834 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xA6;
7835
7836
7837
7838 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
7839 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
7840 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
7841 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
7842 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
7843 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
7844 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
7845 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
7846
7847 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
7848 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
7849 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
7850 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
7851 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
7852 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
7853 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
7854 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
7855
7856
7857 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
7858 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
7859 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
7860 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
7889 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
7890 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
7891 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
7892 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
7893 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
7894 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
7895 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
7896
7897 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
7898 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
7899 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
7900 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
7901 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
7902 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
7903 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
7904 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
7905
7906
7907
7908 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
7909
7910 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
7911
7912 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
7913
7914 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
7915
7916 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
7917
7918
7919
7920
7921
7922
7923
7924 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
7925
7926
7927 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x3C;
7928
7929 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
7930
7931 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x3B;
7932
7933
7934 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
7935
7936 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
7937
7938 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
7939
7940 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;
7941
7942
7943
7944
7945
7946
7947 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
7948 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
7949 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
7950 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
7951
7952
7953
7954
7955 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
7956 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
7957 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
7958 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
7959}
7960
7961static void DAA_Coeff_UK(IXJ *j)
7962{
7963 int i;
7964
7965 j->daa_country = DAA_UK;
7966
7967
7968 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
7969 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
7970 }
7971
7972
7973 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
7974 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xC2;
7975 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
7976 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xA8;
7977 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xCB;
7978 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
7979 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
7980 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
7981
7982 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x40;
7983 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x00;
7984 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
7985 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0A;
7986 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xA4;
7987 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
7988 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
7989 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
7990
7991 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
7992 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9B;
7993 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xED;
7994 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x24;
7995 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0xB2;
7996 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0xA2;
7997 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xA0;
7998 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
7999
8000 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8001 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x92;
8002 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF2;
8003 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0xB2;
8004 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8005 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xD2;
8006 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x30;
8007 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8008
8009 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x1B;
8010 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xA5;
8011 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8012 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8013
8014 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8015 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x27;
8016 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8017 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8018
8019 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8020 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x2D;
8021 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x38;
8022 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x8B;
8023 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xD0;
8024 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x00;
8025 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8026 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8027
8028 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8029 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x5A;
8030 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x53;
8031 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xF0;
8032 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x0B;
8033 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5F;
8034 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x84;
8035 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xD4;
8036
8037 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8038 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8039 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x6A;
8040 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA4;
8041 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x8F;
8042 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x52;
8043 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xF5;
8044 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x32;
8045
8046
8047 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8048 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8049 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8050 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8051 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8052 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8053 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8054 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8055
8056 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8057 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8058 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8059 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8060 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8061 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8062 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8063 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8064
8065 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8066 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8067 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8068 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8069
8070 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8071 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8072 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8073 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8074 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8075 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8076 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8077 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8078
8079 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8080 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8081 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8082 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8083 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8084 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8085 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8086 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8087
8088
8089 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8090
8091 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8092
8093 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8094
8095 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8096
8097 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8098
8099
8100
8101
8102
8103
8104 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
8105
8106
8107 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;
8108
8109
8110 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8111
8112 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8113
8114 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8115
8116 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8117
8118 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8119
8120 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;
8121
8122
8123
8124
8125
8126 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8127 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8128 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8129 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8130
8131
8132
8133
8134 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8135 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8136 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8137 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8138}
8139
8140
8141static void DAA_Coeff_France(IXJ *j)
8142{
8143 int i;
8144
8145 j->daa_country = DAA_FRANCE;
8146
8147
8148 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8149 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8150 }
8151
8152
8153 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x02;
8154 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA2;
8155 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0x43;
8156 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2C;
8157 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0x22;
8158 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xAF;
8159 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8160 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8161
8162 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x67;
8163 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xCE;
8164 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8165 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x2C;
8166 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x22;
8167 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8168 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8169 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8170
8171 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8172 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x9A;
8173 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x28;
8174 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0xF6;
8175 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x23;
8176 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x4A;
8177 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xB0;
8178 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8179
8180 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8181 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8182 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xF9;
8183 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8184 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9E;
8185 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xFA;
8186 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8187 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8188
8189 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x16;
8190 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xB5;
8191 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8192 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8193
8194 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0xE2;
8195 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xC7;
8196 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8197 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8198
8199 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8200 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8201 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8202 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8203 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xA6;
8204 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8205 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8206 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8207
8208 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8209 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAC;
8210 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8211 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x30;
8212 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x78;
8213 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0xAC;
8214 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x8A;
8215 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x2C;
8216
8217 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8218 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8219 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8220 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0xA5;
8221 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x22;
8222 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xBA;
8223 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x2C;
8224 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x45;
8225
8226
8227 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8228 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8229 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8230 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8231 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8232 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8233 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8234 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8235
8236 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8237 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8238 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8239 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8240 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8241 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8242 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8243 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8244
8245 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8246 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8247 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8248 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8249
8250 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8251 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8252 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8253 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8254 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8255 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8256 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8257 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8258
8259 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8260 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8261 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8262 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8263 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8264 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8265 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8266 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8267
8268
8269 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8270
8271 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8272
8273 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8274
8275 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8276
8277 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8278
8279
8280
8281
8282
8283
8284 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
8285
8286
8287 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;
8288
8289
8290 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8291
8292 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x36;
8293
8294 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8295
8296 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8297
8298 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8299
8300 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x46;
8301
8302
8303
8304
8305
8306 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8307 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8308 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8309 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8310
8311
8312
8313
8314 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8315 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8316 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8317 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8318}
8319
8320
8321static void DAA_Coeff_Germany(IXJ *j)
8322{
8323 int i;
8324
8325 j->daa_country = DAA_GERMANY;
8326
8327
8328 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8329 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8330 }
8331
8332
8333 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8334 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xCE;
8335 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xBB;
8336 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0xB8;
8337 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xD2;
8338 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x81;
8339 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xB0;
8340 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8341
8342 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x45;
8343 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x8F;
8344 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8345 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0C;
8346 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0xD2;
8347 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x3A;
8348 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xD0;
8349 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8350
8351 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8352 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0xAA;
8353 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8354 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8355 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x24;
8356 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x89;
8357 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x20;
8358 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8359
8360 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x02;
8361 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x87;
8362 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xFA;
8363 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x37;
8364 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x9A;
8365 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCA;
8366 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xB0;
8367 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8368
8369 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x72;
8370 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xD5;
8371 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8372 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8373
8374 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x72;
8375 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x42;
8376 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x13;
8377 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0x4B;
8378
8379 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8380 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8381 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8382 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8383 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAD;
8384 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8385 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8386 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8387
8388 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8389 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0x42;
8390 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x5A;
8391 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8392 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0xE8;
8393 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x1A;
8394 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x81;
8395 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x27;
8396
8397 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8398 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8399 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x63;
8400 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x26;
8401 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0xBD;
8402 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x4B;
8403 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0xA3;
8404 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xC2;
8405
8406
8407 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8408 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3B;
8409 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x9B;
8410 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0xBA;
8411 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0xD4;
8412 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x1C;
8413 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xB3;
8414 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8415
8416 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x13;
8417 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x42;
8418 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8419 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8420 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0xD4;
8421 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x73;
8422 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0xCA;
8423 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8424
8425 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xB2;
8426 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8427 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8428 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8429
8430 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8431 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8432 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8433 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8434 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8435 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8436 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8437 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8438
8439 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8440 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8441 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8442 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8443 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8444 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8445 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8446 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8447
8448
8449 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8450
8451 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8452
8453 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8454
8455 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8456
8457 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8458
8459
8460
8461
8462
8463
8464 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
8465
8466
8467 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;
8468
8469
8470 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8471
8472 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x32;
8473
8474 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8475
8476 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8477
8478 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8479
8480 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;
8481
8482
8483
8484
8485
8486 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8487 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8488 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8489 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8490
8491
8492
8493
8494 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8495 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8496 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8497 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8498}
8499
8500
8501static void DAA_Coeff_Australia(IXJ *j)
8502{
8503 int i;
8504
8505 j->daa_country = DAA_AUSTRALIA;
8506
8507
8508 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8509 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8510 }
8511
8512
8513 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x00;
8514 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xA3;
8515 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xAA;
8516 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x28;
8517 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xB3;
8518 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0x82;
8519 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xD0;
8520 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8521
8522 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x70;
8523 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0x96;
8524 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8525 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x09;
8526 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x32;
8527 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x6B;
8528 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xC0;
8529 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8530
8531 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x07;
8532 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x96;
8533 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0xE2;
8534 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x34;
8535 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x32;
8536 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x9B;
8537 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0x30;
8538 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8539
8540 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x0F;
8541 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x9A;
8542 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0xE9;
8543 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x2F;
8544 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x22;
8545 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xCC;
8546 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0xA0;
8547 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8548
8549 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0xCB;
8550 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0x45;
8551 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8552 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8553
8554 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x1B;
8555 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0x67;
8556 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8557 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8558
8559 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x80;
8560 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x52;
8561 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8562 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8563 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAF;
8564 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8565 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8566 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8567
8568 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8569 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xDB;
8570 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x52;
8571 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0xB0;
8572 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x38;
8573 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x01;
8574 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x82;
8575 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0xAC;
8576
8577 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8578 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8579 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0x4A;
8580 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x3E;
8581 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x2C;
8582 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0x3B;
8583 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x24;
8584 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0x46;
8585
8586
8587 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8588 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8589 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8590 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8591 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8592 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8593 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8594 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8595
8596 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8597 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8598 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8599 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8600 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8601 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8602 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8603 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8604
8605 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0x32;
8606 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x45;
8607 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0xB5;
8608 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x84;
8609
8610 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8611 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8612 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8613 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8614 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8615 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8616 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8617 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8618
8619 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8620 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8621 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8622 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8623 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8624 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8625 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8626 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8627
8628
8629 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8630
8631 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8632
8633 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8634
8635 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8636
8637 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8638
8639
8640
8641
8642
8643
8644 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
8645
8646
8647 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;
8648
8649
8650 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8651
8652 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x2B;
8653
8654 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8655
8656 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8657
8658 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8659
8660 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;
8661
8662
8663
8664
8665
8666 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8667 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8668 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8669 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8670
8671
8672
8673
8674
8675 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8676 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8677 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8678 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8679}
8680
8681static void DAA_Coeff_Japan(IXJ *j)
8682{
8683 int i;
8684
8685 j->daa_country = DAA_JAPAN;
8686
8687
8688 for (i = 0; i < ALISDAA_CALLERID_SIZE; i++) {
8689 j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID[i] = 0;
8690 }
8691
8692
8693 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7] = 0x06;
8694 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6] = 0xBD;
8695 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5] = 0xE2;
8696 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4] = 0x2D;
8697 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3] = 0xBA;
8698 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2] = 0xF9;
8699 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1] = 0xA0;
8700 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0] = 0x00;
8701
8702 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7] = 0x6F;
8703 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6] = 0xF7;
8704 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5] = 0x00;
8705 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4] = 0x0E;
8706 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3] = 0x34;
8707 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2] = 0x33;
8708 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1] = 0xE0;
8709 j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0] = 0x08;
8710
8711 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7] = 0x02;
8712 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6] = 0x8F;
8713 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5] = 0x68;
8714 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4] = 0x77;
8715 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3] = 0x9C;
8716 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2] = 0x58;
8717 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1] = 0xF0;
8718 j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0] = 0x08;
8719
8720 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7] = 0x03;
8721 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6] = 0x8F;
8722 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5] = 0x38;
8723 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4] = 0x73;
8724 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3] = 0x87;
8725 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2] = 0xEA;
8726 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1] = 0x20;
8727 j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0] = 0x08;
8728
8729 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3] = 0x51;
8730 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2] = 0xC5;
8731 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1] = 0xDD;
8732 j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0] = 0xCA;
8733
8734 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3] = 0x25;
8735 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2] = 0xA7;
8736 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1] = 0x10;
8737 j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0] = 0xD6;
8738
8739 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7] = 0x00;
8740 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6] = 0x42;
8741 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5] = 0x48;
8742 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4] = 0x81;
8743 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3] = 0xAE;
8744 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2] = 0x80;
8745 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1] = 0x00;
8746 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0] = 0x98;
8747
8748 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7] = 0x02;
8749 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6] = 0xAB;
8750 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5] = 0x2A;
8751 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4] = 0x20;
8752 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3] = 0x99;
8753 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2] = 0x5B;
8754 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1] = 0x89;
8755 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0] = 0x28;
8756
8757 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7] = 0x00;
8758 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6] = 0x88;
8759 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5] = 0xDA;
8760 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4] = 0x25;
8761 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3] = 0x34;
8762 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2] = 0xC5;
8763 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1] = 0x4C;
8764 j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0] = 0xBA;
8765
8766
8767 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7] = 0x1B;
8768 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6] = 0x3C;
8769 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5] = 0x93;
8770 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4] = 0x3A;
8771 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3] = 0x22;
8772 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x12;
8773 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0xA3;
8774 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x23;
8775
8776 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x12;
8777 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0xA2;
8778 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6;
8779 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4] = 0xBA;
8780 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3] = 0x22;
8781 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2] = 0x7A;
8782 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1] = 0x0A;
8783 j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0] = 0xD5;
8784
8785 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3] = 0xAA;
8786 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2] = 0x35;
8787 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1] = 0x0F;
8788 j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0] = 0x8E;
8789
8790 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7] = 0xCA;
8791 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6] = 0x0E;
8792 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5] = 0xCA;
8793 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4] = 0x09;
8794 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3] = 0x99;
8795 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2] = 0x99;
8796 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1] = 0x99;
8797 j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0] = 0x99;
8798
8799 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7] = 0xFD;
8800 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6] = 0xB5;
8801 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5] = 0xBA;
8802 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4] = 0x07;
8803 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3] = 0xDA;
8804 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2] = 0x00;
8805 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1] = 0x00;
8806 j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0] = 0x00;
8807
8808
8809 j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = 0xFF;
8810
8811 j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = 0x05;
8812
8813 j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = 0x04;
8814
8815 j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = 0x00;
8816
8817 j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = 0x02;
8818
8819
8820
8821
8822
8823
8824 j->m_DAAShadowRegs.XOP_xr0_W.reg = 0x02;
8825
8826
8827 j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg = 0x1C;
8828
8829
8830 j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg = 0x7D;
8831
8832 j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg = 0x22;
8833
8834 j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg = 0x00;
8835
8836 j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg = 0x22;
8837
8838 j->m_DAAShadowRegs.XOP_xr6_W.reg = 0x00;
8839
8840 j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg = 0x40;
8841
8842
8843
8844
8845
8846 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3] = 0x11;
8847 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2] = 0xB3;
8848 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1] = 0x5A;
8849 j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0] = 0x2C;
8850
8851
8852
8853
8854 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3] = 0x32;
8855 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2] = 0x32;
8856 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1] = 0x52;
8857 j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0] = 0xB3;
8858}
8859
8860static s16 tone_table[][19] =
8861{
8862 {
8863 32538,
8864 -32325,
8865 -343,
8866 0,
8867 343,
8868 32619,
8869 -32520,
8870 19179,
8871 -19178,
8872 19179,
8873 32723,
8874 -32686,
8875 9973,
8876 -9955,
8877 9973,
8878 7,
8879 159,
8880 21,
8881 0x0FF5
8882 },
8883 {
8884 32072,
8885 -31896,
8886 -435,
8887 0,
8888 435,
8889 32188,
8890 -32400,
8891 15139,
8892 -14882,
8893 15139,
8894 32473,
8895 -32524,
8896 23200,
8897 -23113,
8898 23200,
8899 7,
8900 159,
8901 21,
8902 0x0FF5
8903 },
8904 {
8905 31769,
8906 -32584,
8907 -475,
8908 0,
8909 475,
8910 31789,
8911 -32679,
8912 17280,
8913 -16865,
8914 17280,
8915 31841,
8916 -32681,
8917 543,
8918 -525,
8919 543,
8920 5,
8921 159,
8922 21,
8923 0x0FF5
8924 },
8925 {
8926 30750,
8927 -31212,
8928 -804,
8929 0,
8930 804,
8931 30686,
8932 -32145,
8933 14747,
8934 -13703,
8935 14747,
8936 31651,
8937 -32321,
8938 24425,
8939 -23914,
8940 24427,
8941 7,
8942 159,
8943 21,
8944 0x0FF5
8945 },
8946 {
8947 31613,
8948 -32646,
8949 -185,
8950 0,
8951 185,
8952 31620,
8953 -32713,
8954 19253,
8955 -18566,
8956 19253,
8957 31674,
8958 -32715,
8959 2575,
8960 -2495,
8961 2575,
8962 5,
8963 159,
8964 21,
8965 0x0FF5
8966 },
8967 {
8968 30741,
8969 -31475,
8970 -703,
8971 0,
8972 703,
8973 30688,
8974 -32248,
8975 14542,
8976 -13523,
8977 14542,
8978 31494,
8979 -32366,
8980 21577,
8981 -21013,
8982 21577,
8983 7,
8984 159,
8985 21,
8986 0x0FF5
8987 },
8988 {
8989 30627,
8990 -31338,
8991 -843,
8992 0,
8993 843,
8994 30550,
8995 -32221,
8996 13594,
8997 -12589,
8998 13594,
8999 31488,
9000 -32358,
9001 24684,
9002 -24029,
9003 24684,
9004 7,
9005 159,
9006 21,
9007 0x0FF5
9008 },
9009 {
9010 31546,
9011 -32646,
9012 -445,
9013 0,
9014 445,
9015 31551,
9016 -32713,
9017 23884,
9018 -22979,
9019 23884,
9020 31606,
9021 -32715,
9022 863,
9023 -835,
9024 863,
9025 5,
9026 159,
9027 21,
9028 0x0FF5
9029 },
9030 {
9031 31006,
9032 -32029,
9033 -461,
9034 0,
9035 461,
9036 30999,
9037 -32487,
9038 11325,
9039 -10682,
9040 11325,
9041 31441,
9042 -32526,
9043 24324,
9044 -23535,
9045 24324,
9046 7,
9047 159,
9048 21,
9049 0x0FF5
9050 },
9051 {
9052 30634,
9053 -31533,
9054 -680,
9055 0,
9056 680,
9057 30571,
9058 -32277,
9059 12894,
9060 -11945,
9061 12894,
9062 31367,
9063 -32379,
9064 23820,
9065 -23104,
9066 23820,
9067 7,
9068 159,
9069 21,
9070 0x0FF5
9071 },
9072 {
9073 30552,
9074 -31434,
9075 -690,
9076 0,
9077 690,
9078 30472,
9079 -32248,
9080 13385,
9081 -12357,
9082 13385,
9083 31358,
9084 -32366,
9085 26488,
9086 -25692,
9087 26490,
9088 7,
9089 159,
9090 21,
9091 0x0FF5
9092 },
9093 {
9094 31397,
9095 -32623,
9096 -117,
9097 0,
9098 117,
9099 31403,
9100 -32700,
9101 3388,
9102 -3240,
9103 3388,
9104 31463,
9105 -32702,
9106 13346,
9107 -12863,
9108 13346,
9109 5,
9110 159,
9111 21,
9112 0x0FF5
9113 },
9114 {
9115 30831,
9116 -32064,
9117 -367,
9118 0,
9119 367,
9120 30813,
9121 -32456,
9122 11068,
9123 -10338,
9124 11068,
9125 31214,
9126 -32491,
9127 16374,
9128 -15781,
9129 16374,
9130 7,
9131 159,
9132 21,
9133 0x0FF5
9134 },
9135 {
9136 31152,
9137 -32613,
9138 -314,
9139 0,
9140 314,
9141 31156,
9142 -32694,
9143 28847,
9144 -2734,
9145 28847,
9146 31225,
9147 -32696,
9148 462,
9149 -442,
9150 462,
9151 5,
9152 159,
9153 21,
9154 0x0FF5
9155 },
9156 {
9157 30836,
9158 -32296,
9159 -324,
9160 0,
9161 324,
9162 30825,
9163 -32570,
9164 16847,
9165 -15792,
9166 16847,
9167 31106,
9168 -32584,
9169 9579,
9170 -9164,
9171 9579,
9172 7,
9173 159,
9174 21,
9175 0x0FF5
9176 },
9177 {
9178 30702,
9179 -32134,
9180 -517,
9181 0,
9182 517,
9183 30676,
9184 -32520,
9185 8144,
9186 -7596,
9187 8144,
9188 31084,
9189 -32547,
9190 22713,
9191 -21734,
9192 22713,
9193 7,
9194 159,
9195 21,
9196 0x0FF5
9197 },
9198 {
9199 30613,
9200 -32031,
9201 -618,
9202 0,
9203 618,
9204 30577,
9205 -32491,
9206 9612,
9207 -8935,
9208 9612,
9209 31071,
9210 -32524,
9211 21596,
9212 -20667,
9213 21596,
9214 7,
9215 159,
9216 21,
9217 0x0FF5
9218 },
9219 {
9220 30914,
9221 -32584,
9222 -426,
9223 0,
9224 426,
9225 30914,
9226 -32679,
9227 17520,
9228 -16471,
9229 17520,
9230 31004,
9231 -32683,
9232 819,
9233 -780,
9234 819,
9235 5,
9236 159,
9237 21,
9238 0x0FF5
9239 },
9240#if 0
9241 {
9242 30881,
9243 -32603,
9244 -496,
9245 0,
9246 496,
9247 30880,
9248 -32692,
9249 24767,
9250 -23290,
9251 24767,
9252 30967,
9253 -32694,
9254 728,
9255 -691,
9256 728,
9257 5,
9258 159,
9259 21,
9260 0x0FF5
9261 },
9262#else
9263 {
9264 30850,
9265 -32534,
9266 -504,
9267 0,
9268 504,
9269 30831,
9270 -32669,
9271 24303,
9272 -22080,
9273 24303,
9274 30994,
9275 -32673,
9276 1905,
9277 -1811,
9278 1905,
9279 5,
9280 129,
9281 17,
9282 0xff5
9283 },
9284#endif
9285 {
9286 30646,
9287 -32327,
9288 -287,
9289 0,
9290 287,
9291 30627,
9292 -32607,
9293 13269,
9294 -12376,
9295 13269,
9296 30924,
9297 -32619,
9298 19950,
9299 -18940,
9300 19950,
9301 7,
9302 159,
9303 21,
9304 0x0FF5
9305 },
9306 {
9307 30396,
9308 -32014,
9309 -395,
9310 0,
9311 395,
9312 30343,
9313 -32482,
9314 17823,
9315 -16431,
9316 17823,
9317 30872,
9318 -32516,
9319 18124,
9320 -17246,
9321 18124,
9322 7,
9323 159,
9324 21,
9325 0x0FF5
9326 },
9327 {
9328 30796,
9329 -32603,
9330 -254,
9331 0,
9332 254,
9333 30793,
9334 -32692,
9335 18934,
9336 -17751,
9337 18934,
9338 30882,
9339 -32694,
9340 1858,
9341 -1758,
9342 1858,
9343 5,
9344 159,
9345 21,
9346 0x0FF5
9347 },
9348 {
9349 30641,
9350 -32458,
9351 -155,
9352 0,
9353 155,
9354 30631,
9355 -32630,
9356 11453,
9357 -10666,
9358 11453,
9359 30810,
9360 -32634,
9361 12237,
9362 -11588,
9363 12237,
9364 7,
9365 159,
9366 21,
9367 0x0FF5
9368 },
9369 {
9370 30367,
9371 -32147,
9372 -495,
9373 0,
9374 495,
9375 30322,
9376 -32543,
9377 10031,
9378 -9252,
9379 10031,
9380 30770,
9381 -32563,
9382 22674,
9383 -21465,
9384 22674,
9385 7,
9386 159,
9387 21,
9388 0x0FF5
9389 },
9390 {
9391 30709,
9392 -32603,
9393 -83,
9394 0,
9395 83,
9396 30704,
9397 -32692,
9398 10641,
9399 -9947,
9400 10641,
9401 30796,
9402 -32694,
9403 10079,
9404 9513,
9405 10079,
9406 5,
9407 159,
9408 21,
9409 0x0FF5
9410 },
9411 {
9412 30664,
9413 -32603,
9414 -164,
9415 0,
9416 164,
9417 30661,
9418 -32692,
9419 15294,
9420 -14275,
9421 15294,
9422 30751,
9423 -32694,
9424 3548,
9425 -3344,
9426 3548,
9427 5,
9428 159,
9429 21,
9430 0x0FF5
9431 },
9432 {
9433 30653,
9434 -32615,
9435 -209,
9436 0,
9437 209,
9438 30647,
9439 -32702,
9440 18971,
9441 -17716,
9442 18971,
9443 30738,
9444 -32702,
9445 2967,
9446 -2793,
9447 2967,
9448 5,
9449 159,
9450 21,
9451 0x0FF5
9452 },
9453 {
9454 30437,
9455 -32603,
9456 -264,
9457 0,
9458 264,
9459 30430,
9460 -32692,
9461 21681,
9462 -20082,
9463 21681,
9464 30526,
9465 -32694,
9466 1559,
9467 -1459,
9468 1559,
9469 5,
9470 159,
9471 21,
9472 0x0FF5
9473 },
9474 {
9475 28975,
9476 -30955,
9477 -1026,
9478 0,
9479 1026,
9480 28613,
9481 -32089,
9482 14214,
9483 -12202,
9484 14214,
9485 30243,
9486 -32238,
9487 24825,
9488 -23402,
9489 24825,
9490 7,
9491 159,
9492 21,
9493 0x0FF5
9494 },
9495 {
9496 30257,
9497 -32605,
9498 -249,
9499 0,
9500 249,
9501 30247,
9502 -32694,
9503 18088,
9504 -16652,
9505 18088,
9506 30348,
9507 -32696,
9508 2099,
9509 -1953,
9510 2099,
9511 5,
9512 159,
9513 21,
9514 0x0FF5
9515 },
9516 {
9517 30202,
9518 -32624,
9519 -413,
9520 0,
9521 413,
9522 30191,
9523 -32714,
9524 25954,
9525 -23890,
9526 25954,
9527 30296,
9528 -32715,
9529 2007,
9530 -1860,
9531 2007,
9532 5,
9533 159,
9534 21,
9535 0x0FF5
9536 },
9537 {
9538 30001,
9539 -32613,
9540 -155,
9541 0,
9542 155,
9543 29985,
9544 -32710,
9545 6584,
9546 -6018,
9547 6584,
9548 30105,
9549 -32712,
9550 23812,
9551 -21936,
9552 23812,
9553 5,
9554 159,
9555 21,
9556 0x0FF5
9557 },
9558 {
9559 29964,
9560 -32601,
9561 -101,
9562 0,
9563 101,
9564 29949,
9565 -32700,
9566 11041,
9567 -10075,
9568 11041,
9569 30070,
9570 -32702,
9571 16762,
9572 -15437,
9573 16762,
9574 5,
9575 159,
9576 21,
9577 0x0FF5
9578 },
9579 {
9580 29936,
9581 -32584,
9582 -91,
9583 0,
9584 91,
9585 29921,
9586 -32688,
9587 11449,
9588 -10426,
9589 11449,
9590 30045,
9591 -32688,
9592 13055,
9593 -12028,
9594 13055,
9595 5,
9596 159,
9597 21,
9598 0x0FF5
9599 },
9600 {
9601 28499,
9602 -31129,
9603 -849,
9604 0,
9605 849,
9606 28128,
9607 -32130,
9608 14556,
9609 -12251,
9610 14556,
9611 29667,
9612 -32244,
9613 23038,
9614 -21358,
9615 23040,
9616 7,
9617 159,
9618 21,
9619 0x0FF5
9620 },
9621 {
9622 29271,
9623 -32599,
9624 -490,
9625 0,
9626 490,
9627 29246,
9628 -32700,
9629 28961,
9630 -25796,
9631 28961,
9632 29383,
9633 -32700,
9634 1299,
9635 -1169,
9636 1299,
9637 5,
9638 159,
9639 21,
9640 0x0FF5
9641 },
9642 {
9643 29230,
9644 -32584,
9645 -418,
9646 0,
9647 418,
9648 29206,
9649 -32688,
9650 36556,
9651 -32478,
9652 36556,
9653 29345,
9654 -32688,
9655 897,
9656 -808,
9657 897,
9658 5,
9659 159,
9660 21,
9661 0x0FF5
9662 },
9663 {
9664 29116,
9665 -32603,
9666 -165,
9667 0,
9668 165,
9669 29089,
9670 -32708,
9671 6963,
9672 -6172,
9673 6963,
9674 29237,
9675 -32710,
9676 24197,
9677 -21657,
9678 24197,
9679 5,
9680 159,
9681 21,
9682 0x0FF5
9683 },
9684 {
9685 28376,
9686 -32567,
9687 -363,
9688 0,
9689 363,
9690 28337,
9691 -32683,
9692 21766,
9693 -18761,
9694 21766,
9695 28513,
9696 -32686,
9697 2509,
9698 -2196,
9699 2509,
9700 5,
9701 159,
9702 21,
9703 0x0FF5
9704 },
9705 {
9706 27844,
9707 -32563,
9708 -366,
9709 0,
9710 366,
9711 27797,
9712 -32686,
9713 22748,
9714 -19235,
9715 22748,
9716 27995,
9717 -32688,
9718 2964,
9719 -2546,
9720 2964,
9721 5,
9722 159,
9723 21,
9724 0x0FF5
9725 },
9726 {
9727 27297,
9728 -32551,
9729 -345,
9730 0,
9731 345,
9732 27240,
9733 -32683,
9734 22560,
9735 -18688,
9736 22560,
9737 27461,
9738 -32684,
9739 3541,
9740 -2985,
9741 3541,
9742 5,
9743 159,
9744 21,
9745 0x0FF5
9746 },
9747 {
9748 27155,
9749 -32551,
9750 -462,
9751 0,
9752 462,
9753 27097,
9754 -32683,
9755 32495,
9756 -26776,
9757 32495,
9758 27321,
9759 -32684,
9760 1835,
9761 -1539,
9762 1835,
9763 5,
9764 159,
9765 21,
9766 0x0FF5
9767 },
9768 {
9769 19298,
9770 -24471,
9771 -4152,
9772 0,
9773 4152,
9774 12902,
9775 -29091,
9776 12491,
9777 -1794,
9778 12494,
9779 26291,
9780 -30470,
9781 28859,
9782 -26084,
9783 28861,
9784 7,
9785 159,
9786 21,
9787 0x0FF5
9788 },
9789 {
9790 26867,
9791 -32551,
9792 -123,
9793 0,
9794 123,
9795 26805,
9796 -32683,
9797 17297,
9798 -14096,
9799 17297,
9800 27034,
9801 -32684,
9802 12958,
9803 -10756,
9804 12958,
9805 5,
9806 159,
9807 21,
9808 0x0FF5
9809 },
9810 {
9811 26413,
9812 -32547,
9813 -223,
9814 0,
9815 223,
9816 26342,
9817 -32686,
9818 6391,
9819 -5120,
9820 6391,
9821 26593,
9822 -32688,
9823 23681,
9824 -19328,
9825 23681,
9826 5,
9827 159,
9828 21,
9829 0x0FF5
9830 },
9831 {
9832 26168,
9833 -32528,
9834 -235,
9835 0,
9836 235,
9837 26092,
9838 -32675,
9839 20823,
9840 -16510,
9841 20823,
9842 26363,
9843 -32677,
9844 6739,
9845 -5459,
9846 6739,
9847 5,
9848 159,
9849 21,
9850 0x0FF5
9851 },
9852 {
9853 25641,
9854 -32536,
9855 -121,
9856 0,
9857 121,
9858 25560,
9859 -32684,
9860 18341,
9861 -14252,
9862 18341,
9863 25837,
9864 -32684,
9865 16679,
9866 -13232,
9867 16679,
9868 5,
9869 159,
9870 21,
9871 0x0FF5
9872 },
9873 {
9874 16415,
9875 -23669,
9876 -4549,
9877 0,
9878 4549,
9879 8456,
9880 -28996,
9881 13753,
9882 -12,
9883 13757,
9884 24632,
9885 -30271,
9886 29070,
9887 -25265,
9888 29073,
9889 7,
9890 159,
9891 21,
9892 0x0FF5
9893 },
9894 {
9895 24806,
9896 -32501,
9897 -326,
9898 0,
9899 326,
9900 24709,
9901 -32659,
9902 20277,
9903 -15182,
9904 20277,
9905 25022,
9906 -32661,
9907 4320,
9908 -3331,
9909 4320,
9910 5,
9911 159,
9912 21,
9913 0x0FF5
9914 },
9915 {
9916 19776,
9917 -27437,
9918 -2666,
9919 0,
9920 2666,
9921 16302,
9922 -30354,
9923 10389,
9924 -3327,
9925 10389,
9926 24299,
9927 -30930,
9928 25016,
9929 -21171,
9930 25016,
9931 7,
9932 159,
9933 21,
9934 0x0FF5
9935 },
9936 {
9937 20554,
9938 -28764,
9939 -2048,
9940 0,
9941 2048,
9942 18209,
9943 -30951,
9944 9390,
9945 -3955,
9946 9390,
9947 23902,
9948 -31286,
9949 23252,
9950 -19132,
9951 23252,
9952 7,
9953 159,
9954 21,
9955 0x0FF5
9956 },
9957 {
9958 17543,
9959 -26220,
9960 -3298,
9961 0,
9962 3298,
9963 12423,
9964 -30036,
9965 12651,
9966 -2444,
9967 12653,
9968 23518,
9969 -30745,
9970 27282,
9971 -22529,
9972 27286,
9973 7,
9974 159,
9975 21,
9976 0x0FF5
9977 },
9978 {
9979 24104,
9980 -32507,
9981 -351,
9982 0,
9983 351,
9984 23996,
9985 -32671,
9986 22848,
9987 -16639,
9988 22848,
9989 24332,
9990 -32673,
9991 4906,
9992 -3672,
9993 4906,
9994 5,
9995 159,
9996 21,
9997 0x0FF5
9998 },
9999 {
10000 23967,
10001 -32507,
10002 -518,
10003 0,
10004 518,
10005 23856,
10006 -32671,
10007 26287,
10008 -19031,
10009 26287,
10010 24195,
10011 -32673,
10012 2890,
10013 -2151,
10014 2890,
10015 5,
10016 159,
10017 21,
10018 0x0FF5
10019 },
10020 {
10021 18294,
10022 -26962,
10023 -2914,
10024 0,
10025 2914,
10026 14119,
10027 -30227,
10028 11466,
10029 -2833,
10030 11466,
10031 23431,
10032 -30828,
10033 25331,
10034 -20911,
10035 25331,
10036 7,
10037 159,
10038 21,
10039 0x0FF5
10040 },
10041 {
10042 23521,
10043 -32489,
10044 -193,
10045 0,
10046 193,
10047 23404,
10048 -32655,
10049 17740,
10050 -12567,
10051 17740,
10052 23753,
10053 -32657,
10054 9090,
10055 -6662,
10056 9090,
10057 5,
10058 159,
10059 21,
10060 0x0FF5
10061 },
10062 {
10063 23071,
10064 -32489,
10065 -293,
10066 0,
10067 293,
10068 22951,
10069 -32655,
10070 5689,
10071 -3951,
10072 5689,
10073 23307,
10074 -32657,
10075 18692,
10076 -13447,
10077 18692,
10078 5,
10079 159,
10080 21,
10081 0x0FF5
10082 },
10083 {
10084 22701,
10085 -32474,
10086 -292,
10087 0,
10088 292,
10089 22564,
10090 -32655,
10091 20756,
10092 -14176,
10093 20756,
10094 22960,
10095 -32657,
10096 6520,
10097 -4619,
10098 6520,
10099 5,
10100 159,
10101 21,
10102 0x0FF5
10103 },
10104 {
10105 22142,
10106 -32474,
10107 -147,
10108 0,
10109 147,
10110 22000,
10111 -32655,
10112 15379,
10113 -10237,
10114 15379,
10115 22406,
10116 -32657,
10117 17491,
10118 -12096,
10119 17491,
10120 5,
10121 159,
10122 21,
10123 0x0FF5
10124 },
10125 {
10126 12973,
10127 -24916,
10128 6655,
10129 367,
10130 6657,
10131 5915,
10132 -29560,
10133 -7777,
10134 0,
10135 7777,
10136 20510,
10137 -30260,
10138 26662,
10139 -20573,
10140 26668,
10141 7,
10142 159,
10143 21,
10144 0x0FF5
10145 },
10146 {
10147 20392,
10148 -32460,
10149 -270,
10150 0,
10151 270,
10152 20218,
10153 -32655,
10154 21337,
10155 -13044,
10156 21337,
10157 20684,
10158 -32657,
10159 8572,
10160 -5476,
10161 8572,
10162 5,
10163 159,
10164 21,
10165 0x0FF5
10166 },
10167 {
10168 19159,
10169 -32456,
10170 -335,
10171 0,
10172 335,
10173 18966,
10174 -32661,
10175 6802,
10176 -3900,
10177 6802,
10178 19467,
10179 -32661,
10180 25035,
10181 -15049,
10182 25035,
10183 5,
10184 159,
10185 21,
10186 0x0FF5
10187 },
10188 {
10189 18976,
10190 -32439,
10191 -183,
10192 0,
10193 183,
10194 18774,
10195 -32650,
10196 15468,
10197 -8768,
10198 15468,
10199 19300,
10200 -32652,
10201 19840,
10202 -11842,
10203 19840,
10204 5,
10205 159,
10206 21,
10207 0x0FF5
10208 },
10209 {
10210 16357,
10211 -32368,
10212 -217,
10213 0,
10214 217,
10215 16107,
10216 -32601,
10217 11602,
10218 -5555,
10219 11602,
10220 16722,
10221 -32603,
10222 15574,
10223 -8176,
10224 15574,
10225 5,
10226 159,
10227 21,
10228 0x0FF5
10229 },
10230 {
10231 16234,
10232 32404,
10233 -193,
10234 0,
10235 193,
10236 15986,
10237 -32632,
10238 18051,
10239 -8658,
10240 18051,
10241 16591,
10242 -32634,
10243 15736,
10244 -8125,
10245 15736,
10246 5,
10247 159,
10248 21,
10249 0x0FF5
10250 },
10251 {
10252 15564,
10253 -32404,
10254 -269,
10255 0,
10256 269,
10257 15310,
10258 -32632,
10259 10815,
10260 -4962,
10261 10815,
10262 15924,
10263 -32634,
10264 18880,
10265 -9364,
10266 18880,
10267 5,
10268 159,
10269 21,
10270 0x0FF5
10271 },
10272 {
10273 15247,
10274 -32397,
10275 -244,
10276 0,
10277 244,
10278 14989,
10279 -32627,
10280 18961,
10281 -8498,
10282 18961,
10283 15608,
10284 -32628,
10285 11145,
10286 -5430,
10287 11145,
10288 5,
10289 159,
10290 21,
10291 0x0FF5
10292 },
10293 {
10294 14780,
10295 -32393,
10296 -396,
10297 0,
10298 396,
10299 14510,
10300 -32630,
10301 6326,
10302 -2747,
10303 6326,
10304 15154,
10305 -32632,
10306 23235,
10307 -10983,
10308 23235,
10309 5,
10310 159,
10311 21,
10312 0x0FF5
10313 },
10314 {
10315 13005,
10316 -32368,
10317 -500,
10318 0,
10319 500,
10320 12708,
10321 -32615,
10322 11420,
10323 -4306,
10324 11420,
10325 13397,
10326 -32615,
10327 9454,
10328 -3981,
10329 9454,
10330 5,
10331 159,
10332 21,
10333 0x0FF5
10334 },
10335 {
10336 10046,
10337 -32331,
10338 -455,
10339 0,
10340 455,
10341 9694,
10342 -32601,
10343 6023,
10344 -1708,
10345 6023,
10346 10478,
10347 -32603,
10348 22031,
10349 -7342,
10350 22031,
10351 5,
10352 159,
10353 21,
10354 0x0FF5
10355 },
10356 {
10357 9181,
10358 -32256,
10359 -556,
10360 0,
10361 556,
10362 8757,
10363 -32574,
10364 8443,
10365 -2135,
10366 8443,
10367 9691,
10368 -32574,
10369 15446,
10370 -4809,
10371 15446,
10372 7,
10373 159,
10374 21,
10375 0x0FF5
10376 },
10377 {
10378 5076,
10379 -32304,
10380 -508,
10381 0,
10382 508,
10383 4646,
10384 -32605,
10385 6742,
10386 -878,
10387 6742,
10388 5552,
10389 -32605,
10390 23667,
10391 -4297,
10392 23667,
10393 5,
10394 159,
10395 21,
10396 0x0FF5
10397 },
10398 {
10399 3569,
10400 -32292,
10401 -239,
10402 0,
10403 239,
10404 3117,
10405 -32603,
10406 18658,
10407 -1557,
10408 18658,
10409 4054,
10410 -32603,
10411 18886,
10412 -2566,
10413 18886,
10414 5,
10415 159,
10416 21,
10417 0x0FF5
10418 },
10419};
10420static int ixj_init_filter(IXJ *j, IXJ_FILTER * jf)
10421{
10422 unsigned short cmd;
10423 int cnt, max;
10424
10425 if (jf->filter > 3) {
10426 return -1;
10427 }
10428 if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))
10429
10430 return -1;
10431 if (!jf->enable) {
10432 if (ixj_WriteDSPCommand(0x5152, j))
10433
10434 return -1;
10435 else
10436 return 0;
10437 } else {
10438 if (ixj_WriteDSPCommand(0x5153, j))
10439
10440 return -1;
10441
10442 if (ixj_WriteDSPCommand(0x5154 + jf->filter, j))
10443 return -1;
10444 }
10445 if (jf->freq < 12 && jf->freq > 3) {
10446
10447 if (ixj_WriteDSPCommand(0x5170 + jf->freq, j))
10448 return -1;
10449 } else if (jf->freq > 11) {
10450
10451
10452
10453
10454
10455 if (ixj_WriteDSPCommand(0x5170 + jf->filter, j))
10456 return -1;
10457 if (j->ver.low != 0x12) {
10458 cmd = 0x515B;
10459 max = 19;
10460 } else {
10461 cmd = 0x515E;
10462 max = 15;
10463 }
10464 if (ixj_WriteDSPCommand(cmd, j))
10465 return -1;
10466 for (cnt = 0; cnt < max; cnt++) {
10467 if (ixj_WriteDSPCommand(tone_table[jf->freq - 12][cnt], j))
10468 return -1;
10469 }
10470 }
10471 j->filter_en[jf->filter] = jf->enable;
10472 return 0;
10473}
10474
10475static int ixj_init_filter_raw(IXJ *j, IXJ_FILTER_RAW * jfr)
10476{
10477 unsigned short cmd;
10478 int cnt, max;
10479 if (jfr->filter > 3) {
10480 return -1;
10481 }
10482 if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))
10483 return -1;
10484
10485 if (!jfr->enable) {
10486 if (ixj_WriteDSPCommand(0x5152, j))
10487 return -1;
10488 else
10489 return 0;
10490 } else {
10491 if (ixj_WriteDSPCommand(0x5153, j))
10492 return -1;
10493
10494 if (ixj_WriteDSPCommand(0x5154 + jfr->filter, j))
10495 return -1;
10496 }
10497
10498
10499
10500
10501
10502 if (ixj_WriteDSPCommand(0x5170 + jfr->filter, j))
10503 return -1;
10504 if (j->ver.low != 0x12) {
10505 cmd = 0x515B;
10506 max = 19;
10507 } else {
10508 cmd = 0x515E;
10509 max = 15;
10510 }
10511 if (ixj_WriteDSPCommand(cmd, j))
10512 return -1;
10513 for (cnt = 0; cnt < max; cnt++) {
10514 if (ixj_WriteDSPCommand(jfr->coeff[cnt], j))
10515 return -1;
10516 }
10517 j->filter_en[jfr->filter] = jfr->enable;
10518 return 0;
10519}
10520
10521static int ixj_init_tone(IXJ *j, IXJ_TONE * ti)
10522{
10523 int freq0, freq1;
10524 unsigned short data;
10525 if (ti->freq0) {
10526 freq0 = ti->freq0;
10527 } else {
10528 freq0 = 0x7FFF;
10529 }
10530
10531 if (ti->freq1) {
10532 freq1 = ti->freq1;
10533 } else {
10534 freq1 = 0x7FFF;
10535 }
10536
10537 if(ti->tone_index > 12 && ti->tone_index < 28)
10538 {
10539 if (ixj_WriteDSPCommand(0x6800 + ti->tone_index, j))
10540 return -1;
10541 if (ixj_WriteDSPCommand(0x6000 + (ti->gain1 << 4) + ti->gain0, j))
10542 return -1;
10543 data = freq0;
10544 if (ixj_WriteDSPCommand(data, j))
10545 return -1;
10546 data = freq1;
10547 if (ixj_WriteDSPCommand(data, j))
10548 return -1;
10549 }
10550 return freq0;
10551}
10552
10553