[zaptel-commits] dbailey: branch 1.4 r3350 - in /branches/1.4: wctdm.c wctdm24xxp/base.c

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Fri Dec 7 16:57:27 CST 2007


Author: dbailey
Date: Fri Dec  7 16:57:26 2007
New Revision: 3350

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3350
Log:
Add ability to adjust fxo gains on wctdm drivers

Modified:
    branches/1.4/wctdm.c
    branches/1.4/wctdm24xxp/base.c

Modified: branches/1.4/wctdm.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wctdm.c?view=diff&rev=3350&r1=3349&r2=3350
==============================================================================
--- branches/1.4/wctdm.c (original)
+++ branches/1.4/wctdm.c Fri Dec  7 16:57:26 2007
@@ -1433,6 +1433,51 @@
 	while(jiffies < newjiffies);
 }
 
+/*********************************************************************
+ * Set the hwgain on the analog modules
+ *
+ * card = the card position for this module (0-23)
+ * gain = gain in dB x10 (e.g. -3.5dB  would be gain=-35)
+ * tx = (0 for rx; 1 for tx)
+ *
+ *******************************************************************/
+static int wctdm_set_hwgain(struct wctdm *wc, int card, int gain, int tx)
+{
+	if (!(wc->modtype[card] == MOD_TYPE_FXO)) {
+		printk("Cannot adjust gain.  Unsupported module type!\n");
+		return -1;
+	}
+	if (tx) {
+		if (debug)
+			printk("setting FXO tx gain for card=%d to %d\n", card, gain);
+		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) {
+			wctdm_setreg(wc, card, 38, gain/10);
+			wctdm_setreg(wc, card, 40, (gain%10));
+		} else {
+			printk("FXO tx gain is out of range (%d)\n", gain);
+			return -1;
+		}
+	} else { /* rx */
+		if (debug)
+			printk("setting FXO rx gain for card=%d to %d\n", card, gain);
+		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) {
+			wctdm_setreg(wc, card, 39, gain/10);
+			wctdm_setreg(wc, card, 41, (gain%10));
+		} else {
+			printk("FXO rx gain is out of range (%d)\n", gain);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 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;
@@ -1509,41 +1554,15 @@
 		       (wctdm_getreg(wc, card, 13) >> 2) & 0xf);
 	/* Enable on-hook line monitor */
 	wctdm_setreg(wc, card, 5, 0x08);
-	
+
 	/* Take values for fxotxgain and fxorxgain and apply them to module */
-	if (fxotxgain) {
-		if (fxotxgain >=  -150 && fxotxgain < 0) {
-			wctdm_setreg(wc, card, 38, 16 + (fxotxgain/-10));
-			if(fxotxgain % 10) {
-				wctdm_setreg(wc, card, 40, 16 + (-fxotxgain%10));
-			}
-		}
-		else if (fxotxgain <= 120 && fxotxgain > 0) {
-			wctdm_setreg(wc, card, 38, fxotxgain/10);
-			if(fxotxgain%10) {
-				wctdm_setreg(wc, card, 40, (fxotxgain%10));
-			}
-		}
-	}
-	if (fxorxgain) {
-		if (fxorxgain >=  -150 && fxorxgain < 0) {
-			wctdm_setreg(wc, card, 39, 16 + (fxorxgain/-10));
-			if(fxotxgain%10) {
-				wctdm_setreg(wc, card, 41, 16 + (-fxorxgain%10));
-			}
-		}
-		else if (fxorxgain <= 120 && fxorxgain > 0) {
-			wctdm_setreg(wc, card, 39, fxorxgain/10);
-			if(fxorxgain % 10) {
-				wctdm_setreg(wc, card, 41, (fxorxgain%10));
-			}
-		}
-	}
+	wctdm_set_hwgain(wc, card, fxotxgain, 1);
+	wctdm_set_hwgain(wc, card, fxorxgain, 0);
 
 	/* NZ -- crank the tx gain up by 7 dB */
 	if (!strcmp(fxo_modes[_opermode].name, "NEWZEALAND")) {
 		printk("Adjusting gain\n");
-		wctdm_setreg(wc, card, 38, 0x7);
+		wctdm_set_hwgain(wc, card, 7, 1);
 	}
 	
 	if(debug)
@@ -1796,6 +1815,7 @@
 	struct wctdm_regs regs;
 	struct wctdm_regop regop;
 	struct wctdm_echo_coefs echoregs;
+	struct zt_hwgain hwgain;
 	struct wctdm *wc = chan->pvt;
 	int x;
 	switch (cmd) {
@@ -1902,6 +1922,16 @@
 			return -EINVAL;
 
 		}
+		break;
+	case ZT_SET_HWGAIN:
+		if (copy_from_user(&hwgain, (struct zt_hwgain*)data, sizeof(hwgain)))
+			return -EFAULT;
+
+		wctdm_set_hwgain(wc, chan->chanpos-1, hwgain.newgain, hwgain.tx);
+
+		if (debug)
+			printk("Setting hwgain on channel %d to %d for %s direction\n", 
+				chan->chanpos-1, hwgain.newgain, hwgain.tx ? "tx" : "rx");
 		break;
 	default:
 		return -ENOTTY;

Modified: branches/1.4/wctdm24xxp/base.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wctdm24xxp/base.c?view=diff&rev=3350&r1=3349&r2=3350
==============================================================================
--- branches/1.4/wctdm24xxp/base.c (original)
+++ branches/1.4/wctdm24xxp/base.c Fri Dec  7 16:57:26 2007
@@ -2016,6 +2016,51 @@
 	while(jiffies < newjiffies);
 }
 
+/*********************************************************************
+ * Set the hwgain on the analog modules
+ *
+ * card = the card position for this module (0-23)
+ * gain = gain in dB x10 (e.g. -3.5dB  would be gain=-35)
+ * tx = (0 for rx; 1 for tx)
+ *
+ *******************************************************************/
+static int wctdm_set_hwgain(struct wctdm *wc, int card, int gain, int tx)
+{
+	if (!(wc->modtype[card] == MOD_TYPE_FXO)) {
+		printk("Cannot adjust gain.  Unsupported module type!\n");
+		return -1;
+	}
+	if (tx) {
+		if (debug)
+			printk("setting FXO tx gain for card=%d to %d\n", card, gain);
+		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) {
+			wctdm_setreg(wc, card, 38, gain/10);
+			wctdm_setreg(wc, card, 40, (gain%10));
+		} else {
+			printk("FXO tx gain is out of range (%d)\n", gain);
+			return -1;
+		}
+	} else { /* rx */
+		if (debug)
+			printk("setting FXO rx gain for card=%d to %d\n", card, gain);
+		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) {
+			wctdm_setreg(wc, card, 39, gain/10);
+			wctdm_setreg(wc, card, 41, (gain%10));
+		} else {
+			printk("FXO rx gain is out of range (%d)\n", gain);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 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;
@@ -2094,35 +2139,9 @@
 	wctdm_setreg(wc, card, 5, 0x08);
 	
 	/* Take values for fxotxgain and fxorxgain and apply them to module */
-	if (fxotxgain) {
-		if (fxotxgain >=  -150 && fxotxgain < 0) {
-			wctdm_setreg(wc, card, 38, 16 + (fxotxgain/-10));
-			if(fxotxgain % 10) {
-				wctdm_setreg(wc, card, 40, 16 + (-fxotxgain%10));
-			}
-		}
-		else if (fxotxgain <= 120 && fxotxgain > 0) {
-			wctdm_setreg(wc, card, 38, fxotxgain/10);
-			if(fxotxgain % 10) {
-				wctdm_setreg(wc, card, 40, (fxotxgain%10));
-			}
-		}
-	}
-	if (fxorxgain) {
-		if (fxorxgain >=  -150 && fxorxgain < 0) {
-			wctdm_setreg(wc, card, 39, 16+ (fxorxgain/-10));
-			if(fxotxgain % 10) {
-				wctdm_setreg(wc, card, 41, 16 + (-fxorxgain%10));
-			}
-		}
-		else if (fxorxgain <= 120 && fxorxgain > 0) {
-			wctdm_setreg(wc, card, 39, fxorxgain/10);
-			if(fxorxgain % 10) {
-				wctdm_setreg(wc, card, 41, (fxorxgain%10));
-			}
-		}
-	}
-	
+	wctdm_set_hwgain(wc, card, fxotxgain, 1);
+	wctdm_set_hwgain(wc, card, fxorxgain, 0);
+
 	if(debug)
 		printk("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));
 	
@@ -2506,6 +2525,7 @@
 	struct wctdm_regs regs;
 	struct wctdm_regop regop;
 	struct wctdm_echo_coefs echoregs;
+	struct zt_hwgain hwgain;
 	struct wctdm *wc = chan->pvt;
 	int x;
 	union {
@@ -2630,6 +2650,16 @@
 			return -EINVAL;
 
 		}
+		break;
+	case ZT_SET_HWGAIN:
+		if (copy_from_user(&hwgain, (struct zt_hwgain*)data, sizeof(hwgain)))
+			return -EFAULT;
+
+		wctdm_set_hwgain(wc, chan->chanpos-1, hwgain.newgain, hwgain.tx);
+
+		if (debug)
+			printk("Setting hwgain on channel %d to %d for %s direction\n", 
+				chan->chanpos-1, hwgain.newgain, hwgain.tx ? "tx" : "rx");
 		break;
 #ifdef VPM_SUPPORT
 	case ZT_TONEDETECT:




More information about the zaptel-commits mailing list