[zaptel-commits] russell: branch russell/sandbox r2981 - /team/russell/sandbox/wctdm.c
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Thu Aug 30 16:01:10 CDT 2007
Author: russell
Date: Thu Aug 30 16:01:10 2007
New Revision: 2981
URL: http://svn.digium.com/view/zaptel?view=rev&rev=2981
Log:
* Be nice and put "wctdm: " at the beginning of all entries to the kernel log
* Restructure wctdm_init_one().
- Use kcalloc() instead of kmalloc() + memset(). kcalloc is more efficient
in that it gives the kernel a chance to hand the driver memory that it knows
is already zeroed out without having to do it unnecessarily.
- Centralize error handling to the end of the function. There were various
pieces of the error handling that were not done depending on which error
occurred, perhaps causing a memory leak, or hardware in a weird state.
Modified:
team/russell/sandbox/wctdm.c
Modified: team/russell/sandbox/wctdm.c
URL: http://svn.digium.com/view/zaptel/team/russell/sandbox/wctdm.c?view=diff&rev=2981&r1=2980&r2=2981
==============================================================================
--- team/russell/sandbox/wctdm.c (original)
+++ team/russell/sandbox/wctdm.c Thu Aug 30 16:01:10 2007
@@ -34,6 +34,8 @@
#include <asm/io.h>
#include "proslic.h"
#include "wctdm.h"
+
+#define ZAP_MODULE "wctdm: "
/*
* Define for audio vs. register based ring detection
*
@@ -436,13 +438,15 @@
/* Look for pegging to indicate ringing */
sample = ZT_XLAW(wc->chans[card].readchunk[x], (&(wc->chans[card])));
if ((sample > 10000) && (wc->mod[card].fxo.peg != 1)) {
- if (debug > 1) printk("High peg!\n");
+ if (debug > 1)
+ printk(ZAP_MODULE "High peg!\n");
if ((wc->mod[card].fxo.pegtimer < PEGTIME) && (wc->mod[card].fxo.pegtimer > MINPEGTIME))
wc->mod[card].fxo.pegcount++;
wc->mod[card].fxo.pegtimer = 0;
wc->mod[card].fxo.peg = 1;
} else if ((sample < -10000) && (wc->mod[card].fxo.peg != -1)) {
- if (debug > 1) printk("Low peg!\n");
+ if (debug > 1)
+ printk(ZAP_MODULE "Low peg!\n");
if ((wc->mod[card].fxo.pegtimer < (PEGTIME >> 2)) && (wc->mod[card].fxo.pegtimer > (MINPEGTIME >> 2)))
wc->mod[card].fxo.pegcount++;
wc->mod[card].fxo.pegtimer = 0;
@@ -460,7 +464,7 @@
if (!wc->mod[card].fxo.ring && (wc->mod[card].fxo.pegcount > PEGCOUNT)) {
/* It's ringing */
if (debug)
- printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
+ printk(ZAP_MODULE "RING on %d/%d!\n", wc->span.spanno, card + 1);
if (!wc->mod[card].fxo.offhook)
zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
wc->mod[card].fxo.ring = 1;
@@ -468,7 +472,7 @@
if (wc->mod[card].fxo.ring && !wc->mod[card].fxo.pegcount) {
/* No more ring */
if (debug)
- printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
+ printk(ZAP_MODULE "NO RING on %d/%d!\n", wc->span.spanno, card + 1);
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
wc->mod[card].fxo.ring = 0;
}
@@ -696,7 +700,8 @@
}
- if(count > (MAX-1)) printk(" ##### Loop error (%02x) #####\n", data);
+ if (count > (MAX - 1))
+ printk(ZAP_MODULE " ##### Loop error (%02x) #####\n", data);
return 0;
}
@@ -754,9 +759,9 @@
data2 = __wctdm_getreg(wc, card, IDA_HI);
res = data1 | (data2 << 8);
} else
- p = "Failed to wait inside\n";
+ p = "wctdm: Failed to wait inside\n";
} else
- p = "failed to wait\n";
+ p = "wctdm: failed to wait\n";
spin_unlock_irqrestore(&wc->lock, flags);
if (p)
printk(p);
@@ -784,15 +789,15 @@
for (i=0; i<sizeof(indirect_regs) / sizeof(indirect_regs[0]); i++)
{
- if((j = wctdm_proslic_getreg_indirect(wc, card, (unsigned char) indirect_regs[i].address)) < 0) {
- printk("Failed to read indirect register %d\n", i);
+ if ((j = wctdm_proslic_getreg_indirect(wc, card, (unsigned char) indirect_regs[i].address)) < 0) {
+ printk(ZAP_MODULE "Failed to read indirect register %d\n", i);
return -1;
}
initial= indirect_regs[i].initial;
if ( j != initial && (!(wc->flags[card] & FLAG_3215) || (indirect_regs[i].altaddr != 255)))
{
- printk("!!!!!!! %s iREG %X = %X should be %X\n",
+ printk(ZAP_MODULE "!!!!!!! %s iREG %X = %X should be %X\n",
indirect_regs[i].name,indirect_regs[i].address,j,initial );
passed = 0;
}
@@ -800,9 +805,9 @@
if (passed) {
if (debug)
- printk("Init Indirect Registers completed successfully.\n");
+ printk(ZAP_MODULE "Init Indirect Registers completed successfully.\n");
} else {
- printk(" !!!!! Init Indirect Registers UNSUCCESSFULLY.\n");
+ printk(ZAP_MODULE " !!!!! Init Indirect Registers UNSUCCESSFULLY.\n");
return -1;
}
return 0;
@@ -816,17 +821,17 @@
if (!res && (res != wc->mod[card].fxs.lasttxhook)) {
res = wctdm_getreg(wc, card, 8);
if (res) {
- printk("Ouch, part reset, quickly restoring reality (%d)\n", card);
+ printk(ZAP_MODULE "Ouch, part reset, quickly restoring reality (%d)\n", card);
wctdm_init_proslic(wc, card, 1, 0, 1);
} else {
if (wc->mod[card].fxs.palarms++ < MAX_ALARMS) {
- printk("Power alarm on module %d, resetting!\n", card + 1);
+ printk(ZAP_MODULE "Power alarm on module %d, resetting!\n", card + 1);
if (wc->mod[card].fxs.lasttxhook == 4)
wc->mod[card].fxs.lasttxhook = 1;
wctdm_setreg(wc, card, 64, wc->mod[card].fxs.lasttxhook);
} else {
if (wc->mod[card].fxs.palarms == MAX_ALARMS)
- printk("Too many power alarms on card %d, NOT resetting!\n", card + 1);
+ printk(ZAP_MODULE "Too many power alarms on card %d, NOT resetting!\n", card + 1);
}
}
}
@@ -844,7 +849,7 @@
if ((b & 0x2) || !(b & 0x8)) {
/* Not good -- don't look at anything else */
if (debug)
- printk("Poopy (%02x) on card %d!\n", b, card + 1);
+ printk(ZAP_MODULE "Poopy (%02x) on card %d!\n", b, card + 1);
poopy++;
}
b &= 0x9b;
@@ -867,7 +872,7 @@
wc->mod[card].fxo.wasringing = 1;
zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
if (debug)
- printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
+ printk(ZAP_MODULE "RING on %d/%d!\n", wc->span.spanno, card + 1);
}
wc->mod[card].fxo.ringdebounce = ZT_CHUNKSIZE * 64;
}
@@ -878,7 +883,7 @@
wc->mod[card].fxo.wasringing = 0;
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
if (debug)
- printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
+ printk(ZAP_MODULE "NO RING on %d/%d!\n", wc->span.spanno, card + 1);
}
wc->mod[card].fxo.ringdebounce = 0;
}
@@ -891,7 +896,7 @@
{
static int count = 0;
if (!(count++ % 100)) {
- printk("Card %d: Voltage: %d Debounce %d\n", card + 1,
+ printk(ZAP_MODULE "Card %d: Voltage: %d Debounce %d\n", card + 1,
b, wc->mod[card].fxo.battdebounce);
}
}
@@ -900,17 +905,17 @@
wc->mod[card].fxo.nobatttimer++;
#if 0
if (wc->mod[card].fxo.battery)
- printk("Battery loss: %d (%d debounce)\n", b, wc->mod[card].fxo.battdebounce);
+ printk(ZAP_MODULE "Battery loss: %d (%d debounce)\n", b, wc->mod[card].fxo.battdebounce);
#endif
if (wc->mod[card].fxo.battery && !wc->mod[card].fxo.battdebounce) {
if (debug)
- printk("NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
+ printk(ZAP_MODULE "NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
wc->mod[card].fxo.battery = 0;
#ifdef JAPAN
if ((!wc->ohdebounce) && wc->offhook) {
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
if (debug)
- printk("Signalled On Hook\n");
+ printk(ZAP_MODULE "Signalled On Hook\n");
#ifdef ZERO_BATT_RING
wc->onhook++;
#endif
@@ -924,14 +929,14 @@
} else if (abs(b) > battthresh) {
if (!wc->mod[card].fxo.battery && !wc->mod[card].fxo.battdebounce) {
if (debug)
- printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
+ printk(ZAP_MODULE "BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
(b < 0) ? "-" : "+");
#ifdef ZERO_BATT_RING
if (wc->onhook) {
wc->onhook = 0;
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
if (debug)
- printk("Signalled Off Hook\n");
+ printk(ZAP_MODULE "Signalled Off Hook\n");
}
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
@@ -965,7 +970,7 @@
if (wc->mod[card].fxo.polaritydebounce < 1) {
if (wc->mod[card].fxo.lastpol != wc->mod[card].fxo.polarity) {
if (debug)
- printk("%lu Polarity reversed (%d -> %d)\n", jiffies,
+ printk(ZAP_MODULE "%lu Polarity reversed (%d -> %d)\n", jiffies,
wc->mod[card].fxo.polarity,
wc->mod[card].fxo.lastpol);
if (wc->mod[card].fxo.polarity)
@@ -990,17 +995,17 @@
/* Reset the debounce (must be multiple of 4ms) */
wc->mod[card].fxs.debounce = 8 * (4 * 8);
#if 0
- printk("Resetting debounce card %d hook %d, %d\n", card, hook, wc->mod[card].fxs.debounce);
+ printk(ZAP_MODULE "Resetting debounce card %d hook %d, %d\n", card, hook, wc->mod[card].fxs.debounce);
#endif
} else {
if (wc->mod[card].fxs.debounce > 0) {
wc->mod[card].fxs.debounce-= 16 * ZT_CHUNKSIZE;
#if 0
- printk("Sustaining hook %d, %d\n", hook, wc->mod[card].fxs.debounce);
+ printk(ZAP_MODULE "Sustaining hook %d, %d\n", hook, wc->mod[card].fxs.debounce);
#endif
if (!wc->mod[card].fxs.debounce) {
#if 0
- printk("Counted down debounce, newhook: %d...\n", hook);
+ printk(ZAP_MODULE "Counted down debounce, newhook: %d...\n", hook);
#endif
wc->mod[card].fxs.debouncehook = hook;
}
@@ -1009,7 +1014,7 @@
#if 1
if (debug)
#endif
- printk("wctdm: Card %d Going off hook\n", card);
+ printk(ZAP_MODULE "Card %d Going off hook\n", card);
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
if (robust)
wctdm_init_proslic(wc, card, 1, 0, 1);
@@ -1020,7 +1025,7 @@
#if 1
if (debug)
#endif
- printk("wctdm: Card %d Going on hook\n", card);
+ printk(ZAP_MODULE "Card %d Going on hook\n", card);
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
wc->mod[card].fxs.oldrxhook = 0;
}
@@ -1049,7 +1054,7 @@
if (ints & 0x10) {
/* Stop DMA, wait for watchdog */
- printk("TDM PCI Master abort\n");
+ printk(ZAP_MODULE "TDM PCI Master abort\n");
wctdm_stop_dma(wc);
#ifdef LINUX26
return IRQ_RETVAL(1);
@@ -1059,7 +1064,7 @@
}
if (ints & 0x20) {
- printk("PCI Target abort\n");
+ printk(ZAP_MODULE "PCI Target abort\n");
#ifdef LINUX26
return IRQ_RETVAL(1);
#else
@@ -1159,7 +1164,7 @@
return -2;
blah = wctdm_getreg(wc, card, 11);
if (debug)
- printk("VoiceDAA System: %02x\n", blah & 0xf);
+ printk(ZAP_MODULE "VoiceDAA System: %02x\n", blah & 0xf);
return 0;
}
@@ -1170,11 +1175,11 @@
blah = wctdm_getreg(wc, card, 0);
if (debug)
- printk("ProSLIC on module %d, product %d, version %d\n", card, (blah & 0x30) >> 4, (blah & 0xf));
+ printk(ZAP_MODULE "ProSLIC on module %d, product %d, version %d\n", card, (blah & 0x30) >> 4, (blah & 0xf));
#if 0
if ((blah & 0x30) >> 4) {
- printk("ProSLIC on module %d is not a 3210.\n", card);
+ printk(ZAP_MODULE "ProSLIC on module %d is not a 3210.\n", card);
return -1;
}
#endif
@@ -1183,7 +1188,7 @@
return -1;
}
if ((blah & 0xf) < 2) {
- printk("ProSLIC 3210 version %d is too old\n", blah & 0xf);
+ printk(ZAP_MODULE "ProSLIC 3210 version %d is too old\n", blah & 0xf);
return -1;
}
if (wctdm_getreg(wc, card, 1) & 0x80)
@@ -1192,30 +1197,30 @@
blah = wctdm_getreg(wc, card, 8);
if (blah != 0x2) {
- printk("ProSLIC on module %d insane (1) %d should be 2\n", card, blah);
+ printk(ZAP_MODULE "ProSLIC on module %d insane (1) %d should be 2\n", card, blah);
return -1;
} else if ( insane_report)
- printk("ProSLIC on module %d Reg 8 Reads %d Expected is 0x2\n",card,blah);
+ printk(ZAP_MODULE "ProSLIC on module %d Reg 8 Reads %d Expected is 0x2\n",card,blah);
blah = wctdm_getreg(wc, card, 64);
if (blah != 0x0) {
- printk("ProSLIC on module %d insane (2)\n", card);
+ printk(ZAP_MODULE "ProSLIC on module %d insane (2)\n", card);
return -1;
} else if ( insane_report)
- printk("ProSLIC on module %d Reg 64 Reads %d Expected is 0x0\n",card,blah);
+ printk(ZAP_MODULE "ProSLIC on module %d Reg 64 Reads %d Expected is 0x0\n",card,blah);
blah = wctdm_getreg(wc, card, 11);
if (blah != 0x33) {
- printk("ProSLIC on module %d insane (3)\n", card);
+ printk(ZAP_MODULE "ProSLIC on module %d insane (3)\n", card);
return -1;
} else if ( insane_report)
- printk("ProSLIC on module %d Reg 11 Reads %d Expected is 0x33\n",card,blah);
+ printk(ZAP_MODULE "ProSLIC on module %d Reg 11 Reads %d Expected is 0x33\n",card,blah);
/* Just be sure it's setup right. */
wctdm_setreg(wc, card, 30, 0);
if (debug)
- printk("ProSLIC on module %d seems sane.\n", card);
+ printk(ZAP_MODULE "ProSLIC on module %d seems sane.\n", card);
return 0;
}
@@ -1239,11 +1244,11 @@
}
if (vbat < 0x06) {
- printk("Excessive leakage detected on module %d: %d volts (%02x) after %d ms\n", card,
+ printk(ZAP_MODULE "Excessive leakage detected on module %d: %d volts (%02x) after %d ms\n", card,
376 * vbat / 1000, vbat, (int)((jiffies - origjiffies) * 1000 / HZ));
return -1;
} else if (debug) {
- printk("Post-leakage voltage: %d volts\n", 376 * vbat / 1000);
+ printk(ZAP_MODULE "Post-leakage voltage: %d volts\n", 376 * vbat / 1000);
}
return 0;
}
@@ -1276,13 +1281,13 @@
if (vbat < 0xc0) {
if (wc->proslic_power == PROSLIC_POWER_UNKNOWN)
- printk("ProSLIC on module %d failed to powerup within %d ms (%d mV only)\n\n -- DID YOU REMEMBER TO PLUG IN THE HD POWER CABLE TO THE TDM400P??\n",
+ printk(ZAP_MODULE "ProSLIC on module %d failed to powerup within %d ms (%d mV only)\n\n -- DID YOU REMEMBER TO PLUG IN THE HD POWER CABLE TO THE TDM400P??\n",
card, (int)(((jiffies - origjiffies) * 1000 / HZ)),
vbat * 375);
wc->proslic_power = PROSLIC_POWER_WARNED;
return -1;
} else if (debug) {
- printk("ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n",
+ printk(ZAP_MODULE "ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n",
card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ)));
}
wc->proslic_power = PROSLIC_POWER_ON;
@@ -1293,10 +1298,10 @@
if ( loopcurrent > 41 ) {
lim = 0;
if (debug)
- printk("Loop current out of range! Setting to default 20mA!\n");
+ printk(ZAP_MODULE "Loop current out of range! Setting to default 20mA!\n");
}
else if (debug)
- printk("Loop current set to %dmA!\n",(lim*3)+20);
+ printk(ZAP_MODULE "Loop current set to %dmA!\n",(lim*3)+20);
wctdm_setreg(wc,card,LOOP_I_LIMIT,lim);
/* Engage DC-DC converter */
@@ -1305,7 +1310,7 @@
origjiffies = jiffies;
while(0x80 & wctdm_getreg(wc, card, 93)) {
if ((jiffies - origjiffies) > 2 * HZ) {
- printk("Timeout waiting for DC-DC calibration on module %d\n", card);
+ printk(ZAP_MODULE "Timeout waiting for DC-DC calibration on module %d\n", card);
return -1;
}
}
@@ -1412,16 +1417,16 @@
origjiffies = jiffies;
while(wctdm_getreg(wc, card, 96)) {
if ((jiffies - origjiffies) > 2 * HZ) {
- printk("Timeout waiting for calibration of module %d\n", card);
+ printk(ZAP_MODULE "Timeout waiting for calibration of module %d\n", card);
return -1;
}
}
if (debug) {
/* Print calibration parameters */
- printk("Calibration Vector Regs 98 - 107: \n");
+ printk(ZAP_MODULE "Calibration Vector Regs 98 - 107: \n");
for (x=98;x<108;x++) {
- printk("%d: %02x\n", x, wctdm_getreg(wc, card, x));
+ printk(ZAP_MODULE "%d: %02x\n", x, wctdm_getreg(wc, card, x));
}
}
return 0;
@@ -1502,11 +1507,11 @@
wait_just_a_bit(HZ/10);
if (!(wctdm_getreg(wc, card, 11) & 0xf0)) {
- printk("VoiceDAA did not bring up ISO link properly!\n");
+ printk(ZAP_MODULE "VoiceDAA did not bring up ISO link properly!\n");
return -1;
}
if (debug)
- printk("ISO-Cap is now up, line side: %02x rev %02x\n",
+ printk(ZAP_MODULE "ISO-Cap is now up, line side: %02x rev %02x\n",
wctdm_getreg(wc, card, 11) >> 4,
(wctdm_getreg(wc, card, 13) >> 2) & 0xf);
/* Enable on-hook line monitor */
@@ -1544,12 +1549,12 @@
/* NZ -- crank the tx gain up by 7 dB */
if (!strcmp(fxo_modes[_opermode].name, "NEWZEALAND")) {
- printk("Adjusting gain\n");
+ printk(ZAP_MODULE "Adjusting gain\n");
wctdm_setreg(wc, card, 38, 0x7);
}
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));
+ printk(ZAP_MODULE "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;
@@ -1579,7 +1584,7 @@
}
if (wctdm_proslic_init_indirect_regs(wc, card)) {
- printk(KERN_INFO "Indirect Registers failed to initialize on module %d.\n", card);
+ printk(KERN_INFO ZAP_MODULE "Indirect Registers failed to initialize on module %d.\n", card);
return -1;
}
@@ -1609,7 +1614,7 @@
/* Power up the DC-DC converter */
if (wctdm_powerup_proslic(wc, card, fast)) {
- printk("Unable to do INITIAL ProSLIC powerup on module %d\n", card);
+ printk(ZAP_MODULE "Unable to do INITIAL ProSLIC powerup on module %d\n", card);
return -1;
}
@@ -1617,40 +1622,40 @@
/* Check for power leaks */
if (wctdm_proslic_powerleak_test(wc, card)) {
- printk("ProSLIC module %d failed leakage test. Check for short circuit\n", card);
+ printk(ZAP_MODULE "ProSLIC module %d failed leakage test. Check for short circuit\n", card);
}
/* Power up again */
if (wctdm_powerup_proslic(wc, card, fast)) {
- printk("Unable to do FINAL ProSLIC powerup on module %d\n", card);
+ printk(ZAP_MODULE "Unable to do FINAL ProSLIC powerup on module %d\n", card);
return -1;
}
#ifndef NO_CALIBRATION
/* Perform calibration */
if(manual) {
if (wctdm_proslic_manual_calibrate(wc, card)) {
- //printk("Proslic failed on Manual Calibration\n");
+ //printk(ZAP_MODULE "Proslic failed on Manual Calibration\n");
if (wctdm_proslic_manual_calibrate(wc, card)) {
- printk("Proslic Failed on Second Attempt to Calibrate Manually. (Try -DNO_CALIBRATION in Makefile)\n");
+ printk(ZAP_MODULE "Proslic Failed on Second Attempt to Calibrate Manually. (Try -DNO_CALIBRATION in Makefile)\n");
return -1;
}
- printk("Proslic Passed Manual Calibration on Second Attempt\n");
+ printk(ZAP_MODULE "Proslic Passed Manual Calibration on Second Attempt\n");
}
}
else {
if(wctdm_proslic_calibrate(wc, card)) {
- //printk("ProSlic died on Auto Calibration.\n");
+ //printk(ZAP_MODULE "ProSlic died on Auto Calibration.\n");
if (wctdm_proslic_calibrate(wc, card)) {
- printk("Proslic Failed on Second Attempt to Auto Calibrate\n");
+ printk(ZAP_MODULE "Proslic Failed on Second Attempt to Auto Calibrate\n");
return -1;
}
- printk("Proslic Passed Auto Calibration on Second Attempt\n");
+ printk(ZAP_MODULE "Proslic Passed Auto Calibration on Second Attempt\n");
}
}
/* Perform DC-DC calibration */
wctdm_setreg(wc, card, 93, 0x99);
r19 = wctdm_getreg(wc, card, 107);
if ((r19 < 0x2) || (r19 > 0xd)) {
- printk("DC-DC cal has a surprising direct 107 of 0x%02x!\n", r19);
+ printk(ZAP_MODULE "DC-DC cal has a surprising direct 107 of 0x%02x!\n", r19);
wctdm_setreg(wc, card, 107, 0x8);
}
@@ -1670,7 +1675,7 @@
}
if (wctdm_proslic_verify_indirect_regs(wc, card)) {
- printk(KERN_INFO "Indirect Registers failed verification.\n");
+ printk(KERN_INFO ZAP_MODULE "Indirect Registers failed verification.\n");
return -1;
}
@@ -1683,7 +1688,7 @@
#if 0
if (wctdm_proslic_setreg_indirect(wc, card, 97, 0x0)) { // Stanley: for the bad recording fix
- printk(KERN_INFO "ProSlic IndirectReg Died.\n");
+ printk(KERN_INFO ZAP_MODULE "ProSlic IndirectReg Died.\n");
return -1;
}
#endif
@@ -1735,24 +1740,24 @@
wctdm_setreg(wc, card, 74, 0x3f);
if (wctdm_proslic_setreg_indirect(wc, card, 21, 0x247))
return -1;
- printk("Boosting fast ringer on slot %d (89V peak)\n", card + 1);
+ printk(ZAP_MODULE "Boosting fast ringer on slot %d (89V peak)\n", card + 1);
} else if (lowpower) {
if (wctdm_proslic_setreg_indirect(wc, card, 21, 0x14b))
return -1;
- printk("Reducing fast ring power on slot %d (50V peak)\n", card + 1);
+ printk(ZAP_MODULE "Reducing fast ring power on slot %d (50V peak)\n", card + 1);
} else
- printk("Speeding up ringer on slot %d (25Hz)\n", card + 1);
+ printk(ZAP_MODULE "Speeding up ringer on slot %d (25Hz)\n", card + 1);
} else {
/* Beef up Ringing voltage to 89V */
if (boostringer) {
wctdm_setreg(wc, card, 74, 0x3f);
if (wctdm_proslic_setreg_indirect(wc, card, 21, 0x1d1))
return -1;
- printk("Boosting ringer on slot %d (89V peak)\n", card + 1);
+ printk(ZAP_MODULE "Boosting ringer on slot %d (89V peak)\n", card + 1);
} else if (lowpower) {
if (wctdm_proslic_setreg_indirect(wc, card, 21, 0x108))
return -1;
- printk("Reducing ring power on slot %d (50V peak)\n", card + 1);
+ printk(ZAP_MODULE "Reducing ring power on slot %d (50V peak)\n", card + 1);
}
}
@@ -1785,7 +1790,7 @@
}
if(debug)
- printk("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"));
+ printk(ZAP_MODULE "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"));
wctdm_setreg(wc, card, 64, 0x01);
return 0;
@@ -1870,16 +1875,16 @@
if (regop.indirect) {
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS)
return -EINVAL;
- printk("Setting indirect %d to 0x%04x on %d\n", regop.reg, regop.val, chan->chanpos);
+ printk(ZAP_MODULE "Setting indirect %d to 0x%04x on %d\n", regop.reg, regop.val, chan->chanpos);
wctdm_proslic_setreg_indirect(wc, chan->chanpos - 1, regop.reg, regop.val);
} else {
regop.val &= 0xff;
- printk("Setting direct %d to %04x on %d\n", regop.reg, regop.val, chan->chanpos);
+ printk(ZAP_MODULE "Setting direct %d to %04x on %d\n", regop.reg, regop.val, chan->chanpos);
wctdm_setreg(wc, chan->chanpos - 1, regop.reg, regop.val);
}
break;
case WCTDM_SET_ECHOTUNE:
- printk("-- Setting echo registers: \n");
+ printk(ZAP_MODULE "-- Setting echo registers: \n");
if (copy_from_user(&echoregs, (struct wctdm_echo_coefs*)data, sizeof(echoregs)))
return -EFAULT;
@@ -1897,7 +1902,7 @@
wctdm_setreg(wc, chan->chanpos - 1, 51, echoregs.coef7);
wctdm_setreg(wc, chan->chanpos - 1, 52, echoregs.coef8);
- printk("-- Set echo registers successfully\n");
+ printk(ZAP_MODULE "-- Set echo registers successfully\n");
break;
} else {
@@ -1930,7 +1935,7 @@
static int wctdm_watchdog(struct zt_span *span, int event)
{
- printk("TDM: Restarting DMA\n");
+ printk(ZAP_MODULE "TDM: Restarting DMA\n");
wctdm_restart_dma(span->pvt);
return 0;
}
@@ -1973,7 +1978,7 @@
wctdm_setreg(wc, chan->chanpos - 1, 5, 0x8);
break;
default:
- printk("wcfxo: Can't set tx state to %d\n", txsig);
+ printk(ZAP_MODULE "Can't set tx state to %d\n", txsig);
}
} else {
switch(txsig) {
@@ -2006,10 +2011,10 @@
wc->mod[chan->chanpos-1].fxs.lasttxhook = 0;
break;
default:
- printk("wctdm: Can't set tx state to %d\n", txsig);
+ printk(ZAP_MODULE "Can't set tx state to %d\n", txsig);
}
if (debug)
- printk("Setting FXS hook state to %d (%02x)\n", txsig, reg);
+ printk(ZAP_MODULE "Setting FXS hook state to %d (%02x)\n", txsig, reg);
#if 1
wctdm_setreg(wc, chan->chanpos - 1, 64, wc->mod[chan->chanpos-1].fxs.lasttxhook);
@@ -2026,7 +2031,7 @@
sprintf(wc->span.name, "WCTDM/%d", wc->pos);
sprintf(wc->span.desc, "%s Board %d", wc->variety, wc->pos + 1);
if (alawoverride) {
- printk("ALAW override parameter detected. Device will be operating in ALAW\n");
+ printk(ZAP_MODULE "ALAW override parameter detected. Device will be operating in ALAW\n");
wc->span.deflaw = ZT_LAW_ALAW;
} else
wc->span.deflaw = ZT_LAW_MULAW;
@@ -2049,7 +2054,7 @@
wc->span.pvt = wc;
if (zt_register(&wc->span, 0)) {
- printk("Unable to register span with zaptel\n");
+ printk(ZAP_MODULE "Unable to register span with zaptel\n");
return -1;
}
return 0;
@@ -2084,7 +2089,7 @@
ver = __wctdm_getcreg(wc, WC_VER);
failed = 0;
if (ver != 0x59) {
- printk("Freshmaker version: %02x\n", ver);
+ printk(ZAP_MODULE "Freshmaker version: %02x\n", ver);
for (x=0;x<255;x++) {
/* Test registers */
if (ver >= 0x70) {
@@ -2095,21 +2100,21 @@
y = __wctdm_getcreg(wc, WC_TEST);
}
if (x != y) {
- printk("%02x != %02x\n", x, y);
+ printk(ZAP_MODULE "%02x != %02x\n", x, y);
failed++;
}
}
if (!failed) {
- printk("Freshmaker passed register test\n");
+ printk(ZAP_MODULE "Freshmaker passed register test\n");
} else {
- printk("Freshmaker failed register test\n");
+ printk(ZAP_MODULE "Freshmaker failed register test\n");
return -1;
}
/* Go to half-duty FSYNC */
__wctdm_setcreg(wc, WC_SYNC, 0x01);
y = __wctdm_getcreg(wc, WC_SYNC);
} else {
- printk("No freshmaker chip\n");
+ printk(ZAP_MODULE "No freshmaker chip\n");
}
/* Reset PCI Interface chip and registers (and serial) */
@@ -2163,10 +2168,10 @@
wc->cardflag |= (1 << x);
if (debug) {
readi = wctdm_getreg(wc,x,LOOP_I_LIMIT);
- printk("Proslic module %d loop current is %dmA\n",x,
+ printk(ZAP_MODULE "Proslic module %d loop current is %dmA\n",x,
((readi*3)+20));
}
- printk("Module %d: Installed -- AUTO FXS/DPO\n",x);
+ printk(ZAP_MODULE "Module %d: Installed -- AUTO FXS/DPO\n",x);
} else {
if(ret!=-2) {
sane=1;
@@ -2175,18 +2180,18 @@
wc->cardflag |= (1 << x);
if (debug) {
readi = wctdm_getreg(wc,x,LOOP_I_LIMIT);
- printk("Proslic module %d loop current is %dmA\n",x,
+ printk(ZAP_MODULE "Proslic module %d loop current is %dmA\n",x,
((readi*3)+20));
}
- printk("Module %d: Installed -- MANUAL FXS\n",x);
+ printk(ZAP_MODULE "Module %d: Installed -- MANUAL FXS\n",x);
} else {
- printk("Module %d: FAILED FXS (%s)\n", x, fxshonormode ? fxo_modes[_opermode].name : "FCC");
+ printk(ZAP_MODULE "Module %d: FAILED FXS (%s)\n", x, fxshonormode ? fxo_modes[_opermode].name : "FCC");
}
} else if (!(ret = wctdm_init_voicedaa(wc, x, 0, 0, sane))) {
wc->cardflag |= (1 << x);
- printk("Module %d: Installed -- AUTO FXO (%s mode)\n",x, fxo_modes[_opermode].name);
+ printk(ZAP_MODULE "Module %d: Installed -- AUTO FXO (%s mode)\n",x, fxo_modes[_opermode].name);
} else
- printk("Module %d: Not installed\n", x);
+ printk(ZAP_MODULE "Module %d: Not installed\n", x);
}
#endif
}
@@ -2242,121 +2247,128 @@
static int __devinit wctdm_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
- int res;
- struct wctdm *wc;
- struct wctdm_desc *d = (struct wctdm_desc *)ent->driver_data;
- int x;
- int y;
-
- for (x=0;x<WC_MAX_IFACES;x++)
- if (!ifaces[x]) break;
+ int res = 0;
+ struct wctdm *wc = NULL;
+ struct wctdm_desc *d = (struct wctdm_desc *) ent->driver_data;
+ int x, y;
+ int cardcount = 0;
+ struct {
+ unsigned int unset_drvdata:1;
+ unsigned int zt_unreg:1;
+ } cleanup_flags = { 0, };
+
+ for (x = 0; x < WC_MAX_IFACES; x++) {
+ if (!ifaces[x])
+ break;
+ }
+
if (x >= WC_MAX_IFACES) {
- printk("Too many interfaces\n");
- return -EIO;
+ printk(ZAP_MODULE "Too many interfaces\n");
+ res = -EIO;
+ goto init_return;
}
if (pci_enable_device(pdev)) {
res = -EIO;
- } else {
- wc = kmalloc(sizeof(struct wctdm), GFP_KERNEL);
- if (wc) {
- int cardcount = 0;
-
- ifaces[x] = wc;
- memset(wc, 0, sizeof(struct wctdm));
- spin_lock_init(&wc->lock);
- wc->curcard = -1;
- wc->ioaddr = pci_resource_start(pdev, 0);
- wc->dev = pdev;
- wc->pos = x;
- wc->variety = d->name;
- for (y=0;y<NUM_CARDS;y++)
- wc->flags[y] = d->flags;
- /* Keep track of whether we need to free the region */
- if (request_region(wc->ioaddr, 0xff, "wctdm"))
- wc->freeregion = 1;
-
- /* Allocate enough memory for two zt chunks, receive and transmit. Each sample uses
- 32 bits. Allocate an extra set just for control too */
- wc->writechunk = pci_alloc_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, &wc->writedma);
- if (!wc->writechunk) {
- printk("wctdm: Unable to allocate DMA-able memory\n");
- if (wc->freeregion)
- release_region(wc->ioaddr, 0xff);
- return -ENOMEM;
- }
-
- wc->readchunk = wc->writechunk + ZT_MAX_CHUNKSIZE * 2; /* in doublewords */
- wc->readdma = wc->writedma + ZT_MAX_CHUNKSIZE * 8; /* in bytes */
-
- if (wctdm_initialize(wc)) {
- printk("wctdm: Unable to intialize FXS\n");
- /* Set Reset Low */
- x=inb(wc->ioaddr + WC_CNTL);
- outb((~0x1)&x, wc->ioaddr + WC_CNTL);
- /* Free Resources */
- free_irq(pdev->irq, wc);
- if (wc->freeregion)
- release_region(wc->ioaddr, 0xff);
- pci_free_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma);
- kfree(wc);
- return -EIO;
- }
-
- /* Enable bus mastering */
- pci_set_master(pdev);
-
- /* Keep track of which device we are */
- pci_set_drvdata(pdev, wc);
-
- if (request_irq(pdev->irq, wctdm_interrupt, ZAP_IRQ_SHARED, "wctdm", wc)) {
- printk("wctdm: Unable to request IRQ %d\n", pdev->irq);
- if (wc->freeregion)
- release_region(wc->ioaddr, 0xff);
- pci_free_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma);
- pci_set_drvdata(pdev, NULL);
- kfree(wc);
- return -EIO;
- }
-
-
- if (wctdm_hardware_init(wc)) {
- unsigned char x;
-
- /* Set Reset Low */
- x=inb(wc->ioaddr + WC_CNTL);
- outb((~0x1)&x, wc->ioaddr + WC_CNTL);
- /* Free Resources */
- free_irq(pdev->irq, wc);
- if (wc->freeregion)
- release_region(wc->ioaddr, 0xff);
- pci_free_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma);
- pci_set_drvdata(pdev, NULL);
- zt_unregister(&wc->span);
- kfree(wc);
- return -EIO;
-
- }
-
- wctdm_post_initialize(wc);
-
- /* Enable interrupts */
- wctdm_enable_interrupts(wc);
- /* Initialize Write/Buffers to all blank data */
- memset((void *)wc->writechunk,0,ZT_MAX_CHUNKSIZE * 2 * 2 * 4);
-
- /* Start DMA */
- wctdm_start_dma(wc);
-
- for (x = 0; x < NUM_CARDS; x++) {
- if (wc->cardflag & (1 << x))
- cardcount++;
- }
-
- printk("Found a Wildcard TDM: %s (%d modules)\n", wc->variety, cardcount);
- res = 0;
- } else
- res = -ENOMEM;
+ goto init_return;
+ }
+
+ wc = kcalloc(1, sizeof(*wc), GFP_KERNEL);
+ if (!wc) {
+ res = -ENOMEM;
+ goto init_return;
+ }
+
+ ifaces[x] = wc;
+ spin_lock_init(&wc->lock);
+ wc->curcard = -1;
+ wc->ioaddr = pci_resource_start(pdev, 0);
+ wc->dev = pdev;
+ wc->pos = x;
+ wc->variety = d->name;
+
+ for (y = 0; y < NUM_CARDS; y++)
+ wc->flags[y] = d->flags;
+
+ /* Keep track of whether we need to free the region */
+ if (request_region(wc->ioaddr, 0xff, "wctdm"))
+ wc->freeregion = 1;
+
+ /* Allocate enough memory for two zt chunks, receive and transmit. Each sample uses
+ 32 bits. Allocate an extra set just for control too */
+ wc->writechunk = pci_alloc_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, &wc->writedma);
+ if (!wc->writechunk) {
+ printk(ZAP_MODULE "Unable to allocate DMA-able memory\n");
+ res = -ENOMEM;
+ goto init_return;
+ }
+
+ wc->readchunk = wc->writechunk + ZT_MAX_CHUNKSIZE * 2; /* in doublewords */
+ wc->readdma = wc->writedma + ZT_MAX_CHUNKSIZE * 8; /* in bytes */
+
+ if (wctdm_initialize(wc)) {
+ printk(ZAP_MODULE "Unable to intialize\n");
+ res = -EIO;
+ goto init_return;
+ }
+
+ /* wctdm_initialize() calls zt_register() */
+ cleanup_flags.zt_unreg = 1;
+
+ /* Enable bus mastering */
+ pci_set_master(pdev);
+
+ /* Keep track of which device we are */
+ pci_set_drvdata(pdev, wc);
+ cleanup_flags.unset_drvdata = 1;
+
+ if (request_irq(pdev->irq, wctdm_interrupt, ZAP_IRQ_SHARED, "wctdm", wc)) {
+ printk(ZAP_MODULE "Unable to request IRQ %d\n", pdev->irq);
+ goto init_return;
+ }
+
+ if (wctdm_hardware_init(wc)) {
+ res = -EIO;
+ goto init_return;
+ }
+
+ wctdm_post_initialize(wc);
+
+ wctdm_enable_interrupts(wc);
+
+ /* Initialize Write/Buffers to all blank data */
+ memset((void *) wc->writechunk, 0, ZT_MAX_CHUNKSIZE * 2 * 2 * 4);
+
+ wctdm_start_dma(wc);
+
+ for (x = 0; x < NUM_CARDS; x++) {
+ if (wc->cardflag & (1 << x))
+ cardcount++;
+ }
+
+ printk(ZAP_MODULE "Found a Wildcard TDM: %s (%d modules)\n", wc->variety, cardcount);
+
+ return 0;
+
+init_return:
+ /* Clean up when returning on failed init */
+ if (wc) {
+ unsigned int x;
+
+ /* Set Reset Low */
+ x = inb(wc->ioaddr + WC_CNTL);
+ outb(x & (~0x01), wc->ioaddr + WC_CNTL);
+
+ zt_unregister(&wc->span);
+
+ free_irq(pdev->irq, wc);
+ if (cleanup_flags.unset_drvdata)
+ pci_set_drvdata(pdev, NULL);
+ if (wc->freeregion)
+ release_region(wc->ioaddr, 0xff);
+ if (wc->writechunk)
+ pci_free_consistent(pdev, ZT_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *) wc->writechunk, wc->writedma);
+ kfree(wc);
}
return res;
}
@@ -2367,7 +2379,7 @@
if (wc->freeregion)
release_region(wc->ioaddr, 0xff);
kfree(wc);
- printk("Freed a Wildcard\n");
+ printk(ZAP_MODULE "Freed a Wildcard\n");
}
static void __devexit wctdm_remove_one(struct pci_dev *pdev)
@@ -2442,10 +2454,10 @@
if (x < sizeof(fxo_modes) / sizeof(fxo_modes[0])) {
_opermode = x;
} else {
- printk("Invalid/unknown operating mode '%s' specified. Please choose one of:\n", opermode);
+ printk(ZAP_MODULE "Invalid/unknown operating mode '%s' specified. Please choose one of:\n", opermode);
for (x=0;x<sizeof(fxo_modes) / sizeof(fxo_modes[0]); x++)
- printk(" %s\n", fxo_modes[x].name);
- printk("Note this option is CASE SENSITIVE!\n");
+ printk(ZAP_MODULE " %s\n", fxo_modes[x].name);
+ printk(ZAP_MODULE "Note this option is CASE SENSITIVE!\n");
return -ENODEV;
}
if (!strcmp(fxo_modes[_opermode].name, "AUSTRALIA")) {
More information about the zaptel-commits
mailing list