~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to xpp/card_fxo.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2006-10-24 22:41:01 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20061024224101-464p4n2jk16n1jrh
Tags: 1:1.2.10.dfsg-2
* bristuff-0.3.0-PRE-1v
* Remove redundant GPL LICENCE text

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "card_fxo.h"
32
32
#include "zap_debug.h"
33
33
 
34
 
static const char rcsid[] = "$Id: card_fxo.c 1230 2006-07-14 20:19:48Z tzafrir $";
 
34
static const char rcsid[] = "$Id: card_fxo.c 1457 2006-09-09 15:24:12Z tzafrir $";
35
35
 
36
36
DEF_PARM(int, print_dbg, 0, "Print DBG statements");    /* must be before zap_debug.h */
37
37
DEF_PARM(uint, poll_battery_interval, 100, "Poll battery interval in milliseconds");
51
51
#define NUM_LEDS                1
52
52
#define DELAY_UNTIL_DIALTONE    3000
53
53
 
 
54
#define BAT_THRESHOLD           3
 
55
#define BAT_DEBOUNCE            3       /* compensate for battery voltage fluctuation (in poll_battery_interval's) */
 
56
 
54
57
/*---------------- FXO Protocol Commands ----------------------------------*/
55
58
 
56
59
static /* 0x0F */ DECLARE_CMD(FXO, CHAN_ENABLE, xpp_line_t lines, bool on);
57
60
static /* 0x0F */ DECLARE_CMD(FXO, CHAN_CID, int pos);
58
61
static /* 0x0F */ DECLARE_CMD(FXO, RING, int pos, bool on);
59
 
static /* 0x0F */ DECLARE_CMD(FXO, SETHOOK, int pos, bool offhook);
60
62
static /* 0x0F */ DECLARE_CMD(FXO, RELAY_OUT, byte which, bool on);
61
63
static /* 0x0F */ DECLARE_CMD(FXO, DAA_QUERY, int pos, byte reg_num);
62
64
 
70
72
#define PROC_DAA_FNAME          "slics"
71
73
#define PROC_FXO_INFO_FNAME     "fxo_info"
72
74
 
 
75
#ifdef SOFT_RING
 
76
#define POLL_RING_INTERVAL      2
 
77
#define RING_THRESHOLD          3
 
78
#define NORING_THRESHOLD        10
 
79
#endif
 
80
#define DAA_RING_REGISTER       0x05
 
81
 
73
82
struct FXO_priv_data {
74
83
        struct proc_dir_entry           *xpd_slic;
75
84
        struct proc_dir_entry           *fxo_info;
 
85
        uint                            poll_counter;
76
86
        slic_reply_t                    requested_reply;
77
87
        slic_reply_t                    last_reply;
78
88
        xpp_line_t                      battery;
 
89
        ushort                          battery_debounce[CHANNELS_PERXPD];
79
90
        xpp_line_t                      ledstate[NUM_LEDS];     /* 0 - OFF, 1 - ON */
 
91
        xpp_line_t                      ledcontrol[NUM_LEDS];   /* 0 - OFF, 1 - ON */
80
92
        int                             blinking[NUM_LEDS][CHANNELS_PERXPD];
 
93
#ifdef SOFT_RING
 
94
        ushort                          ring_thresh[CHANNELS_PERXPD];
 
95
        ushort                          noring_thresh[CHANNELS_PERXPD];
 
96
        /* ring_sig is set when Reg5, bit 2 (Ring Detect) is set. 
 
97
         * While ring_sig=1 we check R5 bit 20H and 40H for ringing. 
 
98
         * When it drops to 0 that's the end of the ring sequence and 
 
99
         * we clear the ring detection variables */
 
100
        ushort                          ring_sig[CHANNELS_PERXPD];
 
101
#endif
81
102
};
82
103
 
83
104
/*---------------- FXO: Static functions ----------------------------------*/
84
105
 
85
106
#define IS_BLINKING(priv,pos,color)     ((priv)->blinking[color][pos] != 0)
86
 
#define DO_BLINK(priv,pos,color,val)    ((priv)->blinking[color][pos] = (val))
 
107
#define MARK_BLINK(priv,pos,color,val)  ((priv)->blinking[color][pos] = (val))
 
108
 
 
109
void MARK_LED(xpd_t *xpd, lineno_t pos, byte color, bool on)
 
110
{
 
111
        struct FXO_priv_data *priv = xpd->priv;
 
112
 
 
113
        if(on)
 
114
                BIT_SET(priv->ledcontrol[color], pos);
 
115
        else
 
116
                BIT_CLR(priv->ledcontrol[color], pos);
 
117
}
87
118
 
88
119
/*
89
120
 * LED control is done via DAA register 0x20
130
161
 
131
162
static void handle_fxo_leds(xpd_t *xpd)
132
163
{
133
 
        int             i;
134
 
        unsigned long   flags;
 
164
        int                     i;
 
165
        unsigned long           flags;
135
166
        const enum fxo_leds     color = LED_GREEN;
136
 
        unsigned int    timer_count;
 
167
        unsigned int            timer_count;
137
168
        struct FXO_priv_data    *priv;
138
169
 
139
170
        BUG_ON(!xpd);
146
177
                if(IS_BLINKING(priv,i,color)) {
147
178
                        // led state is toggled
148
179
                        if((timer_count % LED_BLINK_PERIOD) == 0) {
149
 
                                DBG("%s/%s/%d: led_state=%s\n", xpd->xbus->busname, xpd->xpdname, i,
 
180
                                DBG("%s/%s/%d: ledstate=%s\n", xpd->xbus->busname, xpd->xpdname, i,
150
181
                                                (IS_SET(priv->ledstate[color], i))?"ON":"OFF");
151
182
                                if(!IS_SET(priv->ledstate[color], i)) {
152
183
                                        do_led(xpd, i, color, 1);
154
185
                                        do_led(xpd, i, color, 0);
155
186
                                }
156
187
                        }
 
188
                } else if(IS_SET(priv->ledcontrol[color], i) && !IS_SET(priv->ledstate[color], i)) {
 
189
                        do_led(xpd, i, color, 1);
 
190
                } else if(!IS_SET(priv->ledcontrol[color], i) && IS_SET(priv->ledstate[color], i)) {
 
191
                        do_led(xpd, i, color, 0);
157
192
                }
158
193
        }
159
194
        spin_unlock_irqrestore(&xpd->lock, flags);
160
195
}
161
196
 
162
 
static void do_sethook(xpd_t *xpd, int pos, bool offhook)
 
197
static void mark_ring(xpd_t *xpd, lineno_t pos, bool on)
 
198
{
 
199
        struct FXO_priv_data    *priv;
 
200
 
 
201
        priv = xpd->priv;
 
202
        BUG_ON(!priv);
 
203
        if(on && !xpd->ringing[pos]) {
 
204
                DBG("%s/%s/%d: START\n", xpd->xbus->busname, xpd->xpdname, pos);
 
205
                xpd->ringing[pos] = 1;
 
206
                MARK_BLINK(priv, pos, LED_GREEN, LED_BLINK);
 
207
                update_zap_ring(xpd, pos, 1);
 
208
        } else if(!on && xpd->ringing[pos]) {
 
209
                DBG("%s/%s/%d: STOP\n", xpd->xbus->busname, xpd->xpdname, pos);
 
210
                xpd->ringing[pos] = 0;
 
211
                if(IS_BLINKING(priv, pos, LED_GREEN))
 
212
                        MARK_BLINK(priv, pos, LED_GREEN, 0);
 
213
                update_zap_ring(xpd, pos, 0);
 
214
        }
 
215
}
 
216
 
 
217
static int do_sethook(xpd_t *xpd, int pos, bool to_offhook)
163
218
{
164
219
        unsigned long           flags;
 
220
        xbus_t                  *xbus;
165
221
        struct FXO_priv_data    *priv;
 
222
        int                     ret = 0;
 
223
        bool                    value;
 
224
        xpacket_t               *pack;
 
225
        slic_cmd_t              *sc;
 
226
        int                     len;
166
227
 
167
228
        BUG_ON(!xpd);
168
229
        BUG_ON(xpd->direction == TO_PHONE);             // We can SETHOOK state only on PSTN
 
230
        xbus = xpd->xbus;
169
231
        priv = xpd->priv;
170
232
        BUG_ON(!priv);
171
233
        if(!IS_SET(priv->battery, pos)) {
172
 
                DBG("%s/%s/%d: WARNING: called while battery is off\n", xpd->xbus->busname, xpd->xpdname, pos);
 
234
                NOTICE("%s/%s/%d: WARNING: called while battery is off\n", xbus->busname, xpd->xpdname, pos);
173
235
        }
174
236
        spin_lock_irqsave(&xpd->lock, flags);
175
 
        xpd->ringing[pos] = 0;                          // No more rings
176
 
        CALL_XMETHOD(SETHOOK, xpd->xbus, xpd, pos, offhook);
177
 
        if(offhook) {
178
 
                BIT_SET(xpd->hookstate, pos);
 
237
        mark_ring(xpd, pos, 0);                         // No more rings
 
238
        value = (to_offhook) ? 0x09 : 0x08;     /* Bit 3 is for CID */
 
239
        DBG("%s/%s/%d: SETHOOK: value=0x%02X %s\n", xbus->busname, xpd->xpdname, pos, value, (to_offhook)?"OFFHOOK":"ONHOOK");
 
240
        MARK_LED(xpd, pos, LED_GREEN, (to_offhook)?LED_ON:LED_OFF);
 
241
        XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
 
242
        sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
 
243
        len = slic_cmd_direct_write(sc, BIT(pos), DAA_RING_REGISTER, value);
 
244
        pack->datalen = len;
 
245
        packet_send(xbus, pack);
 
246
#ifdef  SOFT_RING
 
247
        priv->ring_sig[pos] = 0;
 
248
#endif
 
249
        if(to_offhook) {
 
250
                BIT_SET(xpd->offhook, pos);
179
251
        } else {
180
 
                BIT_CLR(xpd->hookstate, pos);
 
252
                BIT_CLR(xpd->offhook, pos);
 
253
                BIT_CLR(xpd->cid_on, pos);
181
254
                xpd->delay_until_dialtone[pos] = 0;
182
255
        }
183
256
        spin_unlock_irqrestore(&xpd->lock, flags);
184
 
        if(offhook)
 
257
        if(to_offhook)
185
258
                wake_up_interruptible(&xpd->txstateq[pos]);
 
259
        return ret;
186
260
}
187
261
 
188
262
/*---------------- FXO: Methods -------------------------------------------*/
282
356
        xbus_t                  *xbus;
283
357
        struct FXO_priv_data    *priv;
284
358
        int                     i;
285
 
        unsigned long           flags;
286
359
 
287
360
        BUG_ON(!xpd);
288
361
        xbus = xpd->xbus;
300
373
                cur_chan->pvt = xpd;
301
374
                cur_chan->sigcap = FXO_DEFAULT_SIGCAP;
302
375
        }
303
 
        spin_lock_irqsave(&xpd->lock, flags);
304
 
        do_led(xpd, ALL_LINES, LED_GREEN, LED_OFF);
305
 
        spin_unlock_irqrestore(&xpd->lock, flags);
 
376
        MARK_LED(xpd, ALL_LINES, LED_GREEN, LED_OFF);
306
377
        for_each_line(xpd, i) {
307
 
                do_led(xpd, i, LED_GREEN, LED_ON);
 
378
                MARK_LED(xpd, i, LED_GREEN, LED_ON);
308
379
                mdelay(50);
309
380
        }
310
381
        return 0;
323
394
        BUG_ON(!priv);
324
395
        DBG("%s/%s (%d)\n", xbus->busname, xpd->xpdname, on);
325
396
        for_each_line(xpd, i) {
326
 
                do_led(xpd, i, LED_GREEN, LED_OFF);
 
397
                MARK_LED(xpd, i, LED_GREEN, LED_OFF);
327
398
                mdelay(50);
328
399
        }
329
400
        return 0;
330
401
}
331
402
 
332
 
#ifdef WITH_RBS
333
403
int FXO_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig)
334
404
{
335
405
        struct FXO_priv_data    *priv;
355
425
        return 0;
356
426
}
357
427
 
358
 
#else
359
 
int FXO_card_sethook(xbus_t *xbus, xpd_t *xpd, int pos, int hookstate)
360
 
{
361
 
        int                     ret = 0;
362
 
        struct FXO_priv_data    *priv;
363
 
 
364
 
        DBG("%s/%s/%d: %s\n", xbus->busname, xpd->xpdname, pos, hookstate2str(hookstate));
365
 
        switch(hookstate) {
366
 
                /* On-hook, off-hook: The PBX is playing a phone on an FXO line.  */
367
 
                case ZT_ONHOOK:
368
 
                        do_sethook(xpd, pos, 0);
369
 
                        break;
370
 
                case ZT_START:
371
 
                        DBG("%s/%s/%d: fall through ZT_OFFHOOK\n", xbus->busname, xpd->xpdname, pos);
372
 
                        xpd->delay_until_dialtone[pos] = DELAY_UNTIL_DIALTONE;
373
 
                        // Fall through
374
 
                case ZT_OFFHOOK:
375
 
                        do_sethook(xpd, pos, 1);
376
 
                        wait_event_interruptible(xpd->txstateq[pos], xpd->delay_until_dialtone[pos] <= 0);
377
 
                        break;
378
 
                case ZT_WINK:
379
 
                        WARN("No code yet\n");
380
 
                        break;
381
 
                case ZT_FLASH:
382
 
                        WARN("No code yet\n");
383
 
                        break;
384
 
                case ZT_RING:
385
 
                        DBG("%s/%s/%d: ZT_RING: %d\n", xbus->busname, xpd->xpdname, pos, xpd->ringing[pos]);
386
 
                        break;
387
 
                case ZT_RINGOFF:
388
 
                        WARN("No code yet\n");
389
 
                        break;
390
 
        }
391
 
        return ret;
392
 
}
393
 
#endif
394
 
 
395
428
static void poll_battery(xbus_t *xbus, xpd_t *xpd)
396
429
{
397
430
        int     i;
401
434
        }
402
435
}
403
436
 
 
437
#ifdef  SOFT_RING
 
438
static void poll_ring(xbus_t *xbus, xpd_t *xpd)
 
439
{
 
440
        int                     i;
 
441
        struct FXO_priv_data    *priv;
 
442
 
 
443
        priv = xpd->priv;
 
444
        BUG_ON(!priv);
 
445
        for_each_line(xpd, i) {
 
446
                if(priv->ring_sig[i])
 
447
                        CALL_PROTO(FXO, DAA_QUERY, xbus, xpd, i, DAA_RING_REGISTER);
 
448
        }
 
449
}
 
450
#endif
404
451
 
405
452
static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd)
406
453
{
407
 
        static unsigned         rate_limit = 0;
408
454
        struct FXO_priv_data    *priv;
409
455
 
410
456
        BUG_ON(!xpd);
411
457
        priv = xpd->priv;
412
458
        BUG_ON(!priv);
413
 
        rate_limit++;
414
 
        if(poll_battery_interval != 0 && (rate_limit % poll_battery_interval) == 0) {
 
459
        if(poll_battery_interval != 0 && (priv->poll_counter % poll_battery_interval) == 0) {
415
460
                poll_battery(xbus, xpd);
416
461
        }
 
462
#ifdef  SOFT_RING
 
463
        if((priv->poll_counter % POLL_RING_INTERVAL) == 0)
 
464
                poll_ring(xbus, xpd);
 
465
#endif
417
466
        handle_fxo_leds(xpd);
 
467
        priv->poll_counter++;
418
468
        return 0;
419
469
}
420
470
 
433
483
        int             i,ret;
434
484
 
435
485
        BUG_ON(!xpd);
436
 
        DBG("cmd: 0x%x, expecting: 0x%x, pos=%d.\n", cmd, WCTDM_SET_ECHOTUNE, pos);
 
486
        DBG("cmd: 0x%X, expecting: 0x%X, pos=%d.\n", cmd, WCTDM_SET_ECHOTUNE, pos);
437
487
        switch (cmd) {
438
488
                case WCTDM_SET_ECHOTUNE:
439
489
                        DBG("-- Setting echo registers: \n");
440
490
                        /* first off: check if this span is fxs. If not: -EINVALID */
441
491
                        if (copy_from_user(&echoregs.wctdm_struct, 
442
 
                                (struct wctdm_echo_coefs*)arg, sizeof(echoregs.wctdm_struct)))
 
492
                                (struct wctdm_echo_coefs __user *)arg, sizeof(echoregs.wctdm_struct)))
443
493
                                return -EFAULT;
444
494
 
445
495
                        /* Set the ACIM register */
474
524
 
475
525
static /* 0x0F */ HOSTCMD(FXO, CHAN_ENABLE, xpp_line_t lines, bool on)
476
526
{
477
 
        unsigned long           flags;
478
527
        int     ret = 0;
479
528
        int     i;
480
529
 
486
535
        DBG("Channel Activation: 0x%4X %s\n", lines, (on) ? "on" : "off");
487
536
        if(on) {
488
537
                for_each_line(xpd, i) {
489
 
                        spin_lock_irqsave(&xpd->lock, flags);
490
 
                        do_led(xpd, i, LED_GREEN, LED_ON);
491
 
                        spin_unlock_irqrestore(&xpd->lock, flags);
 
538
                        MARK_LED(xpd, i, LED_GREEN, LED_ON);
492
539
                        mdelay(20);
493
540
                }
494
541
                for_each_line(xpd, i) {
495
 
                        spin_lock_irqsave(&xpd->lock, flags);
496
 
                        do_led(xpd, i, LED_GREEN, LED_OFF);
497
 
                        spin_unlock_irqrestore(&xpd->lock, flags);
 
542
                        MARK_LED(xpd, i, LED_GREEN, LED_OFF);
498
543
                        mdelay(20);
499
544
                }
500
545
        }
539
584
        return ret;
540
585
}
541
586
 
542
 
static /* 0x0F */ HOSTCMD(FXO, SETHOOK, int pos, bool offhook)
543
 
{
544
 
        int             ret = 0;
545
 
        xpacket_t       *pack;
546
 
        slic_cmd_t      *sc;
547
 
        int             len;
548
 
        unsigned long   flags;
549
 
        bool            value;
550
 
 
551
 
        BUG_ON(!xbus);
552
 
        BUG_ON(!xpd);
553
 
        value = (offhook) ? 0x09 : 0x08;
554
 
        // value |= BIT(3);     /* Bit 3 is for CID */
555
 
        DBG("%s/%s/%d: SETHOOK: value=0x%02X %s\n", xbus->busname, xpd->xpdname, pos, value, (offhook)?"OFFHOOK":"ONHOOK");
556
 
        spin_lock_irqsave(&xpd->lock, flags);
557
 
        XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
558
 
        sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
559
 
        len = slic_cmd_direct_write(sc, BIT(pos), 0x05, value);
560
 
        pack->datalen = len;
561
 
        packet_send(xbus, pack);
562
 
        do_led(xpd, pos, LED_GREEN, (offhook)?LED_ON:LED_OFF);
563
 
        spin_unlock_irqrestore(&xpd->lock, flags);
564
 
        return ret;
565
 
}
566
 
 
567
587
static /* 0x0F */ HOSTCMD(FXO, RELAY_OUT, byte which, bool on)
568
588
{
569
589
        return -ENOSYS;
597
617
        xpp_line_t      sig_toggles = RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_toggles);
598
618
        unsigned long   flags;
599
619
        int             i;
 
620
        struct FXO_priv_data    *priv;
600
621
 
601
622
        if(!xpd) {
602
623
                NOTICE("%s: received %s for non-existing xpd: %d\n",
603
624
                                __FUNCTION__, cmd->name, XPD_NUM(pack->content.addr));
604
625
                return -EPROTO;
605
626
        }
 
627
        priv = xpd->priv;
 
628
        BUG_ON(!priv);
606
629
        DBG("%s/%s: (PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", xpd->xbus->busname, xpd->xpdname, sig_toggles, sig_status);
607
630
        spin_lock_irqsave(&xpd->lock, flags);
608
631
        for_each_line(xpd, i) {
609
 
                if(IS_SET(sig_status, i)) {
610
 
                        xpd->ringing[i] = 1;
611
 
                } else {
612
 
                        xpd->ringing[i] = 0;
 
632
                if(IS_SET(sig_toggles, i)) {
 
633
                        if(!IS_SET(priv->battery, i)) {
 
634
                                DBG("%s/%s/%d: battery is off. ignore false alarm.\n",
 
635
                                        xbus->busname, xpd->xpdname, i);
 
636
                                continue;
 
637
                        }
 
638
                        if(IS_SET(sig_status, i)) {
 
639
#ifdef  SOFT_RING
 
640
                                priv->ring_sig[i]=1;            /* trigger register polling */
 
641
                                /* reset ring check counters */
 
642
                                priv->ring_thresh[i] = 0;
 
643
                                priv->noring_thresh[i] = 0;
 
644
#else
 
645
                                mark_ring(xpd, i, 1);
 
646
#endif
 
647
                        } else {
 
648
#ifdef  SOFT_RING
 
649
                                priv->ring_sig[i] = 0;
 
650
#endif
 
651
                                mark_ring(xpd, i, 0);
 
652
                        }
613
653
                }
614
654
        }
615
655
        spin_unlock_irqrestore(&xpd->lock, flags);
632
672
        priv = xpd->priv;
633
673
        BUG_ON(!priv);
634
674
        if(!info->indirect && info->reg_num == DAA_VBAT_REGISTER) {
635
 
                xpp_line_t      last_batt_on = priv->battery;
636
 
                xpp_line_t      changed_lines;
637
 
                int             i;
638
 
 
639
 
                if(abs(info->data_low) < BAT_THRESHOLD) {
640
 
                        priv->battery &= ~lines;
641
 
                        // DBG("%s/%s: BATTERY OFF (%04X) = %d\n", xpd->xbus->busname, xpd->xpdname, lines, info->data_low);
642
 
                } else {
643
 
                        priv->battery |= lines;
644
 
                        // DBG("%s/%s: BATTERY ON (%04X) = %d\n", xpd->xbus->busname, xpd->xpdname, lines, info->data_low);
645
 
                }
646
 
                changed_lines = last_batt_on ^ priv->battery;
647
 
                for_each_line(xpd, i) {
648
 
                        if(IS_SET(changed_lines, i)) {
649
 
                                update_line_status(xpd, i, IS_SET(priv->battery, i));
650
 
                        }
651
 
                }
652
 
        }
 
675
                byte            bat = abs((signed char)info->data_low);
 
676
                int             i;
 
677
 
 
678
                for_each_line(xpd, i) {
 
679
                        if(!IS_SET(lines, i))
 
680
                                continue;
 
681
                        if(bat < BAT_THRESHOLD) {
 
682
                                /*
 
683
                                 * Check for battery voltage fluctuations
 
684
                                 */
 
685
                                if(IS_SET(priv->battery, i) && priv->battery_debounce[i]++ > BAT_DEBOUNCE) {
 
686
                                        DBG("%s/%s: BATTERY OFF (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
 
687
                                        BIT_CLR(priv->battery, i);
 
688
                                        update_line_status(xpd, i, 0);
 
689
                                }
 
690
                        } else {
 
691
                                priv->battery_debounce[i] = 0;
 
692
                                if(!IS_SET(priv->battery, i)) {
 
693
                                        DBG("%s/%s: BATTERY ON (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
 
694
                                        BIT_SET(priv->battery, i);
 
695
                                }
 
696
                        }
 
697
                }
 
698
        }
 
699
#ifdef  SOFT_RING
 
700
        if(!info->indirect && info->reg_num == DAA_RING_REGISTER) {
 
701
                bool            ringit = (info->data_low & (0x20 | 0x40)) ? 1 : 0;      /* Ring positive | Ring negative */
 
702
                int             i;
 
703
 
 
704
                for_each_line(xpd, i) {
 
705
                        if(!IS_SET(lines, i))
 
706
                                continue;
 
707
                        if (!priv->ring_sig[i])
 
708
                                continue;
 
709
                        if(ringit) {
 
710
                                if(priv->ring_thresh[i] > RING_THRESHOLD) {
 
711
                                        mark_ring(xpd, i, 1);
 
712
                                        priv->noring_thresh[i] = 0;
 
713
                                } else
 
714
                                        priv->ring_thresh[i]++;
 
715
                        } else {
 
716
                                if(priv->noring_thresh[i] > NORING_THRESHOLD) {
 
717
                                        mark_ring(xpd, i, 0);
 
718
                                        priv->ring_thresh[i] = 0;
 
719
                                } else
 
720
                                        priv->noring_thresh[i]++;
 
721
                        }
 
722
                }
 
723
        }
 
724
#endif
653
725
#if 0
 
726
        if (info->reg_num != 29) 
654
727
        DBG("DAA_REPLY: xpd #%d %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
655
728
                        xpd->id, (info->indirect)?"I":"D",
656
729
                        info->reg_num, info->data_low, info->data_high);
681
754
                .card_remove    = FXO_card_remove,
682
755
                .card_zaptel_preregistration    = FXO_card_zaptel_preregistration,
683
756
                .card_zaptel_postregistration   = FXO_card_zaptel_postregistration,
684
 
#ifdef WITH_RBS
685
757
                .card_hooksig   = FXO_card_hooksig,
686
 
#else
687
 
                .card_sethook   = FXO_card_sethook,
688
 
#endif
689
758
                .card_tick      = FXO_card_tick,
690
759
                .card_ioctl     = FXO_card_ioctl,
691
760
 
692
761
                .RING           = XPROTO_CALLER(FXO, RING),
693
 
                .SETHOOK        = XPROTO_CALLER(FXO, SETHOOK),
694
762
                .RELAY_OUT      = XPROTO_CALLER(FXO, RELAY_OUT),
695
763
                .CHAN_ENABLE    = XPROTO_CALLER(FXO, CHAN_ENABLE),
696
764
                .CHAN_CID       = XPROTO_CALLER(FXO, CHAN_CID),
734
802
        len += sprintf(page + len, "\t%-17s: ", "Channel");
735
803
        for_each_line(xpd, i) {
736
804
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
737
 
                        len += sprintf(page + len, "%d ", i % 10);
 
805
                        len += sprintf(page + len, "%2d ", i % 10);
738
806
        }
739
807
        len += sprintf(page + len, "\n\t%-17s: ", "ledstate");
740
808
        for_each_line(xpd, i) {
741
809
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
742
 
                        len += sprintf(page + len, "%d ", IS_SET(priv->ledstate[LED_GREEN], i));
 
810
                        len += sprintf(page + len, "%2d ", IS_SET(priv->ledstate[LED_GREEN], i));
 
811
        }
 
812
        len += sprintf(page + len, "\n\t%-17s: ", "ledcontrol");
 
813
        for_each_line(xpd, i) {
 
814
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
 
815
                        len += sprintf(page + len, "%2d ", IS_SET(priv->ledcontrol[LED_GREEN], i));
743
816
        }
744
817
        len += sprintf(page + len, "\n\t%-17s: ", "blinking");
745
818
        for_each_line(xpd, i) {
746
819
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
747
 
                        len += sprintf(page + len, "%d ", IS_BLINKING(priv,i,LED_GREEN));
748
 
        }
 
820
                        len += sprintf(page + len, "%2d ", IS_BLINKING(priv,i,LED_GREEN));
 
821
        }
 
822
#ifdef  SOFT_RING
 
823
        len += sprintf(page + len, "\n\t%-17s: ", "ring_thresh");
 
824
        for_each_line(xpd, i) {
 
825
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
 
826
                        len += sprintf(page + len, "%2d ", priv->ring_thresh[i]);
 
827
        }
 
828
        len += sprintf(page + len, "\n\t%-17s: ", "noring_thresh");
 
829
        for_each_line(xpd, i) {
 
830
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
 
831
                        len += sprintf(page + len, "%2d ", priv->noring_thresh[i]);
 
832
        }
 
833
        len += sprintf(page + len, "\n\t%-17s: ", "ring_sig");
 
834
        for_each_line(xpd, i) {
 
835
                if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
 
836
                        len += sprintf(page + len, "%d ", priv->ring_sig[i]);
 
837
        }
 
838
#endif
749
839
        len += sprintf(page + len, "\n\t%-17s: ", "battery");
750
840
        for_each_line(xpd, i) {
751
 
                len += sprintf(page + len, "%d ", IS_SET(priv->battery, i));
 
841
                len += sprintf(page + len, "%2d ", IS_SET(priv->battery, i));
 
842
        }
 
843
        len += sprintf(page + len, "\n\t%-17s: ", "battery_debounce");
 
844
        for_each_line(xpd, i) {
 
845
                len += sprintf(page + len, "%2d ", priv->battery_debounce[i]);
752
846
        }
753
847
        len += sprintf(page + len, "\n");
754
848
        spin_unlock_irqrestore(&xpd->lock, flags);
896
990
static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
897
991
{
898
992
        xpd_t           *xpd = data;
899
 
        const int       LINE_LEN = 500;
900
 
        char            buf[LINE_LEN];
 
993
        char            buf[MAX_PROC_WRITE];
901
994
        char            *p;
902
995
        int             i;
903
996
        int             ret;
905
998
        if(!xpd)
906
999
                return -ENODEV;
907
1000
        for(i = 0; i < count; /* noop */) {
908
 
                for(p = buf; p < buf + LINE_LEN; p++) { /* read a line */
 
1001
                for(p = buf; p < buf + MAX_PROC_WRITE; p++) {   /* read a line */
909
1002
                        if(i >= count)
910
1003
                                break;
911
1004
                        if(get_user(*p, buffer + i))
914
1007
                        if(*p == '\n' || *p == '\r')    /* whatever */
915
1008
                                break;
916
1009
                }
917
 
                if(p >= buf + LINE_LEN)
 
1010
                if(p >= buf + MAX_PROC_WRITE)
918
1011
                        return -E2BIG;
919
1012
                *p = '\0';
920
1013
                ret = process_slic_cmdline(xpd, buf);
929
1022
int __init card_fxo_startup(void)
930
1023
{
931
1024
        INFO("%s revision %s\n", THIS_MODULE->name, ZAPTEL_VERSION);
 
1025
#ifdef  SOFT_RING
 
1026
        INFO("FEATURE: %s with SOFT_RING\n", THIS_MODULE->name);
 
1027
#else
 
1028
        INFO("FEATURE: %s without SOFT_RING\n", THIS_MODULE->name);
 
1029
#endif
932
1030
        xproto_register(&PROTO_TABLE(FXO));
933
1031
        return 0;
934
1032
}