--- wctdm.c.svn2 2009-01-20 20:26:43.000000000 +1300 +++ wctdm.c 2009-01-20 22:27:18.000000000 +1300 @@ -224,9 +224,9 @@ struct wctdm { unsigned int battdebounce; unsigned int battalarm; enum battery_state battery; - int lastpol; - int polarity; - int polaritydebounce; + int lastpol; + int polarity; + int polaritydebounce; } fxo; struct fxs { int oldrxhook; @@ -313,7 +313,7 @@ static inline void wctdm_transmitprep(st /* Calculate Transmission */ dahdi_transmit(&wc->span); - for (x=0;xmodtype[card] != MOD_TYPE_FXO) return; wc->mod[card].fxo.pegtimer += DAHDI_CHUNKSIZE; - for (x=0;xchans[card].readchunk[x], (&(wc->chans[card]))); if ((sample > 10000) && (wc->mod[card].fxo.peg != 1)) { @@ -400,7 +400,7 @@ static inline void wctdm_receiveprep(str else /* Read is at interrupt address. Valid data is available at normal offset */ readchunk = wc->readchunk; - for (x=0;xcardflag & (1 << 3)) wc->chans[3]->readchunk[x] = (readchunk[x]) & 0xff; @@ -422,7 +422,7 @@ static inline void wctdm_receiveprep(str #endif } #ifdef AUDIO_RINGCHECK - for (x=0;xcards;x++) + for (x = 0; x < wc->cards; x++) ring_check(wc, x); #endif /* XXX We're wasting 8 taps. We should get closer :( */ @@ -445,7 +445,7 @@ static inline void __write_8bits(struct outb(wc->ios, wc->ioaddr + WC_AUXD); wc->ios &= ~BIT_CS; outb(wc->ios, wc->ioaddr + WC_AUXD); - for (x=0;x<8;x++) { + for (x = 0; x < 8; x++) { /* Send out each bit, MSB first, drop SCLK as we do so */ if (bits & 0x80) wc->ios |= BIT_SDI; @@ -491,14 +491,14 @@ static inline void __reset_spi(struct wc static inline unsigned char __read_8bits(struct wctdm *wc) { - unsigned char res=0, c; + unsigned char res = 0, c; int x; wc->ios |= BIT_SCLK; outb(wc->ios, wc->ioaddr + WC_AUXD); /* Drop chip select */ wc->ios &= ~BIT_CS; outb(wc->ios, wc->ioaddr + WC_AUXD); - for (x=0;x<8;x++) { + for (x = 0; x < 8; x++) { res <<= 1; /* Get SCLK */ wc->ios &= ~BIT_SCLK; @@ -593,25 +593,25 @@ static unsigned char wctdm_getreg(struct static int __wait_access(struct wctdm *wc, int card) { - unsigned char data = 0; - long origjiffies; - int count = 0; + unsigned char data = 0; + long origjiffies; + int count = 0; - #define MAX 6000 /* attempts */ + #define MAX 6000 /* attempts */ - - origjiffies = jiffies; - /* Wait for indirect access */ - while (count++ < MAX) - { + origjiffies = jiffies; + /* Wait for indirect access */ + while (count++ < MAX) { data = __wctdm_getreg(wc, card, I_STATUS); - if (!data) + if (!data) { return 0; - + } } - if(count > (MAX-1)) printk(KERN_NOTICE " ##### Loop error (%02x) #####\n", data); + if (count > (MAX-1)) { + printk(KERN_NOTICE " ##### Loop error (%02x) #####\n", data); + } return 0; } @@ -619,7 +619,7 @@ static int __wait_access(struct wctdm *w static unsigned char translate_3215(unsigned char address) { int x; - for (x=0;xlock, flags); - if(!__wait_access(wc, card)) { + if (!__wait_access(wc, card)) { __wctdm_setreg(wc, card, IDA_LO,(unsigned char)(data & 0xFF)); __wctdm_setreg(wc, card, IDA_HI,(unsigned char)((data & 0xFF00)>>8)); __wctdm_setreg(wc, card, IAA,address); @@ -682,10 +682,10 @@ static int wctdm_proslic_init_indirect_r { unsigned char i; - for (i=0; iflags[card] & FLAG_3215) || (indirect_regs[i].altaddr != 255))) - { + if ( j != initial && (!(wc->flags[card] & FLAG_3215) || (indirect_regs[i].altaddr != 255))) { printk(KERN_NOTICE "!!!!!!! %s iREG %X = %X should be %X\n", indirect_regs[i].name,indirect_regs[i].address,j,initial ); passed = 0; } } - if (passed) { + if (passed) { if (debug) printk(KERN_DEBUG "Init Indirect Registers completed successfully.\n"); - } else { + } else { printk(KERN_NOTICE " !!!!! Init Indirect Registers UNSUCCESSFULLY.\n"); return -1; - } - return 0; + } + return 0; } static inline void wctdm_proslic_recheck_sanity(struct wctdm *wc, int card) @@ -781,8 +779,7 @@ static inline void wctdm_voicedaa_check_ res = wc->reg0shadow[card] & 0x60; if (fxo->ringdebounce) { --fxo->ringdebounce; - if (res && (res != fxo->lastrdtx) && - (fxo->battery == BATTERY_PRESENT)) { + if (res && (res != fxo->lastrdtx) && (fxo->battery == BATTERY_PRESENT)) { if (!fxo->wasringing) { fxo->wasringing = 1; if (debug) @@ -901,9 +898,10 @@ static inline void wctdm_voicedaa_check_ /* going to BATTERY_PRESENT, see if we are there yet */ if (--fxo->battdebounce == 0) { fxo->battery = BATTERY_PRESENT; - if (debug) + if (debug) { printk(KERN_DEBUG "BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1, - (b < 0) ? "-" : "+"); + (b < 0) ? "-" : "+"); + } #ifdef ZERO_BATT_RING if (wc->onhook) { wc->onhook = 0; @@ -948,15 +946,15 @@ static inline void wctdm_voicedaa_check_ if (fxo->polaritydebounce) { if (--fxo->polaritydebounce == 0) { - if (fxo->lastpol != fxo->polarity) { + if (fxo->lastpol != fxo->polarity) { if (debug) printk(KERN_DEBUG "%lu Polarity reversed (%d -> %d)\n", jiffies, - fxo->polarity, - fxo->lastpol); + fxo->polarity, + fxo->lastpol); if (fxo->polarity) dahdi_qevent_lock(wc->chans[card], DAHDI_EVENT_POLARITY); fxo->polarity = fxo->lastpol; - } + } } } #undef MS_PER_CHECK_HOOK @@ -1041,9 +1039,8 @@ DAHDI_IRQ_HANDLER(wctdm_interrupt) return IRQ_RETVAL(1); } - for (x=0;x<4;x++) { - if (wc->cardflag & (1 << x) && - (wc->modtype[x] == MOD_TYPE_FXS)) { + for (x = 0; x < 4; x++) { + if (wc->cardflag & (1 << x) && (wc->modtype[x] == MOD_TYPE_FXS)) { if (wc->mod[x].fxs.lasttxhook == 0x4) { /* RINGing, prepare for OHT */ wc->mod[x].fxs.ohttimer = OHT_TIMER << 3; @@ -1108,7 +1105,7 @@ DAHDI_IRQ_HANDLER(wctdm_interrupt) } if (!(wc->intcount % 10000)) { /* Accept an alarm once per 10 seconds */ - for (x=0;x<4;x++) + for (x = 0; x < 4; x++) if (wc->modtype[x] == MOD_TYPE_FXS) { if (wc->mod[x].fxs.palarms) wc->mod[x].fxs.palarms--; @@ -1136,7 +1133,7 @@ static int wctdm_voicedaa_insane(struct static int wctdm_proslic_insane(struct wctdm *wc, int card) { int blah,insane_report; - insane_report=0; + insane_report = 0; blah = wctdm_getreg(wc, card, 0); if (debug) @@ -1203,14 +1200,14 @@ static int wctdm_proslic_powerleak_test( /* Wait for one second */ origjiffies = jiffies; - while((vbat = wctdm_getreg(wc, card, 82)) > 0x6) { + while ((vbat = wctdm_getreg(wc, card, 82)) > 0x6) { if ((jiffies - origjiffies) >= (HZ/2)) break;; } if (vbat < 0x06) { printk(KERN_NOTICE "Excessive leakage detected on module %d: %d volts (%02x) after %d ms\n", card, - 376 * vbat / 1000, vbat, (int)((jiffies - origjiffies) * 1000 / HZ)); + 376 * vbat / 1000, vbat, (int)((jiffies - origjiffies) * 1000 / HZ)); return -1; } else if (debug) { printk(KERN_NOTICE "Post-leakage voltage: %d volts\n", 376 * vbat / 1000); @@ -1237,7 +1234,7 @@ static int wctdm_powerup_proslic(struct if (fast) return 0; - while((vbat = wctdm_getreg(wc, card, 82)) < 0xc0) { + while ((vbat = wctdm_getreg(wc, card, 82)) < 0xc0) { /* Wait no more than 500ms */ if ((jiffies - origjiffies) > HZ/2) { break; @@ -1253,27 +1250,27 @@ static int wctdm_powerup_proslic(struct return -1; } else if (debug) { printk(KERN_DEBUG "ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n", - card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); + card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); } wc->proslic_power = PROSLIC_POWER_ON; - /* Proslic max allowed loop current, reg 71 LOOP_I_LIMIT */ - /* If out of range, just set it to the default value */ - lim = (loopcurrent - 20) / 3; - if ( loopcurrent > 41 ) { - lim = 0; - if (debug) - printk(KERN_DEBUG "Loop current out of range! Setting to default 20mA!\n"); - } - else if (debug) - printk(KERN_DEBUG "Loop current set to %dmA!\n",(lim*3)+20); - wctdm_setreg(wc,card,LOOP_I_LIMIT,lim); + /* Proslic max allowed loop current, reg 71 LOOP_I_LIMIT */ + /* If out of range, just set it to the default value */ + lim = (loopcurrent - 20) / 3; + if ( loopcurrent > 41 ) { + lim = 0; + if (debug) + printk(KERN_DEBUG "Loop current out of range! Setting to default 20mA!\n"); + } else if (debug) { + printk(KERN_DEBUG "Loop current set to %dmA!\n",(lim*3)+20); + } + wctdm_setreg(wc,card,LOOP_I_LIMIT,lim); /* Engage DC-DC converter */ wctdm_setreg(wc, card, 93, 0x19 /* was 0x19 */); #if 0 origjiffies = jiffies; - while(0x80 & wctdm_getreg(wc, card, 93)) { + while (0x80 & wctdm_getreg(wc, card, 93)) { if ((jiffies - origjiffies) > 2 * HZ) { printk(KERN_DEBUG "Timeout waiting for DC-DC calibration on module %d\n", card); return -1; @@ -1282,19 +1279,20 @@ static int wctdm_powerup_proslic(struct #if 0 /* Wait a full two seconds */ - while((jiffies - origjiffies) < 2 * HZ); + while ((jiffies - origjiffies) < 2 * HZ); /* Just check to be sure */ vbat = wctdm_getreg(wc, card, 82); printk(KERN_DEBUG "ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n", - card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); + card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); #endif #endif return 0; } -static int wctdm_proslic_manual_calibrate(struct wctdm *wc, int card){ +static int wctdm_proslic_manual_calibrate(struct wctdm *wc, int card) +{ unsigned long origjiffies; unsigned char i; @@ -1307,9 +1305,10 @@ static int wctdm_proslic_manual_calibrat wctdm_setreg(wc, card, 96, 0x47); //(0x47) Calibrate common mode and differential DAC mode DAC + ILIM origjiffies=jiffies; - while( wctdm_getreg(wc,card,96)!=0 ){ - if((jiffies-origjiffies)>80) + while ( wctdm_getreg(wc, card, 96) != 0 ) { + if ((jiffies-origjiffies) > 80) { return -1; + } } //Initialized DR 98 and 99 to get consistant results. // 98 and 99 are the results registers and the search should have same intial conditions. @@ -1318,7 +1317,7 @@ static int wctdm_proslic_manual_calibrat /*******************************This is also available as a function *******************************************/ // Delay 10ms origjiffies=jiffies; - while((jiffies-origjiffies)<1); + while ((jiffies-origjiffies) < 1); wctdm_proslic_setreg_indirect(wc, card, 88, 0); wctdm_proslic_setreg_indirect(wc, card, 89, 0); wctdm_proslic_setreg_indirect(wc, card, 90, 0); @@ -1329,28 +1328,26 @@ static int wctdm_proslic_manual_calibrat wctdm_setreg(wc, card, 98, 0x10); // This is necessary if the calibration occurs other than at reset time wctdm_setreg(wc, card, 99, 0x10); - for ( i=0x1f; i>0; i--) - { + for (i = 0x1f; i > 0; i--) { wctdm_setreg(wc, card, 98, i); origjiffies=jiffies; - while((jiffies-origjiffies)<4); - if((wctdm_getreg(wc, card, 88)) == 0) + while ((jiffies-origjiffies) < 4); + if ((wctdm_getreg(wc, card, 88)) == 0) break; } // for - for ( i=0x1f; i>0; i--) - { + for (i = 0x1f; i > 0; i--) { wctdm_setreg(wc, card, 99, i); origjiffies=jiffies; - while((jiffies-origjiffies)<4); - if((wctdm_getreg(wc, card, 89)) == 0) + while ((jiffies-origjiffies) < 4); + if ((wctdm_getreg(wc, card, 89)) == 0) break; }//for /*******************************The preceding is the manual gain mismatch calibration****************************/ /**********************************The following is the longitudinal Balance Cal***********************************/ - wctdm_setreg(wc,card,64,1); - while((jiffies-origjiffies)<10); // Sleep 100? + wctdm_setreg(wc,card, 64, 1); + while ((jiffies-origjiffies) < 10); // Sleep 100? wctdm_setreg(wc, card, 64, 0); wctdm_setreg(wc, card, 23, 0x4); // enable interrupt for the balance Cal @@ -1380,7 +1377,7 @@ static int wctdm_proslic_calibrate(struc /* Wait for it to finish */ origjiffies = jiffies; - while(wctdm_getreg(wc, card, 96)) { + while (wctdm_getreg(wc, card, 96)) { if ((jiffies - origjiffies) > 2 * HZ) { printk(KERN_NOTICE "Timeout waiting for calibration of module %d\n", card); return -1; @@ -1390,7 +1387,7 @@ static int wctdm_proslic_calibrate(struc if (debug) { /* Print calibration parameters */ printk(KERN_DEBUG "Calibration Vector Regs 98 - 107: \n"); - for (x=98;x<108;x++) { + for (x=98; x<108; x++) { printk(KERN_DEBUG "%d: %02x\n", x, wctdm_getreg(wc, card, x)); } } @@ -1402,7 +1399,7 @@ static void wait_just_a_bit(int foo) { long newjiffies; newjiffies = jiffies + foo; - while(jiffies < newjiffies); + while (jiffies < newjiffies); } /********************************************************************* @@ -1422,7 +1419,7 @@ static int wctdm_set_hwgain(struct wctdm if (tx) { if (debug) printk(KERN_DEBUG "setting FXO tx gain for card=%d to %d\n", card, gain); - if (gain >= -150 && gain <= 0) { + if (gain >= -150 && gain <= 0) { wctdm_setreg(wc, card, 38, 16 + (gain/-10)); wctdm_setreg(wc, card, 40, 16 + (-gain%10)); } else if (gain <= 120 && gain > 0) { @@ -1435,7 +1432,7 @@ static int wctdm_set_hwgain(struct wctdm } else { /* rx */ if (debug) printk(KERN_DEBUG "setting FXO rx gain for card=%d to %d\n", card, gain); - if (gain >= -150 && gain <= 0) { + if (gain >= -150 && gain <= 0) { wctdm_setreg(wc, card, 39, 16+ (gain/-10)); wctdm_setreg(wc, card, 41, 16 + (-gain%10)); } else if (gain <= 120 && gain > 0) { @@ -1452,7 +1449,7 @@ static int wctdm_set_hwgain(struct wctdm static int wctdm_init_voicedaa(struct wctdm *wc, int card, int fast, int manual, int sane) { - unsigned char reg16=0, reg26=0, reg30=0, reg31=0; + unsigned char reg16 = 0, reg26 = 0, reg30 = 0, reg31 = 0; long newjiffies; wc->modtype[card] = MOD_TYPE_FXO; /* Sanity check the ProSLIC */ @@ -1467,7 +1464,7 @@ static int wctdm_init_voicedaa(struct wc wait_just_a_bit(HZ/10); /* Enable PCM, ulaw */ - if (alawoverride){ + if (alawoverride) { wctdm_setreg(wc, card, 33, 0x20); } else { wctdm_setreg(wc, card, 33, 0x28); @@ -1479,7 +1476,7 @@ static int wctdm_init_voicedaa(struct wc reg16 |= (fxo_modes[_opermode].rt); wctdm_setreg(wc, card, 16, reg16); - if(fwringdetect) { + if (fwringdetect) { /* Enable ring detector full-wave rectifier mode */ wctdm_setreg(wc, card, 18, 2); wctdm_setreg(wc, card, 24, 0); @@ -1524,8 +1521,9 @@ static int wctdm_init_voicedaa(struct wc /* Wait 1000ms for ISO-cap to come up */ newjiffies = jiffies; newjiffies += 2 * HZ; - while((jiffies < newjiffies) && !(wctdm_getreg(wc, card, 11) & 0xf0)) + while ((jiffies < newjiffies) && !(wctdm_getreg(wc, card, 11) & 0xf0)) { wait_just_a_bit(HZ/10); + } if (!(wctdm_getreg(wc, card, 11) & 0xf0)) { printk(KERN_NOTICE "VoiceDAA did not bring up ISO link properly!\n"); @@ -1533,8 +1531,8 @@ static int wctdm_init_voicedaa(struct wc } if (debug) printk(KERN_DEBUG "ISO-Cap is now up, line side: %02x rev %02x\n", - wctdm_getreg(wc, card, 11) >> 4, - (wctdm_getreg(wc, card, 13) >> 2) & 0xf); + wctdm_getreg(wc, card, 11) >> 4, + (wctdm_getreg(wc, card, 13) >> 2) & 0xf); /* Enable on-hook line monitor */ wctdm_setreg(wc, card, 5, 0x08); @@ -1548,8 +1546,9 @@ static int wctdm_init_voicedaa(struct wc wctdm_set_hwgain(wc, card, 7, 1); } - if(debug) + if (debug) { printk(KERN_DEBUG "DEBUG fxotxgain:%i.%i fxorxgain:%i.%i\n", (wctdm_getreg(wc, card, 38)/16)?-(wctdm_getreg(wc, card, 38) - 16) : wctdm_getreg(wc, card, 38), (wctdm_getreg(wc, card, 40)/16)? -(wctdm_getreg(wc, card, 40) - 16):wctdm_getreg(wc, card, 40), (wctdm_getreg(wc, card, 39)/16)? -(wctdm_getreg(wc, card, 39) - 16) : wctdm_getreg(wc, card, 39),(wctdm_getreg(wc, card, 41)/16)?-(wctdm_getreg(wc, card, 41) - 16):wctdm_getreg(wc, card, 41)); + } return 0; @@ -1559,20 +1558,20 @@ static int wctdm_init_proslic(struct wct { unsigned short tmp[5]; - unsigned char r19,r9; + unsigned char r19, r9; int x; - int fxsmode=0; + int fxsmode = 0; /* Sanity check the ProSLIC */ if (!sane && wctdm_proslic_insane(wc, card)) return -2; /* default messages to none and method to FSK */ - wc->mod[card].fxs.mwisendtype=DAHDI_VMWI_FSK; - wc->mod[card].fxs.vmwimessages=0; - wc->mod[card].fxs.vmwi_lrev=0; - wc->mod[card].fxs.vmwi_hvdc=0; - wc->mod[card].fxs.vmwi_hvac=0; + wc->mod[card].fxs.mwisendtype = DAHDI_VMWI_FSK; + wc->mod[card].fxs.vmwimessages = 0; + wc->mod[card].fxs.vmwi_lrev = 0; + wc->mod[card].fxs.vmwi_hvdc = 0; + wc->mod[card].fxs.vmwi_hvac = 0; /* By default, don't send on hook */ if (!reversepolarity != !wc->mod[card].fxs.reversepolarity) @@ -1591,7 +1590,7 @@ static int wctdm_init_proslic(struct wct } /* Clear scratch pad area */ - wctdm_proslic_setreg_indirect(wc, card, 97,0); + wctdm_proslic_setreg_indirect(wc, card, 97, 0); /* Clear digital loopback */ wctdm_setreg(wc, card, 8, 0); @@ -1609,7 +1608,7 @@ static int wctdm_init_proslic(struct wct /* Flush ProSLIC digital filters by setting to clear, while saving old values */ - for (x=0;x<5;x++) { + for (x = 0; x < 5; x++) { tmp[x] = wctdm_proslic_getreg_indirect(wc, card, x + 35); wctdm_proslic_setreg_indirect(wc, card, x + 35, 0x8000); } @@ -1633,7 +1632,7 @@ static int wctdm_init_proslic(struct wct } #ifndef NO_CALIBRATION /* Perform calibration */ - if(manual) { + if (manual) { if (wctdm_proslic_manual_calibrate(wc, card)) { //printk(KERN_NOTICE "Proslic failed on Manual Calibration\n"); if (wctdm_proslic_manual_calibrate(wc, card)) { @@ -1644,7 +1643,7 @@ static int wctdm_init_proslic(struct wct } } else { - if(wctdm_proslic_calibrate(wc, card)) { + if (wctdm_proslic_calibrate(wc, card)) { //printk(KERN_NOTICE "ProSlic died on Auto Calibration.\n"); if (wctdm_proslic_calibrate(wc, card)) { printk(KERN_NOTICE "Proslic Failed on Second Attempt to Auto Calibrate\n"); @@ -1662,17 +1661,17 @@ static int wctdm_init_proslic(struct wct } /* Save calibration vectors */ - for (x=0;xmod[card].fxs.calregs.vals[x] = wctdm_getreg(wc, card, 96 + x); #endif } else { /* Restore calibration registers */ - for (x=0;xmod[card].fxs.calregs.vals[x]); } /* Calibration complete, restore original values */ - for (x=0;x<5;x++) { + for (x = 0; x < 5; x++) { wctdm_proslic_setreg_indirect(wc, card, x + 35, tmp[x]); } @@ -1683,31 +1682,32 @@ static int wctdm_init_proslic(struct wct #if 0 - /* Disable Auto Power Alarm Detect and other "features" */ - wctdm_setreg(wc, card, 67, 0x0e); - blah = wctdm_getreg(wc, card, 67); + /* Disable Auto Power Alarm Detect and other "features" */ + wctdm_setreg(wc, card, 67, 0x0e); + blah = wctdm_getreg(wc, card, 67); #endif #if 0 - if (wctdm_proslic_setreg_indirect(wc, card, 97, 0x0)) { // Stanley: for the bad recording fix - printk(KERN_INFO "ProSlic IndirectReg Died.\n"); - return -1; + if (wctdm_proslic_setreg_indirect(wc, card, 97, 0x0)) { // Stanley: for the bad recording fix + printk(KERN_INFO "ProSlic IndirectReg Died.\n"); + return -1; } #endif - if (alawoverride) - wctdm_setreg(wc, card, 1, 0x20); - else - wctdm_setreg(wc, card, 1, 0x28); - // U-Law 8-bit interface - wctdm_setreg(wc, card, 2, (3-card) * 8); // Tx Start count low byte 0 - wctdm_setreg(wc, card, 3, 0); // Tx Start count high byte 0 - wctdm_setreg(wc, card, 4, (3-card) * 8); // Rx Start count low byte 0 - wctdm_setreg(wc, card, 5, 0); // Rx Start count high byte 0 - wctdm_setreg(wc, card, 18, 0xff); // clear all interrupt - wctdm_setreg(wc, card, 19, 0xff); - wctdm_setreg(wc, card, 20, 0xff); - wctdm_setreg(wc, card, 73, 0x04); + if (alawoverride) { + wctdm_setreg(wc, card, 1, 0x20); + } else { + wctdm_setreg(wc, card, 1, 0x28); + } + // U-Law 8-bit interface + wctdm_setreg(wc, card, 2, (3-card) * 8);/* Tx Start count low byte 0 */ + wctdm_setreg(wc, card, 3, 0); /* Tx Start count high byte 0 */ + wctdm_setreg(wc, card, 4, (3-card) * 8);/* Rx Start count low byte 0 */ + wctdm_setreg(wc, card, 5, 0); /* Rx Start count high byte 0 */ + wctdm_setreg(wc, card, 18, 0xff); /* clear all interrupt */ + wctdm_setreg(wc, card, 19, 0xff); + wctdm_setreg(wc, card, 20, 0xff); + wctdm_setreg(wc, card, 73, 0x04); if (fxshonormode) { fxsmode = acim2tiss[fxo_modes[_opermode].acim]; wctdm_setreg(wc, card, 10, 0x08 | fxsmode); @@ -1716,21 +1716,21 @@ static int wctdm_init_proslic(struct wct if (fxo_modes[_opermode].ring_x) wctdm_proslic_setreg_indirect(wc, card, 21, fxo_modes[_opermode].ring_x); } - if (lowpower) - wctdm_setreg(wc, card, 72, 0x10); - + if (lowpower) { + wctdm_setreg(wc, card, 72, 0x10); + } #if 0 - wctdm_setreg(wc, card, 21, 0x00); // enable interrupt - wctdm_setreg(wc, card, 22, 0x02); // Loop detection interrupt - wctdm_setreg(wc, card, 23, 0x01); // DTMF detection interrupt + wctdm_setreg(wc, card, 21, 0x00); // enable interrupt + wctdm_setreg(wc, card, 22, 0x02); // Loop detection interrupt + wctdm_setreg(wc, card, 23, 0x01); // DTMF detection interrupt #endif #if 0 - /* Enable loopback */ - wctdm_setreg(wc, card, 8, 0x2); - wctdm_setreg(wc, card, 14, 0x0); - wctdm_setreg(wc, card, 64, 0x0); - wctdm_setreg(wc, card, 1, 0x08); + /* Enable loopback */ + wctdm_setreg(wc, card, 8, 0x2); + wctdm_setreg(wc, card, 14, 0x0); + wctdm_setreg(wc, card, 64, 0x0); + wctdm_setreg(wc, card, 1, 0x08); #endif if (fastringer) { @@ -1747,8 +1747,9 @@ static int wctdm_init_proslic(struct wct if (wctdm_proslic_setreg_indirect(wc, card, 21, 0x14b)) return -1; printk(KERN_INFO "Reducing fast ring power on slot %d (50V peak)\n", card + 1); - } else + } else { printk(KERN_INFO "Speeding up ringer on slot %d (25Hz)\n", card + 1); + } } else { /* Beef up Ringing voltage to 89V */ if (boostringer) { @@ -1763,37 +1764,35 @@ static int wctdm_init_proslic(struct wct } } - if(fxstxgain || fxsrxgain) { + if (fxstxgain || fxsrxgain) { r9 = wctdm_getreg(wc, card, 9); switch (fxstxgain) { - - case 35: - r9+=8; - break; - case -35: - r9+=4; - break; - case 0: - break; + case 35: + r9 += 8; + break; + case -35: + r9 += 4; + break; + case 0: + break; } switch (fxsrxgain) { - - case 35: - r9+=2; - break; - case -35: - r9+=1; - break; - case 0: - break; + case 35: + r9 += 2; + break; + case -35: + r9 += 1; + break; + case 0: + break; } wctdm_setreg(wc,card,9,r9); } - if(debug) - printk(KERN_DEBUG "DEBUG: fxstxgain:%s fxsrxgain:%s\n",((wctdm_getreg(wc, card, 9)/8) == 1)?"3.5":(((wctdm_getreg(wc,card,9)/4) == 1)?"-3.5":"0.0"),((wctdm_getreg(wc, card, 9)/2) == 1)?"3.5":((wctdm_getreg(wc,card,9)%2)?"-3.5":"0.0")); - + if (debug) { + printk(KERN_DEBUG "DEBUG: fxstxgain:%s fxsrxgain:%s\n",((wctdm_getreg(wc, card, 9)/8) == 1)?"3.5":(((wctdm_getreg(wc,card,9)/4) == 1)?"-3.5":"0.0"),((wctdm_getreg(wc, card, 9)/2) == 1)?"3.5":((wctdm_getreg(wc,card,9)%2)?"-3.5":"0.0")); + } wc->mod[card].fxs.lasttxhook = wc->mod[card].fxs.idletxhookstate; wctdm_setreg(wc, card, 64, wc->mod[card].fxs.lasttxhook); return 0; @@ -1829,8 +1828,8 @@ static int wctdm_ioctl(struct dahdi_chan if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) return -EINVAL; /* Can't change polarity while ringing or when open */ - if ((wc->mod[chan->chanpos -1 ].fxs.lasttxhook == 0x04) || - (wc->mod[chan->chanpos -1 ].fxs.lasttxhook == 0x00)) + if ((wc->mod[chan->chanpos - 1].fxs.lasttxhook == 0x04) || + (wc->mod[chan->chanpos - 1].fxs.lasttxhook == 0x00)) return -EINVAL; wc->mod[chan->chanpos - 1].fxs.reversepolarity = x; @@ -1850,7 +1849,7 @@ static int wctdm_ioctl(struct dahdi_chan wc->mod[chan->chanpos - 1].fxs.vmwimessages = (x & DAHDI_VMWI_NUMBER_MASK); wc->mod[chan->chanpos - 1].fxs.mwisendtype = (x & ~ DAHDI_VMWI_NUMBER_MASK); - if (wc->mod[chan->chanpos - 1].fxs.vmwimessages){ + if (wc->mod[chan->chanpos - 1].fxs.vmwimessages) { x = wc->mod[chan->chanpos - 1].fxs.mwisendtype; wc->mod[chan->chanpos - 1].fxs.vmwi_lrev = (x & DAHDI_VMWI_LREV)?1:0; wc->mod[chan->chanpos - 1].fxs.vmwi_hvdc = (x & DAHDI_VMWI_HVDC)?1:0; @@ -1863,7 +1862,7 @@ static int wctdm_ioctl(struct dahdi_chan if (debug) { printk(KERN_DEBUG "Setting VMWI on channel %d, type=0x%X, messages=%d, lrev=%d, hvdc=%d, hvac=%d\n", - chan->chanpos-1, + chan->chanpos - 1, wc->mod[chan->chanpos - 1].fxs.mwisendtype, wc->mod[chan->chanpos - 1].fxs.vmwimessages, wc->mod[chan->chanpos - 1].fxs.vmwi_lrev, @@ -1871,20 +1870,20 @@ static int wctdm_ioctl(struct dahdi_chan wc->mod[chan->chanpos - 1].fxs.vmwi_hvac ); } - if (POLARITY_XOR(chan->chanpos -1)) { - wc->mod[chan->chanpos -1 ].fxs.idletxhookstate |= 0x4; + if (POLARITY_XOR(chan->chanpos - 1)) { + wc->mod[chan->chanpos - 1].fxs.idletxhookstate |= 0x4; /* Do not set while currently ringing or open */ - if (wc->mod[chan->chanpos -1 ].fxs.lasttxhook != 0x04 && - wc->mod[chan->chanpos -1 ].fxs.lasttxhook != 0x00) { - wc->mod[chan->chanpos -1 ].fxs.lasttxhook |= 0x4; + if (wc->mod[chan->chanpos - 1].fxs.lasttxhook != 0x04 && + wc->mod[chan->chanpos - 1].fxs.lasttxhook != 0x00) { + wc->mod[chan->chanpos - 1].fxs.lasttxhook |= 0x4; wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos - 1].fxs.lasttxhook); } } else { - wc->mod[chan->chanpos -1 ].fxs.idletxhookstate &= ~0x04; + wc->mod[chan->chanpos - 1].fxs.idletxhookstate &= ~0x04; /* Do not set while currently ringing or open */ - if (wc->mod[chan->chanpos -1 ].fxs.lasttxhook != 0x04 && - wc->mod[chan->chanpos -1 ].fxs.lasttxhook != 0x00) { - wc->mod[chan->chanpos -1 ].fxs.lasttxhook &= ~0x04; + if (wc->mod[chan->chanpos - 1].fxs.lasttxhook != 0x04 && + wc->mod[chan->chanpos - 1].fxs.lasttxhook != 0x00) { + wc->mod[chan->chanpos - 1].fxs.lasttxhook &= ~0x04; wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos - 1].fxs.lasttxhook); } } @@ -1905,13 +1904,13 @@ static int wctdm_ioctl(struct dahdi_chan break; case WCTDM_GET_REGS: if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) { - for (x=0;xchanpos -1, x); - for (x=0;xchanpos - 1, x); + for (x = 0; x < NUM_REGS; x++) regs.direct[x] = wctdm_getreg(wc, chan->chanpos - 1, x); } else { memset(®s, 0, sizeof(regs)); - for (x=0;xchanpos - 1, x); } if (copy_to_user((__user void *)data, ®s, sizeof(regs))) @@ -1962,11 +1961,11 @@ static int wctdm_ioctl(struct dahdi_chan if (copy_from_user(&hwgain, (__user void *) data, sizeof(hwgain))) return -EFAULT; - wctdm_set_hwgain(wc, chan->chanpos-1, hwgain.newgain, hwgain.tx); + wctdm_set_hwgain(wc, chan->chanpos - 1, hwgain.newgain, hwgain.tx); if (debug) printk(KERN_DEBUG "Setting hwgain on channel %d to %d for %s direction\n", - chan->chanpos-1, hwgain.newgain, hwgain.tx ? "tx" : "rx"); + chan->chanpos - 1, hwgain.newgain, hwgain.tx ? "tx" : "rx"); break; default: return -ENOTTY; @@ -2033,41 +2032,41 @@ static int wctdm_hooksig(struct dahdi_ch switch(chan->sig) { case DAHDI_SIG_FXOKS: case DAHDI_SIG_FXOLS: - /* wc->mod[chan->chanpos-1].fxs.lasttxhook = (wc->mod[chan->chanpos-1].fxs.vmwi_hvac ? 4 : wc->mod[chan->chanpos-1].fxs.idletxhookstate); */ - wc->mod[chan->chanpos-1].fxs.lasttxhook = wc->mod[chan->chanpos-1].fxs.idletxhookstate; + /* wc->mod[chan->chanpos - 1].fxs.lasttxhook = (wc->mod[chan->chanpos - 1].fxs.vmwi_hvac ? 4 : wc->mod[chan->chanpos - 1].fxs.idletxhookstate); */ + wc->mod[chan->chanpos - 1].fxs.lasttxhook = wc->mod[chan->chanpos - 1].fxs.idletxhookstate; break; case DAHDI_SIG_EM: - wc->mod[chan->chanpos-1].fxs.lasttxhook = wc->mod[chan->chanpos-1].fxs.idletxhookstate; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = wc->mod[chan->chanpos - 1].fxs.idletxhookstate; break; case DAHDI_SIG_FXOGS: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 3; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 3; break; } break; case DAHDI_TXSIG_OFFHOOK: switch(chan->sig) { case DAHDI_SIG_EM: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 5; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 5; break; default: - wc->mod[chan->chanpos-1].fxs.lasttxhook = wc->mod[chan->chanpos-1].fxs.idletxhookstate; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = wc->mod[chan->chanpos - 1].fxs.idletxhookstate; break; } break; case DAHDI_TXSIG_START: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 4; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 4; break; case DAHDI_TXSIG_KEWL: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 0; + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 0; break; default: printk(KERN_NOTICE "wctdm: Can't set tx state to %d\n", txsig); } if (debug) - printk(KERN_DEBUG "Setting FXS hook state to %d (%02x)\n", txsig, wc->mod[chan->chanpos-1].fxs.lasttxhook); + printk(KERN_DEBUG "Setting FXS hook state to %d (%02x)\n", txsig, wc->mod[chan->chanpos - 1].fxs.lasttxhook); #if 1 - wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos-1].fxs.lasttxhook); + wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos - 1].fxs.lasttxhook); #endif } return 0; @@ -2149,7 +2148,7 @@ static int wctdm_hardware_init(struct wc failed = 0; if (ver != 0x59) { printk(KERN_INFO "Freshmaker version: %02x\n", ver); - for (x=0;x<255;x++) { + for (x = 0; x < 255; x++) { /* Test registers */ if (ver >= 0x70) { __wctdm_setcreg(wc, WC_CS, x); @@ -2205,12 +2204,12 @@ static int wctdm_hardware_init(struct wc outb(0x0, wc->ioaddr + WC_FSCDELAY); /* Setup DMA Addresses */ - outl(wc->writedma, wc->ioaddr + WC_DMAWS); /* Write start */ - outl(wc->writedma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMAWI); /* Middle (interrupt) */ - outl(wc->writedma + DAHDI_CHUNKSIZE * 8 - 4, wc->ioaddr + WC_DMAWE); /* End */ + outl(wc->writedma, wc->ioaddr + WC_DMAWS); /* Write start */ + outl(wc->writedma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMAWI); /* Middle (interrupt) */ + outl(wc->writedma + DAHDI_CHUNKSIZE * 8 - 4, wc->ioaddr + WC_DMAWE); /* End */ - outl(wc->readdma, wc->ioaddr + WC_DMARS); /* Read start */ - outl(wc->readdma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMARI); /* Middle (interrupt) */ + outl(wc->readdma, wc->ioaddr + WC_DMARS); /* Read start */ + outl(wc->readdma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMARI); /* Middle (interrupt) */ outl(wc->readdma + DAHDI_CHUNKSIZE * 8 - 4, wc->ioaddr + WC_DMARE); /* End */ /* Clear interrupts */ @@ -2220,28 +2219,28 @@ static int wctdm_hardware_init(struct wc wait_just_a_bit(HZ/4); for (x = 0; x < NUM_CARDS; x++) { - int sane=0,ret=0,readi=0; + int sane = 0, ret = 0, readi = 0; #if 1 /* Init with Auto Calibration */ if (!(ret=wctdm_init_proslic(wc, x, 0, 0, sane))) { wc->cardflag |= (1 << x); - if (debug) { - readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); - printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, - ((readi*3)+20)); - } + if (debug) { + readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); + printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, + ((readi*3)+20)); + } printk(KERN_INFO "Module %d: Installed -- AUTO FXS/DPO\n",x); } else { - if(ret!=-2) { - sane=1; + if (ret != -2) { + sane = 1; /* Init with Manual Calibration */ if (!wctdm_init_proslic(wc, x, 0, 1, sane)) { wc->cardflag |= (1 << x); - if (debug) { - readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); - printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, - ((readi*3)+20)); - } + if (debug) { + readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); + printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, + ((readi*3)+20)); + } printk(KERN_INFO "Module %d: Installed -- MANUAL FXS\n",x); } else { printk(KERN_NOTICE "Module %d: FAILED FXS (%s)\n", x, fxshonormode ? fxo_modes[_opermode].name : "FCC"); @@ -2250,8 +2249,9 @@ static int wctdm_hardware_init(struct wc } else if (!(ret = wctdm_init_voicedaa(wc, x, 0, 0, sane))) { wc->cardflag |= (1 << x); printk(KERN_INFO "Module %d: Installed -- AUTO FXO (%s mode)\n",x, fxo_modes[_opermode].name); - } else + } else { printk(KERN_NOTICE "Module %d: Not installed\n", x); + } } #endif } @@ -2313,7 +2313,7 @@ static int __devinit wctdm_init_one(stru int x; int y; - for (x=0;x= WC_MAX_IFACES) { printk(KERN_NOTICE "Too many interfaces\n"); @@ -2329,7 +2329,7 @@ static int __devinit wctdm_init_one(stru ifaces[x] = wc; memset(wc, 0, sizeof(struct wctdm)); - for (x=0; x < sizeof(wc->chans)/sizeof(wc->chans[0]); ++x) { + for (x = 0; x < sizeof(wc->chans)/sizeof(wc->chans[0]); ++x) { wc->chans[x] = &wc->_chans[x]; } spin_lock_init(&wc->lock); @@ -2338,7 +2338,7 @@ static int __devinit wctdm_init_one(stru wc->dev = pdev; wc->pos = x; wc->variety = d->name; - for (y=0;yflags[y] = d->flags; /* Keep track of whether we need to free the region */ if (request_region(wc->ioaddr, 0xff, "wctdm")) @@ -2409,7 +2409,7 @@ static int __devinit wctdm_init_one(stru /* Enable interrupts */ wctdm_enable_interrupts(wc); /* Initialize Write/Buffers to all blank data */ - memset((void *)wc->writechunk,0,DAHDI_MAX_CHUNKSIZE * 2 * 2 * 4); + memset( (void *) wc->writechunk, 0, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 4); /* Start DMA */ wctdm_start_dma(wc);