--- wctdm.c.4873 2008-10-23 21:01:31.000000000 +1300 +++ wctdm.c 2008-10-23 20:59:35.000000000 +1300 @@ -224,6 +224,7 @@ unsigned int battalarm; enum battery_state battery; int lastpol; + int polarityignore; int polarity; int polaritydebounce; } fxo; @@ -760,11 +761,19 @@ } b &= 0x9b; if (fxo->offhook) { - if (b != 0x9) + if (b != 0x9){ wctdm_setreg(wc, card, 5, 0x9); + if (debug) { + printk(KERN_DEBUG "check hook: HOOK Off, chan %d\n", card); + } + } } else { - if (b != 0x8) + if (b != 0x8) { wctdm_setreg(wc, card, 5, 0x8); + if (debug) { + printk(KERN_DEBUG "check hook; HOOK On, chan %d\n", card ); + } + } } if (poopy) return; @@ -933,13 +942,22 @@ if (fxo->polaritydebounce) { if (--fxo->polaritydebounce == 0) { if (fxo->lastpol != fxo->polarity) { - if (debug) - printk(KERN_DEBUG "%lu Polarity reversed (%d -> %d)\n", jiffies, - fxo->polarity, - fxo->lastpol); - if (fxo->polarity) + if (debug) { + printk(KERN_DEBUG "%lu Polarity Reversed (%d -> %d)\n", jiffies, + fxo->polarity, + fxo->lastpol); + } + + if (fxo->polarityignore) { + if (debug) { + printk(KERN_DEBUG "But ignored\n" ); + } + } else { + if (fxo->polarity) { dahdi_qevent_lock(wc->chans[card], DAHDI_EVENT_POLARITY); - fxo->polarity = fxo->lastpol; + } + } + fxo->polarity = fxo->lastpol; } } } @@ -1086,7 +1104,7 @@ wctdm_proslic_check_hook(wc, x); if (!(wc->intcount & 0xf0)) wctdm_proslic_recheck_sanity(wc, x); - } else if (wc->modtype[x] == MOD_TYPE_FXO) { + } else if (wc->modtype[x] == MOD_TYPE_FXO) { wctdm_voicedaa_check_hook(wc, x); } break; @@ -1094,11 +1112,12 @@ } 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--; } + } } wctdm_receiveprep(wc, ints); wctdm_transmitprep(wc, ints); @@ -1947,22 +1966,34 @@ static int wctdm_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) { struct wctdm *wc = chan->pvt; - int reg=0; - if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXO) { + int reg = 0; + int card = (3 & (chan->chanpos - 1)) ; + + if (wc->modtype[card] == MOD_TYPE_FXO) { /* XXX Enable hooksig for FXO XXX */ switch(txsig) { case DAHDI_TXSIG_START: + wc->mod[card].fxo.polarityignore = 1; + wc->mod[card].fxo.offhook = 1; + reg = 0x9; + break; case DAHDI_TXSIG_OFFHOOK: - wc->mod[chan->chanpos - 1].fxo.offhook = 1; - wctdm_setreg(wc, chan->chanpos - 1, 5, 0x9); + wc->mod[card].fxo.polarityignore = 0; + wc->mod[card].fxo.offhook = 1; + reg = 0x9; break; case DAHDI_TXSIG_ONHOOK: - wc->mod[chan->chanpos - 1].fxo.offhook = 0; - wctdm_setreg(wc, chan->chanpos - 1, 5, 0x8); + wc->mod[card].fxo.polarityignore = 0; + wc->mod[card].fxo.offhook = 0; + reg = 0x8; break; default: printk(KERN_NOTICE "wcfxo: Can't set tx state to %d\n", txsig); } + if (debug) { + printk(KERN_DEBUG "Setting FXO hook state %d to (%02x), PolIgnore to (%d)\n", txsig, reg, wc->mod[card].fxo.polarityignore); + } + wctdm_setreg(wc, card, 5, reg); } else { switch(txsig) { case DAHDI_TXSIG_ONHOOK: @@ -1970,38 +2001,36 @@ case DAHDI_SIG_EM: case DAHDI_SIG_FXOKS: case DAHDI_SIG_FXOLS: - wc->mod[chan->chanpos-1].fxs.lasttxhook = wc->mod[chan->chanpos-1].fxs.idletxhookstate; + wc->mod[card].fxs.lasttxhook = wc->mod[card].fxs.idletxhookstate; break; case DAHDI_SIG_FXOGS: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 3; + wc->mod[card].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[card].fxs.lasttxhook = 5; break; default: - wc->mod[chan->chanpos-1].fxs.lasttxhook = wc->mod[chan->chanpos-1].fxs.idletxhookstate; + wc->mod[card].fxs.lasttxhook = wc->mod[card].fxs.idletxhookstate; break; } break; case DAHDI_TXSIG_START: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 4; + wc->mod[card].fxs.lasttxhook = 4; break; case DAHDI_TXSIG_KEWL: - wc->mod[chan->chanpos-1].fxs.lasttxhook = 0; + wc->mod[card].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, reg); + printk(KERN_DEBUG "Setting FXS hook state %d to (%02x)\n", txsig, reg); -#if 1 - wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos-1].fxs.lasttxhook); -#endif + wctdm_setreg(wc, card, 64, wc->mod[card].fxs.lasttxhook); } return 0; }