From 6eca58a73b73c5d0144c85fbf01dd96ee81c1537 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Mon, 13 Aug 2012 22:51:02 -0500 Subject: [PATCH] wctdm24xxp-wip: Add ring state debug flags Mostly adding some debug information. [ 6121.922070] wctdm24xxp 0000:0a:07.0: Ring State: RINGOFF -> DEBOUNCING_RINGING_NEGATIVE (-65) (0x4c) [ 6121.933044] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGING_NEGATIVE -> DEBOUNCING_RINGING_POSITIVE (-36) (0x2c) [ 6121.956017] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGING_POSITIVE -> DEBOUNCING_RINGING_NEGATIVE (-6) (0x4c) [ 6121.974023] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGING_NEGATIVE -> DEBOUNCING_RINGING_POSITIVE (-16) (0x2c) [ 6121.995021] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGING_POSITIVE -> DEBOUNCING_RINGING_NEGATIVE (-3) (0x4c) [ 6122.014023] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGING_NEGATIVE -> RINGING (-6) (0x2c) [ 6122.014031] wctdm24xxp 0000:0a:07.0: RING on WCTDM/1/0! [ 6122.032027] wctdm24xxp 0000:0a:07.0: Ring State: RINGING -> DEBOUNCING_RINGOFF (30) (0xc) [ 6122.034013] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGOFF -> RINGING (4) (0x4c) [ 6122.051030] wctdm24xxp 0000:0a:07.0: Ring State: RINGING -> DEBOUNCING_RINGOFF (-36) (0xc) [ 6122.054013] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGOFF -> RINGING (1) (0x2c) [ 6122.071027] wctdm24xxp 0000:0a:07.0: Ring State: RINGING -> DEBOUNCING_RINGOFF (36) (0xc) [ 6122.073014] wctdm24xxp 0000:0a:07.0: Ring State: DEBOUNCING_RINGOFF -> RINGING (9) (0x4c) [ 6122.090058] wctdm24xxp 0000:0a:07.0: Ring State: RINGING -> DEBOUNCING_RINGOFF (-42) (0xc) --- drivers/dahdi/wctdm24xxp/base.c | 62 ++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/drivers/dahdi/wctdm24xxp/base.c b/drivers/dahdi/wctdm24xxp/base.c index a1eff33..5a65cd3 100644 --- a/drivers/dahdi/wctdm24xxp/base.c +++ b/drivers/dahdi/wctdm24xxp/base.c @@ -1833,24 +1833,54 @@ static void wctdm_qrvdri_check_hook(struct wctdm *wc, int card) static inline bool is_fxo_ringing(const struct fxo *const fxo) { return ((fxo->hook_ring_shadow & 0x60) && - (fxo->battery_state == BATTERY_PRESENT)); + ((fxo->battery_state == BATTERY_PRESENT) || + (fxo->battery_state == BATTERY_DEBOUNCING_LOST))); } static inline bool is_fxo_ringing_positive(const struct fxo *const fxo) { return (((fxo->hook_ring_shadow & 0x60) == 0x20) && - (fxo->battery_state == BATTERY_PRESENT)); + ((fxo->battery_state == BATTERY_PRESENT) || + (fxo->battery_state == BATTERY_DEBOUNCING_LOST))); } static inline bool is_fxo_ringing_negative(const struct fxo *const fxo) { return (((fxo->hook_ring_shadow & 0x60) == 0x40) && - (fxo->battery_state == BATTERY_PRESENT)); + ((fxo->battery_state == BATTERY_PRESENT) || + (fxo->battery_state == BATTERY_DEBOUNCING_LOST))); } -static inline void set_ring(struct fxo *fxo, enum ring_detector_state new) +static const char *get_state_name(enum ring_detector_state state) { - fxo->ring_state = new; + switch (state) { + case RINGOFF: + return "RINGOFF"; + case DEBOUNCING_RINGING_POSITIVE: + return "DEBOUNCING_RINGING_POSITIVE"; + case DEBOUNCING_RINGING_NEGATIVE: + return "DEBOUNCING_RINGING_NEGATIVE"; + case RINGING: + return "RINGING"; + case DEBOUNCING_RINGOFF: + return "DEBOUNCING_RINGOFF"; + } + return "UNKNOWN"; +} + +static void set_ring(struct wctdm *wc, struct fxo *fxo, + enum ring_detector_state new) +{ + if (fxo->ring_state != new) { + if (debug) { + dev_info(&wc->vb.pdev->dev, + "Ring State: %s -> %s (%d) (0x%x)\n", + get_state_name(fxo->ring_state), + get_state_name(new), fxo->line_voltage_status, + fxo->hook_ring_shadow); + } + fxo->ring_state = new; + } } static void wctdm_fxo_ring_detect(struct wctdm *wc, struct wctdm_module *mod) @@ -1870,41 +1900,41 @@ static void wctdm_fxo_ring_detect(struct wctdm *wc, struct wctdm_module *mod) if (is_fxo_ringing_negative(fxo)) { if (++fxo->ring_polarity_change_count > 4) { mod_hooksig(wc, mod, DAHDI_RXSIG_RING); - set_ring(fxo, RINGING); + set_ring(wc, fxo, RINGING); if (debug) { dev_info(&wc->vb.pdev->dev, "RING on %s!\n", get_dahdi_chan(wc, mod)->name); } } else { - set_ring(fxo, DEBOUNCING_RINGING_NEGATIVE); + set_ring(wc, fxo, DEBOUNCING_RINGING_NEGATIVE); } } else if (time_after(wc->framecount, fxo->ringdebounce_timer)) { - set_ring(fxo, RINGOFF); + set_ring(wc, fxo, RINGOFF); } break; case DEBOUNCING_RINGING_NEGATIVE: if (is_fxo_ringing_positive(fxo)) { if (++fxo->ring_polarity_change_count > 4) { mod_hooksig(wc, mod, DAHDI_RXSIG_RING); - set_ring(fxo, RINGING); + set_ring(wc, fxo, RINGING); if (debug) { dev_info(&wc->vb.pdev->dev, "RING on %s!\n", get_dahdi_chan(wc, mod)->name); } } else { - set_ring(fxo, DEBOUNCING_RINGING_POSITIVE); + set_ring(wc, fxo, DEBOUNCING_RINGING_POSITIVE); } } else if (time_after(wc->framecount, fxo->ringdebounce_timer)) { - set_ring(fxo, RINGOFF); + set_ring(wc, fxo, RINGOFF); } break; case RINGING: if (!is_fxo_ringing(fxo)) { - set_ring(fxo, DEBOUNCING_RINGOFF); + set_ring(wc, fxo, DEBOUNCING_RINGOFF); fxo->ringdebounce_timer = wc->framecount + ringdebounce / 8; } @@ -1919,10 +1949,10 @@ static void wctdm_fxo_ring_detect(struct wctdm *wc, struct wctdm_module *mod) get_dahdi_chan(wc, mod)->name); } mod_hooksig(wc, mod, DAHDI_RXSIG_OFFHOOK); - set_ring(fxo, RINGOFF); + set_ring(wc, fxo, RINGOFF); } } else { - set_ring(fxo, RINGING); + set_ring(wc, fxo, RINGING); } break; case RINGOFF: @@ -1930,9 +1960,9 @@ static void wctdm_fxo_ring_detect(struct wctdm *wc, struct wctdm_module *mod) /* Look for positive/negative crossings in ring status * reg */ if (is_fxo_ringing_positive(fxo)) - set_ring(fxo, DEBOUNCING_RINGING_POSITIVE); + set_ring(wc, fxo, DEBOUNCING_RINGING_POSITIVE); else - set_ring(fxo, DEBOUNCING_RINGING_NEGATIVE); + set_ring(wc, fxo, DEBOUNCING_RINGING_NEGATIVE); fxo->ringdebounce_timer = wc->framecount + ringdebounce / 8; fxo->ring_polarity_change_count = 0; -- 1.7.11.3