From 81600fe9610fd0b976bbe85a003fba6fcf699fd5 Mon Sep 17 00:00:00 2001 From: markster Date: Thu, 4 Aug 2005 20:33:33 +0000 Subject: Allow polarity on TDM card FXS interface to be reversed... git-svn-id: http://svn.digium.com/svn/zaptel/trunk@717 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- wctdm.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/wctdm.c b/wctdm.c index 463c36f..cac3db3 100755 --- a/wctdm.c +++ b/wctdm.c @@ -55,6 +55,8 @@ */ static int loopcurrent = 20; +static int reversepolarity = 0; + static alpha indirect_regs[] = { {0,255,"DTMF_ROW_0_PEAK",0x55C2}, @@ -1058,15 +1060,24 @@ static void wctdm_interrupt(int irq, void *dev_id, struct pt_regs *regs) if (wc->mod[x].fxs.lasttxhook == 0x4) { /* RINGing, prepare for OHT */ wc->mod[x].fxs.ohttimer = OHT_TIMER << 3; - wc->mod[x].fxs.idletxhookstate = 0x2; /* OHT mode when idle */ + if (reversepolarity) + wc->mod[x].fxs.idletxhookstate = 0x6; /* OHT mode when idle */ + else + wc->mod[x].fxs.idletxhookstate = 0x2; } else { if (wc->mod[x].fxs.ohttimer) { wc->mod[x].fxs.ohttimer-= ZT_CHUNKSIZE; if (!wc->mod[x].fxs.ohttimer) { - wc->mod[x].fxs.idletxhookstate = 0x1; /* Switch to active */ - if (wc->mod[x].fxs.lasttxhook == 0x2) { + if (reversepolarity) + wc->mod[x].fxs.idletxhookstate = 0x5; /* Switch to active */ + else + wc->mod[x].fxs.idletxhookstate = 0x1; + if ((wc->mod[x].fxs.lasttxhook == 0x2) || (wc->mod[x].fxs.lasttxhook = 0x6)) { /* Apply the change if appropriate */ - wc->mod[x].fxs.lasttxhook = 0x1; + if (reversepolarity) + wc->mod[x].fxs.lasttxhook = 0x5; + else + wc->mod[x].fxs.lasttxhook = 0x1; wctdm_setreg(wc, x, 64, wc->mod[x].fxs.lasttxhook); } } @@ -1474,7 +1485,10 @@ static int wctdm_init_proslic(struct wctdm *wc, int card, int fast, int manual, int fxsmode=0; /* By default, don't send on hook */ - wc->mod[card].fxs.idletxhookstate = 1; + if (reversepolarity) + wc->mod[card].fxs.idletxhookstate = 5; + else + wc->mod[card].fxs.idletxhookstate = 1; /* Sanity check the ProSLIC */ if (!sane && wctdm_proslic_insane(wc, card)) @@ -1662,10 +1676,16 @@ static int wctdm_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long dat if (get_user(x, (int *)data)) return -EFAULT; wc->mod[chan->chanpos - 1].fxs.ohttimer = x << 3; - wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 0x2; /* OHT mode when idle */ + if (reversepolarity) + wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 0x6; /* OHT mode when idle */ + else + wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 0x2; if (wc->mod[chan->chanpos - 1].fxs.lasttxhook == 0x1) { /* Apply the change if appropriate */ - wc->mod[chan->chanpos - 1].fxs.lasttxhook = 0x2; + if (reversepolarity) + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 0x6; + else + wc->mod[chan->chanpos - 1].fxs.lasttxhook = 0x2; wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos - 1].fxs.lasttxhook); } break; @@ -1679,7 +1699,7 @@ static int wctdm_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long dat (wc->mod[chan->chanpos -1 ].fxs.lasttxhook == 0x00)) return -EINVAL; - if (x) + if ((x && !reversepolarity) || (!x && reversepolarity)) wc->mod[chan->chanpos - 1].fxs.lasttxhook |= 0x04; else wc->mod[chan->chanpos - 1].fxs.lasttxhook &= ~0x04; @@ -1793,9 +1813,12 @@ static int wctdm_close(struct zt_chan *chan) #else module_put(THIS_MODULE); #endif - if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) - wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 1; - + if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) { + if (reversepolarity) + wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 5; + else + wc->mod[chan->chanpos - 1].fxs.idletxhookstate = 1; + } /* If we're dead, release us now */ if (!wc->usecount && wc->dead) wctdm_release(wc); @@ -2313,6 +2336,7 @@ static void __exit wctdm_cleanup(void) #ifdef LINUX26 module_param(debug, int, 0600); module_param(loopcurrent, int, 0600); +module_param(reversepolarity, int, 0600); module_param(robust, int, 0600); module_param(_opermode, int, 0600); module_param(opermode, charp, 0600); @@ -2326,6 +2350,7 @@ module_param(alawoverride, int, 0600); #else MODULE_PARM(debug, "i"); MODULE_PARM(loopcurrent, "i"); +MODULE_PARM(reversepolarity, "i"); MODULE_PARM(robust, "i"); MODULE_PARM(_opermode, "i"); MODULE_PARM(opermode, "s"); -- cgit v1.2.3