| 1 |
/* |
| 2 |
* Wildcard TDM400P TDM FXS/FXO Interface Driver for DAHDI Telephony interface |
| 3 |
* |
| 4 |
* Written by Mark Spencer <[email protected]> |
| 5 |
* Matthew Fredrickson <[email protected]> |
| 6 |
* |
| 7 |
* Copyright (C) 2001-2008, Digium, Inc. |
| 8 |
* |
| 9 |
* All rights reserved. |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
* See http://www.asterisk.org for more information about |
| 15 |
* the Asterisk project. Please do not directly contact |
| 16 |
* any of the maintainers of this project for assistance; |
| 17 |
* the project provides a web site, mailing lists and IRC |
| 18 |
* channels for your use. |
| 19 |
* |
| 20 |
* This program is free software, distributed under the terms of |
| 21 |
* the GNU General Public License Version 2 as published by the |
| 22 |
* Free Software Foundation. See the LICENSE file included with |
| 23 |
* this program for more details. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <linux/kernel.h> |
| 27 |
#include <linux/errno.h> |
| 28 |
#include <linux/module.h> |
| 29 |
#include <linux/init.h> |
| 30 |
#include <linux/pci.h> |
| 31 |
#include <linux/interrupt.h> |
| 32 |
#include <linux/moduleparam.h> |
| 33 |
#include <linux/sched.h> |
| 34 |
#include <linux/slab.h> |
| 35 |
#include <asm/io.h> |
| 36 |
#include "proslic.h" |
| 37 |
|
| 38 |
/* |
| 39 |
* Define for audio vs. register based ring detection |
| 40 |
* |
| 41 |
*/ |
| 42 |
/* #define AUDIO_RINGCHECK */ |
| 43 |
|
| 44 |
/* |
| 45 |
Experimental max loop current limit for the proslic |
| 46 |
Loop current limit is from 20 mA to 41 mA in steps of 3 |
| 47 |
(according to datasheet) |
| 48 |
So set the value below to: |
| 49 |
0x00 : 20mA (default) |
| 50 |
0x01 : 23mA |
| 51 |
0x02 : 26mA |
| 52 |
0x03 : 29mA |
| 53 |
0x04 : 32mA |
| 54 |
0x05 : 35mA |
| 55 |
0x06 : 37mA |
| 56 |
0x07 : 41mA |
| 57 |
*/ |
| 58 |
static int loopcurrent = 20; |
| 59 |
#define POLARITY_XOR (\ |
| 60 |
(reversepolarity != 0) ^ (fxs->reversepolarity != 0) ^\ |
| 61 |
(fxs->vmwi_lrev != 0) ^\ |
| 62 |
((fxs->vmwisetting.vmwi_type & DAHDI_VMWI_HVAC) != 0)) |
| 63 |
|
| 64 |
static int reversepolarity = 0; |
| 65 |
|
| 66 |
static alpha indirect_regs[] = |
| 67 |
{ |
| 68 |
{0,255,"DTMF_ROW_0_PEAK",0x55C2}, |
| 69 |
{1,255,"DTMF_ROW_1_PEAK",0x51E6}, |
| 70 |
{2,255,"DTMF_ROW2_PEAK",0x4B85}, |
| 71 |
{3,255,"DTMF_ROW3_PEAK",0x4937}, |
| 72 |
{4,255,"DTMF_COL1_PEAK",0x3333}, |
| 73 |
{5,255,"DTMF_FWD_TWIST",0x0202}, |
| 74 |
{6,255,"DTMF_RVS_TWIST",0x0202}, |
| 75 |
{7,255,"DTMF_ROW_RATIO_TRES",0x0198}, |
| 76 |
{8,255,"DTMF_COL_RATIO_TRES",0x0198}, |
| 77 |
{9,255,"DTMF_ROW_2ND_ARM",0x0611}, |
| 78 |
{10,255,"DTMF_COL_2ND_ARM",0x0202}, |
| 79 |
{11,255,"DTMF_PWR_MIN_TRES",0x00E5}, |
| 80 |
{12,255,"DTMF_OT_LIM_TRES",0x0A1C}, |
| 81 |
{13,0,"OSC1_COEF",0x7B30}, |
| 82 |
{14,1,"OSC1X",0x0063}, |
| 83 |
{15,2,"OSC1Y",0x0000}, |
| 84 |
{16,3,"OSC2_COEF",0x7870}, |
| 85 |
{17,4,"OSC2X",0x007D}, |
| 86 |
{18,5,"OSC2Y",0x0000}, |
| 87 |
{19,6,"RING_V_OFF",0x0000}, |
| 88 |
{20,7,"RING_OSC",0x7EF0}, |
| 89 |
{21,8,"RING_X",0x0160}, |
| 90 |
{22,9,"RING_Y",0x0000}, |
| 91 |
{23,255,"PULSE_ENVEL",0x2000}, |
| 92 |
{24,255,"PULSE_X",0x2000}, |
| 93 |
{25,255,"PULSE_Y",0x0000}, |
| 94 |
//{26,13,"RECV_DIGITAL_GAIN",0x4000}, // playback volume set lower |
| 95 |
{26,13,"RECV_DIGITAL_GAIN",0x2000}, // playback volume set lower |
| 96 |
{27,14,"XMIT_DIGITAL_GAIN",0x4000}, |
| 97 |
//{27,14,"XMIT_DIGITAL_GAIN",0x2000}, |
| 98 |
{28,15,"LOOP_CLOSE_TRES",0x1000}, |
| 99 |
{29,16,"RING_TRIP_TRES",0x3600}, |
| 100 |
{30,17,"COMMON_MIN_TRES",0x1000}, |
| 101 |
{31,18,"COMMON_MAX_TRES",0x0200}, |
| 102 |
{32,19,"PWR_ALARM_Q1Q2",0x07C0}, |
| 103 |
{33,20,"PWR_ALARM_Q3Q4",0x2600}, |
| 104 |
{34,21,"PWR_ALARM_Q5Q6",0x1B80}, |
| 105 |
{35,22,"LOOP_CLOSURE_FILTER",0x8000}, |
| 106 |
{36,23,"RING_TRIP_FILTER",0x0320}, |
| 107 |
{37,24,"TERM_LP_POLE_Q1Q2",0x008C}, |
| 108 |
{38,25,"TERM_LP_POLE_Q3Q4",0x0100}, |
| 109 |
{39,26,"TERM_LP_POLE_Q5Q6",0x0010}, |
| 110 |
{40,27,"CM_BIAS_RINGING",0x0C00}, |
| 111 |
{41,64,"DCDC_MIN_V",0x0C00}, |
| 112 |
{42,255,"DCDC_XTRA",0x1000}, |
| 113 |
{43,66,"LOOP_CLOSE_TRES_LOW",0x1000}, |
| 114 |
}; |
| 115 |
|
| 116 |
#include <dahdi/kernel.h> |
| 117 |
#include <dahdi/wctdm_user.h> |
| 118 |
|
| 119 |
#include "fxo_modes.h" |
| 120 |
|
| 121 |
#define NUM_FXO_REGS 60 |
| 122 |
|
| 123 |
#define WC_MAX_IFACES 128 |
| 124 |
|
| 125 |
#define WC_CNTL 0x00 |
| 126 |
#define WC_OPER 0x01 |
| 127 |
#define WC_AUXC 0x02 |
| 128 |
#define WC_AUXD 0x03 |
| 129 |
#define WC_MASK0 0x04 |
| 130 |
#define WC_MASK1 0x05 |
| 131 |
#define WC_INTSTAT 0x06 |
| 132 |
#define WC_AUXR 0x07 |
| 133 |
|
| 134 |
#define WC_DMAWS 0x08 |
| 135 |
#define WC_DMAWI 0x0c |
| 136 |
#define WC_DMAWE 0x10 |
| 137 |
#define WC_DMARS 0x18 |
| 138 |
#define WC_DMARI 0x1c |
| 139 |
#define WC_DMARE 0x20 |
| 140 |
|
| 141 |
#define WC_AUXFUNC 0x2b |
| 142 |
#define WC_SERCTL 0x2d |
| 143 |
#define WC_FSCDELAY 0x2f |
| 144 |
|
| 145 |
#define WC_REGBASE 0xc0 |
| 146 |
|
| 147 |
#define WC_SYNC 0x0 |
| 148 |
#define WC_TEST 0x1 |
| 149 |
#define WC_CS 0x2 |
| 150 |
#define WC_VER 0x3 |
| 151 |
|
| 152 |
#define BIT_CS (1 << 2) |
| 153 |
#define BIT_SCLK (1 << 3) |
| 154 |
#define BIT_SDI (1 << 4) |
| 155 |
#define BIT_SDO (1 << 5) |
| 156 |
|
| 157 |
#define FLAG_EMPTY 0 |
| 158 |
#define FLAG_WRITE 1 |
| 159 |
#define FLAG_READ 2 |
| 160 |
|
| 161 |
#define DEFAULT_RING_DEBOUNCE 64 /* Ringer Debounce (64 ms) */ |
| 162 |
|
| 163 |
#define POLARITY_DEBOUNCE 64 /* Polarity debounce (64 ms) */ |
| 164 |
|
| 165 |
#define OHT_TIMER 6000 /* How long after RING to retain OHT */ |
| 166 |
|
| 167 |
/* NEON MWI pulse width - Make larger for longer period time |
| 168 |
* For more information on NEON MWI generation using the proslic |
| 169 |
* refer to Silicon Labs App Note "AN33-SI321X NEON FLASHING" |
| 170 |
* RNGY = RNGY 1/2 * Period * 8000 |
| 171 |
*/ |
| 172 |
#define NEON_MWI_RNGY_PULSEWIDTH 0x3e8 /*=> period of 250 mS */ |
| 173 |
|
| 174 |
#define FLAG_3215 (1 << 0) |
| 175 |
|
| 176 |
#define NUM_CARDS 4 |
| 177 |
|
| 178 |
#define MAX_ALARMS 10 |
| 179 |
|
| 180 |
#define MOD_TYPE_FXS 0 |
| 181 |
#define MOD_TYPE_FXO 1 |
| 182 |
|
| 183 |
#define MINPEGTIME 10 * 8 /* 30 ms peak to peak gets us no more than 100 Hz */ |
| 184 |
#define PEGTIME 50 * 8 /* 50ms peak to peak gets us rings of 10 Hz or more */ |
| 185 |
#define PEGCOUNT 5 /* 5 cycles of pegging means RING */ |
| 186 |
|
| 187 |
#define NUM_CAL_REGS 12 |
| 188 |
|
| 189 |
struct calregs { |
| 190 |
unsigned char vals[NUM_CAL_REGS]; |
| 191 |
}; |
| 192 |
|
| 193 |
enum proslic_power_warn { |
| 194 |
PROSLIC_POWER_UNKNOWN = 0, |
| 195 |
PROSLIC_POWER_ON, |
| 196 |
PROSLIC_POWER_WARNED, |
| 197 |
}; |
| 198 |
|
| 199 |
enum battery_state { |
| 200 |
BATTERY_UNKNOWN = 0, |
| 201 |
BATTERY_PRESENT, |
| 202 |
BATTERY_LOST, |
| 203 |
}; |
| 204 |
|
| 205 |
struct wctdm { |
| 206 |
struct pci_dev *dev; |
| 207 |
char *variety; |
| 208 |
struct dahdi_span span; |
| 209 |
struct dahdi_device *ddev; |
| 210 |
unsigned char ios; |
| 211 |
int usecount; |
| 212 |
unsigned int intcount; |
| 213 |
int dead; |
| 214 |
int pos; |
| 215 |
int flags[NUM_CARDS]; |
| 216 |
int freeregion; |
| 217 |
int alt; |
| 218 |
int curcard; |
| 219 |
int cardflag; /* Bit-map of present cards */ |
| 220 |
enum proslic_power_warn proslic_power; |
| 221 |
spinlock_t lock; |
| 222 |
|
| 223 |
union { |
| 224 |
struct fxo { |
| 225 |
#ifdef AUDIO_RINGCHECK |
| 226 |
unsigned int pegtimer; |
| 227 |
int pegcount; |
| 228 |
int peg; |
| 229 |
int ring; |
| 230 |
#else |
| 231 |
int wasringing; |
| 232 |
int lastrdtx; |
| 233 |
#endif |
| 234 |
int ringdebounce; |
| 235 |
int offhook; |
| 236 |
unsigned int battdebounce; |
| 237 |
unsigned int battalarm; |
| 238 |
enum battery_state battery; |
| 239 |
int lastpol; |
| 240 |
int polarity; |
| 241 |
int polaritydebounce; |
| 242 |
} fxo; |
| 243 |
struct fxs { |
| 244 |
int oldrxhook; |
| 245 |
int debouncehook; |
| 246 |
int lastrxhook; |
| 247 |
int debounce; |
| 248 |
int ohttimer; |
| 249 |
int idletxhookstate; /* IDLE changing hook state */ |
| 250 |
int lasttxhook; |
| 251 |
int palarms; |
| 252 |
int reversepolarity; /* Reverse Line */ |
| 253 |
int mwisendtype; |
| 254 |
struct dahdi_vmwi_info vmwisetting; |
| 255 |
int vmwi_active_messages; |
| 256 |
u32 vmwi_lrev:1; /*MWI Line Reversal*/ |
| 257 |
u32 vmwi_hvdc:1; /*MWI High Voltage DC Idle line*/ |
| 258 |
u32 vmwi_hvac:1; /*MWI Neon High Voltage AC Idle line*/ |
| 259 |
u32 neonringing:1; /*Ring Generator is set for NEON*/ |
| 260 |
struct calregs calregs; |
| 261 |
} fxs; |
| 262 |
} mod[NUM_CARDS]; |
| 263 |
|
| 264 |
/* Receive hook state and debouncing */ |
| 265 |
int modtype[NUM_CARDS]; |
| 266 |
unsigned char reg0shadow[NUM_CARDS]; |
| 267 |
unsigned char reg1shadow[NUM_CARDS]; |
| 268 |
|
| 269 |
unsigned long ioaddr; |
| 270 |
dma_addr_t readdma; |
| 271 |
dma_addr_t writedma; |
| 272 |
volatile unsigned int *writechunk; /* Double-word aligned write memory */ |
| 273 |
volatile unsigned int *readchunk; /* Double-word aligned read memory */ |
| 274 |
struct dahdi_chan _chans[NUM_CARDS]; |
| 275 |
struct dahdi_chan *chans[NUM_CARDS]; |
| 276 |
}; |
| 277 |
|
| 278 |
|
| 279 |
struct wctdm_desc { |
| 280 |
char *name; |
| 281 |
int flags; |
| 282 |
}; |
| 283 |
|
| 284 |
static struct wctdm_desc wctdm = { "Wildcard S400P Prototype", 0 }; |
| 285 |
static struct wctdm_desc wctdme = { "Wildcard TDM400P REV E/F", 0 }; |
| 286 |
static struct wctdm_desc wctdmh = { "Wildcard TDM400P REV H", 0 }; |
| 287 |
static struct wctdm_desc wctdmi = { "Wildcard TDM400P REV I", 0 }; |
| 288 |
static int acim2tiss[16] = { 0x0, 0x1, 0x4, 0x5, 0x7, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x2, 0x0, 0x3 }; |
| 289 |
|
| 290 |
static struct wctdm *ifaces[WC_MAX_IFACES]; |
| 291 |
|
| 292 |
static void wctdm_release(struct wctdm *wc); |
| 293 |
|
| 294 |
static unsigned int fxovoltage; |
| 295 |
static unsigned int battdebounce; |
| 296 |
static unsigned int battalarm; |
| 297 |
static unsigned int battthresh; |
| 298 |
static int ringdebounce = DEFAULT_RING_DEBOUNCE; |
| 299 |
/* times 4, because must be a multiple of 4ms: */ |
| 300 |
static int dialdebounce = 8 * 8; |
| 301 |
static int fwringdetect = 0; |
| 302 |
static int debug = 0; |
| 303 |
static int robust = 0; |
| 304 |
static int timingonly = 0; |
| 305 |
static int lowpower = 0; |
| 306 |
static int boostringer = 0; |
| 307 |
static int fastringer = 0; |
| 308 |
static int _opermode = 0; |
| 309 |
static char *opermode = "FCC"; |
| 310 |
static int fxshonormode = 0; |
| 311 |
static int alawoverride = 0; |
| 312 |
static int fastpickup = 0; |
| 313 |
static int fxotxgain = 0; |
| 314 |
static int fxorxgain = 0; |
| 315 |
static int fxstxgain = 0; |
| 316 |
static int fxsrxgain = 0; |
| 317 |
|
| 318 |
static int wctdm_init_proslic(struct wctdm *wc, int card, int fast , int manual, int sane); |
| 319 |
static int wctdm_init_ring_generator_mode(struct wctdm *wc, int card); |
| 320 |
static int wctdm_set_ring_generator_mode(struct wctdm *wc, int card, int mode); |
| 321 |
|
| 322 |
static inline void wctdm_transmitprep(struct wctdm *wc, unsigned char ints) |
| 323 |
{ |
| 324 |
volatile unsigned int *writechunk; |
| 325 |
int x; |
| 326 |
if (ints & 0x01) |
| 327 |
/* Write is at interrupt address. Start writing from normal offset */ |
| 328 |
writechunk = wc->writechunk; |
| 329 |
else |
| 330 |
writechunk = wc->writechunk + DAHDI_CHUNKSIZE; |
| 331 |
/* Calculate Transmission */ |
| 332 |
dahdi_transmit(&wc->span); |
| 333 |
|
| 334 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
| 335 |
/* Send a sample, as a 32-bit word */ |
| 336 |
writechunk[x] = 0; |
| 337 |
#ifdef __BIG_ENDIAN |
| 338 |
if (wc->cardflag & (1 << 3)) |
| 339 |
writechunk[x] |= (wc->chans[3]->writechunk[x]); |
| 340 |
if (wc->cardflag & (1 << 2)) |
| 341 |
writechunk[x] |= (wc->chans[2]->writechunk[x] << 8); |
| 342 |
if (wc->cardflag & (1 << 1)) |
| 343 |
writechunk[x] |= (wc->chans[1]->writechunk[x] << 16); |
| 344 |
if (wc->cardflag & (1 << 0)) |
| 345 |
writechunk[x] |= (wc->chans[0]->writechunk[x] << 24); |
| 346 |
#else |
| 347 |
if (wc->cardflag & (1 << 3)) |
| 348 |
writechunk[x] |= (wc->chans[3]->writechunk[x] << 24); |
| 349 |
if (wc->cardflag & (1 << 2)) |
| 350 |
writechunk[x] |= (wc->chans[2]->writechunk[x] << 16); |
| 351 |
if (wc->cardflag & (1 << 1)) |
| 352 |
writechunk[x] |= (wc->chans[1]->writechunk[x] << 8); |
| 353 |
if (wc->cardflag & (1 << 0)) |
| 354 |
writechunk[x] |= (wc->chans[0]->writechunk[x]); |
| 355 |
#endif |
| 356 |
} |
| 357 |
|
| 358 |
} |
| 359 |
|
| 360 |
#ifdef AUDIO_RINGCHECK |
| 361 |
static inline void ring_check(struct wctdm *wc, int card) |
| 362 |
{ |
| 363 |
int x; |
| 364 |
short sample; |
| 365 |
if (wc->modtype[card] != MOD_TYPE_FXO) |
| 366 |
return; |
| 367 |
wc->mod[card].fxo.pegtimer += DAHDI_CHUNKSIZE; |
| 368 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
| 369 |
/* Look for pegging to indicate ringing */ |
| 370 |
sample = DAHDI_XLAW(wc->chans[card].readchunk[x], (&(wc->chans[card]))); |
| 371 |
if ((sample > 10000) && (wc->mod[card].fxo.peg != 1)) { |
| 372 |
if (debug > 1) printk(KERN_DEBUG "High peg!\n"); |
| 373 |
if ((wc->mod[card].fxo.pegtimer < PEGTIME) && (wc->mod[card].fxo.pegtimer > MINPEGTIME)) |
| 374 |
wc->mod[card].fxo.pegcount++; |
| 375 |
wc->mod[card].fxo.pegtimer = 0; |
| 376 |
wc->mod[card].fxo.peg = 1; |
| 377 |
} else if ((sample < -10000) && (wc->mod[card].fxo.peg != -1)) { |
| 378 |
if (debug > 1) printk(KERN_DEBUG "Low peg!\n"); |
| 379 |
if ((wc->mod[card].fxo.pegtimer < (PEGTIME >> 2)) && (wc->mod[card].fxo.pegtimer > (MINPEGTIME >> 2))) |
| 380 |
wc->mod[card].fxo.pegcount++; |
| 381 |
wc->mod[card].fxo.pegtimer = 0; |
| 382 |
wc->mod[card].fxo.peg = -1; |
| 383 |
} |
| 384 |
} |
| 385 |
if (wc->mod[card].fxo.pegtimer > PEGTIME) { |
| 386 |
/* Reset pegcount if our timer expires */ |
| 387 |
wc->mod[card].fxo.pegcount = 0; |
| 388 |
} |
| 389 |
/* Decrement debouncer if appropriate */ |
| 390 |
if (wc->mod[card].fxo.ringdebounce) |
| 391 |
wc->mod[card].fxo.ringdebounce--; |
| 392 |
if (!wc->mod[card].fxo.offhook && !wc->mod[card].fxo.ringdebounce) { |
| 393 |
if (!wc->mod[card].fxo.ring && (wc->mod[card].fxo.pegcount > PEGCOUNT)) { |
| 394 |
/* It's ringing */ |
| 395 |
if (debug) |
| 396 |
printk(KERN_DEBUG "RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 397 |
if (!wc->mod[card].fxo.offhook) |
| 398 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_RING); |
| 399 |
wc->mod[card].fxo.ring = 1; |
| 400 |
} |
| 401 |
if (wc->mod[card].fxo.ring && !wc->mod[card].fxo.pegcount) { |
| 402 |
/* No more ring */ |
| 403 |
if (debug) |
| 404 |
printk(KERN_DEBUG "NO RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 405 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 406 |
wc->mod[card].fxo.ring = 0; |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
#endif |
| 411 |
static inline void wctdm_receiveprep(struct wctdm *wc, unsigned char ints) |
| 412 |
{ |
| 413 |
volatile unsigned int *readchunk; |
| 414 |
int x; |
| 415 |
|
| 416 |
if (ints & 0x08) |
| 417 |
readchunk = wc->readchunk + DAHDI_CHUNKSIZE; |
| 418 |
else |
| 419 |
/* Read is at interrupt address. Valid data is available at normal offset */ |
| 420 |
readchunk = wc->readchunk; |
| 421 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
| 422 |
#ifdef __BIG_ENDIAN |
| 423 |
if (wc->cardflag & (1 << 3)) |
| 424 |
wc->chans[3]->readchunk[x] = (readchunk[x]) & 0xff; |
| 425 |
if (wc->cardflag & (1 << 2)) |
| 426 |
wc->chans[2]->readchunk[x] = (readchunk[x] >> 8) & 0xff; |
| 427 |
if (wc->cardflag & (1 << 1)) |
| 428 |
wc->chans[1]->readchunk[x] = (readchunk[x] >> 16) & 0xff; |
| 429 |
if (wc->cardflag & (1 << 0)) |
| 430 |
wc->chans[0]->readchunk[x] = (readchunk[x] >> 24) & 0xff; |
| 431 |
#else |
| 432 |
if (wc->cardflag & (1 << 3)) |
| 433 |
wc->chans[3]->readchunk[x] = (readchunk[x] >> 24) & 0xff; |
| 434 |
if (wc->cardflag & (1 << 2)) |
| 435 |
wc->chans[2]->readchunk[x] = (readchunk[x] >> 16) & 0xff; |
| 436 |
if (wc->cardflag & (1 << 1)) |
| 437 |
wc->chans[1]->readchunk[x] = (readchunk[x] >> 8) & 0xff; |
| 438 |
if (wc->cardflag & (1 << 0)) |
| 439 |
wc->chans[0]->readchunk[x] = (readchunk[x]) & 0xff; |
| 440 |
#endif |
| 441 |
} |
| 442 |
#ifdef AUDIO_RINGCHECK |
| 443 |
for (x=0;x<wc->cards;x++) |
| 444 |
ring_check(wc, x); |
| 445 |
#endif |
| 446 |
/* XXX We're wasting 8 taps. We should get closer :( */ |
| 447 |
for (x = 0; x < NUM_CARDS; x++) { |
| 448 |
if (wc->cardflag & (1 << x)) |
| 449 |
dahdi_ec_chunk(wc->chans[x], wc->chans[x]->readchunk, wc->chans[x]->writechunk); |
| 450 |
} |
| 451 |
dahdi_receive(&wc->span); |
| 452 |
} |
| 453 |
|
| 454 |
static void wctdm_stop_dma(struct wctdm *wc); |
| 455 |
static void wctdm_reset_tdm(struct wctdm *wc); |
| 456 |
static void wctdm_restart_dma(struct wctdm *wc); |
| 457 |
|
| 458 |
static inline void __write_8bits(struct wctdm *wc, unsigned char bits) |
| 459 |
{ |
| 460 |
/* Out BIT_CS --\________________________________/---- */ |
| 461 |
/* Out BIT_SCLK ---\_/-\_/-\_/-\_/-\_/-\_/-\_/-\_/------ */ |
| 462 |
/* Out BIT_SDI ---\___/---\___/---\___/---\___/-------- */ |
| 463 |
/* Data Bit 7 6 5 4 3 2 1 0 */ |
| 464 |
/* Data written 0 1 0 1 0 1 0 1 */ |
| 465 |
|
| 466 |
int x; |
| 467 |
/* Drop chip select */ |
| 468 |
wc->ios &= ~BIT_CS; |
| 469 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 470 |
for (x=0;x<8;x++) { |
| 471 |
/* Send out each bit, MSB first, drop SCLK as we do so */ |
| 472 |
if (bits & 0x80) |
| 473 |
wc->ios |= BIT_SDI; |
| 474 |
else |
| 475 |
wc->ios &= ~BIT_SDI; |
| 476 |
wc->ios &= ~BIT_SCLK; |
| 477 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 478 |
|
| 479 |
/* Now raise SCLK high again and repeat */ |
| 480 |
wc->ios |= BIT_SCLK; |
| 481 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 482 |
bits <<= 1; |
| 483 |
} |
| 484 |
/* Finally raise CS back high again */ |
| 485 |
wc->ios |= BIT_CS; |
| 486 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 487 |
} |
| 488 |
|
| 489 |
static inline void __reset_spi(struct wctdm *wc) |
| 490 |
{ |
| 491 |
/* Drop chip select and clock once and raise and clock once */ |
| 492 |
wc->ios |= BIT_SCLK; |
| 493 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 494 |
wc->ios &= ~BIT_CS; |
| 495 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 496 |
wc->ios |= BIT_SDI; |
| 497 |
wc->ios &= ~BIT_SCLK; |
| 498 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 499 |
/* Now raise SCLK high again and repeat */ |
| 500 |
wc->ios |= BIT_SCLK; |
| 501 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 502 |
/* Finally raise CS back high again */ |
| 503 |
wc->ios |= BIT_CS; |
| 504 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 505 |
/* Clock again */ |
| 506 |
wc->ios &= ~BIT_SCLK; |
| 507 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 508 |
/* Now raise SCLK high again and repeat */ |
| 509 |
wc->ios |= BIT_SCLK; |
| 510 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 511 |
|
| 512 |
} |
| 513 |
|
| 514 |
static inline unsigned char __read_8bits(struct wctdm *wc) |
| 515 |
{ |
| 516 |
/* Out BIT_CS --\________________________________________/----*/ |
| 517 |
/* Out BIT_SCLK ---\_/--\_/--\_/--\_/--\_/--\_/--\_/--\_/-------*/ |
| 518 |
/* In BIT_SDO ????/1111\0000/1111\0000/1111\0000/1111\0000/???*/ |
| 519 |
/* Data bit 7 6 5 4 3 2 1 0 */ |
| 520 |
/* Data Read 1 0 1 0 1 0 1 0 */ |
| 521 |
|
| 522 |
/* Note: Clock High time is 2x Low time, due to input read */ |
| 523 |
|
| 524 |
unsigned char res=0, c; |
| 525 |
int x; |
| 526 |
/* Drop chip select */ |
| 527 |
wc->ios &= ~BIT_CS; |
| 528 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 529 |
for (x=0;x<8;x++) { |
| 530 |
res <<= 1; |
| 531 |
/* Drop SCLK */ |
| 532 |
wc->ios &= ~BIT_SCLK; |
| 533 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 534 |
/* Now raise SCLK high again */ |
| 535 |
wc->ios |= BIT_SCLK; |
| 536 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 537 |
|
| 538 |
/* Read back the value */ |
| 539 |
c = inb(wc->ioaddr + WC_AUXR); |
| 540 |
if (c & BIT_SDO) |
| 541 |
res |= 1; |
| 542 |
} |
| 543 |
/* Finally raise CS back high again */ |
| 544 |
wc->ios |= BIT_CS; |
| 545 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 546 |
|
| 547 |
/* And return our result */ |
| 548 |
return res; |
| 549 |
} |
| 550 |
|
| 551 |
static void __wctdm_setcreg(struct wctdm *wc, unsigned char reg, unsigned char val) |
| 552 |
{ |
| 553 |
outb(val, wc->ioaddr + WC_REGBASE + ((reg & 0xf) << 2)); |
| 554 |
} |
| 555 |
|
| 556 |
static unsigned char __wctdm_getcreg(struct wctdm *wc, unsigned char reg) |
| 557 |
{ |
| 558 |
return inb(wc->ioaddr + WC_REGBASE + ((reg & 0xf) << 2)); |
| 559 |
} |
| 560 |
|
| 561 |
static inline void __wctdm_setcard(struct wctdm *wc, int card) |
| 562 |
{ |
| 563 |
if (wc->curcard != card) { |
| 564 |
__wctdm_setcreg(wc, WC_CS, (1 << card)); |
| 565 |
wc->curcard = card; |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
static void __wctdm_setreg(struct wctdm *wc, int card, unsigned char reg, unsigned char value) |
| 570 |
{ |
| 571 |
__wctdm_setcard(wc, card); |
| 572 |
if (wc->modtype[card] == MOD_TYPE_FXO) { |
| 573 |
__write_8bits(wc, 0x20); |
| 574 |
__write_8bits(wc, reg & 0x7f); |
| 575 |
} else { |
| 576 |
__write_8bits(wc, reg & 0x7f); |
| 577 |
} |
| 578 |
__write_8bits(wc, value); |
| 579 |
} |
| 580 |
|
| 581 |
static void wctdm_setreg(struct wctdm *wc, int card, unsigned char reg, unsigned char value) |
| 582 |
{ |
| 583 |
unsigned long flags; |
| 584 |
spin_lock_irqsave(&wc->lock, flags); |
| 585 |
__wctdm_setreg(wc, card, reg, value); |
| 586 |
spin_unlock_irqrestore(&wc->lock, flags); |
| 587 |
} |
| 588 |
|
| 589 |
static unsigned char __wctdm_getreg(struct wctdm *wc, int card, unsigned char reg) |
| 590 |
{ |
| 591 |
__wctdm_setcard(wc, card); |
| 592 |
if (wc->modtype[card] == MOD_TYPE_FXO) { |
| 593 |
__write_8bits(wc, 0x60); |
| 594 |
__write_8bits(wc, reg & 0x7f); |
| 595 |
} else { |
| 596 |
__write_8bits(wc, reg | 0x80); |
| 597 |
} |
| 598 |
return __read_8bits(wc); |
| 599 |
} |
| 600 |
|
| 601 |
static inline void reset_spi(struct wctdm *wc, int card) |
| 602 |
{ |
| 603 |
unsigned long flags; |
| 604 |
spin_lock_irqsave(&wc->lock, flags); |
| 605 |
__wctdm_setcard(wc, card); |
| 606 |
__reset_spi(wc); |
| 607 |
__reset_spi(wc); |
| 608 |
spin_unlock_irqrestore(&wc->lock, flags); |
| 609 |
} |
| 610 |
|
| 611 |
static unsigned char wctdm_getreg(struct wctdm *wc, int card, unsigned char reg) |
| 612 |
{ |
| 613 |
unsigned long flags; |
| 614 |
unsigned char res; |
| 615 |
spin_lock_irqsave(&wc->lock, flags); |
| 616 |
res = __wctdm_getreg(wc, card, reg); |
| 617 |
spin_unlock_irqrestore(&wc->lock, flags); |
| 618 |
return res; |
| 619 |
} |
| 620 |
|
| 621 |
static int __wait_access(struct wctdm *wc, int card) |
| 622 |
{ |
| 623 |
unsigned char data = 0; |
| 624 |
int count = 0; |
| 625 |
|
| 626 |
#define MAX 6000 /* attempts */ |
| 627 |
|
| 628 |
|
| 629 |
/* Wait for indirect access */ |
| 630 |
while (count++ < MAX) |
| 631 |
{ |
| 632 |
data = __wctdm_getreg(wc, card, I_STATUS); |
| 633 |
|
| 634 |
if (!data) |
| 635 |
return 0; |
| 636 |
|
| 637 |
} |
| 638 |
|
| 639 |
if(count > (MAX-1)) printk(KERN_NOTICE " ##### Loop error (%02x) #####\n", data); |
| 640 |
|
| 641 |
return 0; |
| 642 |
} |
| 643 |
|
| 644 |
static unsigned char translate_3215(unsigned char address) |
| 645 |
{ |
| 646 |
int x; |
| 647 |
for (x=0;x<sizeof(indirect_regs)/sizeof(indirect_regs[0]);x++) { |
| 648 |
if (indirect_regs[x].address == address) { |
| 649 |
address = indirect_regs[x].altaddr; |
| 650 |
break; |
| 651 |
} |
| 652 |
} |
| 653 |
return address; |
| 654 |
} |
| 655 |
|
| 656 |
static int wctdm_proslic_setreg_indirect(struct wctdm *wc, int card, unsigned char address, unsigned short data) |
| 657 |
{ |
| 658 |
unsigned long flags; |
| 659 |
int res = -1; |
| 660 |
/* Translate 3215 addresses */ |
| 661 |
if (wc->flags[card] & FLAG_3215) { |
| 662 |
address = translate_3215(address); |
| 663 |
if (address == 255) |
| 664 |
return 0; |
| 665 |
} |
| 666 |
spin_lock_irqsave(&wc->lock, flags); |
| 667 |
if(!__wait_access(wc, card)) { |
| 668 |
__wctdm_setreg(wc, card, IDA_LO,(unsigned char)(data & 0xFF)); |
| 669 |
__wctdm_setreg(wc, card, IDA_HI,(unsigned char)((data & 0xFF00)>>8)); |
| 670 |
__wctdm_setreg(wc, card, IAA,address); |
| 671 |
res = 0; |
| 672 |
}; |
| 673 |
spin_unlock_irqrestore(&wc->lock, flags); |
| 674 |
return res; |
| 675 |
} |
| 676 |
|
| 677 |
static int wctdm_proslic_getreg_indirect(struct wctdm *wc, int card, unsigned char address) |
| 678 |
{ |
| 679 |
unsigned long flags; |
| 680 |
int res = -1; |
| 681 |
char *p=NULL; |
| 682 |
/* Translate 3215 addresses */ |
| 683 |
if (wc->flags[card] & FLAG_3215) { |
| 684 |
address = translate_3215(address); |
| 685 |
if (address == 255) |
| 686 |
return 0; |
| 687 |
} |
| 688 |
spin_lock_irqsave(&wc->lock, flags); |
| 689 |
if (!__wait_access(wc, card)) { |
| 690 |
__wctdm_setreg(wc, card, IAA, address); |
| 691 |
if (!__wait_access(wc, card)) { |
| 692 |
unsigned char data1, data2; |
| 693 |
data1 = __wctdm_getreg(wc, card, IDA_LO); |
| 694 |
data2 = __wctdm_getreg(wc, card, IDA_HI); |
| 695 |
res = data1 | (data2 << 8); |
| 696 |
} else |
| 697 |
p = "Failed to wait inside\n"; |
| 698 |
} else |
| 699 |
p = "failed to wait\n"; |
| 700 |
spin_unlock_irqrestore(&wc->lock, flags); |
| 701 |
if (p) |
| 702 |
printk(KERN_NOTICE "%s", p); |
| 703 |
return res; |
| 704 |
} |
| 705 |
|
| 706 |
static int wctdm_proslic_init_indirect_regs(struct wctdm *wc, int card) |
| 707 |
{ |
| 708 |
unsigned char i; |
| 709 |
|
| 710 |
for (i=0; i<sizeof(indirect_regs) / sizeof(indirect_regs[0]); i++) |
| 711 |
{ |
| 712 |
if(wctdm_proslic_setreg_indirect(wc, card, indirect_regs[i].address,indirect_regs[i].initial)) |
| 713 |
return -1; |
| 714 |
} |
| 715 |
|
| 716 |
return 0; |
| 717 |
} |
| 718 |
|
| 719 |
static int wctdm_proslic_verify_indirect_regs(struct wctdm *wc, int card) |
| 720 |
{ |
| 721 |
int passed = 1; |
| 722 |
unsigned short i, initial; |
| 723 |
int j; |
| 724 |
|
| 725 |
for (i=0; i<sizeof(indirect_regs) / sizeof(indirect_regs[0]); i++) |
| 726 |
{ |
| 727 |
if((j = wctdm_proslic_getreg_indirect(wc, card, (unsigned char) indirect_regs[i].address)) < 0) { |
| 728 |
printk(KERN_NOTICE "Failed to read indirect register %d\n", i); |
| 729 |
return -1; |
| 730 |
} |
| 731 |
initial= indirect_regs[i].initial; |
| 732 |
|
| 733 |
if ( j != initial && (!(wc->flags[card] & FLAG_3215) || (indirect_regs[i].altaddr != 255))) |
| 734 |
{ |
| 735 |
printk(KERN_NOTICE "!!!!!!! %s iREG %X = %X should be %X\n", |
| 736 |
indirect_regs[i].name,indirect_regs[i].address,j,initial ); |
| 737 |
passed = 0; |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
if (passed) { |
| 742 |
if (debug) |
| 743 |
printk(KERN_DEBUG "Init Indirect Registers completed successfully.\n"); |
| 744 |
} else { |
| 745 |
printk(KERN_NOTICE " !!!!! Init Indirect Registers UNSUCCESSFULLY.\n"); |
| 746 |
return -1; |
| 747 |
} |
| 748 |
return 0; |
| 749 |
} |
| 750 |
|
| 751 |
static inline void wctdm_proslic_recheck_sanity(struct wctdm *wc, int card) |
| 752 |
{ |
| 753 |
struct fxs *const fxs = &wc->mod[card].fxs; |
| 754 |
int res; |
| 755 |
/* Check loopback */ |
| 756 |
res = wc->reg1shadow[card]; |
| 757 |
if (!res && (res != fxs->lasttxhook)) { |
| 758 |
res = wctdm_getreg(wc, card, 8); |
| 759 |
if (res) { |
| 760 |
printk(KERN_NOTICE "Ouch, part reset, quickly restoring reality (%d)\n", card); |
| 761 |
wctdm_init_proslic(wc, card, 1, 0, 1); |
| 762 |
} else { |
| 763 |
if (fxs->palarms++ < MAX_ALARMS) { |
| 764 |
printk(KERN_NOTICE "Power alarm on module %d, resetting!\n", card + 1); |
| 765 |
if (fxs->lasttxhook == SLIC_LF_RINGING) |
| 766 |
fxs->lasttxhook = SLIC_LF_ACTIVE_FWD; |
| 767 |
wctdm_setreg(wc, card, 64, fxs->lasttxhook); |
| 768 |
} else { |
| 769 |
if (fxs->palarms == MAX_ALARMS) |
| 770 |
printk(KERN_NOTICE "Too many power alarms on card %d, NOT resetting!\n", card + 1); |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
static inline void wctdm_voicedaa_check_hook(struct wctdm *wc, int card) |
| 777 |
{ |
| 778 |
#define MS_PER_CHECK_HOOK 16 |
| 779 |
|
| 780 |
#ifndef AUDIO_RINGCHECK |
| 781 |
unsigned char res; |
| 782 |
#endif |
| 783 |
signed char b; |
| 784 |
int errors = 0; |
| 785 |
struct fxo *fxo = &wc->mod[card].fxo; |
| 786 |
|
| 787 |
/* Try to track issues that plague slot one FXO's */ |
| 788 |
b = wc->reg0shadow[card]; |
| 789 |
if ((b & 0x2) || !(b & 0x8)) { |
| 790 |
/* Not good -- don't look at anything else */ |
| 791 |
if (debug) |
| 792 |
printk(KERN_DEBUG "Error (%02x) on card %d!\n", b, card + 1); |
| 793 |
errors++; |
| 794 |
} |
| 795 |
b &= 0x9b; |
| 796 |
if (fxo->offhook) { |
| 797 |
if (b != 0x9) |
| 798 |
wctdm_setreg(wc, card, 5, 0x9); |
| 799 |
} else { |
| 800 |
if (b != 0x8) |
| 801 |
wctdm_setreg(wc, card, 5, 0x8); |
| 802 |
} |
| 803 |
if (errors) |
| 804 |
return; |
| 805 |
if (!fxo->offhook) { |
| 806 |
if (fwringdetect) { |
| 807 |
res = wc->reg0shadow[card] & 0x60; |
| 808 |
if (fxo->ringdebounce) { |
| 809 |
--fxo->ringdebounce; |
| 810 |
if (res && (res != fxo->lastrdtx) && |
| 811 |
(fxo->battery == BATTERY_PRESENT)) { |
| 812 |
if (!fxo->wasringing) { |
| 813 |
fxo->wasringing = 1; |
| 814 |
if (debug) |
| 815 |
printk(KERN_DEBUG "RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 816 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_RING); |
| 817 |
} |
| 818 |
fxo->lastrdtx = res; |
| 819 |
fxo->ringdebounce = 10; |
| 820 |
} else if (!res) { |
| 821 |
if ((fxo->ringdebounce == 0) && fxo->wasringing) { |
| 822 |
fxo->wasringing = 0; |
| 823 |
if (debug) |
| 824 |
printk(KERN_DEBUG "NO RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 825 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 826 |
} |
| 827 |
} |
| 828 |
} else if (res && (fxo->battery == BATTERY_PRESENT)) { |
| 829 |
fxo->lastrdtx = res; |
| 830 |
fxo->ringdebounce = 10; |
| 831 |
} |
| 832 |
} else { |
| 833 |
res = wc->reg0shadow[card]; |
| 834 |
if ((res & 0x60) && (fxo->battery == BATTERY_PRESENT)) { |
| 835 |
fxo->ringdebounce += (DAHDI_CHUNKSIZE * 16); |
| 836 |
if (fxo->ringdebounce >= DAHDI_CHUNKSIZE * ringdebounce) { |
| 837 |
if (!fxo->wasringing) { |
| 838 |
fxo->wasringing = 1; |
| 839 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_RING); |
| 840 |
if (debug) |
| 841 |
printk(KERN_DEBUG "RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 842 |
} |
| 843 |
fxo->ringdebounce = DAHDI_CHUNKSIZE * ringdebounce; |
| 844 |
} |
| 845 |
} else { |
| 846 |
fxo->ringdebounce -= DAHDI_CHUNKSIZE * 4; |
| 847 |
if (fxo->ringdebounce <= 0) { |
| 848 |
if (fxo->wasringing) { |
| 849 |
fxo->wasringing = 0; |
| 850 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 851 |
if (debug) |
| 852 |
printk(KERN_DEBUG "NO RING on %d/%d!\n", wc->span.spanno, card + 1); |
| 853 |
} |
| 854 |
fxo->ringdebounce = 0; |
| 855 |
} |
| 856 |
} |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
b = wc->reg1shadow[card]; |
| 861 |
|
| 862 |
if (fxovoltage) { |
| 863 |
static int count = 0; |
| 864 |
if (!(count++ % 100)) { |
| 865 |
printk(KERN_DEBUG "Card %d: Voltage: %d Debounce %d\n", card + 1, b, fxo->battdebounce); |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
if (unlikely(DAHDI_RXSIG_INITIAL == wc->chans[card]->rxhooksig)) { |
| 870 |
/* |
| 871 |
* dahdi-base will set DAHDI_RXSIG_INITIAL after a |
| 872 |
* DAHDI_STARTUP or DAHDI_CHANCONFIG ioctl so that new events |
| 873 |
* will be queued on the channel with the current received |
| 874 |
* hook state. Channels that use robbed-bit signalling always |
| 875 |
* report the current received state via the dahdi_rbsbits |
| 876 |
* call. Since we only call dahdi_hooksig when we've detected |
| 877 |
* a change to report, let's forget our current state in order |
| 878 |
* to force us to report it again via dahdi_hooksig. |
| 879 |
* |
| 880 |
*/ |
| 881 |
fxo->battery = BATTERY_UNKNOWN; |
| 882 |
} |
| 883 |
|
| 884 |
if (abs(b) < battthresh) { |
| 885 |
/* possible existing states: |
| 886 |
battery lost, no debounce timer |
| 887 |
battery lost, debounce timer (going to battery present) |
| 888 |
battery present or unknown, no debounce timer |
| 889 |
battery present or unknown, debounce timer (going to battery lost) |
| 890 |
*/ |
| 891 |
|
| 892 |
if (fxo->battery == BATTERY_LOST) { |
| 893 |
if (fxo->battdebounce) { |
| 894 |
/* we were going to BATTERY_PRESENT, but battery was lost again, |
| 895 |
so clear the debounce timer */ |
| 896 |
fxo->battdebounce = 0; |
| 897 |
} |
| 898 |
} else { |
| 899 |
if (fxo->battdebounce) { |
| 900 |
/* going to BATTERY_LOST, see if we are there yet */ |
| 901 |
if (--fxo->battdebounce == 0) { |
| 902 |
fxo->battery = BATTERY_LOST; |
| 903 |
if (debug) |
| 904 |
printk(KERN_DEBUG "NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1); |
| 905 |
#ifdef JAPAN |
| 906 |
if (!wc->ohdebounce && wc->offhook) { |
| 907 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_ONHOOK); |
| 908 |
if (debug) |
| 909 |
printk(KERN_DEBUG "Signalled On Hook\n"); |
| 910 |
#ifdef ZERO_BATT_RING |
| 911 |
wc->onhook++; |
| 912 |
#endif |
| 913 |
} |
| 914 |
#else |
| 915 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_ONHOOK); |
| 916 |
/* set the alarm timer, taking into account that part of its time |
| 917 |
period has already passed while debouncing occurred */ |
| 918 |
fxo->battalarm = (battalarm - battdebounce) / MS_PER_CHECK_HOOK; |
| 919 |
#endif |
| 920 |
} |
| 921 |
} else { |
| 922 |
/* start the debounce timer to verify that battery has been lost */ |
| 923 |
fxo->battdebounce = battdebounce / MS_PER_CHECK_HOOK; |
| 924 |
} |
| 925 |
} |
| 926 |
} else { |
| 927 |
/* possible existing states: |
| 928 |
battery lost or unknown, no debounce timer |
| 929 |
battery lost or unknown, debounce timer (going to battery present) |
| 930 |
battery present, no debounce timer |
| 931 |
battery present, debounce timer (going to battery lost) |
| 932 |
*/ |
| 933 |
|
| 934 |
if (fxo->battery == BATTERY_PRESENT) { |
| 935 |
if (fxo->battdebounce) { |
| 936 |
/* we were going to BATTERY_LOST, but battery appeared again, |
| 937 |
so clear the debounce timer */ |
| 938 |
fxo->battdebounce = 0; |
| 939 |
} |
| 940 |
} else { |
| 941 |
if (fxo->battdebounce) { |
| 942 |
/* going to BATTERY_PRESENT, see if we are there yet */ |
| 943 |
if (--fxo->battdebounce == 0) { |
| 944 |
fxo->battery = BATTERY_PRESENT; |
| 945 |
if (debug) |
| 946 |
printk(KERN_DEBUG "BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1, |
| 947 |
(b < 0) ? "-" : "+"); |
| 948 |
#ifdef ZERO_BATT_RING |
| 949 |
if (wc->onhook) { |
| 950 |
wc->onhook = 0; |
| 951 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 952 |
if (debug) |
| 953 |
printk(KERN_DEBUG "Signalled Off Hook\n"); |
| 954 |
} |
| 955 |
#else |
| 956 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 957 |
#endif |
| 958 |
/* set the alarm timer, taking into account that part of its time |
| 959 |
period has already passed while debouncing occurred */ |
| 960 |
fxo->battalarm = (battalarm - battdebounce) / MS_PER_CHECK_HOOK; |
| 961 |
} |
| 962 |
} else { |
| 963 |
/* start the debounce timer to verify that battery has appeared */ |
| 964 |
fxo->battdebounce = battdebounce / MS_PER_CHECK_HOOK; |
| 965 |
} |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
if (fxo->lastpol >= 0) { |
| 970 |
if (b < 0) { |
| 971 |
fxo->lastpol = -1; |
| 972 |
fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK; |
| 973 |
} |
| 974 |
} |
| 975 |
if (fxo->lastpol <= 0) { |
| 976 |
if (b > 0) { |
| 977 |
fxo->lastpol = 1; |
| 978 |
fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK; |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
if (fxo->battalarm) { |
| 983 |
if (--fxo->battalarm == 0) { |
| 984 |
/* the alarm timer has expired, so update the battery alarm state |
| 985 |
for this channel */ |
| 986 |
dahdi_alarm_channel(wc->chans[card], fxo->battery == BATTERY_LOST ? DAHDI_ALARM_RED : DAHDI_ALARM_NONE); |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
if (fxo->polaritydebounce) { |
| 991 |
if (--fxo->polaritydebounce == 0) { |
| 992 |
if (fxo->lastpol != fxo->polarity) { |
| 993 |
if (debug) |
| 994 |
printk(KERN_DEBUG "%lu Polarity reversed (%d -> %d)\n", jiffies, |
| 995 |
fxo->polarity, |
| 996 |
fxo->lastpol); |
| 997 |
if (fxo->polarity) |
| 998 |
dahdi_qevent_lock(wc->chans[card], DAHDI_EVENT_POLARITY); |
| 999 |
fxo->polarity = fxo->lastpol; |
| 1000 |
} |
| 1001 |
} |
| 1002 |
} |
| 1003 |
#undef MS_PER_CHECK_HOOK |
| 1004 |
} |
| 1005 |
|
| 1006 |
static void wctdm_fxs_hooksig(struct wctdm *wc, const int card, enum dahdi_txsig txsig) |
| 1007 |
{ |
| 1008 |
struct fxs *const fxs = &wc->mod[card].fxs; |
| 1009 |
switch (txsig) { |
| 1010 |
case DAHDI_TXSIG_ONHOOK: |
| 1011 |
switch (wc->span.chans[card]->sig) { |
| 1012 |
case DAHDI_SIG_FXOKS: |
| 1013 |
case DAHDI_SIG_FXOLS: |
| 1014 |
/* Can't change Ring Generator during OHT */ |
| 1015 |
if (!fxs->ohttimer) { |
| 1016 |
wctdm_set_ring_generator_mode(wc, |
| 1017 |
card, fxs->vmwi_hvac); |
| 1018 |
fxs->lasttxhook = fxs->vmwi_hvac ? |
| 1019 |
SLIC_LF_RINGING : |
| 1020 |
fxs->idletxhookstate; |
| 1021 |
} else { |
| 1022 |
fxs->lasttxhook = fxs->idletxhookstate; |
| 1023 |
} |
| 1024 |
break; |
| 1025 |
case DAHDI_SIG_EM: |
| 1026 |
fxs->lasttxhook = fxs->idletxhookstate; |
| 1027 |
break; |
| 1028 |
case DAHDI_SIG_FXOGS: |
| 1029 |
fxs->lasttxhook = SLIC_LF_TIP_OPEN; |
| 1030 |
break; |
| 1031 |
} |
| 1032 |
break; |
| 1033 |
case DAHDI_TXSIG_OFFHOOK: |
| 1034 |
switch (wc->span.chans[card]->sig) { |
| 1035 |
case DAHDI_SIG_EM: |
| 1036 |
fxs->lasttxhook = SLIC_LF_ACTIVE_REV; |
| 1037 |
break; |
| 1038 |
default: |
| 1039 |
fxs->lasttxhook = fxs->idletxhookstate; |
| 1040 |
break; |
| 1041 |
} |
| 1042 |
break; |
| 1043 |
case DAHDI_TXSIG_START: |
| 1044 |
/* Set ringer mode */ |
| 1045 |
wctdm_set_ring_generator_mode(wc, card, 0); |
| 1046 |
fxs->lasttxhook = SLIC_LF_RINGING; |
| 1047 |
break; |
| 1048 |
case DAHDI_TXSIG_KEWL: |
| 1049 |
fxs->lasttxhook = SLIC_LF_OPEN; |
| 1050 |
break; |
| 1051 |
default: |
| 1052 |
printk(KERN_NOTICE "wctdm: Can't set tx state to %d\n", txsig); |
| 1053 |
return; |
| 1054 |
} |
| 1055 |
if (debug) { |
| 1056 |
printk(KERN_DEBUG |
| 1057 |
"Setting FXS hook state to %d (%02x)\n", |
| 1058 |
txsig, fxs->lasttxhook); |
| 1059 |
} |
| 1060 |
wctdm_setreg(wc, card, LINE_STATE, fxs->lasttxhook); |
| 1061 |
} |
| 1062 |
|
| 1063 |
static inline void wctdm_proslic_check_hook(struct wctdm *wc, int card) |
| 1064 |
{ |
| 1065 |
struct fxs *const fxs = &wc->mod[card].fxs; |
| 1066 |
char res; |
| 1067 |
int hook; |
| 1068 |
|
| 1069 |
/* For some reason we have to debounce the |
| 1070 |
hook detector. */ |
| 1071 |
|
| 1072 |
res = wc->reg0shadow[card]; |
| 1073 |
hook = (res & 1); |
| 1074 |
if (hook != fxs->lastrxhook) { |
| 1075 |
/* Reset the debounce (must be multiple of 4ms) */ |
| 1076 |
fxs->debounce = dialdebounce * 4; |
| 1077 |
#if 0 |
| 1078 |
printk(KERN_DEBUG "Resetting debounce card %d hook %d, %d\n", |
| 1079 |
card, hook, fxs->debounce); |
| 1080 |
#endif |
| 1081 |
} else { |
| 1082 |
if (fxs->debounce > 0) { |
| 1083 |
fxs->debounce -= 16 * DAHDI_CHUNKSIZE; |
| 1084 |
#if 0 |
| 1085 |
printk(KERN_DEBUG "Sustaining hook %d, %d\n", |
| 1086 |
hook, fxs->debounce); |
| 1087 |
#endif |
| 1088 |
if (!fxs->debounce) { |
| 1089 |
#if 0 |
| 1090 |
printk(KERN_DEBUG "Counted down debounce, newhook: %d...\n", hook); |
| 1091 |
#endif |
| 1092 |
fxs->debouncehook = hook; |
| 1093 |
} |
| 1094 |
if (!fxs->oldrxhook && fxs->debouncehook) { |
| 1095 |
/* Off hook */ |
| 1096 |
#if 1 |
| 1097 |
if (debug) |
| 1098 |
#endif |
| 1099 |
printk(KERN_DEBUG "wctdm: Card %d Going off hook\n", card); |
| 1100 |
|
| 1101 |
switch (fxs->lasttxhook) { |
| 1102 |
case SLIC_LF_RINGING: |
| 1103 |
case SLIC_LF_OHTRAN_FWD: |
| 1104 |
case SLIC_LF_OHTRAN_REV: |
| 1105 |
/* just detected OffHook, during |
| 1106 |
* Ringing or OnHookTransfer */ |
| 1107 |
fxs->idletxhookstate = |
| 1108 |
POLARITY_XOR ? |
| 1109 |
SLIC_LF_ACTIVE_REV : |
| 1110 |
SLIC_LF_ACTIVE_FWD; |
| 1111 |
break; |
| 1112 |
} |
| 1113 |
|
| 1114 |
wctdm_fxs_hooksig(wc, card, DAHDI_TXSIG_OFFHOOK); |
| 1115 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_OFFHOOK); |
| 1116 |
if (robust) |
| 1117 |
wctdm_init_proslic(wc, card, 1, 0, 1); |
| 1118 |
fxs->oldrxhook = 1; |
| 1119 |
|
| 1120 |
} else if (fxs->oldrxhook && !fxs->debouncehook) { |
| 1121 |
/* On hook */ |
| 1122 |
#if 1 |
| 1123 |
if (debug) |
| 1124 |
#endif |
| 1125 |
printk(KERN_DEBUG "wctdm: Card %d Going on hook\n", card); |
| 1126 |
wctdm_fxs_hooksig(wc, card, DAHDI_TXSIG_ONHOOK); |
| 1127 |
dahdi_hooksig(wc->chans[card], DAHDI_RXSIG_ONHOOK); |
| 1128 |
fxs->oldrxhook = 0; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
fxs->lastrxhook = hook; |
| 1133 |
} |
| 1134 |
|
| 1135 |
DAHDI_IRQ_HANDLER(wctdm_interrupt) |
| 1136 |
{ |
| 1137 |
struct wctdm *wc = dev_id; |
| 1138 |
unsigned char ints; |
| 1139 |
int x; |
| 1140 |
int mode; |
| 1141 |
|
| 1142 |
ints = inb(wc->ioaddr + WC_INTSTAT); |
| 1143 |
|
| 1144 |
if (!ints) |
| 1145 |
return IRQ_NONE; |
| 1146 |
|
| 1147 |
outb(ints, wc->ioaddr + WC_INTSTAT); |
| 1148 |
|
| 1149 |
if (ints & 0x10) { |
| 1150 |
/* Stop DMA, wait for watchdog */ |
| 1151 |
printk(KERN_INFO "TDM PCI Master abort\n"); |
| 1152 |
wctdm_stop_dma(wc); |
| 1153 |
return IRQ_RETVAL(1); |
| 1154 |
} |
| 1155 |
|
| 1156 |
if (ints & 0x20) { |
| 1157 |
printk(KERN_INFO "PCI Target abort\n"); |
| 1158 |
return IRQ_RETVAL(1); |
| 1159 |
} |
| 1160 |
|
| 1161 |
for (x=0;x<4;x++) { |
| 1162 |
if (wc->cardflag & (1 << x) && |
| 1163 |
(wc->modtype[x] == MOD_TYPE_FXS)) { |
| 1164 |
struct fxs *const fxs = &wc->mod[x].fxs; |
| 1165 |
if (fxs->lasttxhook == SLIC_LF_RINGING && |
| 1166 |
!fxs->neonringing) { |
| 1167 |
/* RINGing, prepare for OHT */ |
| 1168 |
fxs->ohttimer = OHT_TIMER << 3; |
| 1169 |
|
| 1170 |
/* logical XOR 3 variables |
| 1171 |
module parameter 'reversepolarity', global reverse all FXS lines. |
| 1172 |
ioctl channel variable fxs 'reversepolarity', Line Reversal Alert Signal if required. |
| 1173 |
ioctl channel variable fxs 'vmwi_lrev', VMWI pending. |
| 1174 |
*/ |
| 1175 |
|
| 1176 |
/* OHT mode when idle */ |
| 1177 |
fxs->idletxhookstate = POLARITY_XOR ? |
| 1178 |
SLIC_LF_OHTRAN_REV : |
| 1179 |
SLIC_LF_OHTRAN_FWD; |
| 1180 |
} else if (fxs->ohttimer) { |
| 1181 |
/* check if still OnHook */ |
| 1182 |
if (!fxs->oldrxhook) { |
| 1183 |
fxs->ohttimer -= DAHDI_CHUNKSIZE; |
| 1184 |
if (!fxs->ohttimer) { |
| 1185 |
fxs->idletxhookstate = POLARITY_XOR ? SLIC_LF_ACTIVE_REV : SLIC_LF_ACTIVE_FWD; /* Switch to Active, Rev or Fwd */ |
| 1186 |
/* if currently OHT */ |
| 1187 |
if ((fxs->lasttxhook == SLIC_LF_OHTRAN_FWD) || (fxs->lasttxhook == SLIC_LF_OHTRAN_REV)) { |
| 1188 |
if (fxs->vmwi_hvac) { |
| 1189 |
/* force idle polarity Forward if ringing */ |
| 1190 |
fxs->idletxhookstate = SLIC_LF_ACTIVE_FWD; |
| 1191 |
/* Set ring generator for neon */ |
| 1192 |
wctdm_set_ring_generator_mode(wc, x, 1); |
| 1193 |
fxs->lasttxhook = SLIC_LF_RINGING; |
| 1194 |
} else { |
| 1195 |
fxs->lasttxhook = fxs->idletxhookstate; |
| 1196 |
} |
| 1197 |
/* Apply the change as appropriate */ |
| 1198 |
wctdm_setreg(wc, x, LINE_STATE, fxs->lasttxhook); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
} else { |
| 1202 |
fxs->ohttimer = 0; |
| 1203 |
/* Switch to Active, Rev or Fwd */ |
| 1204 |
fxs->idletxhookstate = POLARITY_XOR ? SLIC_LF_ACTIVE_REV : SLIC_LF_ACTIVE_FWD; |
| 1205 |
} |
| 1206 |
} |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
if (ints & 0x0f) { |
| 1211 |
wc->intcount++; |
| 1212 |
x = wc->intcount & 0x3; |
| 1213 |
mode = wc->intcount & 0xc; |
| 1214 |
if (wc->cardflag & (1 << x)) { |
| 1215 |
switch(mode) { |
| 1216 |
case 0: |
| 1217 |
/* Rest */ |
| 1218 |
break; |
| 1219 |
case 4: |
| 1220 |
/* Read first shadow reg */ |
| 1221 |
if (wc->modtype[x] == MOD_TYPE_FXS) |
| 1222 |
wc->reg0shadow[x] = wctdm_getreg(wc, x, 68); |
| 1223 |
else if (wc->modtype[x] == MOD_TYPE_FXO) |
| 1224 |
wc->reg0shadow[x] = wctdm_getreg(wc, x, 5); |
| 1225 |
break; |
| 1226 |
case 8: |
| 1227 |
/* Read second shadow reg */ |
| 1228 |
if (wc->modtype[x] == MOD_TYPE_FXS) |
| 1229 |
wc->reg1shadow[x] = wctdm_getreg(wc, x, LINE_STATE); |
| 1230 |
else if (wc->modtype[x] == MOD_TYPE_FXO) |
| 1231 |
wc->reg1shadow[x] = wctdm_getreg(wc, x, 29); |
| 1232 |
break; |
| 1233 |
case 12: |
| 1234 |
/* Perform processing */ |
| 1235 |
if (wc->modtype[x] == MOD_TYPE_FXS) { |
| 1236 |
wctdm_proslic_check_hook(wc, x); |
| 1237 |
if (!(wc->intcount & 0xf0)) { |
| 1238 |
wctdm_proslic_recheck_sanity(wc, x); |
| 1239 |
} |
| 1240 |
} else if (wc->modtype[x] == MOD_TYPE_FXO) { |
| 1241 |
wctdm_voicedaa_check_hook(wc, x); |
| 1242 |
} |
| 1243 |
break; |
| 1244 |
} |
| 1245 |
} |
| 1246 |
if (!(wc->intcount % 10000)) { |
| 1247 |
/* Accept an alarm once per 10 seconds */ |
| 1248 |
for (x=0;x<4;x++) |
| 1249 |
if (wc->modtype[x] == MOD_TYPE_FXS) { |
| 1250 |
if (wc->mod[x].fxs.palarms) |
| 1251 |
wc->mod[x].fxs.palarms--; |
| 1252 |
} |
| 1253 |
} |
| 1254 |
wctdm_receiveprep(wc, ints); |
| 1255 |
wctdm_transmitprep(wc, ints); |
| 1256 |
} |
| 1257 |
|
| 1258 |
return IRQ_RETVAL(1); |
| 1259 |
} |
| 1260 |
|
| 1261 |
static int wctdm_voicedaa_insane(struct wctdm *wc, int card) |
| 1262 |
{ |
| 1263 |
int blah; |
| 1264 |
blah = wctdm_getreg(wc, card, 2); |
| 1265 |
if (blah != 0x3) |
| 1266 |
return -2; |
| 1267 |
blah = wctdm_getreg(wc, card, 11); |
| 1268 |
if (debug) |
| 1269 |
printk(KERN_DEBUG "VoiceDAA System: %02x\n", blah & 0xf); |
| 1270 |
return 0; |
| 1271 |
} |
| 1272 |
|
| 1273 |
static int wctdm_proslic_insane(struct wctdm *wc, int card) |
| 1274 |
{ |
| 1275 |
int blah,insane_report; |
| 1276 |
insane_report=0; |
| 1277 |
|
| 1278 |
blah = wctdm_getreg(wc, card, 0); |
| 1279 |
if (debug) |
| 1280 |
printk(KERN_DEBUG "ProSLIC on module %d, product %d, version %d\n", card, (blah & 0x30) >> 4, (blah & 0xf)); |
| 1281 |
|
| 1282 |
#if 0 |
| 1283 |
if ((blah & 0x30) >> 4) { |
| 1284 |
printk(KERN_DEBUG "ProSLIC on module %d is not a 3210.\n", card); |
| 1285 |
return -1; |
| 1286 |
} |
| 1287 |
#endif |
| 1288 |
if (((blah & 0xf) == 0) || ((blah & 0xf) == 0xf)) { |
| 1289 |
/* SLIC not loaded */ |
| 1290 |
return -1; |
| 1291 |
} |
| 1292 |
if ((blah & 0xf) < 2) { |
| 1293 |
printk(KERN_NOTICE "ProSLIC 3210 version %d is too old\n", blah & 0xf); |
| 1294 |
return -1; |
| 1295 |
} |
| 1296 |
if (wctdm_getreg(wc, card, 1) & 0x80) |
| 1297 |
/* ProSLIC 3215, not a 3210 */ |
| 1298 |
wc->flags[card] |= FLAG_3215; |
| 1299 |
|
| 1300 |
blah = wctdm_getreg(wc, card, 8); |
| 1301 |
if (blah != 0x2) { |
| 1302 |
printk(KERN_NOTICE "ProSLIC on module %d insane (1) %d should be 2\n", card, blah); |
| 1303 |
return -1; |
| 1304 |
} else if ( insane_report) |
| 1305 |
printk(KERN_NOTICE "ProSLIC on module %d Reg 8 Reads %d Expected is 0x2\n",card,blah); |
| 1306 |
|
| 1307 |
blah = wctdm_getreg(wc, card, 64); |
| 1308 |
if (blah != 0x0) { |
| 1309 |
printk(KERN_NOTICE "ProSLIC on module %d insane (2)\n", card); |
| 1310 |
return -1; |
| 1311 |
} else if ( insane_report) |
| 1312 |
printk(KERN_NOTICE "ProSLIC on module %d Reg 64 Reads %d Expected is 0x0\n",card,blah); |
| 1313 |
|
| 1314 |
blah = wctdm_getreg(wc, card, 11); |
| 1315 |
if (blah != 0x33) { |
| 1316 |
printk(KERN_NOTICE "ProSLIC on module %d insane (3)\n", card); |
| 1317 |
return -1; |
| 1318 |
} else if ( insane_report) |
| 1319 |
printk(KERN_NOTICE "ProSLIC on module %d Reg 11 Reads %d Expected is 0x33\n",card,blah); |
| 1320 |
|
| 1321 |
/* Just be sure it's setup right. */ |
| 1322 |
wctdm_setreg(wc, card, 30, 0); |
| 1323 |
|
| 1324 |
if (debug) |
| 1325 |
printk(KERN_DEBUG "ProSLIC on module %d seems sane.\n", card); |
| 1326 |
return 0; |
| 1327 |
} |
| 1328 |
|
| 1329 |
static int wctdm_proslic_powerleak_test(struct wctdm *wc, int card) |
| 1330 |
{ |
| 1331 |
unsigned long origjiffies; |
| 1332 |
unsigned char vbat; |
| 1333 |
|
| 1334 |
/* Turn off linefeed */ |
| 1335 |
wctdm_setreg(wc, card, 64, 0); |
| 1336 |
|
| 1337 |
/* Power down */ |
| 1338 |
wctdm_setreg(wc, card, 14, 0x10); |
| 1339 |
|
| 1340 |
/* Wait for one second */ |
| 1341 |
origjiffies = jiffies; |
| 1342 |
|
| 1343 |
while((vbat = wctdm_getreg(wc, card, 82)) > 0x6) { |
| 1344 |
if ((jiffies - origjiffies) >= (HZ/2)) |
| 1345 |
break;; |
| 1346 |
} |
| 1347 |
|
| 1348 |
if (vbat < 0x06) { |
| 1349 |
printk(KERN_NOTICE "Excessive leakage detected on module %d: %d volts (%02x) after %d ms\n", card, |
| 1350 |
376 * vbat / 1000, vbat, (int)((jiffies - origjiffies) * 1000 / HZ)); |
| 1351 |
return -1; |
| 1352 |
} else if (debug) { |
| 1353 |
printk(KERN_NOTICE "Post-leakage voltage: %d volts\n", 376 * vbat / 1000); |
| 1354 |
} |
| 1355 |
return 0; |
| 1356 |
} |
| 1357 |
|
| 1358 |
static int wctdm_powerup_proslic(struct wctdm *wc, int card, int fast) |
| 1359 |
{ |
| 1360 |
unsigned char vbat; |
| 1361 |
unsigned long origjiffies; |
| 1362 |
int lim; |
| 1363 |
|
| 1364 |
/* Set period of DC-DC converter to 1/64 khz */ |
| 1365 |
wctdm_setreg(wc, card, 92, 0xff /* was 0xff */); |
| 1366 |
|
| 1367 |
/* Wait for VBat to powerup */ |
| 1368 |
origjiffies = jiffies; |
| 1369 |
|
| 1370 |
/* Disable powerdown */ |
| 1371 |
wctdm_setreg(wc, card, 14, 0); |
| 1372 |
|
| 1373 |
/* If fast, don't bother checking anymore */ |
| 1374 |
if (fast) |
| 1375 |
return 0; |
| 1376 |
|
| 1377 |
while((vbat = wctdm_getreg(wc, card, 82)) < 0xc0) { |
| 1378 |
/* Wait no more than 500ms */ |
| 1379 |
if ((jiffies - origjiffies) > HZ/2) { |
| 1380 |
break; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
|
| 1384 |
if (vbat < 0xc0) { |
| 1385 |
if (wc->proslic_power == PROSLIC_POWER_UNKNOWN) |
| 1386 |
printk(KERN_NOTICE "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", |
| 1387 |
card, (int)(((jiffies - origjiffies) * 1000 / HZ)), |
| 1388 |
vbat * 375); |
| 1389 |
wc->proslic_power = PROSLIC_POWER_WARNED; |
| 1390 |
return -1; |
| 1391 |
} else if (debug) { |
| 1392 |
printk(KERN_DEBUG "ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n", |
| 1393 |
card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); |
| 1394 |
} |
| 1395 |
wc->proslic_power = PROSLIC_POWER_ON; |
| 1396 |
|
| 1397 |
/* Proslic max allowed loop current, reg 71 LOOP_I_LIMIT */ |
| 1398 |
/* If out of range, just set it to the default value */ |
| 1399 |
lim = (loopcurrent - 20) / 3; |
| 1400 |
if ( loopcurrent > 41 ) { |
| 1401 |
lim = 0; |
| 1402 |
if (debug) |
| 1403 |
printk(KERN_DEBUG "Loop current out of range! Setting to default 20mA!\n"); |
| 1404 |
} |
| 1405 |
else if (debug) |
| 1406 |
printk(KERN_DEBUG "Loop current set to %dmA!\n",(lim*3)+20); |
| 1407 |
wctdm_setreg(wc,card,LOOP_I_LIMIT,lim); |
| 1408 |
|
| 1409 |
/* Engage DC-DC converter */ |
| 1410 |
wctdm_setreg(wc, card, 93, 0x19 /* was 0x19 */); |
| 1411 |
#if 0 |
| 1412 |
origjiffies = jiffies; |
| 1413 |
while(0x80 & wctdm_getreg(wc, card, 93)) { |
| 1414 |
if ((jiffies - origjiffies) > 2 * HZ) { |
| 1415 |
printk(KERN_DEBUG "Timeout waiting for DC-DC calibration on module %d\n", card); |
| 1416 |
return -1; |
| 1417 |
} |
| 1418 |
} |
| 1419 |
|
| 1420 |
#if 0 |
| 1421 |
/* Wait a full two seconds */ |
| 1422 |
while((jiffies - origjiffies) < 2 * HZ); |
| 1423 |
|
| 1424 |
/* Just check to be sure */ |
| 1425 |
vbat = wctdm_getreg(wc, card, 82); |
| 1426 |
printk(KERN_DEBUG "ProSLIC on module %d powered up to -%d volts (%02x) in %d ms\n", |
| 1427 |
card, vbat * 376 / 1000, vbat, (int)(((jiffies - origjiffies) * 1000 / HZ))); |
| 1428 |
#endif |
| 1429 |
#endif |
| 1430 |
return 0; |
| 1431 |
|
| 1432 |
} |
| 1433 |
|
| 1434 |
static int wctdm_proslic_manual_calibrate(struct wctdm *wc, int card){ |
| 1435 |
unsigned long origjiffies; |
| 1436 |
unsigned char i; |
| 1437 |
|
| 1438 |
wctdm_setreg(wc, card, 21, 0);//(0) Disable all interupts in DR21 |
| 1439 |
wctdm_setreg(wc, card, 22, 0);//(0)Disable all interupts in DR21 |
| 1440 |
wctdm_setreg(wc, card, 23, 0);//(0)Disable all interupts in DR21 |
| 1441 |
wctdm_setreg(wc, card, 64, 0);//(0) |
| 1442 |
|
| 1443 |
wctdm_setreg(wc, card, 97, 0x18); //(0x18)Calibrations without the ADC and DAC offset and without common mode calibration. |
| 1444 |
wctdm_setreg(wc, card, 96, 0x47); //(0x47) Calibrate common mode and differential DAC mode DAC + ILIM |
| 1445 |
|
| 1446 |
origjiffies=jiffies; |
| 1447 |
while( wctdm_getreg(wc,card,96)!=0 ){ |
| 1448 |
if((jiffies-origjiffies)>80) |
| 1449 |
return -1; |
| 1450 |
} |
| 1451 |
//Initialized DR 98 and 99 to get consistant results. |
| 1452 |
// 98 and 99 are the results registers and the search should have same intial conditions. |
| 1453 |
|
| 1454 |
/*******************************The following is the manual gain mismatch calibration****************************/ |
| 1455 |
/*******************************This is also available as a function *******************************************/ |
| 1456 |
// Delay 10ms |
| 1457 |
origjiffies=jiffies; |
| 1458 |
while((jiffies-origjiffies)<1); |
| 1459 |
wctdm_proslic_setreg_indirect(wc, card, 88, 0); |
| 1460 |
wctdm_proslic_setreg_indirect(wc, card, 89, 0); |
| 1461 |
wctdm_proslic_setreg_indirect(wc, card, 90, 0); |
| 1462 |
wctdm_proslic_setreg_indirect(wc, card, 91, 0); |
| 1463 |
wctdm_proslic_setreg_indirect(wc, card, 92, 0); |
| 1464 |
wctdm_proslic_setreg_indirect(wc, card, 93, 0); |
| 1465 |
|
| 1466 |
wctdm_setreg(wc, card, 98, 0x10); // This is necessary if the calibration occurs other than at reset time |
| 1467 |
wctdm_setreg(wc, card, 99, 0x10); |
| 1468 |
|
| 1469 |
for ( i=0x1f; i>0; i--) |
| 1470 |
{ |
| 1471 |
wctdm_setreg(wc, card, 98, i); |
| 1472 |
origjiffies=jiffies; |
| 1473 |
while((jiffies-origjiffies)<4); |
| 1474 |
if((wctdm_getreg(wc, card, 88)) == 0) |
| 1475 |
break; |
| 1476 |
} // for |
| 1477 |
|
| 1478 |
for ( i=0x1f; i>0; i--) |
| 1479 |
{ |
| 1480 |
wctdm_setreg(wc, card, 99, i); |
| 1481 |
origjiffies=jiffies; |
| 1482 |
while((jiffies-origjiffies)<4); |
| 1483 |
if((wctdm_getreg(wc, card, 89)) == 0) |
| 1484 |
break; |
| 1485 |
}//for |
| 1486 |
|
| 1487 |
/*******************************The preceding is the manual gain mismatch calibration****************************/ |
| 1488 |
/**********************************The following is the longitudinal Balance Cal***********************************/ |
| 1489 |
wctdm_setreg(wc,card,64,1); |
| 1490 |
while((jiffies-origjiffies)<10); // Sleep 100? |
| 1491 |
|
| 1492 |
wctdm_setreg(wc, card, 64, 0); |
| 1493 |
wctdm_setreg(wc, card, 23, 0x4); // enable interrupt for the balance Cal |
| 1494 |
wctdm_setreg(wc, card, 97, 0x1); // this is a singular calibration bit for longitudinal calibration |
| 1495 |
wctdm_setreg(wc, card, 96, 0x40); |
| 1496 |
|
| 1497 |
wctdm_getreg(wc, card, 96); /* Read Reg 96 just cause */ |
| 1498 |
|
| 1499 |
wctdm_setreg(wc, card, 21, 0xFF); |
| 1500 |
wctdm_setreg(wc, card, 22, 0xFF); |
| 1501 |
wctdm_setreg(wc, card, 23, 0xFF); |
| 1502 |
|
| 1503 |
/**The preceding is the longitudinal Balance Cal***/ |
| 1504 |
return(0); |
| 1505 |
|
| 1506 |
} |
| 1507 |
#if 1 |
| 1508 |
static int wctdm_proslic_calibrate(struct wctdm *wc, int card) |
| 1509 |
{ |
| 1510 |
unsigned long origjiffies; |
| 1511 |
int x; |
| 1512 |
/* Perform all calibrations */ |
| 1513 |
wctdm_setreg(wc, card, 97, 0x1f); |
| 1514 |
|
| 1515 |
/* Begin, no speedup */ |
| 1516 |
wctdm_setreg(wc, card, 96, 0x5f); |
| 1517 |
|
| 1518 |
/* Wait for it to finish */ |
| 1519 |
origjiffies = jiffies; |
| 1520 |
while(wctdm_getreg(wc, card, 96)) { |
| 1521 |
if ((jiffies - origjiffies) > 2 * HZ) { |
| 1522 |
printk(KERN_NOTICE "Timeout waiting for calibration of module %d\n", card); |
| 1523 |
return -1; |
| 1524 |
} |
| 1525 |
} |
| 1526 |
|
| 1527 |
if (debug) { |
| 1528 |
/* Print calibration parameters */ |
| 1529 |
printk(KERN_DEBUG "Calibration Vector Regs 98 - 107: \n"); |
| 1530 |
for (x=98;x<108;x++) { |
| 1531 |
printk(KERN_DEBUG "%d: %02x\n", x, wctdm_getreg(wc, card, x)); |
| 1532 |
} |
| 1533 |
} |
| 1534 |
return 0; |
| 1535 |
} |
| 1536 |
#endif |
| 1537 |
|
| 1538 |
static void wait_just_a_bit(int foo) |
| 1539 |
{ |
| 1540 |
long newjiffies; |
| 1541 |
newjiffies = jiffies + foo; |
| 1542 |
while(jiffies < newjiffies); |
| 1543 |
} |
| 1544 |
|
| 1545 |
/********************************************************************* |
| 1546 |
* Set the hwgain on the analog modules |
| 1547 |
* |
| 1548 |
* card = the card position for this module (0-23) |
| 1549 |
* gain = gain in dB x10 (e.g. -3.5dB would be gain=-35) |
| 1550 |
* tx = (0 for rx; 1 for tx) |
| 1551 |
* |
| 1552 |
*******************************************************************/ |
| 1553 |
static int wctdm_set_hwgain(struct wctdm *wc, int card, __s32 gain, __u32 tx) |
| 1554 |
{ |
| 1555 |
if (!(wc->modtype[card] == MOD_TYPE_FXO)) { |
| 1556 |
printk(KERN_NOTICE "Cannot adjust gain. Unsupported module type!\n"); |
| 1557 |
return -1; |
| 1558 |
} |
| 1559 |
if (tx) { |
| 1560 |
if (debug) |
| 1561 |
printk(KERN_DEBUG "setting FXO tx gain for card=%d to %d\n", card, gain); |
| 1562 |
if (gain >= -150 && gain <= 0) { |
| 1563 |
wctdm_setreg(wc, card, 38, 16 + (gain/-10)); |
| 1564 |
wctdm_setreg(wc, card, 40, 16 + (-gain%10)); |
| 1565 |
} else if (gain <= 120 && gain > 0) { |
| 1566 |
wctdm_setreg(wc, card, 38, gain/10); |
| 1567 |
wctdm_setreg(wc, card, 40, (gain%10)); |
| 1568 |
} else { |
| 1569 |
printk(KERN_INFO "FXO tx gain is out of range (%d)\n", gain); |
| 1570 |
return -1; |
| 1571 |
} |
| 1572 |
} else { /* rx */ |
| 1573 |
if (debug) |
| 1574 |
printk(KERN_DEBUG "setting FXO rx gain for card=%d to %d\n", card, gain); |
| 1575 |
if (gain >= -150 && gain <= 0) { |
| 1576 |
wctdm_setreg(wc, card, 39, 16+ (gain/-10)); |
| 1577 |
wctdm_setreg(wc, card, 41, 16 + (-gain%10)); |
| 1578 |
} else if (gain <= 120 && gain > 0) { |
| 1579 |
wctdm_setreg(wc, card, 39, gain/10); |
| 1580 |
wctdm_setreg(wc, card, 41, (gain%10)); |
| 1581 |
} else { |
| 1582 |
printk(KERN_INFO "FXO rx gain is out of range (%d)\n", gain); |
| 1583 |
return -1; |
| 1584 |
} |
| 1585 |
} |
| 1586 |
|
| 1587 |
return 0; |
| 1588 |
} |
| 1589 |
|
| 1590 |
static int set_vmwi(struct wctdm * wc, int chan_idx) |
| 1591 |
{ |
| 1592 |
struct fxs *const fxs = &wc->mod[chan_idx].fxs; |
| 1593 |
if (fxs->vmwi_active_messages) { |
| 1594 |
fxs->vmwi_lrev = |
| 1595 |
(fxs->vmwisetting.vmwi_type & DAHDI_VMWI_LREV) ? 1 : 0; |
| 1596 |
fxs->vmwi_hvdc = |
| 1597 |
(fxs->vmwisetting.vmwi_type & DAHDI_VMWI_HVDC) ? 1 : 0; |
| 1598 |
fxs->vmwi_hvac = |
| 1599 |
(fxs->vmwisetting.vmwi_type & DAHDI_VMWI_HVAC) ? 1 : 0; |
| 1600 |
} else { |
| 1601 |
fxs->vmwi_lrev = 0; |
| 1602 |
fxs->vmwi_hvdc = 0; |
| 1603 |
fxs->vmwi_hvac = 0; |
| 1604 |
} |
| 1605 |
|
| 1606 |
if (debug) { |
| 1607 |
printk(KERN_DEBUG "Setting VMWI on channel %d, messages=%d, " |
| 1608 |
"lrev=%d, hvdc=%d, hvac=%d\n", |
| 1609 |
chan_idx, |
| 1610 |
fxs->vmwi_active_messages, |
| 1611 |
fxs->vmwi_lrev, |
| 1612 |
fxs->vmwi_hvdc, |
| 1613 |
fxs->vmwi_hvac |
| 1614 |
); |
| 1615 |
} |
| 1616 |
if (fxs->vmwi_hvac) { |
| 1617 |
/* Can't change ring generator while in On Hook Transfer mode*/ |
| 1618 |
if (!fxs->ohttimer) { |
| 1619 |
if (POLARITY_XOR) |
| 1620 |
fxs->idletxhookstate |= SLIC_LF_REVMASK; |
| 1621 |
else |
| 1622 |
fxs->idletxhookstate &= ~SLIC_LF_REVMASK; |
| 1623 |
/* Set ring generator for neon */ |
| 1624 |
wctdm_set_ring_generator_mode(wc, chan_idx, 1); |
| 1625 |
/* Activate ring to send neon pulses */ |
| 1626 |
fxs->lasttxhook = SLIC_LF_RINGING; |
| 1627 |
wctdm_setreg(wc, chan_idx, LINE_STATE, fxs->lasttxhook); |
| 1628 |
} |
| 1629 |
} else { |
| 1630 |
if (fxs->neonringing) { |
| 1631 |
/* Set ring generator for normal ringer */ |
| 1632 |
wctdm_set_ring_generator_mode(wc, chan_idx, 0); |
| 1633 |
/* ACTIVE, polarity determined later */ |
| 1634 |
fxs->lasttxhook = SLIC_LF_ACTIVE_FWD; |
| 1635 |
} else if ((fxs->lasttxhook == SLIC_LF_RINGING) || |
| 1636 |
(fxs->lasttxhook == SLIC_LF_OPEN)) { |
| 1637 |
/* Can't change polarity while ringing or when open, |
| 1638 |
set idlehookstate instead */ |
| 1639 |
if (POLARITY_XOR) |
| 1640 |
fxs->idletxhookstate |= SLIC_LF_REVMASK; |
| 1641 |
else |
| 1642 |
fxs->idletxhookstate &= ~SLIC_LF_REVMASK; |
| 1643 |
|
| 1644 |
printk(KERN_DEBUG "Unable to change polarity on channel" |
| 1645 |
"%d, lasttxhook=0x%X\n", |
| 1646 |
chan_idx, |
| 1647 |
fxs->lasttxhook |
| 1648 |
); |
| 1649 |
return 0; |
| 1650 |
} |
| 1651 |
if (POLARITY_XOR) { |
| 1652 |
fxs->idletxhookstate |= SLIC_LF_REVMASK; |
| 1653 |
fxs->lasttxhook |= SLIC_LF_REVMASK; |
| 1654 |
} else { |
| 1655 |
fxs->idletxhookstate &= ~SLIC_LF_REVMASK; |
| 1656 |
fxs->lasttxhook &= ~SLIC_LF_REVMASK; |
| 1657 |
} |
| 1658 |
wctdm_setreg(wc, chan_idx, LINE_STATE, fxs->lasttxhook); |
| 1659 |
} |
| 1660 |
return 0; |
| 1661 |
} |
| 1662 |
|
| 1663 |
static int wctdm_init_voicedaa(struct wctdm *wc, int card, int fast, int manual, int sane) |
| 1664 |
{ |
| 1665 |
unsigned char reg16=0, reg26=0, reg30=0, reg31=0; |
| 1666 |
long newjiffies; |
| 1667 |
wc->modtype[card] = MOD_TYPE_FXO; |
| 1668 |
/* Sanity check the ProSLIC */ |
| 1669 |
reset_spi(wc, card); |
| 1670 |
if (!sane && wctdm_voicedaa_insane(wc, card)) |
| 1671 |
return -2; |
| 1672 |
|
| 1673 |
/* Software reset */ |
| 1674 |
wctdm_setreg(wc, card, 1, 0x80); |
| 1675 |
|
| 1676 |
/* Wait just a bit */ |
| 1677 |
wait_just_a_bit(HZ/10); |
| 1678 |
|
| 1679 |
/* Enable PCM, ulaw */ |
| 1680 |
if (alawoverride){ |
| 1681 |
wctdm_setreg(wc, card, 33, 0x20); |
| 1682 |
} else { |
| 1683 |
wctdm_setreg(wc, card, 33, 0x28); |
| 1684 |
} |
| 1685 |
|
| 1686 |
/* Set On-hook speed, Ringer impedence, and ringer threshold */ |
| 1687 |
reg16 |= (fxo_modes[_opermode].ohs << 6); |
| 1688 |
reg16 |= (fxo_modes[_opermode].rz << 1); |
| 1689 |
reg16 |= (fxo_modes[_opermode].rt); |
| 1690 |
wctdm_setreg(wc, card, 16, reg16); |
| 1691 |
|
| 1692 |
if(fwringdetect) { |
| 1693 |
/* Enable ring detector full-wave rectifier mode */ |
| 1694 |
wctdm_setreg(wc, card, 18, 2); |
| 1695 |
wctdm_setreg(wc, card, 24, 0); |
| 1696 |
} else { |
| 1697 |
/* Set to the device defaults */ |
| 1698 |
wctdm_setreg(wc, card, 18, 0); |
| 1699 |
wctdm_setreg(wc, card, 24, 0x19); |
| 1700 |
} |
| 1701 |
|
| 1702 |
/* Set DC Termination: |
| 1703 |
Tip/Ring voltage adjust, minimum operational current, current limitation */ |
| 1704 |
reg26 |= (fxo_modes[_opermode].dcv << 6); |
| 1705 |
reg26 |= (fxo_modes[_opermode].mini << 4); |
| 1706 |
reg26 |= (fxo_modes[_opermode].ilim << 1); |
| 1707 |
wctdm_setreg(wc, card, 26, reg26); |
| 1708 |
|
| 1709 |
/* Set AC Impedence */ |
| 1710 |
reg30 = (fxo_modes[_opermode].acim); |
| 1711 |
wctdm_setreg(wc, card, 30, reg30); |
| 1712 |
|
| 1713 |
/* Misc. DAA parameters */ |
| 1714 |
if (fastpickup) |
| 1715 |
reg31 = 0xe3; |
| 1716 |
else |
| 1717 |
reg31 = 0xa3; |
| 1718 |
|
| 1719 |
reg31 |= (fxo_modes[_opermode].ohs2 << 3); |
| 1720 |
wctdm_setreg(wc, card, 31, reg31); |
| 1721 |
|
| 1722 |
/* Set Transmit/Receive timeslot */ |
| 1723 |
wctdm_setreg(wc, card, 34, (3-card) * 8); |
| 1724 |
wctdm_setreg(wc, card, 35, 0x00); |
| 1725 |
wctdm_setreg(wc, card, 36, (3-card) * 8); |
| 1726 |
wctdm_setreg(wc, card, 37, 0x00); |
| 1727 |
|
| 1728 |
/* Enable ISO-Cap */ |
| 1729 |
wctdm_setreg(wc, card, 6, 0x00); |
| 1730 |
|
| 1731 |
if (fastpickup) |
| 1732 |
wctdm_setreg(wc, card, 17, wctdm_getreg(wc, card, 17) | 0x20); |
| 1733 |
|
| 1734 |
/* Wait 1000ms for ISO-cap to come up */ |
| 1735 |
newjiffies = jiffies; |
| 1736 |
newjiffies += 2 * HZ; |
| 1737 |
while((jiffies < newjiffies) && !(wctdm_getreg(wc, card, 11) & 0xf0)) |
| 1738 |
wait_just_a_bit(HZ/10); |
| 1739 |
|
| 1740 |
if (!(wctdm_getreg(wc, card, 11) & 0xf0)) { |
| 1741 |
printk(KERN_NOTICE "VoiceDAA did not bring up ISO link properly!\n"); |
| 1742 |
return -1; |
| 1743 |
} |
| 1744 |
if (debug) |
| 1745 |
printk(KERN_DEBUG "ISO-Cap is now up, line side: %02x rev %02x\n", |
| 1746 |
wctdm_getreg(wc, card, 11) >> 4, |
| 1747 |
(wctdm_getreg(wc, card, 13) >> 2) & 0xf); |
| 1748 |
/* Enable on-hook line monitor */ |
| 1749 |
wctdm_setreg(wc, card, 5, 0x08); |
| 1750 |
|
| 1751 |
/* Take values for fxotxgain and fxorxgain and apply them to module */ |
| 1752 |
wctdm_set_hwgain(wc, card, fxotxgain, 1); |
| 1753 |
wctdm_set_hwgain(wc, card, fxorxgain, 0); |
| 1754 |
|
| 1755 |
/* NZ -- crank the tx gain up by 7 dB */ |
| 1756 |
if (!strcmp(fxo_modes[_opermode].name, "NEWZEALAND")) { |
| 1757 |
printk(KERN_INFO "Adjusting gain\n"); |
| 1758 |
wctdm_set_hwgain(wc, card, 7, 1); |
| 1759 |
} |
| 1760 |
|
| 1761 |
if(debug) |
| 1762 |
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)); |
| 1763 |
|
| 1764 |
return 0; |
| 1765 |
|
| 1766 |
} |
| 1767 |
|
| 1768 |
static int wctdm_init_proslic(struct wctdm *wc, int card, int fast, int manual, int sane) |
| 1769 |
{ |
| 1770 |
|
| 1771 |
unsigned short tmp[5]; |
| 1772 |
unsigned char r19,r9; |
| 1773 |
int x; |
| 1774 |
int fxsmode=0; |
| 1775 |
struct fxs *const fxs = &wc->mod[card].fxs; |
| 1776 |
|
| 1777 |
/* Sanity check the ProSLIC */ |
| 1778 |
if (!sane && wctdm_proslic_insane(wc, card)) |
| 1779 |
return -2; |
| 1780 |
|
| 1781 |
/* default messages to none and method to FSK */ |
| 1782 |
memset(&fxs->vmwisetting, 0, sizeof(fxs->vmwisetting)); |
| 1783 |
fxs->vmwi_lrev = 0; |
| 1784 |
fxs->vmwi_hvdc = 0; |
| 1785 |
fxs->vmwi_hvac = 0; |
| 1786 |
|
| 1787 |
|
| 1788 |
/* By default, don't send on hook */ |
| 1789 |
if (!reversepolarity != !fxs->reversepolarity) |
| 1790 |
fxs->idletxhookstate = SLIC_LF_ACTIVE_REV; |
| 1791 |
else |
| 1792 |
fxs->idletxhookstate = SLIC_LF_ACTIVE_FWD; |
| 1793 |
|
| 1794 |
if (sane) { |
| 1795 |
/* Make sure we turn off the DC->DC converter to prevent anything from blowing up */ |
| 1796 |
wctdm_setreg(wc, card, 14, 0x10); |
| 1797 |
} |
| 1798 |
|
| 1799 |
if (wctdm_proslic_init_indirect_regs(wc, card)) { |
| 1800 |
printk(KERN_INFO "Indirect Registers failed to initialize on module %d.\n", card); |
| 1801 |
return -1; |
| 1802 |
} |
| 1803 |
|
| 1804 |
/* Clear scratch pad area */ |
| 1805 |
wctdm_proslic_setreg_indirect(wc, card, 97,0); |
| 1806 |
|
| 1807 |
/* Clear digital loopback */ |
| 1808 |
wctdm_setreg(wc, card, 8, 0); |
| 1809 |
|
| 1810 |
/* Revision C optimization */ |
| 1811 |
wctdm_setreg(wc, card, 108, 0xeb); |
| 1812 |
|
| 1813 |
/* Disable automatic VBat switching for safety to prevent |
| 1814 |
Q7 from accidently turning on and burning out. */ |
| 1815 |
wctdm_setreg(wc, card, 67, 0x07); /* Note, if pulse dialing has problems at high REN loads |
| 1816 |
change this to 0x17 */ |
| 1817 |
|
| 1818 |
/* Turn off Q7 */ |
| 1819 |
wctdm_setreg(wc, card, 66, 1); |
| 1820 |
|
| 1821 |
/* Flush ProSLIC digital filters by setting to clear, while |
| 1822 |
saving old values */ |
| 1823 |
for (x=0;x<5;x++) { |
| 1824 |
tmp[x] = wctdm_proslic_getreg_indirect(wc, card, x + 35); |
| 1825 |
wctdm_proslic_setreg_indirect(wc, card, x + 35, 0x8000); |
| 1826 |
} |
| 1827 |
|
| 1828 |
/* Power up the DC-DC converter */ |
| 1829 |
if (wctdm_powerup_proslic(wc, card, fast)) { |
| 1830 |
printk(KERN_NOTICE "Unable to do INITIAL ProSLIC powerup on module %d\n", card); |
| 1831 |
return -1; |
| 1832 |
} |
| 1833 |
|
| 1834 |
if (!fast) { |
| 1835 |
|
| 1836 |
/* Check for power leaks */ |
| 1837 |
if (wctdm_proslic_powerleak_test(wc, card)) { |
| 1838 |
printk(KERN_NOTICE "ProSLIC module %d failed leakage test. Check for short circuit\n", card); |
| 1839 |
} |
| 1840 |
/* Power up again */ |
| 1841 |
if (wctdm_powerup_proslic(wc, card, fast)) { |
| 1842 |
printk(KERN_NOTICE "Unable to do FINAL ProSLIC powerup on module %d\n", card); |
| 1843 |
return -1; |
| 1844 |
} |
| 1845 |
#ifndef NO_CALIBRATION |
| 1846 |
/* Perform calibration */ |
| 1847 |
if(manual) { |
| 1848 |
if (wctdm_proslic_manual_calibrate(wc, card)) { |
| 1849 |
//printk(KERN_NOTICE "Proslic failed on Manual Calibration\n"); |
| 1850 |
if (wctdm_proslic_manual_calibrate(wc, card)) { |
| 1851 |
printk(KERN_NOTICE "Proslic Failed on Second Attempt to Calibrate Manually. (Try -DNO_CALIBRATION in Makefile)\n"); |
| 1852 |
return -1; |
| 1853 |
} |
| 1854 |
printk(KERN_NOTICE "Proslic Passed Manual Calibration on Second Attempt\n"); |
| 1855 |
} |
| 1856 |
} |
| 1857 |
else { |
| 1858 |
if(wctdm_proslic_calibrate(wc, card)) { |
| 1859 |
//printk(KERN_NOTICE "ProSlic died on Auto Calibration.\n"); |
| 1860 |
if (wctdm_proslic_calibrate(wc, card)) { |
| 1861 |
printk(KERN_NOTICE "Proslic Failed on Second Attempt to Auto Calibrate\n"); |
| 1862 |
return -1; |
| 1863 |
} |
| 1864 |
printk(KERN_NOTICE "Proslic Passed Auto Calibration on Second Attempt\n"); |
| 1865 |
} |
| 1866 |
} |
| 1867 |
/* Perform DC-DC calibration */ |
| 1868 |
wctdm_setreg(wc, card, 93, 0x99); |
| 1869 |
r19 = wctdm_getreg(wc, card, 107); |
| 1870 |
if ((r19 < 0x2) || (r19 > 0xd)) { |
| 1871 |
printk(KERN_NOTICE "DC-DC cal has a surprising direct 107 of 0x%02x!\n", r19); |
| 1872 |
wctdm_setreg(wc, card, 107, 0x8); |
| 1873 |
} |
| 1874 |
|
| 1875 |
/* Save calibration vectors */ |
| 1876 |
for (x=0;x<NUM_CAL_REGS;x++) |
| 1877 |
fxs->calregs.vals[x] = wctdm_getreg(wc, card, 96 + x); |
| 1878 |
#endif |
| 1879 |
|
| 1880 |
} else { |
| 1881 |
/* Restore calibration registers */ |
| 1882 |
for (x=0;x<NUM_CAL_REGS;x++) |
| 1883 |
wctdm_setreg(wc, card, 96 + x, fxs->calregs.vals[x]); |
| 1884 |
} |
| 1885 |
/* Calibration complete, restore original values */ |
| 1886 |
for (x=0;x<5;x++) { |
| 1887 |
wctdm_proslic_setreg_indirect(wc, card, x + 35, tmp[x]); |
| 1888 |
} |
| 1889 |
|
| 1890 |
if (wctdm_proslic_verify_indirect_regs(wc, card)) { |
| 1891 |
printk(KERN_INFO "Indirect Registers failed verification.\n"); |
| 1892 |
return -1; |
| 1893 |
} |
| 1894 |
|
| 1895 |
|
| 1896 |
#if 0 |
| 1897 |
/* Disable Auto Power Alarm Detect and other "features" */ |
| 1898 |
wctdm_setreg(wc, card, 67, 0x0e); |
| 1899 |
blah = wctdm_getreg(wc, card, 67); |
| 1900 |
#endif |
| 1901 |
|
| 1902 |
#if 0 |
| 1903 |
if (wctdm_proslic_setreg_indirect(wc, card, 97, 0x0)) { // Stanley: for the bad recording fix |
| 1904 |
printk(KERN_INFO "ProSlic IndirectReg Died.\n"); |
| 1905 |
return -1; |
| 1906 |
} |
| 1907 |
#endif |
| 1908 |
|
| 1909 |
if (alawoverride) |
| 1910 |
wctdm_setreg(wc, card, 1, 0x20); |
| 1911 |
else |
| 1912 |
wctdm_setreg(wc, card, 1, 0x28); |
| 1913 |
// U-Law 8-bit interface |
| 1914 |
wctdm_setreg(wc, card, 2, (3-card) * 8); // Tx Start count low byte 0 |
| 1915 |
wctdm_setreg(wc, card, 3, 0); // Tx Start count high byte 0 |
| 1916 |
wctdm_setreg(wc, card, 4, (3-card) * 8); // Rx Start count low byte 0 |
| 1917 |
wctdm_setreg(wc, card, 5, 0); // Rx Start count high byte 0 |
| 1918 |
wctdm_setreg(wc, card, 18, 0xff); // clear all interrupt |
| 1919 |
wctdm_setreg(wc, card, 19, 0xff); |
| 1920 |
wctdm_setreg(wc, card, 20, 0xff); |
| 1921 |
wctdm_setreg(wc, card, 73, 0x04); |
| 1922 |
if (fxshonormode) { |
| 1923 |
fxsmode = acim2tiss[fxo_modes[_opermode].acim]; |
| 1924 |
wctdm_setreg(wc, card, 10, 0x08 | fxsmode); |
| 1925 |
} |
| 1926 |
if (lowpower) |
| 1927 |
wctdm_setreg(wc, card, 72, 0x10); |
| 1928 |
|
| 1929 |
#if 0 |
| 1930 |
wctdm_setreg(wc, card, 21, 0x00); // enable interrupt |
| 1931 |
wctdm_setreg(wc, card, 22, 0x02); // Loop detection interrupt |
| 1932 |
wctdm_setreg(wc, card, 23, 0x01); // DTMF detection interrupt |
| 1933 |
#endif |
| 1934 |
|
| 1935 |
#if 0 |
| 1936 |
/* Enable loopback */ |
| 1937 |
wctdm_setreg(wc, card, 8, 0x2); |
| 1938 |
wctdm_setreg(wc, card, 14, 0x0); |
| 1939 |
wctdm_setreg(wc, card, 64, 0x0); |
| 1940 |
wctdm_setreg(wc, card, 1, 0x08); |
| 1941 |
#endif |
| 1942 |
if (wctdm_init_ring_generator_mode(wc, card)) { |
| 1943 |
return -1; |
| 1944 |
} |
| 1945 |
|
| 1946 |
if(fxstxgain || fxsrxgain) { |
| 1947 |
r9 = wctdm_getreg(wc, card, 9); |
| 1948 |
switch (fxstxgain) { |
| 1949 |
|
| 1950 |
case 35: |
| 1951 |
r9+=8; |
| 1952 |
break; |
| 1953 |
case -35: |
| 1954 |
r9+=4; |
| 1955 |
break; |
| 1956 |
case 0: |
| 1957 |
break; |
| 1958 |
} |
| 1959 |
|
| 1960 |
switch (fxsrxgain) { |
| 1961 |
|
| 1962 |
case 35: |
| 1963 |
r9+=2; |
| 1964 |
break; |
| 1965 |
case -35: |
| 1966 |
r9+=1; |
| 1967 |
break; |
| 1968 |
case 0: |
| 1969 |
break; |
| 1970 |
} |
| 1971 |
wctdm_setreg(wc,card,9,r9); |
| 1972 |
} |
| 1973 |
|
| 1974 |
if(debug) |
| 1975 |
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")); |
| 1976 |
|
| 1977 |
fxs->lasttxhook = fxs->idletxhookstate; |
| 1978 |
wctdm_setreg(wc, card, LINE_STATE, fxs->lasttxhook); |
| 1979 |
return 0; |
| 1980 |
} |
| 1981 |
|
| 1982 |
static int wctdm_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data) |
| 1983 |
{ |
| 1984 |
struct wctdm_stats stats; |
| 1985 |
struct wctdm_regs regs; |
| 1986 |
struct wctdm_regop regop; |
| 1987 |
struct wctdm_echo_coefs echoregs; |
| 1988 |
struct dahdi_hwgain hwgain; |
| 1989 |
struct wctdm *wc = chan->pvt; |
| 1990 |
struct fxs *const fxs = &wc->mod[chan->chanpos - 1].fxs; |
| 1991 |
int x; |
| 1992 |
switch (cmd) { |
| 1993 |
case DAHDI_ONHOOKTRANSFER: |
| 1994 |
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) |
| 1995 |
return -EINVAL; |
| 1996 |
if (get_user(x, (__user int *) data)) |
| 1997 |
return -EFAULT; |
| 1998 |
fxs->ohttimer = x << 3; |
| 1999 |
|
| 2000 |
/* Active mode when idle */ |
| 2001 |
fxs->idletxhookstate = POLARITY_XOR ? |
| 2002 |
SLIC_LF_ACTIVE_REV : SLIC_LF_ACTIVE_FWD; |
| 2003 |
if (fxs->neonringing) { |
| 2004 |
/* keep same Forward polarity */ |
| 2005 |
fxs->lasttxhook = SLIC_LF_OHTRAN_FWD; |
| 2006 |
printk(KERN_INFO "ioctl: Start OnHookTrans, card %d\n", |
| 2007 |
chan->chanpos - 1); |
| 2008 |
wctdm_setreg(wc, chan->chanpos - 1, |
| 2009 |
LINE_STATE, fxs->lasttxhook); |
| 2010 |
} else if (fxs->lasttxhook == SLIC_LF_ACTIVE_FWD || |
| 2011 |
fxs->lasttxhook == SLIC_LF_ACTIVE_REV) { |
| 2012 |
/* Apply the change if appropriate */ |
| 2013 |
fxs->lasttxhook = POLARITY_XOR ? |
| 2014 |
SLIC_LF_OHTRAN_REV : SLIC_LF_OHTRAN_FWD; |
| 2015 |
printk(KERN_INFO "ioctl: Start OnHookTrans, card %d\n", |
| 2016 |
chan->chanpos - 1); |
| 2017 |
wctdm_setreg(wc, chan->chanpos - 1, |
| 2018 |
LINE_STATE, fxs->lasttxhook); |
| 2019 |
} |
| 2020 |
break; |
| 2021 |
case DAHDI_SETPOLARITY: |
| 2022 |
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) |
| 2023 |
return -EINVAL; |
| 2024 |
if (get_user(x, (__user int *) data)) |
| 2025 |
return -EFAULT; |
| 2026 |
/* Can't change polarity while ringing or when open */ |
| 2027 |
if ((fxs->lasttxhook == SLIC_LF_RINGING) || |
| 2028 |
(fxs->lasttxhook == SLIC_LF_OPEN)) |
| 2029 |
return -EINVAL; |
| 2030 |
fxs->reversepolarity = x; |
| 2031 |
if (POLARITY_XOR) { |
| 2032 |
fxs->lasttxhook |= SLIC_LF_REVMASK; |
| 2033 |
printk(KERN_INFO "ioctl: Reverse Polarity, card %d\n", |
| 2034 |
chan->chanpos - 1); |
| 2035 |
} else { |
| 2036 |
fxs->lasttxhook &= ~SLIC_LF_REVMASK; |
| 2037 |
printk(KERN_INFO "ioctl: Normal Polarity, card %d\n", |
| 2038 |
chan->chanpos - 1); |
| 2039 |
} |
| 2040 |
wctdm_setreg(wc, chan->chanpos - 1, |
| 2041 |
LINE_STATE, fxs->lasttxhook); |
| 2042 |
break; |
| 2043 |
case DAHDI_VMWI_CONFIG: |
| 2044 |
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) |
| 2045 |
return -EINVAL; |
| 2046 |
if (copy_from_user(&(fxs->vmwisetting), (__user void *) data, |
| 2047 |
sizeof(fxs->vmwisetting))) |
| 2048 |
return -EFAULT; |
| 2049 |
set_vmwi(wc, chan->chanpos - 1); |
| 2050 |
break; |
| 2051 |
case DAHDI_VMWI: |
| 2052 |
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) |
| 2053 |
return -EINVAL; |
| 2054 |
if (get_user(x, (__user int *) data)) |
| 2055 |
return -EFAULT; |
| 2056 |
if (0 > x) |
| 2057 |
return -EFAULT; |
| 2058 |
fxs->vmwi_active_messages = x; |
| 2059 |
set_vmwi(wc, chan->chanpos - 1); |
| 2060 |
break; |
| 2061 |
case WCTDM_GET_STATS: |
| 2062 |
if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) { |
| 2063 |
stats.tipvolt = wctdm_getreg(wc, chan->chanpos - 1, 80) * -376; |
| 2064 |
stats.ringvolt = wctdm_getreg(wc, chan->chanpos - 1, 81) * -376; |
| 2065 |
stats.batvolt = wctdm_getreg(wc, chan->chanpos - 1, 82) * -376; |
| 2066 |
} else if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXO) { |
| 2067 |
stats.tipvolt = (signed char)wctdm_getreg(wc, chan->chanpos - 1, 29) * 1000; |
| 2068 |
stats.ringvolt = (signed char)wctdm_getreg(wc, chan->chanpos - 1, 29) * 1000; |
| 2069 |
stats.batvolt = (signed char)wctdm_getreg(wc, chan->chanpos - 1, 29) * 1000; |
| 2070 |
} else |
| 2071 |
return -EINVAL; |
| 2072 |
if (copy_to_user((__user void *)data, &stats, sizeof(stats))) |
| 2073 |
return -EFAULT; |
| 2074 |
break; |
| 2075 |
case WCTDM_GET_REGS: |
| 2076 |
if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) { |
| 2077 |
for (x=0;x<NUM_INDIRECT_REGS;x++) |
| 2078 |
regs.indirect[x] = wctdm_proslic_getreg_indirect(wc, chan->chanpos -1, x); |
| 2079 |
for (x=0;x<NUM_REGS;x++) |
| 2080 |
regs.direct[x] = wctdm_getreg(wc, chan->chanpos - 1, x); |
| 2081 |
} else { |
| 2082 |
memset(®s, 0, sizeof(regs)); |
| 2083 |
for (x=0;x<NUM_FXO_REGS;x++) |
| 2084 |
regs.direct[x] = wctdm_getreg(wc, chan->chanpos - 1, x); |
| 2085 |
} |
| 2086 |
if (copy_to_user((__user void *)data, ®s, sizeof(regs))) |
| 2087 |
return -EFAULT; |
| 2088 |
break; |
| 2089 |
case WCTDM_SET_REG: |
| 2090 |
if (copy_from_user(®op, (__user void *) data, sizeof(regop))) |
| 2091 |
return -EFAULT; |
| 2092 |
if (regop.indirect) { |
| 2093 |
if (wc->modtype[chan->chanpos - 1] != MOD_TYPE_FXS) |
| 2094 |
return -EINVAL; |
| 2095 |
printk(KERN_INFO "Setting indirect %d to 0x%04x on %d\n", regop.reg, regop.val, chan->chanpos); |
| 2096 |
wctdm_proslic_setreg_indirect(wc, chan->chanpos - 1, regop.reg, regop.val); |
| 2097 |
} else { |
| 2098 |
regop.val &= 0xff; |
| 2099 |
printk(KERN_INFO "Setting direct %d to %04x on %d\n", regop.reg, regop.val, chan->chanpos); |
| 2100 |
wctdm_setreg(wc, chan->chanpos - 1, regop.reg, regop.val); |
| 2101 |
} |
| 2102 |
break; |
| 2103 |
case WCTDM_SET_ECHOTUNE: |
| 2104 |
printk(KERN_INFO "-- Setting echo registers: \n"); |
| 2105 |
if (copy_from_user(&echoregs, (__user void *)data, sizeof(echoregs))) |
| 2106 |
return -EFAULT; |
| 2107 |
|
| 2108 |
if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXO) { |
| 2109 |
/* Set the ACIM register */ |
| 2110 |
wctdm_setreg(wc, chan->chanpos - 1, 30, echoregs.acim); |
| 2111 |
|
| 2112 |
/* Set the digital echo canceller registers */ |
| 2113 |
wctdm_setreg(wc, chan->chanpos - 1, 45, echoregs.coef1); |
| 2114 |
wctdm_setreg(wc, chan->chanpos - 1, 46, echoregs.coef2); |
| 2115 |
wctdm_setreg(wc, chan->chanpos - 1, 47, echoregs.coef3); |
| 2116 |
wctdm_setreg(wc, chan->chanpos - 1, 48, echoregs.coef4); |
| 2117 |
wctdm_setreg(wc, chan->chanpos - 1, 49, echoregs.coef5); |
| 2118 |
wctdm_setreg(wc, chan->chanpos - 1, 50, echoregs.coef6); |
| 2119 |
wctdm_setreg(wc, chan->chanpos - 1, 51, echoregs.coef7); |
| 2120 |
wctdm_setreg(wc, chan->chanpos - 1, 52, echoregs.coef8); |
| 2121 |
|
| 2122 |
printk(KERN_INFO "-- Set echo registers successfully\n"); |
| 2123 |
|
| 2124 |
break; |
| 2125 |
} else { |
| 2126 |
return -EINVAL; |
| 2127 |
|
| 2128 |
} |
| 2129 |
break; |
| 2130 |
case DAHDI_SET_HWGAIN: |
| 2131 |
if (copy_from_user(&hwgain, (__user void *) data, sizeof(hwgain))) |
| 2132 |
return -EFAULT; |
| 2133 |
|
| 2134 |
wctdm_set_hwgain(wc, chan->chanpos-1, hwgain.newgain, hwgain.tx); |
| 2135 |
|
| 2136 |
if (debug) |
| 2137 |
printk(KERN_DEBUG "Setting hwgain on channel %d to %d for %s direction\n", |
| 2138 |
chan->chanpos-1, hwgain.newgain, hwgain.tx ? "tx" : "rx"); |
| 2139 |
break; |
| 2140 |
default: |
| 2141 |
return -ENOTTY; |
| 2142 |
} |
| 2143 |
return 0; |
| 2144 |
|
| 2145 |
} |
| 2146 |
|
| 2147 |
static int _wctdm_open(struct dahdi_chan *chan) |
| 2148 |
{ |
| 2149 |
struct wctdm *wc = chan->pvt; |
| 2150 |
if (!(wc->cardflag & (1 << (chan->chanpos - 1)))) |
| 2151 |
return -ENODEV; |
| 2152 |
if (wc->dead) |
| 2153 |
return -ENODEV; |
| 2154 |
wc->usecount++; |
| 2155 |
return 0; |
| 2156 |
} |
| 2157 |
|
| 2158 |
static int wctdm_open(struct dahdi_chan *chan) |
| 2159 |
{ |
| 2160 |
unsigned long flags; |
| 2161 |
int res; |
| 2162 |
spin_lock_irqsave(&chan->lock, flags); |
| 2163 |
res = _wctdm_open(chan); |
| 2164 |
spin_unlock_irqrestore(&chan->lock, flags); |
| 2165 |
return res; |
| 2166 |
} |
| 2167 |
|
| 2168 |
static inline struct wctdm *wctdm_from_span(struct dahdi_span *span) |
| 2169 |
{ |
| 2170 |
return container_of(span, struct wctdm, span); |
| 2171 |
} |
| 2172 |
|
| 2173 |
static int wctdm_watchdog(struct dahdi_span *span, int event) |
| 2174 |
{ |
| 2175 |
printk(KERN_INFO "TDM: Restarting DMA\n"); |
| 2176 |
wctdm_restart_dma(wctdm_from_span(span)); |
| 2177 |
return 0; |
| 2178 |
} |
| 2179 |
|
| 2180 |
static int wctdm_close(struct dahdi_chan *chan) |
| 2181 |
{ |
| 2182 |
struct wctdm *wc = chan->pvt; |
| 2183 |
struct fxs *const fxs = &wc->mod[chan->chanpos - 1].fxs; |
| 2184 |
wc->usecount--; |
| 2185 |
if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) { |
| 2186 |
int idlehookstate; |
| 2187 |
idlehookstate = POLARITY_XOR ? |
| 2188 |
SLIC_LF_ACTIVE_REV : |
| 2189 |
SLIC_LF_ACTIVE_FWD; |
| 2190 |
fxs->idletxhookstate = idlehookstate; |
| 2191 |
} |
| 2192 |
/* If we're dead, release us now */ |
| 2193 |
if (!wc->usecount && wc->dead) |
| 2194 |
wctdm_release(wc); |
| 2195 |
return 0; |
| 2196 |
} |
| 2197 |
|
| 2198 |
static int wctdm_init_ring_generator_mode(struct wctdm *wc, int card) |
| 2199 |
{ |
| 2200 |
wctdm_setreg(wc, card, 34, 0x00); /* Ringing Osc. Control */ |
| 2201 |
|
| 2202 |
/* neon trapezoid timers */ |
| 2203 |
wctdm_setreg(wc, card, 48, 0xe0); /* Active Timer low byte */ |
| 2204 |
wctdm_setreg(wc, card, 49, 0x01); /* Active Timer high byte */ |
| 2205 |
wctdm_setreg(wc, card, 50, 0xF0); /* Inactive Timer low byte */ |
| 2206 |
wctdm_setreg(wc, card, 51, 0x05); /* Inactive Timer high byte */ |
| 2207 |
|
| 2208 |
wctdm_set_ring_generator_mode(wc, card, 0); |
| 2209 |
|
| 2210 |
return 0; |
| 2211 |
} |
| 2212 |
|
| 2213 |
static int wctdm_set_ring_generator_mode(struct wctdm *wc, int card, int mode) |
| 2214 |
{ |
| 2215 |
int reg20, reg21, reg74; /* RCO, RNGX, VBATH */ |
| 2216 |
struct fxs *const fxs = &wc->mod[card].fxs; |
| 2217 |
|
| 2218 |
fxs->neonringing = mode; /* track ring generator mode */ |
| 2219 |
|
| 2220 |
if (mode) { /* Neon */ |
| 2221 |
if (debug) |
| 2222 |
printk(KERN_DEBUG "NEON ring on chan %d, " |
| 2223 |
"lasttxhook was 0x%x\n", card, fxs->lasttxhook); |
| 2224 |
/* Must be in FORWARD ACTIVE before setting ringer */ |
| 2225 |
fxs->lasttxhook = SLIC_LF_ACTIVE_FWD; |
| 2226 |
wctdm_setreg(wc, card, LINE_STATE, fxs->lasttxhook); |
| 2227 |
|
| 2228 |
wctdm_proslic_setreg_indirect(wc, card, 22, |
| 2229 |
NEON_MWI_RNGY_PULSEWIDTH); |
| 2230 |
wctdm_proslic_setreg_indirect(wc, card, 21, |
| 2231 |
0x7bef); /* RNGX (91.5Vpk) */ |
| 2232 |
wctdm_proslic_setreg_indirect(wc, card, 20, |
| 2233 |
0x009f); /* RCO (RNGX, t rise)*/ |
| 2234 |
|
| 2235 |
wctdm_setreg(wc, card, 34, 0x19); /* Ringing Osc. Control */ |
| 2236 |
wctdm_setreg(wc, card, 74, 0x3f); /* VBATH 94.5V */ |
| 2237 |
wctdm_proslic_setreg_indirect(wc, card, 29, 0x4600); /* RPTP */ |
| 2238 |
/* A write of 0x04 to register 64 will turn on the VM led */ |
| 2239 |
} else { |
| 2240 |
wctdm_setreg(wc, card, 34, 0x00); /* Ringing Osc. Control */ |
| 2241 |
/* RNGY Initial Phase */ |
| 2242 |
wctdm_proslic_setreg_indirect(wc, card, 22, 0x0000); |
| 2243 |
wctdm_proslic_setreg_indirect(wc, card, 29, 0x3600); /* RPTP */ |
| 2244 |
/* A write of 0x04 to register 64 will turn on the ringer */ |
| 2245 |
|
| 2246 |
if (fastringer) { |
| 2247 |
/* Speed up Ringer */ |
| 2248 |
reg20 = 0x7e6d; |
| 2249 |
reg74 = 0x32; /* Default */ |
| 2250 |
/* Beef up Ringing voltage to 89V */ |
| 2251 |
if (boostringer) { |
| 2252 |
reg74 = 0x3f; |
| 2253 |
reg21 = 0x0247; /* RNGX */ |
| 2254 |
if (debug) |
| 2255 |
printk(KERN_DEBUG "Boosting fast ringer" |
| 2256 |
" on chan %d (89V peak)\n", |
| 2257 |
card); |
| 2258 |
} else if (lowpower) { |
| 2259 |
reg21 = 0x014b; /* RNGX */ |
| 2260 |
if (debug) |
| 2261 |
printk(KERN_DEBUG "Reducing fast ring " |
| 2262 |
"power on chan %d (50V peak)\n", |
| 2263 |
card); |
| 2264 |
} else if (fxshonormode && |
| 2265 |
fxo_modes[_opermode].ring_x) { |
| 2266 |
reg21 = fxo_modes[_opermode].ring_x; |
| 2267 |
if (debug) |
| 2268 |
printk(KERN_DEBUG "fxshonormode: fast " |
| 2269 |
"ring_x power on chan %d\n", |
| 2270 |
card); |
| 2271 |
} else { |
| 2272 |
reg21 = 0x01b9; |
| 2273 |
if (debug) |
| 2274 |
printk(KERN_DEBUG "Speeding up ringer " |
| 2275 |
"on chan %d (25Hz)\n", |
| 2276 |
card); |
| 2277 |
} |
| 2278 |
/* VBATH */ |
| 2279 |
wctdm_setreg(wc, card, 74, reg74); |
| 2280 |
/*RCO*/ |
| 2281 |
wctdm_proslic_setreg_indirect(wc, card, 20, reg20); |
| 2282 |
/*RNGX*/ |
| 2283 |
wctdm_proslic_setreg_indirect(wc, card, 21, reg21); |
| 2284 |
|
| 2285 |
} else { |
| 2286 |
/* Ringer Speed */ |
| 2287 |
if (fxshonormode && fxo_modes[_opermode].ring_osc) { |
| 2288 |
reg20 = fxo_modes[_opermode].ring_osc; |
| 2289 |
if (debug) |
| 2290 |
printk(KERN_DEBUG "fxshonormode: " |
| 2291 |
"ring_osc speed on chan %d\n", |
| 2292 |
card); |
| 2293 |
} else { |
| 2294 |
reg20 = 0x7ef0; /* Default */ |
| 2295 |
} |
| 2296 |
|
| 2297 |
reg74 = 0x32; /* Default */ |
| 2298 |
/* Beef up Ringing voltage to 89V */ |
| 2299 |
if (boostringer) { |
| 2300 |
reg74 = 0x3f; |
| 2301 |
reg21 = 0x1d1; |
| 2302 |
if (debug) |
| 2303 |
printk(KERN_DEBUG "Boosting ringer on " |
| 2304 |
"chan %d (89V peak)\n", |
| 2305 |
card); |
| 2306 |
} else if (lowpower) { |
| 2307 |
reg21 = 0x108; |
| 2308 |
if (debug) |
| 2309 |
printk(KERN_DEBUG "Reducing ring power " |
| 2310 |
"on chan %d (50V peak)\n", |
| 2311 |
card); |
| 2312 |
} else if (fxshonormode && |
| 2313 |
fxo_modes[_opermode].ring_x) { |
| 2314 |
reg21 = fxo_modes[_opermode].ring_x; |
| 2315 |
if (debug) |
| 2316 |
printk(KERN_DEBUG "fxshonormode: ring_x" |
| 2317 |
" power on chan %d\n", |
| 2318 |
card); |
| 2319 |
} else { |
| 2320 |
reg21 = 0x160; |
| 2321 |
if (debug) |
| 2322 |
printk(KERN_DEBUG "Normal ring power on" |
| 2323 |
" chan %d\n", |
| 2324 |
card); |
| 2325 |
} |
| 2326 |
/* VBATH */ |
| 2327 |
wctdm_setreg(wc, card, 74, reg74); |
| 2328 |
/* RCO */ |
| 2329 |
wctdm_proslic_setreg_indirect(wc, card, 20, reg20); |
| 2330 |
/* RNGX */ |
| 2331 |
wctdm_proslic_setreg_indirect(wc, card, 21, reg21); |
| 2332 |
} |
| 2333 |
} |
| 2334 |
return 0; |
| 2335 |
} |
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
static int wctdm_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) |
| 2340 |
{ |
| 2341 |
struct wctdm *wc = chan->pvt; |
| 2342 |
int chan_entry = chan->chanpos - 1; |
| 2343 |
if (wc->modtype[chan_entry] == MOD_TYPE_FXO) { |
| 2344 |
/* XXX Enable hooksig for FXO XXX */ |
| 2345 |
switch(txsig) { |
| 2346 |
case DAHDI_TXSIG_START: |
| 2347 |
case DAHDI_TXSIG_OFFHOOK: |
| 2348 |
wc->mod[chan_entry].fxo.offhook = 1; |
| 2349 |
wctdm_setreg(wc, chan_entry, 5, 0x9); |
| 2350 |
break; |
| 2351 |
case DAHDI_TXSIG_ONHOOK: |
| 2352 |
wc->mod[chan_entry].fxo.offhook = 0; |
| 2353 |
wctdm_setreg(wc, chan_entry, 5, 0x8); |
| 2354 |
break; |
| 2355 |
default: |
| 2356 |
printk(KERN_NOTICE "wcfxo: Can't set tx state to %d\n", txsig); |
| 2357 |
} |
| 2358 |
} else { |
| 2359 |
wctdm_fxs_hooksig(wc, chan_entry, txsig); |
| 2360 |
} |
| 2361 |
return 0; |
| 2362 |
} |
| 2363 |
|
| 2364 |
static const struct dahdi_span_ops wctdm_span_ops = { |
| 2365 |
.owner = THIS_MODULE, |
| 2366 |
.hooksig = wctdm_hooksig, |
| 2367 |
.open = wctdm_open, |
| 2368 |
.close = wctdm_close, |
| 2369 |
.ioctl = wctdm_ioctl, |
| 2370 |
.watchdog = wctdm_watchdog, |
| 2371 |
}; |
| 2372 |
|
| 2373 |
static int wctdm_initialize(struct wctdm *wc) |
| 2374 |
{ |
| 2375 |
int x; |
| 2376 |
|
| 2377 |
wc->ddev = dahdi_create_device(); |
| 2378 |
if (!wc->ddev) |
| 2379 |
return -ENOMEM; |
| 2380 |
|
| 2381 |
/* DAHDI stuff */ |
| 2382 |
sprintf(wc->span.name, "WCTDM/%d", wc->pos); |
| 2383 |
snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1); |
| 2384 |
wc->ddev->location = kasprintf(GFP_KERNEL, |
| 2385 |
"PCI Bus %02d Slot %02d", |
| 2386 |
wc->dev->bus->number, |
| 2387 |
PCI_SLOT(wc->dev->devfn) + 1); |
| 2388 |
if (!wc->ddev->location) { |
| 2389 |
dahdi_free_device(wc->ddev); |
| 2390 |
wc->ddev = NULL; |
| 2391 |
return -ENOMEM; |
| 2392 |
} |
| 2393 |
|
| 2394 |
wc->ddev->manufacturer = "Digium"; |
| 2395 |
wc->ddev->devicetype = wc->variety; |
| 2396 |
|
| 2397 |
if (alawoverride) { |
| 2398 |
printk(KERN_INFO "ALAW override parameter detected. Device will be operating in ALAW\n"); |
| 2399 |
wc->span.deflaw = DAHDI_LAW_ALAW; |
| 2400 |
} else { |
| 2401 |
wc->span.deflaw = DAHDI_LAW_MULAW; |
| 2402 |
} |
| 2403 |
for (x = 0; x < NUM_CARDS; x++) { |
| 2404 |
sprintf(wc->chans[x]->name, "WCTDM/%d/%d", wc->pos, x); |
| 2405 |
wc->chans[x]->sigcap = DAHDI_SIG_FXOKS | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_SF | DAHDI_SIG_EM | DAHDI_SIG_CLEAR; |
| 2406 |
wc->chans[x]->sigcap |= DAHDI_SIG_FXSKS | DAHDI_SIG_FXSLS | DAHDI_SIG_SF | DAHDI_SIG_CLEAR; |
| 2407 |
wc->chans[x]->chanpos = x+1; |
| 2408 |
wc->chans[x]->pvt = wc; |
| 2409 |
} |
| 2410 |
wc->span.chans = wc->chans; |
| 2411 |
wc->span.channels = NUM_CARDS; |
| 2412 |
wc->span.flags = DAHDI_FLAG_RBS; |
| 2413 |
wc->span.ops = &wctdm_span_ops; |
| 2414 |
wc->span.spantype = SPANTYPE_ANALOG_MIXED; |
| 2415 |
|
| 2416 |
list_add_tail(&wc->span.device_node, &wc->ddev->spans); |
| 2417 |
if (dahdi_register_device(wc->ddev, &wc->dev->dev)) { |
| 2418 |
printk(KERN_NOTICE "Unable to register span with DAHDI\n"); |
| 2419 |
kfree(wc->ddev->location); |
| 2420 |
dahdi_free_device(wc->ddev); |
| 2421 |
wc->ddev = NULL; |
| 2422 |
return -1; |
| 2423 |
} |
| 2424 |
return 0; |
| 2425 |
} |
| 2426 |
|
| 2427 |
static void wctdm_post_initialize(struct wctdm *wc) |
| 2428 |
{ |
| 2429 |
int x; |
| 2430 |
|
| 2431 |
/* Finalize signalling */ |
| 2432 |
for (x = 0; x < NUM_CARDS; x++) { |
| 2433 |
if (wc->cardflag & (1 << x)) { |
| 2434 |
if (wc->modtype[x] == MOD_TYPE_FXO) |
| 2435 |
wc->chans[x]->sigcap = DAHDI_SIG_FXSKS | DAHDI_SIG_FXSLS | DAHDI_SIG_SF | DAHDI_SIG_CLEAR; |
| 2436 |
else |
| 2437 |
wc->chans[x]->sigcap = DAHDI_SIG_FXOKS | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_SF | DAHDI_SIG_EM | DAHDI_SIG_CLEAR; |
| 2438 |
} else if (!(wc->chans[x]->sigcap & DAHDI_SIG_BROKEN)) { |
| 2439 |
wc->chans[x]->sigcap = 0; |
| 2440 |
} |
| 2441 |
} |
| 2442 |
} |
| 2443 |
|
| 2444 |
static int wctdm_hardware_init(struct wctdm *wc) |
| 2445 |
{ |
| 2446 |
/* Hardware stuff */ |
| 2447 |
unsigned char ver; |
| 2448 |
unsigned char x,y; |
| 2449 |
int failed; |
| 2450 |
|
| 2451 |
/* Signal Reset */ |
| 2452 |
outb(0x01, wc->ioaddr + WC_CNTL); |
| 2453 |
|
| 2454 |
/* Check Freshmaker chip */ |
| 2455 |
x=inb(wc->ioaddr + WC_CNTL); |
| 2456 |
ver = __wctdm_getcreg(wc, WC_VER); |
| 2457 |
failed = 0; |
| 2458 |
if (ver != 0x59) { |
| 2459 |
printk(KERN_INFO "Freshmaker version: %02x\n", ver); |
| 2460 |
for (x=0;x<255;x++) { |
| 2461 |
/* Test registers */ |
| 2462 |
if (ver >= 0x70) { |
| 2463 |
__wctdm_setcreg(wc, WC_CS, x); |
| 2464 |
y = __wctdm_getcreg(wc, WC_CS); |
| 2465 |
} else { |
| 2466 |
__wctdm_setcreg(wc, WC_TEST, x); |
| 2467 |
y = __wctdm_getcreg(wc, WC_TEST); |
| 2468 |
} |
| 2469 |
if (x != y) { |
| 2470 |
printk(KERN_INFO "%02x != %02x\n", x, y); |
| 2471 |
failed++; |
| 2472 |
} |
| 2473 |
} |
| 2474 |
if (!failed) { |
| 2475 |
printk(KERN_INFO "Freshmaker passed register test\n"); |
| 2476 |
} else { |
| 2477 |
printk(KERN_NOTICE "Freshmaker failed register test\n"); |
| 2478 |
return -1; |
| 2479 |
} |
| 2480 |
/* Go to half-duty FSYNC */ |
| 2481 |
__wctdm_setcreg(wc, WC_SYNC, 0x01); |
| 2482 |
y = __wctdm_getcreg(wc, WC_SYNC); |
| 2483 |
} else { |
| 2484 |
printk(KERN_INFO "No freshmaker chip\n"); |
| 2485 |
} |
| 2486 |
|
| 2487 |
/* Reset PCI Interface chip and registers (and serial) */ |
| 2488 |
outb(0x06, wc->ioaddr + WC_CNTL); |
| 2489 |
/* Setup our proper outputs for when we switch for our "serial" port */ |
| 2490 |
wc->ios = BIT_CS | BIT_SCLK | BIT_SDI; |
| 2491 |
|
| 2492 |
outb(wc->ios, wc->ioaddr + WC_AUXD); |
| 2493 |
|
| 2494 |
/* Set all to outputs except AUX 5, which is an input */ |
| 2495 |
outb(0xdf, wc->ioaddr + WC_AUXC); |
| 2496 |
|
| 2497 |
/* Select alternate function for AUX0 */ |
| 2498 |
outb(0x4, wc->ioaddr + WC_AUXFUNC); |
| 2499 |
|
| 2500 |
/* Wait 1/4 of a sec */ |
| 2501 |
wait_just_a_bit(HZ/4); |
| 2502 |
|
| 2503 |
/* Back to normal, with automatic DMA wrap around */ |
| 2504 |
outb(0x30 | 0x01, wc->ioaddr + WC_CNTL); |
| 2505 |
|
| 2506 |
/* Make sure serial port and DMA are out of reset */ |
| 2507 |
outb(inb(wc->ioaddr + WC_CNTL) & 0xf9, wc->ioaddr + WC_CNTL); |
| 2508 |
|
| 2509 |
/* Configure serial port for MSB->LSB operation */ |
| 2510 |
outb(0xc1, wc->ioaddr + WC_SERCTL); |
| 2511 |
|
| 2512 |
/* Delay FSC by 0 so it's properly aligned */ |
| 2513 |
outb(0x0, wc->ioaddr + WC_FSCDELAY); |
| 2514 |
|
| 2515 |
/* Setup DMA Addresses */ |
| 2516 |
outl(wc->writedma, wc->ioaddr + WC_DMAWS); /* Write start */ |
| 2517 |
outl(wc->writedma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMAWI); /* Middle (interrupt) */ |
| 2518 |
outl(wc->writedma + DAHDI_CHUNKSIZE * 8 - 4, wc->ioaddr + WC_DMAWE); /* End */ |
| 2519 |
|
| 2520 |
outl(wc->readdma, wc->ioaddr + WC_DMARS); /* Read start */ |
| 2521 |
outl(wc->readdma + DAHDI_CHUNKSIZE * 4 - 4, wc->ioaddr + WC_DMARI); /* Middle (interrupt) */ |
| 2522 |
outl(wc->readdma + DAHDI_CHUNKSIZE * 8 - 4, wc->ioaddr + WC_DMARE); /* End */ |
| 2523 |
|
| 2524 |
/* Clear interrupts */ |
| 2525 |
outb(0xff, wc->ioaddr + WC_INTSTAT); |
| 2526 |
|
| 2527 |
/* Wait 1/4 of a second more */ |
| 2528 |
wait_just_a_bit(HZ/4); |
| 2529 |
|
| 2530 |
for (x = 0; x < NUM_CARDS; x++) { |
| 2531 |
int sane=0,ret=0,readi=0; |
| 2532 |
#if 1 |
| 2533 |
/* Init with Auto Calibration */ |
| 2534 |
if (!(ret=wctdm_init_proslic(wc, x, 0, 0, sane))) { |
| 2535 |
wc->cardflag |= (1 << x); |
| 2536 |
if (debug) { |
| 2537 |
readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); |
| 2538 |
printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, |
| 2539 |
((readi*3)+20)); |
| 2540 |
} |
| 2541 |
printk(KERN_INFO "Module %d: Installed -- AUTO FXS/DPO\n",x); |
| 2542 |
} else { |
| 2543 |
if(ret!=-2) { |
| 2544 |
sane=1; |
| 2545 |
/* Init with Manual Calibration */ |
| 2546 |
if (!wctdm_init_proslic(wc, x, 0, 1, sane)) { |
| 2547 |
wc->cardflag |= (1 << x); |
| 2548 |
if (debug) { |
| 2549 |
readi = wctdm_getreg(wc,x,LOOP_I_LIMIT); |
| 2550 |
printk(KERN_DEBUG "Proslic module %d loop current is %dmA\n",x, |
| 2551 |
((readi*3)+20)); |
| 2552 |
} |
| 2553 |
printk(KERN_INFO "Module %d: Installed -- MANUAL FXS\n",x); |
| 2554 |
} else { |
| 2555 |
printk(KERN_NOTICE "Module %d: FAILED FXS (%s)\n", x, fxshonormode ? fxo_modes[_opermode].name : "FCC"); |
| 2556 |
wc->chans[x]->sigcap = __DAHDI_SIG_FXO | DAHDI_SIG_BROKEN; |
| 2557 |
} |
| 2558 |
} else if (!(ret = wctdm_init_voicedaa(wc, x, 0, 0, sane))) { |
| 2559 |
wc->cardflag |= (1 << x); |
| 2560 |
printk(KERN_INFO "Module %d: Installed -- AUTO FXO (%s mode)\n",x, fxo_modes[_opermode].name); |
| 2561 |
} else |
| 2562 |
printk(KERN_NOTICE "Module %d: Not installed\n", x); |
| 2563 |
} |
| 2564 |
#endif |
| 2565 |
} |
| 2566 |
|
| 2567 |
/* Return error if nothing initialized okay. */ |
| 2568 |
if (!wc->cardflag && !timingonly) |
| 2569 |
return -1; |
| 2570 |
__wctdm_setcreg(wc, WC_SYNC, (wc->cardflag << 1) | 0x1); |
| 2571 |
return 0; |
| 2572 |
} |
| 2573 |
|
| 2574 |
static void wctdm_enable_interrupts(struct wctdm *wc) |
| 2575 |
{ |
| 2576 |
/* Enable interrupts (we care about all of them) */ |
| 2577 |
outb(0x3f, wc->ioaddr + WC_MASK0); |
| 2578 |
/* No external interrupts */ |
| 2579 |
outb(0x00, wc->ioaddr + WC_MASK1); |
| 2580 |
} |
| 2581 |
|
| 2582 |
static void wctdm_restart_dma(struct wctdm *wc) |
| 2583 |
{ |
| 2584 |
/* Reset Master and TDM */ |
| 2585 |
outb(0x01, wc->ioaddr + WC_CNTL); |
| 2586 |
outb(0x01, wc->ioaddr + WC_OPER); |
| 2587 |
} |
| 2588 |
|
| 2589 |
static void wctdm_start_dma(struct wctdm *wc) |
| 2590 |
{ |
| 2591 |
/* Reset Master and TDM */ |
| 2592 |
outb(0x0f, wc->ioaddr + WC_CNTL); |
| 2593 |
set_current_state(TASK_INTERRUPTIBLE); |
| 2594 |
schedule_timeout(1); |
| 2595 |
outb(0x01, wc->ioaddr + WC_CNTL); |
| 2596 |
outb(0x01, wc->ioaddr + WC_OPER); |
| 2597 |
} |
| 2598 |
|
| 2599 |
static void wctdm_stop_dma(struct wctdm *wc) |
| 2600 |
{ |
| 2601 |
outb(0x00, wc->ioaddr + WC_OPER); |
| 2602 |
} |
| 2603 |
|
| 2604 |
static void wctdm_reset_tdm(struct wctdm *wc) |
| 2605 |
{ |
| 2606 |
/* Reset TDM */ |
| 2607 |
outb(0x0f, wc->ioaddr + WC_CNTL); |
| 2608 |
} |
| 2609 |
|
| 2610 |
static void wctdm_disable_interrupts(struct wctdm *wc) |
| 2611 |
{ |
| 2612 |
outb(0x00, wc->ioaddr + WC_MASK0); |
| 2613 |
outb(0x00, wc->ioaddr + WC_MASK1); |
| 2614 |
} |
| 2615 |
|
| 2616 |
static int __devinit wctdm_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2617 |
{ |
| 2618 |
int res; |
| 2619 |
struct wctdm *wc; |
| 2620 |
struct wctdm_desc *d = (struct wctdm_desc *)ent->driver_data; |
| 2621 |
int x; |
| 2622 |
int y; |
| 2623 |
|
| 2624 |
for (x=0;x<WC_MAX_IFACES;x++) |
| 2625 |
if (!ifaces[x]) break; |
| 2626 |
if (x >= WC_MAX_IFACES) { |
| 2627 |
printk(KERN_NOTICE "Too many interfaces\n"); |
| 2628 |
return -EIO; |
| 2629 |
} |
| 2630 |
|
| 2631 |
if (pci_enable_device(pdev)) { |
| 2632 |
res = -EIO; |
| 2633 |
} else { |
| 2634 |
wc = kmalloc(sizeof(struct wctdm), GFP_KERNEL); |
| 2635 |
if (wc) { |
| 2636 |
int cardcount = 0; |
| 2637 |
|
| 2638 |
ifaces[x] = wc; |
| 2639 |
memset(wc, 0, sizeof(struct wctdm)); |
| 2640 |
for (x=0; x < sizeof(wc->chans)/sizeof(wc->chans[0]); ++x) { |
| 2641 |
wc->chans[x] = &wc->_chans[x]; |
| 2642 |
} |
| 2643 |
spin_lock_init(&wc->lock); |
| 2644 |
wc->curcard = -1; |
| 2645 |
wc->ioaddr = pci_resource_start(pdev, 0); |
| 2646 |
wc->dev = pdev; |
| 2647 |
wc->pos = x; |
| 2648 |
wc->variety = d->name; |
| 2649 |
for (y=0;y<NUM_CARDS;y++) |
| 2650 |
wc->flags[y] = d->flags; |
| 2651 |
/* Keep track of whether we need to free the region */ |
| 2652 |
if (request_region(wc->ioaddr, 0xff, "wctdm")) |
| 2653 |
wc->freeregion = 1; |
| 2654 |
|
| 2655 |
/* Allocate enough memory for two zt chunks, receive and transmit. Each sample uses |
| 2656 |
32 bits. Allocate an extra set just for control too */ |
| 2657 |
wc->writechunk = pci_alloc_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, &wc->writedma); |
| 2658 |
if (!wc->writechunk) { |
| 2659 |
printk(KERN_NOTICE "wctdm: Unable to allocate DMA-able memory\n"); |
| 2660 |
if (wc->freeregion) |
| 2661 |
release_region(wc->ioaddr, 0xff); |
| 2662 |
return -ENOMEM; |
| 2663 |
} |
| 2664 |
|
| 2665 |
wc->readchunk = wc->writechunk + DAHDI_MAX_CHUNKSIZE * 2; /* in doublewords */ |
| 2666 |
wc->readdma = wc->writedma + DAHDI_MAX_CHUNKSIZE * 8; /* in bytes */ |
| 2667 |
|
| 2668 |
if (wctdm_initialize(wc)) { |
| 2669 |
printk(KERN_NOTICE "wctdm: Unable to intialize FXS\n"); |
| 2670 |
/* Set Reset Low */ |
| 2671 |
x=inb(wc->ioaddr + WC_CNTL); |
| 2672 |
outb((~0x1)&x, wc->ioaddr + WC_CNTL); |
| 2673 |
/* Free Resources */ |
| 2674 |
free_irq(pdev->irq, wc); |
| 2675 |
if (wc->freeregion) |
| 2676 |
release_region(wc->ioaddr, 0xff); |
| 2677 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma); |
| 2678 |
kfree(wc); |
| 2679 |
return -EIO; |
| 2680 |
} |
| 2681 |
|
| 2682 |
/* Enable bus mastering */ |
| 2683 |
pci_set_master(pdev); |
| 2684 |
|
| 2685 |
/* Keep track of which device we are */ |
| 2686 |
pci_set_drvdata(pdev, wc); |
| 2687 |
|
| 2688 |
if (request_irq(pdev->irq, wctdm_interrupt, |
| 2689 |
IRQF_SHARED, "wctdm", wc)) { |
| 2690 |
printk(KERN_NOTICE "wctdm: Unable to request IRQ %d\n", pdev->irq); |
| 2691 |
if (wc->freeregion) |
| 2692 |
release_region(wc->ioaddr, 0xff); |
| 2693 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma); |
| 2694 |
pci_set_drvdata(pdev, NULL); |
| 2695 |
kfree(wc); |
| 2696 |
return -EIO; |
| 2697 |
} |
| 2698 |
|
| 2699 |
|
| 2700 |
if (wctdm_hardware_init(wc)) { |
| 2701 |
/* Set Reset Low */ |
| 2702 |
x=inb(wc->ioaddr + WC_CNTL); |
| 2703 |
outb((~0x1)&x, wc->ioaddr + WC_CNTL); |
| 2704 |
/* Free Resources */ |
| 2705 |
free_irq(pdev->irq, wc); |
| 2706 |
if (wc->freeregion) |
| 2707 |
release_region(wc->ioaddr, 0xff); |
| 2708 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma); |
| 2709 |
pci_set_drvdata(pdev, NULL); |
| 2710 |
dahdi_unregister_device(wc->ddev); |
| 2711 |
kfree(wc->ddev->location); |
| 2712 |
dahdi_free_device(wc->ddev); |
| 2713 |
kfree(wc); |
| 2714 |
return -EIO; |
| 2715 |
|
| 2716 |
} |
| 2717 |
|
| 2718 |
wctdm_post_initialize(wc); |
| 2719 |
|
| 2720 |
/* Enable interrupts */ |
| 2721 |
wctdm_enable_interrupts(wc); |
| 2722 |
/* Initialize Write/Buffers to all blank data */ |
| 2723 |
memset((void *)wc->writechunk,0,DAHDI_MAX_CHUNKSIZE * 2 * 2 * 4); |
| 2724 |
|
| 2725 |
/* Start DMA */ |
| 2726 |
wctdm_start_dma(wc); |
| 2727 |
|
| 2728 |
for (x = 0; x < NUM_CARDS; x++) { |
| 2729 |
if (wc->cardflag & (1 << x)) |
| 2730 |
cardcount++; |
| 2731 |
} |
| 2732 |
|
| 2733 |
printk(KERN_INFO "Found a Wildcard TDM: %s (%d modules)\n", wc->variety, cardcount); |
| 2734 |
res = 0; |
| 2735 |
} else |
| 2736 |
res = -ENOMEM; |
| 2737 |
} |
| 2738 |
return res; |
| 2739 |
} |
| 2740 |
|
| 2741 |
static void wctdm_release(struct wctdm *wc) |
| 2742 |
{ |
| 2743 |
dahdi_unregister_device(wc->ddev); |
| 2744 |
if (wc->freeregion) |
| 2745 |
release_region(wc->ioaddr, 0xff); |
| 2746 |
|
| 2747 |
kfree(wc->ddev->location); |
| 2748 |
dahdi_free_device(wc->ddev); |
| 2749 |
kfree(wc); |
| 2750 |
|
| 2751 |
printk(KERN_INFO "Freed a Wildcard\n"); |
| 2752 |
} |
| 2753 |
|
| 2754 |
static void __devexit wctdm_remove_one(struct pci_dev *pdev) |
| 2755 |
{ |
| 2756 |
struct wctdm *wc = pci_get_drvdata(pdev); |
| 2757 |
if (wc) { |
| 2758 |
|
| 2759 |
/* Stop any DMA */ |
| 2760 |
wctdm_stop_dma(wc); |
| 2761 |
wctdm_reset_tdm(wc); |
| 2762 |
|
| 2763 |
/* In case hardware is still there */ |
| 2764 |
wctdm_disable_interrupts(wc); |
| 2765 |
|
| 2766 |
/* Immediately free resources */ |
| 2767 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)wc->writechunk, wc->writedma); |
| 2768 |
free_irq(pdev->irq, wc); |
| 2769 |
|
| 2770 |
/* Reset PCI chip and registers */ |
| 2771 |
outb(0x0e, wc->ioaddr + WC_CNTL); |
| 2772 |
|
| 2773 |
/* Release span, possibly delayed */ |
| 2774 |
if (!wc->usecount) |
| 2775 |
wctdm_release(wc); |
| 2776 |
else |
| 2777 |
wc->dead = 1; |
| 2778 |
} |
| 2779 |
} |
| 2780 |
|
| 2781 |
static DEFINE_PCI_DEVICE_TABLE(wctdm_pci_tbl) = { |
| 2782 |
{ 0xe159, 0x0001, 0xa159, PCI_ANY_ID, 0, 0, (unsigned long) &wctdm }, |
| 2783 |
{ 0xe159, 0x0001, 0xe159, PCI_ANY_ID, 0, 0, (unsigned long) &wctdm }, |
| 2784 |
{ 0xe159, 0x0001, 0xb100, PCI_ANY_ID, 0, 0, (unsigned long) &wctdme }, |
| 2785 |
{ 0xe159, 0x0001, 0xb1d9, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmi }, |
| 2786 |
{ 0xe159, 0x0001, 0xb118, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmi }, |
| 2787 |
{ 0xe159, 0x0001, 0xb119, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmi }, |
| 2788 |
{ 0xe159, 0x0001, 0xa9fd, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2789 |
{ 0xe159, 0x0001, 0xa8fd, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2790 |
{ 0xe159, 0x0001, 0xa800, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2791 |
{ 0xe159, 0x0001, 0xa801, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2792 |
{ 0xe159, 0x0001, 0xa908, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2793 |
{ 0xe159, 0x0001, 0xa901, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2794 |
#ifdef TDM_REVH_MATCHALL |
| 2795 |
{ 0xe159, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &wctdmh }, |
| 2796 |
#endif |
| 2797 |
{ 0 } |
| 2798 |
}; |
| 2799 |
|
| 2800 |
MODULE_DEVICE_TABLE(pci, wctdm_pci_tbl); |
| 2801 |
|
| 2802 |
static int wctdm_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2803 |
{ |
| 2804 |
return -ENOSYS; |
| 2805 |
} |
| 2806 |
|
| 2807 |
static struct pci_driver wctdm_driver = { |
| 2808 |
.name = "wctdm", |
| 2809 |
.probe = wctdm_init_one, |
| 2810 |
.remove =__devexit_p(wctdm_remove_one), |
| 2811 |
.suspend = wctdm_suspend, |
| 2812 |
.id_table = wctdm_pci_tbl, |
| 2813 |
}; |
| 2814 |
|
| 2815 |
static int __init wctdm_init(void) |
| 2816 |
{ |
| 2817 |
int res; |
| 2818 |
int x; |
| 2819 |
|
| 2820 |
for (x = 0; x < (sizeof(fxo_modes) / sizeof(fxo_modes[0])); x++) { |
| 2821 |
if (!strcmp(fxo_modes[x].name, opermode)) |
| 2822 |
break; |
| 2823 |
} |
| 2824 |
if (x < sizeof(fxo_modes) / sizeof(fxo_modes[0])) { |
| 2825 |
_opermode = x; |
| 2826 |
} else { |
| 2827 |
printk(KERN_NOTICE "Invalid/unknown operating mode '%s' specified. Please choose one of:\n", opermode); |
| 2828 |
for (x = 0; x < sizeof(fxo_modes) / sizeof(fxo_modes[0]); x++) |
| 2829 |
printk(KERN_INFO " %s\n", fxo_modes[x].name); |
| 2830 |
printk(KERN_INFO "Note this option is CASE SENSITIVE!\n"); |
| 2831 |
return -ENODEV; |
| 2832 |
} |
| 2833 |
|
| 2834 |
if (!strcmp(opermode, "AUSTRALIA")) { |
| 2835 |
boostringer = 1; |
| 2836 |
fxshonormode = 1; |
| 2837 |
} |
| 2838 |
|
| 2839 |
/* for the voicedaa_check_hook defaults, if the user has not overridden |
| 2840 |
them by specifying them as module parameters, then get the values |
| 2841 |
from the selected operating mode |
| 2842 |
*/ |
| 2843 |
if (battdebounce == 0) { |
| 2844 |
battdebounce = fxo_modes[_opermode].battdebounce; |
| 2845 |
} |
| 2846 |
if (battalarm == 0) { |
| 2847 |
battalarm = fxo_modes[_opermode].battalarm; |
| 2848 |
} |
| 2849 |
if (battthresh == 0) { |
| 2850 |
battthresh = fxo_modes[_opermode].battthresh; |
| 2851 |
} |
| 2852 |
|
| 2853 |
res = dahdi_pci_module(&wctdm_driver); |
| 2854 |
if (res) |
| 2855 |
return -ENODEV; |
| 2856 |
return 0; |
| 2857 |
} |
| 2858 |
|
| 2859 |
static void __exit wctdm_cleanup(void) |
| 2860 |
{ |
| 2861 |
pci_unregister_driver(&wctdm_driver); |
| 2862 |
} |
| 2863 |
|
| 2864 |
module_param(debug, int, 0600); |
| 2865 |
module_param(fxovoltage, int, 0600); |
| 2866 |
module_param(loopcurrent, int, 0600); |
| 2867 |
module_param(reversepolarity, int, 0600); |
| 2868 |
module_param(robust, int, 0600); |
| 2869 |
module_param(opermode, charp, 0600); |
| 2870 |
module_param(timingonly, int, 0600); |
| 2871 |
module_param(lowpower, int, 0600); |
| 2872 |
module_param(boostringer, int, 0600); |
| 2873 |
module_param(fastringer, int, 0600); |
| 2874 |
module_param(fxshonormode, int, 0600); |
| 2875 |
module_param(battdebounce, uint, 0600); |
| 2876 |
module_param(battalarm, uint, 0600); |
| 2877 |
module_param(battthresh, uint, 0600); |
| 2878 |
module_param(ringdebounce, int, 0600); |
| 2879 |
module_param(dialdebounce, int, 0600); |
| 2880 |
module_param(fwringdetect, int, 0600); |
| 2881 |
module_param(alawoverride, int, 0600); |
| 2882 |
module_param(fastpickup, int, 0600); |
| 2883 |
module_param(fxotxgain, int, 0600); |
| 2884 |
module_param(fxorxgain, int, 0600); |
| 2885 |
module_param(fxstxgain, int, 0600); |
| 2886 |
module_param(fxsrxgain, int, 0600); |
| 2887 |
|
| 2888 |
MODULE_DESCRIPTION("Wildcard TDM400P Driver"); |
| 2889 |
MODULE_AUTHOR("Mark Spencer <[email protected]>"); |
| 2890 |
MODULE_ALIAS("wcfxs"); |
| 2891 |
MODULE_LICENSE("GPL v2"); |
| 2892 |
|
| 2893 |
module_init(wctdm_init); |
| 2894 |
module_exit(wctdm_cleanup); |