ixj.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:316k
- checksum %= 256;
- checksum ^= 0xFF;
- checksum += 1;
- ixj_write_cid_byte(j, (char) checksum);
- pad = j->fskdcnt % 240;
- if (pad) {
- pad = 240 - pad;
- }
- ixj_pad_fsk(j, pad);
- }
- static void ixj_write_frame(IXJ *j)
- {
- int cnt, frame_count, dly;
- IXJ_WORD dat;
- BYTES blankword;
- frame_count = 0;
- if(j->flags.cidplay) {
- for(cnt = 0; cnt < 480; cnt++) {
- if (!(cnt % 16) && !IsTxReady(j)) {
- dly = 0;
- while (!IsTxReady(j)) {
- if (dly++ > 5) {
- dly = 0;
- break;
- }
- udelay(10);
- }
- }
- dat.word = j->fskdata[j->cidcnt++];
- outb_p(dat.bytes.low, j->DSPbase + 0x0C);
- outb_p(dat.bytes.high, j->DSPbase + 0x0D);
- cnt++;
- }
- if(j->cidcnt >= j->fskdcnt) {
- ixj_post_cid(j);
- }
- /* This may seem rude, but if we just played one frame of FSK data for CallerID
- and there is real audio data in the buffer, we need to throw it away because
- we just used it's time slot */
- if (j->write_buffer_rp > j->write_buffer_wp) {
- j->write_buffer_rp += j->cid_play_frame_size * 2;
- if (j->write_buffer_rp >= j->write_buffer_end) {
- j->write_buffer_rp = j->write_buffer;
- }
- j->write_buffers_empty++;
- wake_up_interruptible(&j->write_q); /* Wake any blocked writers */
- wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
- }
- } else if (j->write_buffer && j->write_buffers_empty < 1) {
- if (j->write_buffer_wp > j->write_buffer_rp) {
- frame_count =
- (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2);
- }
- if (j->write_buffer_rp > j->write_buffer_wp) {
- frame_count =
- (j->write_buffer_wp - j->write_buffer) / (j->play_frame_size * 2) +
- (j->write_buffer_end - j->write_buffer_rp) / (j->play_frame_size * 2);
- }
- if (frame_count >= 1) {
- if (j->ver.low == 0x12 && j->play_mode && j->flags.play_first_frame) {
- switch (j->play_mode) {
- case PLAYBACK_MODE_ULAW:
- case PLAYBACK_MODE_ALAW:
- blankword.low = blankword.high = 0xFF;
- break;
- case PLAYBACK_MODE_8LINEAR:
- case PLAYBACK_MODE_16LINEAR:
- blankword.low = blankword.high = 0x00;
- break;
- case PLAYBACK_MODE_8LINEAR_WSS:
- blankword.low = blankword.high = 0x80;
- break;
- }
- for (cnt = 0; cnt < 16; cnt++) {
- if (!(cnt % 16) && !IsTxReady(j)) {
- dly = 0;
- while (!IsTxReady(j)) {
- if (dly++ > 5) {
- dly = 0;
- break;
- }
- udelay(10);
- }
- }
- outb_p((blankword.low), j->DSPbase + 0x0C);
- outb_p((blankword.high), j->DSPbase + 0x0D);
- }
- j->flags.play_first_frame = 0;
- } else if (j->play_codec == G723_63 && j->flags.play_first_frame) {
- for (cnt = 0; cnt < 24; cnt++) {
- if(cnt == 12) {
- blankword.low = 0x02;
- blankword.high = 0x00;
- }
- else {
- blankword.low = blankword.high = 0x00;
- }
- if (!(cnt % 16) && !IsTxReady(j)) {
- dly = 0;
- while (!IsTxReady(j)) {
- if (dly++ > 5) {
- dly = 0;
- break;
- }
- udelay(10);
- }
- }
- outb_p((blankword.low), j->DSPbase + 0x0C);
- outb_p((blankword.high), j->DSPbase + 0x0D);
- }
- j->flags.play_first_frame = 0;
- }
- for (cnt = 0; cnt < j->play_frame_size * 2; cnt += 2) {
- if (!(cnt % 16) && !IsTxReady(j)) {
- dly = 0;
- while (!IsTxReady(j)) {
- if (dly++ > 5) {
- dly = 0;
- break;
- }
- udelay(10);
- }
- }
- /* Add word 0 to G.729 frames for the 8021. Right now we don't do VAD/CNG */
- if (j->play_codec == G729 && (cnt == 0 || cnt == 10 || cnt == 20)) {
- if(j->write_buffer_rp + cnt == 0 && j->write_buffer_rp + cnt + 1 == 0 && j->write_buffer_rp + cnt + 2 == 0 &&
- j->write_buffer_rp + cnt + 3 == 0 && j->write_buffer_rp + cnt + 4 == 0 && j->write_buffer_rp + cnt + 5 == 0 &&
- j->write_buffer_rp + cnt + 6 == 0 && j->write_buffer_rp + cnt + 7 == 0 && j->write_buffer_rp + cnt + 8 == 0 &&
- j->write_buffer_rp + cnt + 9 == 0) {
- /* someone is trying to write silence lets make this a type 0 frame. */
- outb_p(0x00, j->DSPbase + 0x0C);
- outb_p(0x00, j->DSPbase + 0x0D);
- } else {
- /* so all other frames are type 1. */
- outb_p(0x01, j->DSPbase + 0x0C);
- outb_p(0x00, j->DSPbase + 0x0D);
- }
- }
- outb_p(*(j->write_buffer_rp + cnt), j->DSPbase + 0x0C);
- outb_p(*(j->write_buffer_rp + cnt + 1), j->DSPbase + 0x0D);
- *(j->write_buffer_rp + cnt) = 0;
- *(j->write_buffer_rp + cnt + 1) = 0;
- }
- j->write_buffer_rp += j->play_frame_size * 2;
- if (j->write_buffer_rp >= j->write_buffer_end) {
- j->write_buffer_rp = j->write_buffer;
- }
- j->write_buffers_empty++;
- wake_up_interruptible(&j->write_q); /* Wake any blocked writers */
- wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
- ++j->frameswritten;
- }
- } else {
- j->drybuffer++;
- }
- if(j->ixj_signals[SIG_WRITE_READY]) {
- ixj_kill_fasync(j, SIG_WRITE_READY, POLL_OUT);
- }
- }
- static int idle(IXJ *j)
- {
- if (ixj_WriteDSPCommand(0x0000, j)) /* DSP Idle */
- return 0;
- if (j->ssr.high || j->ssr.low) {
- return 0;
- } else {
- j->play_mode = -1;
- j->flags.playing = 0;
- j->rec_mode = -1;
- j->flags.recording = 0;
- return 1;
- }
- }
- static int set_base_frame(IXJ *j, int size)
- {
- unsigned short cmd;
- int cnt;
- idle(j);
- j->cid_play_aec_level = j->aec_level;
- aec_stop(j);
- for (cnt = 0; cnt < 10; cnt++) {
- if (idle(j))
- break;
- }
- if (j->ssr.high || j->ssr.low)
- return -1;
- if (j->dsp.low != 0x20) {
- switch (size) {
- case 30:
- cmd = 0x07F0;
- /* Set Base Frame Size to 240 pg9-10 8021 */
- break;
- case 20:
- cmd = 0x07A0;
- /* Set Base Frame Size to 160 pg9-10 8021 */
- break;
- case 10:
- cmd = 0x0750;
- /* Set Base Frame Size to 80 pg9-10 8021 */
- break;
- default:
- return -1;
- }
- } else {
- if (size == 30)
- return size;
- else
- return -1;
- }
- if (ixj_WriteDSPCommand(cmd, j)) {
- j->baseframe.high = j->baseframe.low = 0xFF;
- return -1;
- } else {
- j->baseframe.high = j->ssr.high;
- j->baseframe.low = j->ssr.low;
- /* If the status returned is 0x0000 (pg9-9 8021) the call failed */
- if(j->baseframe.high == 0x00 && j->baseframe.low == 0x00) {
- return -1;
- }
- }
- ixj_aec_start(j, j->cid_play_aec_level);
- return size;
- }
- static int set_rec_codec(IXJ *j, int rate)
- {
- int retval = 0;
- j->rec_codec = rate;
- switch (rate) {
- case G723_63:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->rec_frame_size = 12;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G723_53:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->rec_frame_size = 10;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS85:
- if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
- j->rec_frame_size = 16;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS48:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->rec_frame_size = 9;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS41:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->rec_frame_size = 8;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G728:
- if (j->dsp.low != 0x20) {
- j->rec_frame_size = 48;
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G729:
- if (j->dsp.low != 0x20) {
- if (!j->flags.g729_loaded) {
- retval = 1;
- break;
- }
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 10;
- break;
- case 0x50:
- j->rec_frame_size = 5;
- break;
- default:
- j->rec_frame_size = 15;
- break;
- }
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G729B:
- if (j->dsp.low != 0x20) {
- if (!j->flags.g729_loaded) {
- retval = 1;
- break;
- }
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 12;
- break;
- case 0x50:
- j->rec_frame_size = 6;
- break;
- default:
- j->rec_frame_size = 18;
- break;
- }
- j->rec_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case ULAW:
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 80;
- break;
- case 0x50:
- j->rec_frame_size = 40;
- break;
- default:
- j->rec_frame_size = 120;
- break;
- }
- j->rec_mode = 4;
- break;
- case ALAW:
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 80;
- break;
- case 0x50:
- j->rec_frame_size = 40;
- break;
- default:
- j->rec_frame_size = 120;
- break;
- }
- j->rec_mode = 4;
- break;
- case LINEAR16:
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 160;
- break;
- case 0x50:
- j->rec_frame_size = 80;
- break;
- default:
- j->rec_frame_size = 240;
- break;
- }
- j->rec_mode = 5;
- break;
- case LINEAR8:
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 80;
- break;
- case 0x50:
- j->rec_frame_size = 40;
- break;
- default:
- j->rec_frame_size = 120;
- break;
- }
- j->rec_mode = 6;
- break;
- case WSS:
- switch (j->baseframe.low) {
- case 0xA0:
- j->rec_frame_size = 80;
- break;
- case 0x50:
- j->rec_frame_size = 40;
- break;
- default:
- j->rec_frame_size = 120;
- break;
- }
- j->rec_mode = 7;
- break;
- default:
- j->rec_frame_size = 0;
- j->rec_mode = -1;
- if (j->read_buffer) {
- kfree(j->read_buffer);
- j->read_buffer = NULL;
- j->read_buffer_size = 0;
- }
- retval = 1;
- break;
- }
- return retval;
- }
- static int ixj_record_start(IXJ *j)
- {
- unsigned short cmd = 0x0000;
- if (j->read_buffer) {
- ixj_record_stop(j);
- }
- j->flags.recording = 1;
- ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
- if(ixjdebug & 0x0002)
- printk("IXJ %d Starting Record Codec %d at %ldn", j->board, j->rec_codec, jiffies);
- if (!j->rec_mode) {
- switch (j->rec_codec) {
- case G723_63:
- cmd = 0x5131;
- break;
- case G723_53:
- cmd = 0x5132;
- break;
- case TS85:
- cmd = 0x5130; /* TrueSpeech 8.5 */
- break;
- case TS48:
- cmd = 0x5133; /* TrueSpeech 4.8 */
- break;
- case TS41:
- cmd = 0x5134; /* TrueSpeech 4.1 */
- break;
- case G728:
- cmd = 0x5135;
- break;
- case G729:
- case G729B:
- cmd = 0x5136;
- break;
- default:
- return 1;
- }
- if (ixj_WriteDSPCommand(cmd, j))
- return -1;
- }
- if (!j->read_buffer) {
- if (!j->read_buffer)
- j->read_buffer = kmalloc(j->rec_frame_size * 2, GFP_ATOMIC);
- if (!j->read_buffer) {
- printk("Read buffer allocation for ixj board %d failed!n", j->board);
- return -ENOMEM;
- }
- }
- j->read_buffer_size = j->rec_frame_size * 2;
- if (ixj_WriteDSPCommand(0x5102, j)) /* Set Poll sync mode */
- return -1;
- switch (j->rec_mode) {
- case 0:
- cmd = 0x1C03; /* Record C1 */
- break;
- case 4:
- if (j->ver.low == 0x12) {
- cmd = 0x1E03; /* Record C1 */
- } else {
- cmd = 0x1E01; /* Record C1 */
- }
- break;
- case 5:
- if (j->ver.low == 0x12) {
- cmd = 0x1E83; /* Record C1 */
- } else {
- cmd = 0x1E81; /* Record C1 */
- }
- break;
- case 6:
- if (j->ver.low == 0x12) {
- cmd = 0x1F03; /* Record C1 */
- } else {
- cmd = 0x1F01; /* Record C1 */
- }
- break;
- case 7:
- if (j->ver.low == 0x12) {
- cmd = 0x1F83; /* Record C1 */
- } else {
- cmd = 0x1F81; /* Record C1 */
- }
- break;
- }
- if (ixj_WriteDSPCommand(cmd, j))
- return -1;
- if (j->flags.playing) {
- ixj_aec_start(j, j->aec_level);
- }
- return 0;
- }
- static void ixj_record_stop(IXJ *j)
- {
- if(ixjdebug & 0x0002)
- printk("IXJ %d Stopping Record Codec %d at %ldn", j->board, j->rec_codec, jiffies);
- if (j->read_buffer) {
- kfree(j->read_buffer);
- j->read_buffer = NULL;
- j->read_buffer_size = 0;
- }
- if (j->rec_mode > -1) {
- ixj_WriteDSPCommand(0x5120, j);
- j->rec_mode = -1;
- }
- j->flags.recording = 0;
- }
- static void ixj_vad(IXJ *j, int arg)
- {
- if (arg)
- ixj_WriteDSPCommand(0x513F, j);
- else
- ixj_WriteDSPCommand(0x513E, j);
- }
- static void set_rec_depth(IXJ *j, int depth)
- {
- if (depth > 60)
- depth = 60;
- if (depth < 0)
- depth = 0;
- ixj_WriteDSPCommand(0x5180 + depth, j);
- }
- static void set_dtmf_prescale(IXJ *j, int volume)
- {
- ixj_WriteDSPCommand(0xCF07, j);
- ixj_WriteDSPCommand(volume, j);
- }
- static int get_dtmf_prescale(IXJ *j)
- {
- ixj_WriteDSPCommand(0xCF05, j);
- return j->ssr.high << 8 | j->ssr.low;
- }
- static void set_rec_volume(IXJ *j, int volume)
- {
- if(j->aec_level == AEC_AGC) {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "IXJ: /dev/phone%d Setting AGC Threshold to 0x%4.4xn", j->board, volume);
- ixj_WriteDSPCommand(0xCF96, j);
- ixj_WriteDSPCommand(volume, j);
- } else {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "IXJ: /dev/phone %d Setting Record Volume to 0x%4.4xn", j->board, volume);
- ixj_WriteDSPCommand(0xCF03, j);
- ixj_WriteDSPCommand(volume, j);
- }
- }
- static int set_rec_volume_linear(IXJ *j, int volume)
- {
- int newvolume, dsprecmax;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "IXJ: /dev/phone %d Setting Linear Record Volume to 0x%4.4xn", j->board, volume);
- if(volume > 100 || volume < 0) {
- return -1;
- }
- /* This should normalize the perceived volumes between the different cards caused by differences in the hardware */
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- dsprecmax = 0x440;
- break;
- case QTI_LINEJACK:
- dsprecmax = 0x180;
- ixj_mixer(0x0203, j); /*Voice Left Volume unmute 6db */
- ixj_mixer(0x0303, j); /*Voice Right Volume unmute 6db */
- ixj_mixer(0x0C00, j); /*Mono1 unmute 12db */
- break;
- case QTI_PHONEJACK_LITE:
- dsprecmax = 0x4C0;
- break;
- case QTI_PHONEJACK_PCI:
- dsprecmax = 0x100;
- break;
- case QTI_PHONECARD:
- dsprecmax = 0x400;
- break;
- default:
- return -1;
- }
- newvolume = (dsprecmax * volume) / 100;
- set_rec_volume(j, newvolume);
- return 0;
- }
- static int get_rec_volume(IXJ *j)
- {
- if(j->aec_level == AEC_AGC) {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Getting AGC Thresholdn");
- ixj_WriteDSPCommand(0xCF86, j);
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "AGC Threshold is 0x%2.2x%2.2xn", j->ssr.high, j->ssr.low);
- return j->ssr.high << 8 | j->ssr.low;
- } else {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Getting Record Volumen");
- ixj_WriteDSPCommand(0xCF01, j);
- return j->ssr.high << 8 | j->ssr.low;
- }
- }
- static int get_rec_volume_linear(IXJ *j)
- {
- int volume, newvolume, dsprecmax;
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- dsprecmax = 0x440;
- break;
- case QTI_LINEJACK:
- dsprecmax = 0x180;
- break;
- case QTI_PHONEJACK_LITE:
- dsprecmax = 0x4C0;
- break;
- case QTI_PHONEJACK_PCI:
- dsprecmax = 0x100;
- break;
- case QTI_PHONECARD:
- dsprecmax = 0x400;
- break;
- default:
- return -1;
- }
- volume = get_rec_volume(j);
- newvolume = (volume * 100) / dsprecmax;
- if(newvolume > 100)
- newvolume = 100;
- return newvolume;
- }
- static int get_rec_level(IXJ *j)
- {
- int retval;
- ixj_WriteDSPCommand(0xCF88, j);
- retval = j->ssr.high << 8 | j->ssr.low;
- retval = (retval * 256) / 240;
- return retval;
- }
- static void ixj_aec_start(IXJ *j, int level)
- {
- j->aec_level = level;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "AGC set = 0x%2.2xn", j->aec_level);
- if (!level) {
- aec_stop(j);
- } else {
- if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
- ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer */
- ixj_WriteDSPCommand(0x0300, j);
- }
- ixj_WriteDSPCommand(0xB001, j); /* AEC On */
- ixj_WriteDSPCommand(0xE013, j); /* Advanced AEC C1 */
- switch (level) {
- case AEC_LOW:
- ixj_WriteDSPCommand(0x0000, j); /* Advanced AEC C2 = off */
- ixj_WriteDSPCommand(0xE011, j);
- ixj_WriteDSPCommand(0xFFFF, j);
- ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
- ixj_WriteDSPCommand(0x0000, j); /* to off */
-
- break;
- case AEC_MED:
- ixj_WriteDSPCommand(0x0600, j); /* Advanced AEC C2 = on medium */
- ixj_WriteDSPCommand(0xE011, j);
- ixj_WriteDSPCommand(0x0080, j);
- ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
- ixj_WriteDSPCommand(0x0000, j); /* to off */
-
- break;
- case AEC_HIGH:
- ixj_WriteDSPCommand(0x0C00, j); /* Advanced AEC C2 = on high */
- ixj_WriteDSPCommand(0xE011, j);
- ixj_WriteDSPCommand(0x0080, j);
- ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
- ixj_WriteDSPCommand(0x0000, j); /* to off */
-
- break;
- case AEC_AGC:
- /* First we have to put the AEC into advance auto mode so that AGC will not conflict with it */
- ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
- ixj_WriteDSPCommand(0xE011, j);
- ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
- ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
- if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
- ixj_WriteDSPCommand(0x0224, j);
- else
- ixj_WriteDSPCommand(0x1224, j);
- ixj_WriteDSPCommand(0xE014, j);
- ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
- ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
- /* Now we can set the AGC initial parameters and turn it on */
- ixj_WriteDSPCommand(0xCF90, j); /* Set AGC Minumum gain */
- ixj_WriteDSPCommand(0x0020, j); /* to 0.125 (-18dB) */
-
- ixj_WriteDSPCommand(0xCF91, j); /* Set AGC Maximum gain */
- ixj_WriteDSPCommand(0x1000, j); /* to 16 (24dB) */
-
- ixj_WriteDSPCommand(0xCF92, j); /* Set AGC start gain */
- ixj_WriteDSPCommand(0x0800, j); /* to 8 (+18dB) */
-
- ixj_WriteDSPCommand(0xCF93, j); /* Set AGC hold time */
- ixj_WriteDSPCommand(0x1F40, j); /* to 2 seconds (units are 250us) */
-
- ixj_WriteDSPCommand(0xCF94, j); /* Set AGC Attack Time Constant */
- ixj_WriteDSPCommand(0x0005, j); /* to 8ms */
-
- ixj_WriteDSPCommand(0xCF95, j); /* Set AGC Decay Time Constant */
- ixj_WriteDSPCommand(0x000D, j); /* to 4096ms */
-
- ixj_WriteDSPCommand(0xCF96, j); /* Set AGC Attack Threshold */
- ixj_WriteDSPCommand(0x1200, j); /* to 25% */
-
- ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
- ixj_WriteDSPCommand(0x0001, j); /* to on */
-
- break;
- case AEC_AUTO:
- ixj_WriteDSPCommand(0x0002, j); /* Attenuation scaling factor of 2 */
- ixj_WriteDSPCommand(0xE011, j);
- ixj_WriteDSPCommand(0x0100, j); /* Higher Threshold Floor */
- ixj_WriteDSPCommand(0xE012, j); /* Set Train and Lock */
- if(j->cardtype == QTI_LINEJACK || j->cardtype == QTI_PHONECARD)
- ixj_WriteDSPCommand(0x0224, j);
- else
- ixj_WriteDSPCommand(0x1224, j);
- ixj_WriteDSPCommand(0xE014, j);
- ixj_WriteDSPCommand(0x0003, j); /* Lock threashold at 3dB */
- ixj_WriteDSPCommand(0xE338, j); /* Set Echo Suppresser Attenuation to 0dB */
- break;
- }
- }
- }
- static void aec_stop(IXJ *j)
- {
- j->aec_level = AEC_OFF;
- if (j->rec_codec == G729 || j->play_codec == G729 || j->rec_codec == G729B || j->play_codec == G729B) {
- ixj_WriteDSPCommand(0xE022, j); /* Move AEC filter buffer back */
- ixj_WriteDSPCommand(0x0700, j);
- }
- if (j->play_mode != -1 && j->rec_mode != -1)
- {
- ixj_WriteDSPCommand(0xB002, j); /* AEC Stop */
- }
- }
- static int set_play_codec(IXJ *j, int rate)
- {
- int retval = 0;
- j->play_codec = rate;
- switch (rate) {
- case G723_63:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->play_frame_size = 12;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G723_53:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->play_frame_size = 10;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS85:
- if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
- j->play_frame_size = 16;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS48:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->play_frame_size = 9;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case TS41:
- if (j->ver.low != 0x12 || ixj_convert_loaded) {
- j->play_frame_size = 8;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G728:
- if (j->dsp.low != 0x20) {
- j->play_frame_size = 48;
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G729:
- if (j->dsp.low != 0x20) {
- if (!j->flags.g729_loaded) {
- retval = 1;
- break;
- }
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 10;
- break;
- case 0x50:
- j->play_frame_size = 5;
- break;
- default:
- j->play_frame_size = 15;
- break;
- }
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case G729B:
- if (j->dsp.low != 0x20) {
- if (!j->flags.g729_loaded) {
- retval = 1;
- break;
- }
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 12;
- break;
- case 0x50:
- j->play_frame_size = 6;
- break;
- default:
- j->play_frame_size = 18;
- break;
- }
- j->play_mode = 0;
- } else {
- retval = 1;
- }
- break;
- case ULAW:
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 80;
- break;
- case 0x50:
- j->play_frame_size = 40;
- break;
- default:
- j->play_frame_size = 120;
- break;
- }
- j->play_mode = 2;
- break;
- case ALAW:
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 80;
- break;
- case 0x50:
- j->play_frame_size = 40;
- break;
- default:
- j->play_frame_size = 120;
- break;
- }
- j->play_mode = 2;
- break;
- case LINEAR16:
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 160;
- break;
- case 0x50:
- j->play_frame_size = 80;
- break;
- default:
- j->play_frame_size = 240;
- break;
- }
- j->play_mode = 6;
- break;
- case LINEAR8:
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 80;
- break;
- case 0x50:
- j->play_frame_size = 40;
- break;
- default:
- j->play_frame_size = 120;
- break;
- }
- j->play_mode = 4;
- break;
- case WSS:
- switch (j->baseframe.low) {
- case 0xA0:
- j->play_frame_size = 80;
- break;
- case 0x50:
- j->play_frame_size = 40;
- break;
- default:
- j->play_frame_size = 120;
- break;
- }
- j->play_mode = 5;
- break;
- default:
- j->play_frame_size = 0;
- j->play_mode = -1;
- if (j->write_buffer) {
- kfree(j->write_buffer);
- j->write_buffer = NULL;
- j->write_buffer_size = 0;
- }
- retval = 1;
- break;
- }
- return retval;
- }
- static int ixj_play_start(IXJ *j)
- {
- unsigned short cmd = 0x0000;
- if (j->write_buffer) {
- ixj_play_stop(j);
- }
- if(ixjdebug & 0x0002)
- printk("IXJ %d Starting Play Codec %d at %ldn", j->board, j->play_codec, jiffies);
- j->flags.playing = 1;
- ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
- j->flags.play_first_frame = 1;
- j->drybuffer = 0;
- if (!j->play_mode) {
- switch (j->play_codec) {
- case G723_63:
- cmd = 0x5231;
- break;
- case G723_53:
- cmd = 0x5232;
- break;
- case TS85:
- cmd = 0x5230; /* TrueSpeech 8.5 */
- break;
- case TS48:
- cmd = 0x5233; /* TrueSpeech 4.8 */
- break;
- case TS41:
- cmd = 0x5234; /* TrueSpeech 4.1 */
- break;
- case G728:
- cmd = 0x5235;
- break;
- case G729:
- case G729B:
- cmd = 0x5236;
- break;
- default:
- return 1;
- }
- if (ixj_WriteDSPCommand(cmd, j))
- return -1;
- }
- j->write_buffer = kmalloc(j->play_frame_size * 2, GFP_ATOMIC);
- if (!j->write_buffer) {
- printk("Write buffer allocation for ixj board %d failed!n", j->board);
- return -ENOMEM;
- }
- /* j->write_buffers_empty = 2; */
- j->write_buffers_empty = 1;
- j->write_buffer_size = j->play_frame_size * 2;
- j->write_buffer_end = j->write_buffer + j->play_frame_size * 2;
- j->write_buffer_rp = j->write_buffer_wp = j->write_buffer;
- if (ixj_WriteDSPCommand(0x5202, j)) /* Set Poll sync mode */
- return -1;
- switch (j->play_mode) {
- case 0:
- cmd = 0x2C03;
- break;
- case 2:
- if (j->ver.low == 0x12) {
- cmd = 0x2C23;
- } else {
- cmd = 0x2C21;
- }
- break;
- case 4:
- if (j->ver.low == 0x12) {
- cmd = 0x2C43;
- } else {
- cmd = 0x2C41;
- }
- break;
- case 5:
- if (j->ver.low == 0x12) {
- cmd = 0x2C53;
- } else {
- cmd = 0x2C51;
- }
- break;
- case 6:
- if (j->ver.low == 0x12) {
- cmd = 0x2C63;
- } else {
- cmd = 0x2C61;
- }
- break;
- }
- if (ixj_WriteDSPCommand(cmd, j))
- return -1;
- if (ixj_WriteDSPCommand(0x2000, j)) /* Playback C2 */
- return -1;
- if (ixj_WriteDSPCommand(0x2000 + j->play_frame_size, j)) /* Playback C3 */
- return -1;
- if (j->flags.recording) {
- ixj_aec_start(j, j->aec_level);
- }
- return 0;
- }
- static void ixj_play_stop(IXJ *j)
- {
- if(ixjdebug & 0x0002)
- printk("IXJ %d Stopping Play Codec %d at %ldn", j->board, j->play_codec, jiffies);
- if (j->write_buffer) {
- kfree(j->write_buffer);
- j->write_buffer = NULL;
- j->write_buffer_size = 0;
- }
- if (j->play_mode > -1) {
- ixj_WriteDSPCommand(0x5221, j); /* Stop playback and flush buffers. 8022 reference page 9-40 */
- j->play_mode = -1;
- }
- j->flags.playing = 0;
- }
- static inline int get_play_level(IXJ *j)
- {
- int retval;
- ixj_WriteDSPCommand(0xCF8F, j); /* 8022 Reference page 9-38 */
- return j->ssr.high << 8 | j->ssr.low;
- retval = j->ssr.high << 8 | j->ssr.low;
- retval = (retval * 256) / 240;
- return retval;
- }
- static unsigned int ixj_poll(struct file *file_p, poll_table * wait)
- {
- unsigned int mask = 0;
- IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode->i_rdev));
- poll_wait(file_p, &(j->poll_q), wait);
- if (j->read_buffer_ready > 0)
- mask |= POLLIN | POLLRDNORM; /* readable */
- if (j->write_buffers_empty > 0)
- mask |= POLLOUT | POLLWRNORM; /* writable */
- if (j->ex.bytes)
- mask |= POLLPRI;
- return mask;
- }
- static int ixj_play_tone(IXJ *j, char tone)
- {
- if (!j->tone_state) {
- if(ixjdebug & 0x0002) {
- printk("IXJ %d starting tone %d at %ldn", j->board, tone, jiffies);
- }
- if (j->dsp.low == 0x20) {
- idle(j);
- }
- j->tone_start_jif = jiffies;
- j->tone_state = 1;
- }
- j->tone_index = tone;
- if (ixj_WriteDSPCommand(0x6000 + j->tone_index, j))
- return -1;
- return 0;
- }
- static int ixj_set_tone_on(unsigned short arg, IXJ *j)
- {
- j->tone_on_time = arg;
- if (ixj_WriteDSPCommand(0x6E04, j)) /* Set Tone On Period */
- return -1;
- if (ixj_WriteDSPCommand(arg, j))
- return -1;
- return 0;
- }
- static int SCI_WaitHighSCI(IXJ *j)
- {
- int cnt;
- j->pld_scrr.byte = inb_p(j->XILINXbase);
- if (!j->pld_scrr.bits.sci) {
- for (cnt = 0; cnt < 10; cnt++) {
- udelay(32);
- j->pld_scrr.byte = inb_p(j->XILINXbase);
- if ((j->pld_scrr.bits.sci))
- return 1;
- }
- if (ixjdebug & 0x0001)
- printk(KERN_INFO "SCI Wait High failed %xn", j->pld_scrr.byte);
- return 0;
- } else
- return 1;
- }
- static int SCI_WaitLowSCI(IXJ *j)
- {
- int cnt;
- j->pld_scrr.byte = inb_p(j->XILINXbase);
- if (j->pld_scrr.bits.sci) {
- for (cnt = 0; cnt < 10; cnt++) {
- udelay(32);
- j->pld_scrr.byte = inb_p(j->XILINXbase);
- if (!(j->pld_scrr.bits.sci))
- return 1;
- }
- if (ixjdebug & 0x0001)
- printk(KERN_INFO "SCI Wait Low failed %xn", j->pld_scrr.byte);
- return 0;
- } else
- return 1;
- }
- static int SCI_Control(IXJ *j, int control)
- {
- switch (control) {
- case SCI_End:
- j->pld_scrw.bits.c0 = 0; /* Set PLD Serial control interface */
- j->pld_scrw.bits.c1 = 0; /* to no selection */
- break;
- case SCI_Enable_DAA:
- j->pld_scrw.bits.c0 = 1; /* Set PLD Serial control interface */
- j->pld_scrw.bits.c1 = 0; /* to write to DAA */
- break;
- case SCI_Enable_Mixer:
- j->pld_scrw.bits.c0 = 0; /* Set PLD Serial control interface */
- j->pld_scrw.bits.c1 = 1; /* to write to mixer */
- break;
- case SCI_Enable_EEPROM:
- j->pld_scrw.bits.c0 = 1; /* Set PLD Serial control interface */
- j->pld_scrw.bits.c1 = 1; /* to write to EEPROM */
- break;
- default:
- return 0;
- break;
- }
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- switch (control) {
- case SCI_End:
- return 1;
- break;
- case SCI_Enable_DAA:
- case SCI_Enable_Mixer:
- case SCI_Enable_EEPROM:
- if (!SCI_WaitHighSCI(j))
- return 0;
- break;
- default:
- return 0;
- break;
- }
- return 1;
- }
- static int SCI_Prepare(IXJ *j)
- {
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- return 1;
- }
- static int ixj_get_mixer(long val, IXJ *j)
- {
- int reg = (val & 0x1F00) >> 8;
- return j->mix.vol[reg];
- }
- static int ixj_mixer(long val, IXJ *j)
- {
- BYTES bytes;
- bytes.high = (val & 0x1F00) >> 8;
- bytes.low = val & 0x00FF;
- /* save mixer value so we can get back later on */
- j->mix.vol[bytes.high] = bytes.low;
- outb_p(bytes.high & 0x1F, j->XILINXbase + 0x03); /* Load Mixer Address */
- outb_p(bytes.low, j->XILINXbase + 0x02); /* Load Mixer Data */
- SCI_Control(j, SCI_Enable_Mixer);
- SCI_Control(j, SCI_End);
- return 0;
- }
- static int daa_load(BYTES * p_bytes, IXJ *j)
- {
- outb_p(p_bytes->high, j->XILINXbase + 0x03);
- outb_p(p_bytes->low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- else
- return 1;
- }
- static int ixj_daa_cr4(IXJ *j, char reg)
- {
- BYTES bytes;
- switch (j->daa_mode) {
- case SOP_PU_SLEEP:
- bytes.high = 0x14;
- break;
- case SOP_PU_RINGING:
- bytes.high = 0x54;
- break;
- case SOP_PU_CONVERSATION:
- bytes.high = 0x94;
- break;
- case SOP_PU_PULSEDIALING:
- bytes.high = 0xD4;
- break;
- }
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = reg;
- switch (j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGX) {
- case 0:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 0;
- break;
- case 1:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 2;
- break;
- case 2:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 1;
- break;
- case 3:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.bitreg.AGR_Z = 3;
- break;
- }
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Prepare(j))
- return 0;
- return 1;
- }
- static char daa_int_read(IXJ *j)
- {
- BYTES bytes;
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x38;
- bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (bytes.low != ALISDAA_ID_BYTE) {
- if (ixjdebug & 0x0001)
- printk("Cannot read DAA ID Byte high = %d low = %dn", bytes.high, bytes.low);
- return 0;
- }
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.reg = bytes.high;
- return 1;
- }
- static char daa_CR_read(IXJ *j, int cr)
- {
- IXJ_WORD wdata;
- BYTES bytes;
- if (!SCI_Prepare(j))
- return 0;
- switch (j->daa_mode) {
- case SOP_PU_SLEEP:
- bytes.high = 0x30 + cr;
- break;
- case SOP_PU_RINGING:
- bytes.high = 0x70 + cr;
- break;
- case SOP_PU_CONVERSATION:
- bytes.high = 0xB0 + cr;
- break;
- case SOP_PU_PULSEDIALING:
- bytes.high = 0xF0 + cr;
- break;
- }
- bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (bytes.low != ALISDAA_ID_BYTE) {
- if (ixjdebug & 0x0001)
- printk("Cannot read DAA ID Byte high = %d low = %dn", bytes.high, bytes.low);
- return 0;
- }
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- wdata.word = inw_p(j->XILINXbase + 0x02);
- switch(cr){
- case 5:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = wdata.bytes.high;
- break;
- case 4:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg = wdata.bytes.high;
- break;
- case 3:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg = wdata.bytes.high;
- break;
- case 2:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg = wdata.bytes.high;
- break;
- case 1:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg = wdata.bytes.high;
- break;
- case 0:
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg = wdata.bytes.high;
- break;
- default:
- return 0;
- }
- return 1;
- }
- static int ixj_daa_cid_reset(IXJ *j)
- {
- int i;
- BYTES bytes;
- if (ixjdebug & 0x0002)
- printk("DAA Clearing CID ramn");
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x58;
- bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_WaitHighSCI(j))
- return 0;
- for (i = 0; i < ALISDAA_CALLERID_SIZE - 1; i += 2) {
- bytes.high = bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- if (i < ALISDAA_CALLERID_SIZE - 1)
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_WaitHighSCI(j))
- return 0;
- }
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (ixjdebug & 0x0002)
- printk("DAA CID ram clearedn");
- return 1;
- }
- static int ixj_daa_cid_read(IXJ *j)
- {
- int i;
- BYTES bytes;
- char CID[ALISDAA_CALLERID_SIZE], mContinue;
- char *pIn, *pOut;
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x78;
- bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_WaitHighSCI(j))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (bytes.low != ALISDAA_ID_BYTE) {
- if (ixjdebug & 0x0001)
- printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %dn", bytes.high, bytes.low);
- return 0;
- }
- for (i = 0; i < ALISDAA_CALLERID_SIZE; i += 2) {
- bytes.high = bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_WaitHighSCI(j))
- return 0;
- CID[i + 0] = inb_p(j->XILINXbase + 0x03);
- CID[i + 1] = inb_p(j->XILINXbase + 0x02);
- }
- if (!SCI_Control(j, SCI_End))
- return 0;
- pIn = CID;
- pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
- mContinue = 1;
- while (mContinue) {
- if ((pIn[1] & 0x03) == 0x01) {
- pOut[0] = pIn[0];
- }
- if ((pIn[2] & 0x0c) == 0x04) {
- pOut[1] = ((pIn[2] & 0x03) << 6) | ((pIn[1] & 0xfc) >> 2);
- }
- if ((pIn[3] & 0x30) == 0x10) {
- pOut[2] = ((pIn[3] & 0x0f) << 4) | ((pIn[2] & 0xf0) >> 4);
- }
- if ((pIn[4] & 0xc0) == 0x40) {
- pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6);
- } else {
- mContinue = FALSE;
- }
- pIn += 5, pOut += 4;
- }
- memset(&j->cid, 0, sizeof(PHONE_CID));
- pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
- pOut += 4;
- strncpy(j->cid.month, pOut, 2);
- pOut += 2;
- strncpy(j->cid.day, pOut, 2);
- pOut += 2;
- strncpy(j->cid.hour, pOut, 2);
- pOut += 2;
- strncpy(j->cid.min, pOut, 2);
- pOut += 3;
- j->cid.numlen = *pOut;
- pOut += 1;
- strncpy(j->cid.number, pOut, j->cid.numlen);
- pOut += j->cid.numlen + 1;
- j->cid.namelen = *pOut;
- pOut += 1;
- strncpy(j->cid.name, pOut, j->cid.namelen);
- ixj_daa_cid_reset(j);
- return 1;
- }
- static char daa_get_version(IXJ *j)
- {
- BYTES bytes;
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x35;
- bytes.low = 0x00;
- outb_p(bytes.high, j->XILINXbase + 0x03);
- outb_p(bytes.low, j->XILINXbase + 0x02);
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (bytes.low != ALISDAA_ID_BYTE) {
- if (ixjdebug & 0x0001)
- printk("DAA Get Version Cannot read DAA ID Byte high = %d low = %dn", bytes.high, bytes.low);
- return 0;
- }
- if (!SCI_Control(j, SCI_Enable_DAA))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- bytes.high = inb_p(j->XILINXbase + 0x03);
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (ixjdebug & 0x0002)
- printk("DAA CR5 Byte high = 0x%x low = 0x%xn", bytes.high, bytes.low);
- j->m_DAAShadowRegs.SOP_REGS.SOP.cr5.reg = bytes.high;
- return bytes.high;
- }
- static int daa_set_mode(IXJ *j, int mode)
- {
- /* NOTE:
- The DAA *MUST* be in the conversation mode if the
- PSTN line is to be seized (PSTN line off-hook).
- Taking the PSTN line off-hook while the DAA is in
- a mode other than conversation mode will cause a
- hardware failure of the ALIS-A part.
- NOTE:
- The DAA can only go to SLEEP, RINGING or PULSEDIALING modes
- if the PSTN line is on-hook. Failure to have the PSTN line
- in the on-hook state WILL CAUSE A HARDWARE FAILURE OF THE
- ALIS-A part.
- */
- BYTES bytes;
- j->flags.pstn_rmr = 0;
- if (!SCI_Prepare(j))
- return 0;
- switch (mode) {
- case SOP_PU_RESET:
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly2 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- bytes.high = 0x10;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- j->daa_mode = SOP_PU_SLEEP;
- break;
- case SOP_PU_SLEEP:
- if(j->daa_mode == SOP_PU_SLEEP)
- {
- break;
- }
- if (ixjdebug & 0x0008)
- printk(KERN_INFO "phone DAA: SOP_PU_SLEEP at %ldn", jiffies);
- /* if(j->daa_mode == SOP_PU_CONVERSATION) */
- {
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly2 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- bytes.high = 0x10;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- }
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly2 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- bytes.high = 0x10;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- j->daa_mode = SOP_PU_SLEEP;
- j->flags.pstn_ringing = 0;
- j->ex.bits.pstn_ring = 0;
- j->pstn_sleeptil = jiffies + (hertz / 4);
- wake_up_interruptible(&j->read_q); /* Wake any blocked readers */
- wake_up_interruptible(&j->write_q); /* Wake any blocked writers */
- wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
- break;
- case SOP_PU_RINGING:
- if (ixjdebug & 0x0008)
- printk(KERN_INFO "phone DAA: SOP_PU_RINGING at %ldn", jiffies);
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly2 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- bytes.high = 0x50;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- j->daa_mode = SOP_PU_RINGING;
- break;
- case SOP_PU_CONVERSATION:
- if (ixjdebug & 0x0008)
- printk(KERN_INFO "phone DAA: SOP_PU_CONVERSATION at %ldn", jiffies);
- bytes.high = 0x90;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- j->pld_slicw.bits.rly2 = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- j->pld_scrw.bits.daafsyncen = 1; /* Turn on DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->daa_mode = SOP_PU_CONVERSATION;
- j->flags.pstn_ringing = 0;
- j->ex.bits.pstn_ring = 0;
- j->pstn_sleeptil = jiffies;
- j->pstn_ring_start = j->pstn_ring_stop = j->pstn_ring_int = 0;
- break;
- case SOP_PU_PULSEDIALING:
- if (ixjdebug & 0x0008)
- printk(KERN_INFO "phone DAA: SOP_PU_PULSEDIALING at %ldn", jiffies);
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly2 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- bytes.high = 0xD0;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- daa_load(&bytes, j);
- if (!SCI_Prepare(j))
- return 0;
- j->daa_mode = SOP_PU_PULSEDIALING;
- break;
- default:
- break;
- }
- return 1;
- }
- static int ixj_daa_write(IXJ *j)
- {
- BYTES bytes;
- j->flags.pstncheck = 1;
- daa_set_mode(j, SOP_PU_SLEEP);
- if (!SCI_Prepare(j))
- return 0;
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- bytes.high = 0x14;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr4.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr3.reg;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr2.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.SOP_REGS.SOP.cr1.reg;
- bytes.low = j->m_DAAShadowRegs.SOP_REGS.SOP.cr0.reg;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x1F;
- bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr7.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.XOP_xr6_W.reg;
- bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr5.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr4.reg;
- bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr3.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.XOP_REGS.XOP.xr2.reg;
- bytes.low = j->m_DAAShadowRegs.XOP_REGS.XOP.xr1.reg;
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.XOP_xr0_W.reg;
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Prepare(j))
- return 0;
- bytes.high = 0x00;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_1[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x01;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_2[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x02;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.THFilterCoeff_3[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x03;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x04;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_1[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x05;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.IMFilterCoeff_2[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x06;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x07;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRRFilterCoeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x08;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.FRXFilterCoeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x09;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.ARFilterCoeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0A;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.AXFilterCoeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0B;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone1Coeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0C;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.Tone2Coeff[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0D;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.LevelmeteringRinging[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0E;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID1stTone[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- if (!SCI_Control(j, SCI_End))
- return 0;
- if (!SCI_WaitLowSCI(j))
- return 0;
- bytes.high = 0x0F;
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[7];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[6];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[5];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[4];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[3];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[2];
- bytes.low = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[1];
- if (!daa_load(&bytes, j))
- return 0;
- bytes.high = j->m_DAAShadowRegs.COP_REGS.COP.CallerID2ndTone[0];
- bytes.low = 0x00;
- if (!daa_load(&bytes, j))
- return 0;
- udelay(32);
- j->pld_scrr.byte = inb_p(j->XILINXbase);
- if (!SCI_Control(j, SCI_End))
- return 0;
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- if (ixjdebug & 0x0002)
- printk("DAA Coefficients Loadedn");
- j->flags.pstncheck = 0;
- return 1;
- }
- int ixj_set_tone_off(unsigned short arg, IXJ *j)
- {
- j->tone_off_time = arg;
- if (ixj_WriteDSPCommand(0x6E05, j)) /* Set Tone Off Period */
- return -1;
- if (ixj_WriteDSPCommand(arg, j))
- return -1;
- return 0;
- }
- static int ixj_get_tone_on(IXJ *j)
- {
- if (ixj_WriteDSPCommand(0x6E06, j)) /* Get Tone On Period */
- return -1;
- return 0;
- }
- static int ixj_get_tone_off(IXJ *j)
- {
- if (ixj_WriteDSPCommand(0x6E07, j)) /* Get Tone Off Period */
- return -1;
- return 0;
- }
- static void ixj_busytone(IXJ *j)
- {
- j->flags.ringback = 0;
- j->flags.dialtone = 0;
- j->flags.busytone = 1;
- ixj_set_tone_on(0x07D0, j);
- ixj_set_tone_off(0x07D0, j);
- ixj_play_tone(j, 27);
- }
- static void ixj_dialtone(IXJ *j)
- {
- j->flags.ringback = 0;
- j->flags.dialtone = 1;
- j->flags.busytone = 0;
- if (j->dsp.low == 0x20) {
- return;
- } else {
- ixj_set_tone_on(0xFFFF, j);
- ixj_set_tone_off(0x0000, j);
- ixj_play_tone(j, 25);
- }
- }
- static void ixj_cpt_stop(IXJ *j)
- {
- if(j->tone_state || j->tone_cadence_state)
- {
- j->flags.dialtone = 0;
- j->flags.busytone = 0;
- j->flags.ringback = 0;
- ixj_set_tone_on(0x0001, j);
- ixj_set_tone_off(0x0000, j);
- ixj_play_tone(j, 0);
- j->tone_state = j->tone_cadence_state = 0;
- if (j->cadence_t) {
- if (j->cadence_t->ce) {
- kfree(j->cadence_t->ce);
- }
- kfree(j->cadence_t);
- j->cadence_t = NULL;
- }
- }
- if (j->play_mode == -1 && j->rec_mode == -1)
- idle(j);
- if (j->play_mode != -1 && j->dsp.low == 0x20)
- ixj_play_start(j);
- if (j->rec_mode != -1 && j->dsp.low == 0x20)
- ixj_record_start(j);
- }
- static void ixj_ringback(IXJ *j)
- {
- j->flags.busytone = 0;
- j->flags.dialtone = 0;
- j->flags.ringback = 1;
- ixj_set_tone_on(0x0FA0, j);
- ixj_set_tone_off(0x2EE0, j);
- ixj_play_tone(j, 26);
- }
- static void ixj_testram(IXJ *j)
- {
- ixj_WriteDSPCommand(0x3001, j); /* Test External SRAM */
- }
- static int ixj_build_cadence(IXJ *j, IXJ_CADENCE * cp)
- {
- IXJ_CADENCE *lcp;
- IXJ_CADENCE_ELEMENT *lcep;
- IXJ_TONE ti;
- lcp = kmalloc(sizeof(IXJ_CADENCE), GFP_KERNEL);
- if (lcp == NULL)
- return -ENOMEM;
- if (copy_from_user(lcp, (char *) cp, sizeof(IXJ_CADENCE)) || (unsigned)lcp->elements_used >= ~0U/sizeof(IXJ_CADENCE_ELEMENT) )
- {
- kfree(lcp);
- return -EFAULT;
- }
- lcep = kmalloc(sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used, GFP_KERNEL);
- if (lcep == NULL) {
- kfree(lcp);
- return -ENOMEM;
- }
- if (copy_from_user(lcep, lcp->ce, sizeof(IXJ_CADENCE_ELEMENT) * lcp->elements_used))
- {
- kfree(lcep);
- kfree(lcp);
- return -EFAULT;
- }
- if (j->cadence_t) {
- kfree(j->cadence_t->ce);
- kfree(j->cadence_t);
- }
- lcp->ce = (void *) lcep;
- j->cadence_t = lcp;
- j->tone_cadence_state = 0;
- ixj_set_tone_on(lcp->ce[0].tone_on_time, j);
- ixj_set_tone_off(lcp->ce[0].tone_off_time, j);
- if (j->cadence_t->ce[j->tone_cadence_state].freq0) {
- ti.tone_index = j->cadence_t->ce[j->tone_cadence_state].index;
- ti.freq0 = j->cadence_t->ce[j->tone_cadence_state].freq0;
- ti.gain0 = j->cadence_t->ce[j->tone_cadence_state].gain0;
- ti.freq1 = j->cadence_t->ce[j->tone_cadence_state].freq1;
- ti.gain1 = j->cadence_t->ce[j->tone_cadence_state].gain1;
- ixj_init_tone(j, &ti);
- }
- ixj_play_tone(j, lcp->ce[0].index);
- return 1;
- }
- static int ixj_build_filter_cadence(IXJ *j, IXJ_FILTER_CADENCE * cp)
- {
- IXJ_FILTER_CADENCE *lcp;
- lcp = kmalloc(sizeof(IXJ_FILTER_CADENCE), GFP_KERNEL);
- if (lcp == NULL) {
- if(ixjdebug & 0x0001) {
- printk(KERN_INFO "Could not allocate memory for cadencen");
- }
- return -ENOMEM;
- }
- if (copy_from_user(lcp, (char *) cp, sizeof(IXJ_FILTER_CADENCE))) {
- if(ixjdebug & 0x0001) {
- printk(KERN_INFO "Could not copy cadence to kerneln");
- }
- return -EFAULT;
- }
- if (lcp->filter > 5) {
- if(ixjdebug & 0x0001) {
- printk(KERN_INFO "Cadence out of rangen");
- }
- return -1;
- }
- j->cadence_f[lcp->filter].state = 0;
- j->cadence_f[lcp->filter].enable = lcp->enable;
- j->filter_en[lcp->filter] = j->cadence_f[lcp->filter].en_filter = lcp->en_filter;
- j->cadence_f[lcp->filter].on1 = lcp->on1;
- j->cadence_f[lcp->filter].on1min = 0;
- j->cadence_f[lcp->filter].on1max = 0;
- j->cadence_f[lcp->filter].off1 = lcp->off1;
- j->cadence_f[lcp->filter].off1min = 0;
- j->cadence_f[lcp->filter].off1max = 0;
- j->cadence_f[lcp->filter].on2 = lcp->on2;
- j->cadence_f[lcp->filter].on2min = 0;
- j->cadence_f[lcp->filter].on2max = 0;
- j->cadence_f[lcp->filter].off2 = lcp->off2;
- j->cadence_f[lcp->filter].off2min = 0;
- j->cadence_f[lcp->filter].off2max = 0;
- j->cadence_f[lcp->filter].on3 = lcp->on3;
- j->cadence_f[lcp->filter].on3min = 0;
- j->cadence_f[lcp->filter].on3max = 0;
- j->cadence_f[lcp->filter].off3 = lcp->off3;
- j->cadence_f[lcp->filter].off3min = 0;
- j->cadence_f[lcp->filter].off3max = 0;
- kfree(lcp);
- if(ixjdebug & 0x0002) {
- printk(KERN_INFO "Cadence %d loadedn", lcp->filter);
- }
- return 0;
- }
- static void add_caps(IXJ *j)
- {
- j->caps = 0;
- j->caplist[j->caps].cap = PHONE_VENDOR_QUICKNET;
- strcpy(j->caplist[j->caps].desc, "Quicknet Technologies, Inc. (www.quicknet.net)");
- j->caplist[j->caps].captype = vendor;
- j->caplist[j->caps].handle = j->caps++;
- j->caplist[j->caps].captype = device;
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK");
- break;
- case QTI_LINEJACK:
- strcpy(j->caplist[j->caps].desc, "Quicknet Internet LineJACK");
- break;
- case QTI_PHONEJACK_LITE:
- strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK Lite");
- break;
- case QTI_PHONEJACK_PCI:
- strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneJACK PCI");
- break;
- case QTI_PHONECARD:
- strcpy(j->caplist[j->caps].desc, "Quicknet Internet PhoneCARD");
- break;
- }
- j->caplist[j->caps].cap = j->cardtype;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "POTS");
- j->caplist[j->caps].captype = port;
- j->caplist[j->caps].cap = pots;
- j->caplist[j->caps].handle = j->caps++;
- /* add devices that can do speaker/mic */
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- case QTI_LINEJACK:
- case QTI_PHONEJACK_PCI:
- case QTI_PHONECARD:
- strcpy(j->caplist[j->caps].desc, "SPEAKER");
- j->caplist[j->caps].captype = port;
- j->caplist[j->caps].cap = speaker;
- j->caplist[j->caps].handle = j->caps++;
- default:
- break;
- }
- /* add devices that can do handset */
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- strcpy(j->caplist[j->caps].desc, "HANDSET");
- j->caplist[j->caps].captype = port;
- j->caplist[j->caps].cap = handset;
- j->caplist[j->caps].handle = j->caps++;
- break;
- default:
- break;
- }
- /* add devices that can do PSTN */
- switch (j->cardtype) {
- case QTI_LINEJACK:
- strcpy(j->caplist[j->caps].desc, "PSTN");
- j->caplist[j->caps].captype = port;
- j->caplist[j->caps].cap = pstn;
- j->caplist[j->caps].handle = j->caps++;
- break;
- default:
- break;
- }
- /* add codecs - all cards can do uLaw, linear 8/16, and Windows sound system */
- strcpy(j->caplist[j->caps].desc, "ULAW");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = ULAW;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "LINEAR 16 bit");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = LINEAR16;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "LINEAR 8 bit");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = LINEAR8;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "Windows Sound System");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = WSS;
- j->caplist[j->caps].handle = j->caps++;
- /* software ALAW codec, made from ULAW */
- strcpy(j->caplist[j->caps].desc, "ALAW");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = ALAW;
- j->caplist[j->caps].handle = j->caps++;
- /* version 12 of the 8020 does the following codecs in a broken way */
- if (j->dsp.low != 0x20 || j->ver.low != 0x12) {
- strcpy(j->caplist[j->caps].desc, "G.723.1 6.3kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = G723_63;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "G.723.1 5.3kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = G723_53;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.8kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = TS48;
- j->caplist[j->caps].handle = j->caps++;
- strcpy(j->caplist[j->caps].desc, "TrueSpeech 4.1kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = TS41;
- j->caplist[j->caps].handle = j->caps++;
- }
- /* 8020 chips can do TS8.5 native, and 8021/8022 can load it */
- if (j->dsp.low == 0x20 || j->flags.ts85_loaded) {
- strcpy(j->caplist[j->caps].desc, "TrueSpeech 8.5kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = TS85;
- j->caplist[j->caps].handle = j->caps++;
- }
- /* 8021 chips can do G728 */
- if (j->dsp.low == 0x21) {
- strcpy(j->caplist[j->caps].desc, "G.728 16kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = G728;
- j->caplist[j->caps].handle = j->caps++;
- }
- /* 8021/8022 chips can do G729 if loaded */
- if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
- strcpy(j->caplist[j->caps].desc, "G.729A 8kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = G729;
- j->caplist[j->caps].handle = j->caps++;
- }
- if (j->dsp.low != 0x20 && j->flags.g729_loaded) {
- strcpy(j->caplist[j->caps].desc, "G.729B 8kbps");
- j->caplist[j->caps].captype = codec;
- j->caplist[j->caps].cap = G729B;
- j->caplist[j->caps].handle = j->caps++;
- }
- }
- static int capabilities_check(IXJ *j, struct phone_capability *pcreq)
- {
- int cnt;
- int retval = 0;
- for (cnt = 0; cnt < j->caps; cnt++) {
- if (pcreq->captype == j->caplist[cnt].captype
- && pcreq->cap == j->caplist[cnt].cap) {
- retval = 1;
- break;
- }
- }
- return retval;
- }
- static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd, unsigned long arg)
- {
- IXJ_TONE ti;
- IXJ_FILTER jf;
- IXJ_FILTER_RAW jfr;
- unsigned int raise, mant;
- unsigned int minor = MINOR(inode->i_rdev);
- int board = NUM(inode->i_rdev);
- IXJ *j = get_ixj(NUM(inode->i_rdev));
- int retval = 0;
- /*
- * Set up locks to ensure that only one process is talking to the DSP at a time.
- * This is necessary to keep the DSP from locking up.
- */
- while(test_and_set_bit(board, (void *)&j->busyflags) != 0) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- if (ixjdebug & 0x0040)
- printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lxn", minor, cmd, arg);
- if (minor >= IXJMAX) {
- clear_bit(board, &j->busyflags);
- return -ENODEV;
- }
- /*
- * Check ioctls only root can use.
- */
- if (!capable(CAP_SYS_ADMIN)) {
- switch (cmd) {
- case IXJCTL_TESTRAM:
- case IXJCTL_HZ:
- retval = -EPERM;
- }
- }
- switch (cmd) {
- case IXJCTL_TESTRAM:
- ixj_testram(j);
- retval = (j->ssr.high << 8) + j->ssr.low;
- break;
- case IXJCTL_CARDTYPE:
- retval = j->cardtype;
- break;
- case IXJCTL_SERIAL:
- retval = j->serial;
- break;
- case IXJCTL_VERSION:
- if (copy_to_user((char *) arg, ixj_c_revision, strlen(ixj_c_revision)))
- retval = -EFAULT;
- break;
- case PHONE_RING_CADENCE:
- j->ring_cadence = arg;
- break;
- case IXJCTL_CIDCW:
- if(arg) {
- copy_from_user(&j->cid_send, (char *)arg, sizeof(PHONE_CID));
- }
- else {
- memset(&j->cid_send, 0, sizeof(PHONE_CID));
- }
- ixj_write_cidcw(j);
- break;
- /* Binary compatbility */
- case OLD_PHONE_RING_START:
- arg = 0;
- /* Fall through */
- case PHONE_RING_START:
- if(arg) {
- if(copy_from_user(&j->cid_send, (char *)arg, sizeof(PHONE_CID)))
- {
- retval = -EFAULT;
- break;
- }
- ixj_write_cid(j);
- }
- else {
- memset(&j->cid_send, 0, sizeof(PHONE_CID));
- }
- ixj_ring_start(j);
- break;
- case PHONE_RING_STOP:
- j->flags.cringing = 0;
- if(j->cadence_f[5].enable) {
- j->cadence_f[5].state = 0;
- }
- ixj_ring_off(j);
- break;
- case PHONE_RING:
- retval = ixj_ring(j);
- break;
- case PHONE_EXCEPTION:
- retval = j->ex.bytes;
- if(j->ex.bits.flash) {
- j->flash_end = 0;
- j->ex.bits.flash = 0;
- }
- j->ex.bits.pstn_ring = 0;
- j->ex.bits.caller_id = 0;
- j->ex.bits.pstn_wink = 0;
- j->ex.bits.f0 = 0;
- j->ex.bits.f1 = 0;
- j->ex.bits.f2 = 0;
- j->ex.bits.f3 = 0;
- j->ex.bits.fc0 = 0;
- j->ex.bits.fc1 = 0;
- j->ex.bits.fc2 = 0;
- j->ex.bits.fc3 = 0;
- j->ex.bits.reserved = 0;
- break;
- case PHONE_HOOKSTATE:
- j->ex.bits.hookstate = 0;
- retval = j->hookstate; //j->r_hook;
- break;
- case IXJCTL_SET_LED:
- LED_SetState(arg, j);
- break;
- case PHONE_FRAME:
- retval = set_base_frame(j, arg);
- break;
- case PHONE_REC_CODEC:
- retval = set_rec_codec(j, arg);
- break;
- case PHONE_VAD:
- ixj_vad(j, arg);
- break;
- case PHONE_REC_START:
- ixj_record_start(j);
- break;
- case PHONE_REC_STOP:
- ixj_record_stop(j);
- break;
- case PHONE_REC_DEPTH:
- set_rec_depth(j, arg);
- break;
- case PHONE_REC_VOLUME:
- if(arg == -1) {
- retval = get_rec_volume(j);
- }
- else {
- set_rec_volume(j, arg);
- retval = arg;
- }
- break;
- case PHONE_REC_VOLUME_LINEAR:
- if(arg == -1) {
- retval = get_rec_volume_linear(j);
- }
- else {
- set_rec_volume_linear(j, arg);
- retval = arg;
- }
- break;
- case IXJCTL_DTMF_PRESCALE:
- if(arg == -1) {
- retval = get_dtmf_prescale(j);
- }
- else {
- set_dtmf_prescale(j, arg);
- retval = arg;
- }
- break;
- case PHONE_REC_LEVEL:
- retval = get_rec_level(j);
- break;
- case IXJCTL_SC_RXG:
- retval = ixj_siadc(j, arg);
- break;
- case IXJCTL_SC_TXG:
- retval = ixj_sidac(j, arg);
- break;
- case IXJCTL_AEC_START:
- ixj_aec_start(j, arg);
- break;
- case IXJCTL_AEC_STOP:
- aec_stop(j);
- break;
- case IXJCTL_AEC_GET_LEVEL:
- retval = j->aec_level;
- break;
- case PHONE_PLAY_CODEC:
- retval = set_play_codec(j, arg);
- break;
- case PHONE_PLAY_START:
- retval = ixj_play_start(j);
- break;
- case PHONE_PLAY_STOP:
- ixj_play_stop(j);
- break;
- case PHONE_PLAY_DEPTH:
- set_play_depth(j, arg);
- break;
- case PHONE_PLAY_VOLUME:
- if(arg == -1) {
- retval = get_play_volume(j);
- }
- else {
- set_play_volume(j, arg);
- retval = arg;
- }
- break;
- case PHONE_PLAY_VOLUME_LINEAR:
- if(arg == -1) {
- retval = get_play_volume_linear(j);
- }
- else {
- set_play_volume_linear(j, arg);
- retval = arg;
- }
- break;
- case PHONE_PLAY_LEVEL:
- retval = get_play_level(j);
- break;
- case IXJCTL_DSP_TYPE:
- retval = (j->dsp.high << 8) + j->dsp.low;
- break;
- case IXJCTL_DSP_VERSION:
- retval = (j->ver.high << 8) + j->ver.low;
- break;
- case IXJCTL_HZ:
- hertz = arg;
- break;
- case IXJCTL_RATE:
- if (arg > hertz)
- retval = -1;
- else
- samplerate = arg;
- break;
- case IXJCTL_DRYBUFFER_READ:
- put_user(j->drybuffer, (unsigned long *) arg);
- break;
- case IXJCTL_DRYBUFFER_CLEAR:
- j->drybuffer = 0;
- break;
- case IXJCTL_FRAMES_READ:
- put_user(j->framesread, (unsigned long *) arg);
- break;
- case IXJCTL_FRAMES_WRITTEN:
- put_user(j->frameswritten, (unsigned long *) arg);
- break;
- case IXJCTL_READ_WAIT:
- put_user(j->read_wait, (unsigned long *) arg);
- break;
- case IXJCTL_WRITE_WAIT:
- put_user(j->write_wait, (unsigned long *) arg);
- break;
- case PHONE_MAXRINGS:
- j->maxrings = arg;
- break;
- case PHONE_SET_TONE_ON_TIME:
- ixj_set_tone_on(arg, j);
- break;
- case PHONE_SET_TONE_OFF_TIME:
- ixj_set_tone_off(arg, j);
- break;
- case PHONE_GET_TONE_ON_TIME:
- if (ixj_get_tone_on(j)) {
- retval = -1;
- } else {
- retval = (j->ssr.high << 8) + j->ssr.low;
- }
- break;
- case PHONE_GET_TONE_OFF_TIME:
- if (ixj_get_tone_off(j)) {
- retval = -1;
- } else {
- retval = (j->ssr.high << 8) + j->ssr.low;
- }
- break;
- case PHONE_PLAY_TONE:
- if (!j->tone_state)
- retval = ixj_play_tone(j, arg);
- else
- retval = -1;
- break;
- case PHONE_GET_TONE_STATE:
- retval = j->tone_state;
- break;
- case PHONE_DTMF_READY:
- retval = j->ex.bits.dtmf_ready;
- break;
- case PHONE_GET_DTMF:
- if (ixj_hookstate(j)) {
- if (j->dtmf_rp != j->dtmf_wp) {
- retval = j->dtmfbuffer[j->dtmf_rp];
- j->dtmf_rp++;
- if (j->dtmf_rp == 79)
- j->dtmf_rp = 0;
- if (j->dtmf_rp == j->dtmf_wp) {
- j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
- }
- }
- }
- break;
- case PHONE_GET_DTMF_ASCII:
- if (ixj_hookstate(j)) {
- if (j->dtmf_rp != j->dtmf_wp) {
- switch (j->dtmfbuffer[j->dtmf_rp]) {
- case 10:
- retval = 42; /* '*'; */
- break;
- case 11:
- retval = 48; /*'0'; */
- break;
- case 12:
- retval = 35; /*'#'; */
- break;
- case 28:
- retval = 65; /*'A'; */
- break;
- case 29:
- retval = 66; /*'B'; */
- break;
- case 30:
- retval = 67; /*'C'; */
- break;
- case 31:
- retval = 68; /*'D'; */
- break;
- default:
- retval = 48 + j->dtmfbuffer[j->dtmf_rp];
- break;
- }
- j->dtmf_rp++;
- if (j->dtmf_rp == 79)
- j->dtmf_rp = 0;
- if(j->dtmf_rp == j->dtmf_wp)
- {
- j->ex.bits.dtmf_ready = j->dtmf_rp = j->dtmf_wp = 0;
- }
- }
- }
- break;
- case PHONE_DTMF_OOB:
- j->flags.dtmf_oob = arg;
- break;
- case PHONE_DIALTONE:
- ixj_dialtone(j);
- break;
- case PHONE_BUSY:
- ixj_busytone(j);
- break;
- case PHONE_RINGBACK:
- ixj_ringback(j);
- break;
- case PHONE_WINK:
- if(j->cardtype == QTI_PHONEJACK)
- retval = -1;
- else
- retval = ixj_wink(j);
- break;
- case PHONE_CPT_STOP:
- ixj_cpt_stop(j);
- break;
- case PHONE_QUERY_CODEC:
- {
- struct phone_codec_data pd;
- int val;
- int proto_size[] = {
- -1,
- 12, 10, 16, 9, 8, 48, 5,
- 40, 40, 80, 40, 40, 6
- };
- if(copy_from_user(&pd, (void *)arg, sizeof(pd))) {
- retval = -EFAULT;
- break;
- }
- if(pd.type<1 || pd.type>13) {
- retval = -EPROTONOSUPPORT;
- break;
- }
- if(pd.type<G729)
- val=proto_size[pd.type];
- else switch(j->baseframe.low)
- {
- case 0xA0:val=2*proto_size[pd.type];break;
- case 0x50:val=proto_size[pd.type];break;
- default:val=proto_size[pd.type]*3;break;
- }
- pd.buf_min=pd.buf_max=pd.buf_opt=val;
- if(copy_to_user((void *)arg, &pd, sizeof(pd)))
- retval = -EFAULT;
- break;
- }
- case IXJCTL_DSP_IDLE:
- idle(j);
- break;
- case IXJCTL_MIXER:
- if ((arg & 0xff) == 0xff)
- retval = ixj_get_mixer(arg, j);
- else
- ixj_mixer(arg, j);
- break;
- case IXJCTL_DAA_COEFF_SET:
- switch (arg) {
- case DAA_US:
- DAA_Coeff_US(j);
- retval = ixj_daa_write(j);
- break;
- case DAA_UK:
- DAA_Coeff_UK(j);
- retval = ixj_daa_write(j);
- break;
- case DAA_FRANCE:
- DAA_Coeff_France(j);
- retval = ixj_daa_write(j);
- break;
- case DAA_GERMANY:
- DAA_Coeff_Germany(j);
- retval = ixj_daa_write(j);
- break;
- case DAA_AUSTRALIA:
- DAA_Coeff_Australia(j);
- retval = ixj_daa_write(j);
- break;
- case DAA_JAPAN:
- DAA_Coeff_Japan(j);
- retval = ixj_daa_write(j);
- break;
- default:
- retval = 1;
- break;
- }
- break;
- case IXJCTL_DAA_AGAIN:
- ixj_daa_cr4(j, arg | 0x02);
- break;
- case IXJCTL_PSTN_LINETEST:
- retval = ixj_linetest(j);
- break;
- case IXJCTL_VMWI:
- ixj_write_vmwi(j, arg);
- break;
- case IXJCTL_CID:
- if (copy_to_user((char *) arg, &j->cid, sizeof(PHONE_CID)))
- retval = -EFAULT;
- j->ex.bits.caller_id = 0;
- break;
- case IXJCTL_WINK_DURATION:
- j->winktime = arg;
- break;
- case IXJCTL_PORT:
- if (arg)
- retval = ixj_set_port(j, arg);
- else
- retval = j->port;
- break;
- case IXJCTL_POTS_PSTN:
- retval = ixj_set_pots(j, arg);
- break;
- case PHONE_CAPABILITIES:
- add_caps(j);
- retval = j->caps;
- break;
- case PHONE_CAPABILITIES_LIST:
- add_caps(j);
- if (copy_to_user((char *) arg, j->caplist, sizeof(struct phone_capability) * j->caps))
- retval = -EFAULT;
- break;
- case PHONE_CAPABILITIES_CHECK:
- {
- struct phone_capability cap;
- if (copy_from_user(&cap, (char *) arg, sizeof(cap)))
- retval = -EFAULT;
- else {
- add_caps(j);
- retval = capabilities_check(j, &cap);
- }
- }
- break;
- case PHONE_PSTN_SET_STATE:
- daa_set_mode(j, arg);
- break;
- case PHONE_PSTN_GET_STATE:
- retval = j->daa_mode;
- j->ex.bits.pstn_ring = 0;
- break;
- case IXJCTL_SET_FILTER:
- if (copy_from_user(&jf, (char *) arg, sizeof(jf)))
- retval = -EFAULT;
- retval = ixj_init_filter(j, &jf);
- break;
- case IXJCTL_SET_FILTER_RAW:
- if (copy_from_user(&jfr, (char *) arg, sizeof(jfr)))
- retval = -EFAULT;
- retval = ixj_init_filter_raw(j, &jfr);
- break;
- case IXJCTL_GET_FILTER_HIST:
- if(arg<0||arg>3)
- retval = -EINVAL;
- else
- retval = j->filter_hist[arg];
- break;
- case IXJCTL_INIT_TONE:
- copy_from_user(&ti, (char *) arg, sizeof(ti));
- retval = ixj_init_tone(j, &ti);
- break;
- case IXJCTL_TONE_CADENCE:
- retval = ixj_build_cadence(j, (IXJ_CADENCE *) arg);
- break;
- case IXJCTL_FILTER_CADENCE:
- retval = ixj_build_filter_cadence(j, (IXJ_FILTER_CADENCE *) arg);
- break;
- case IXJCTL_SIGCTL:
- if (copy_from_user(&j->sigdef, (char *)arg, sizeof(IXJ_SIGDEF)))
- retval = -EFAULT;
- j->ixj_signals[j->sigdef.event] = j->sigdef.signal;
- if(j->sigdef.event < 33) {
- raise = 1;
- for(mant = 0; mant < j->sigdef.event; mant++){
- raise *= 2;
- }
- if(j->sigdef.signal)
- j->ex_sig.bytes |= raise;
- else
- j->ex_sig.bytes &= (raise^0xffff);
- }
- break;
- case IXJCTL_INTERCOM_STOP:
- if(arg < 0 || arg >= IXJMAX)
- return -EINVAL;
- j->intercom = -1;
- ixj_record_stop(j);
- ixj_play_stop(j);
- idle(j);
- get_ixj(arg)->intercom = -1;
- ixj_record_stop(get_ixj(arg));
- ixj_play_stop(get_ixj(arg));
- idle(get_ixj(arg));
- break;
- case IXJCTL_INTERCOM_START:
- if(arg < 0 || arg >= IXJMAX)
- return -EINVAL;
- j->intercom = arg;
- ixj_record_start(j);
- ixj_play_start(j);
- get_ixj(arg)->intercom = board;
- ixj_play_start(get_ixj(arg));
- ixj_record_start(get_ixj(arg));
- break;
- }
- if (ixjdebug & 0x0040)
- printk("phone%d ioctl end, cmd: 0x%x, arg: 0x%lxn", minor, cmd, arg);
- clear_bit(board, &j->busyflags);
- return retval;
- }
- static int ixj_fasync(int fd, struct file *file_p, int mode)
- {
- IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode->i_rdev));
- return fasync_helper(fd, file_p, mode, &j->async_queue);
- }
- struct file_operations ixj_fops =
- {
- owner: THIS_MODULE,
- read: ixj_enhanced_read,
- write: ixj_enhanced_write,
- poll: ixj_poll,
- ioctl: ixj_ioctl,
- release: ixj_release,
- fasync: ixj_fasync
- };
- static int ixj_linetest(IXJ *j)
- {
- unsigned long jifwait;
- j->flags.pstncheck = 1; /* Testing */
- j->flags.pstn_present = 0; /* Assume the line is not there */
- daa_int_read(j); /*Clear DAA Interrupt flags */
- /* */
- /* Hold all relays in the normally de-energized position. */
- /* */
- j->pld_slicw.bits.rly1 = 0;
- j->pld_slicw.bits.rly2 = 0;
- j->pld_slicw.bits.rly3 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicr.byte = inb_p(j->XILINXbase + 0x01);
- if (j->pld_slicr.bits.potspstn) {
- j->flags.pots_pstn = 1;
- j->flags.pots_correct = 0;
- LED_SetState(0x4, j);
- } else {
- j->flags.pots_pstn = 0;
- j->pld_slicw.bits.rly1 = 0;
- j->pld_slicw.bits.rly2 = 0;
- j->pld_slicw.bits.rly3 = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- daa_set_mode(j, SOP_PU_CONVERSATION);
- jifwait = jiffies + hertz;
- while (time_before(jiffies, jifwait)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- daa_int_read(j);
- daa_set_mode(j, SOP_PU_RESET);
- if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
- j->flags.pots_correct = 0; /* Should not be line voltage on POTS port. */
- LED_SetState(0x4, j);
- j->pld_slicw.bits.rly3 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- } else {
- j->flags.pots_correct = 1;
- LED_SetState(0x8, j);
- j->pld_slicw.bits.rly1 = 1;
- j->pld_slicw.bits.rly2 = 0;
- j->pld_slicw.bits.rly3 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- }
- }
- j->pld_slicw.bits.rly3 = 0;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- daa_set_mode(j, SOP_PU_CONVERSATION);
- jifwait = jiffies + hertz;
- while (time_before(jiffies, jifwait)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- daa_int_read(j);
- daa_set_mode(j, SOP_PU_RESET);
- if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
- j->pstn_sleeptil = jiffies + (hertz / 4);
- j->flags.pstn_present = 1;
- } else {
- j->flags.pstn_present = 0;
- }
- if (j->flags.pstn_present) {
- if (j->flags.pots_correct) {
- LED_SetState(0xA, j);
- } else {
- LED_SetState(0x6, j);
- }
- } else {
- if (j->flags.pots_correct) {
- LED_SetState(0x9, j);
- } else {
- LED_SetState(0x5, j);
- }
- }
- j->flags.pstncheck = 0; /* Testing */
- return j->flags.pstn_present;
- }
- static int ixj_selfprobe(IXJ *j)
- {
- unsigned short cmd;
- unsigned long jif;
- int cnt;
- BYTES bytes;
- init_waitqueue_head(&j->poll_q);
- init_waitqueue_head(&j->read_q);
- init_waitqueue_head(&j->write_q);
- while(atomic_read(&j->DSPWrite) > 0)
- atomic_dec(&j->DSPWrite);
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Write IDLE to Software Control Registern");
- ixj_WriteDSPCommand(0x0FE0, j); /* Put the DSP in full power mode. */
- if (ixj_WriteDSPCommand(0x0000, j)) /* Write IDLE to Software Control Register */
- return -1;
- /* The read values of the SSR should be 0x00 for the IDLE command */
- if (j->ssr.low || j->ssr.high)
- return -1;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Get Device ID Coden");
- if (ixj_WriteDSPCommand(0x3400, j)) /* Get Device ID Code */
- return -1;
- j->dsp.low = j->ssr.low;
- j->dsp.high = j->ssr.high;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Get Device Version Coden");
- if (ixj_WriteDSPCommand(0x3800, j)) /* Get Device Version Code */
- return -1;
- j->ver.low = j->ssr.low;
- j->ver.high = j->ssr.high;
- if (!j->cardtype) {
- if (j->dsp.low == 0x21) {
- bytes.high = bytes.low = inb_p(j->XILINXbase + 0x02);
- outb_p(bytes.low ^ 0xFF, j->XILINXbase + 0x02);
- /* Test for Internet LineJACK or Internet PhoneJACK Lite */
- bytes.low = inb_p(j->XILINXbase + 0x02);
- if (bytes.low == bytes.high) /* Register is read only on */
- /* Internet PhoneJack Lite */
- {
- j->cardtype = QTI_PHONEJACK_LITE;
- if (check_region(j->XILINXbase, 4)) {
- printk(KERN_INFO "ixj: can't get I/O address 0x%xn", j->XILINXbase);
- return -1;
- }
- request_region(j->XILINXbase, 4, "ixj control");
- j->pld_slicw.pcib.e1 = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase);
- } else {
- j->cardtype = QTI_LINEJACK;
- if (check_region(j->XILINXbase, 8)) {
- printk(KERN_INFO "ixj: can't get I/O address 0x%xn", j->XILINXbase);
- return -1;
- }
- request_region(j->XILINXbase, 8, "ixj control");
- }
- } else if (j->dsp.low == 0x22) {
- j->cardtype = QTI_PHONEJACK_PCI;
- request_region(j->XILINXbase, 4, "ixj control");
- j->pld_slicw.pcib.e1 = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase);
- } else
- j->cardtype = QTI_PHONEJACK;
- } else {
- switch (j->cardtype) {
- case QTI_PHONEJACK:
- if (!j->dsp.low != 0x20) {
- j->dsp.high = 0x80;
- j->dsp.low = 0x20;
- ixj_WriteDSPCommand(0x3800, j);
- j->ver.low = j->ssr.low;
- j->ver.high = j->ssr.high;
- }
- break;
- case QTI_LINEJACK:
- if (check_region(j->XILINXbase, 8)) {
- printk(KERN_INFO "ixj: can't get I/O address 0x%xn", j->XILINXbase);
- return -1;
- }
- request_region(j->XILINXbase, 8, "ixj control");
- break;
- case QTI_PHONEJACK_LITE:
- case QTI_PHONEJACK_PCI:
- if (check_region(j->XILINXbase, 4)) {
- printk(KERN_INFO "ixj: can't get I/O address 0x%xn", j->XILINXbase);
- return -1;
- }
- request_region(j->XILINXbase, 4, "ixj control");
- j->pld_slicw.pcib.e1 = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase);
- break;
- case QTI_PHONECARD:
- break;
- }
- }
- if (j->dsp.low == 0x20 || j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Write CODEC config to Software Control Registern");
- if (ixj_WriteDSPCommand(0xC462, j)) /* Write CODEC config to Software Control Register */
- return -1;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Write CODEC timing to Software Control Registern");
- if (j->cardtype == QTI_PHONEJACK) {
- cmd = 0x9FF2;
- } else {
- cmd = 0x9FF5;
- }
- if (ixj_WriteDSPCommand(cmd, j)) /* Write CODEC timing to Software Control Register */
- return -1;
- } else {
- if (set_base_frame(j, 30) != 30)
- return -1;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Write CODEC config to Software Control Registern");
- if (j->cardtype == QTI_PHONECARD) {
- if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to Software Control Register */
- return -1;
- }
- if (j->cardtype == QTI_LINEJACK) {
- if (ixj_WriteDSPCommand(0xC528, j)) /* Write CODEC config to Software Control Register */
- return -1;
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Turn on the PLD Clock at 8Khzn");
- j->pld_clock.byte = 0;
- outb_p(j->pld_clock.byte, j->XILINXbase + 0x04);
- }
- }
- if (j->dsp.low == 0x20) {
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Configure GPIO pinsn");
- j->gpio.bytes.high = 0x09;
- /* bytes.low = 0xEF; 0xF7 */
- j->gpio.bits.gpio1 = 1;
- j->gpio.bits.gpio2 = 1;
- j->gpio.bits.gpio3 = 0;
- j->gpio.bits.gpio4 = 1;
- j->gpio.bits.gpio5 = 1;
- j->gpio.bits.gpio6 = 1;
- j->gpio.bits.gpio7 = 1;
- ixj_WriteDSPCommand(j->gpio.word, j); /* Set GPIO pin directions */
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Enable SLICn");
- j->gpio.bytes.high = 0x0B;
- j->gpio.bytes.low = 0x00;
- j->gpio.bits.gpio1 = 0;
- j->gpio.bits.gpio2 = 1;
- j->gpio.bits.gpio5 = 0;
- ixj_WriteDSPCommand(j->gpio.word, j); /* send the ring stop signal */
- j->port = PORT_POTS;
- } else {
- if (j->cardtype == QTI_LINEJACK) {
- LED_SetState(0x1, j);
- jif = jiffies + (hertz / 10);
- while (time_before(jiffies, jif)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- LED_SetState(0x2, j);
- jif = jiffies + (hertz / 10);
- while (time_before(jiffies, jif)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- LED_SetState(0x4, j);
- jif = jiffies + (hertz / 10);
- while (time_before(jiffies, jif)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- LED_SetState(0x8, j);
- jif = jiffies + (hertz / 10);
- while (time_before(jiffies, jif)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- LED_SetState(0x0, j);
- daa_get_version(j);
- if (ixjdebug & 0x0002)
- printk("Loading DAA Coefficientsn");
- DAA_Coeff_US(j);
- if (!ixj_daa_write(j)) {
- printk("DAA write failed on board %dn", j->board);
- return -1;
- }
- if(!ixj_daa_cid_reset(j)) {
- printk("DAA CID reset failed on board %dn", j->board);
- return -1;
- }
- j->flags.pots_correct = 0;
- j->flags.pstn_present = 0;
- ixj_linetest(j);
- if (j->flags.pots_correct) {
- j->pld_scrw.bits.daafsyncen = 0; /* Turn off DAA Frame Sync */
- outb_p(j->pld_scrw.byte, j->XILINXbase);
- j->pld_slicw.bits.rly1 = 1;
- j->pld_slicw.bits.spken = 1;
- outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
- SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);
- /* SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */
- j->port = PORT_POTS;
- }
- ixj_set_port(j, PORT_PSTN);
- ixj_set_pots(j, 1);
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Enable Mixern");
- ixj_mixer(0x0000, j); /*Master Volume Left unmute 0db */
- ixj_mixer(0x0100, j); /*Master Volume Right unmute 0db */
- ixj_mixer(0x0203, j); /*Voice Left Volume unmute 6db */
- ixj_mixer(0x0303, j); /*Voice Right Volume unmute 6db */
- ixj_mixer(0x0480, j); /*FM Left mute */
- ixj_mixer(0x0580, j); /*FM Right mute */
- ixj_mixer(0x0680, j); /*CD Left mute */
- ixj_mixer(0x0780, j); /*CD Right mute */
- ixj_mixer(0x0880, j); /*Line Left mute */
- ixj_mixer(0x0980, j); /*Line Right mute */
- ixj_mixer(0x0A80, j); /*Aux left mute */
- ixj_mixer(0x0B80, j); /*Aux right mute */
- ixj_mixer(0x0C00, j); /*Mono1 unmute 12db */
- ixj_mixer(0x0D80, j); /*Mono2 mute */
- ixj_mixer(0x0E80, j); /*Mic mute */
- ixj_mixer(0x0F00, j); /*Mono Out Volume unmute 0db */
- ixj_mixer(0x1000, j); /*Voice Left and Right out only */
- ixj_mixer(0x110C, j);
- ixj_mixer(0x1200, j); /*Mono1 switch on mixer left */
- ixj_mixer(0x1401, j);
- ixj_mixer(0x1300, j); /*Mono1 switch on mixer right */
- ixj_mixer(0x1501, j);
- ixj_mixer(0x1700, j); /*Clock select */
- ixj_mixer(0x1800, j); /*ADC input from mixer */
- ixj_mixer(0x1901, j); /*Mic gain 30db */
- if (ixjdebug & 0x0002)
- printk(KERN_INFO "Setting Default US Ring Cadence Detectionn");
- j->cadence_f[4].state = 0;
- j->cadence_f[4].on1 = 0; /*Cadence Filter 4 is used for PSTN ring cadence */
- j->cadence_f[4].off1 = 0;
- j->cadence_f[4].on2 = 0;
- j->cadence_f[4].off2 = 0;
- j->cadence_f[4].on3 = 0;
- j->cadence_f[4].off3 = 0; /* These should represent standard US ring pulse. */
- j->pstn_last_rmr = jiffies;