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