2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Wildcard TDM2400P TDM FXS/FXO Interface Driver for DAHDI Telephony interface
|
|
|
|
*
|
|
|
|
* Written by Mark Spencer <markster@digium.com>
|
|
|
|
* Support for TDM800P and VPM150M by Matthew Fredrickson <creslin@digium.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2010 Digium, Inc.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2 as published by the
|
|
|
|
* Free Software Foundation. See the LICENSE file included with
|
|
|
|
* this program for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WCTDM24XXP_H
|
|
|
|
#define _WCTDM24XXP_H
|
|
|
|
|
|
|
|
#include <dahdi/kernel.h>
|
|
|
|
|
|
|
|
#include <linux/version.h>
|
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
|
|
|
|
#include <linux/semaphore.h>
|
|
|
|
#else
|
|
|
|
#include <asm/semaphore.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "voicebus/voicebus.h"
|
|
|
|
|
|
|
|
#define NUM_FXO_REGS 60
|
|
|
|
|
|
|
|
#define WC_MAX_IFACES 128
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Default ringer debounce (in ms)
|
|
|
|
*/
|
|
|
|
#define DEFAULT_RING_DEBOUNCE 1024
|
|
|
|
#define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
|
|
|
|
|
|
|
|
#define OHT_TIMER 6000 /* How long after RING to retain OHT */
|
|
|
|
|
2011-06-03 04:03:24 +08:00
|
|
|
#define FLAG_EXPRESS (1 << 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define EFRAME_SIZE 108L
|
|
|
|
#define EFRAME_GAP 20L
|
|
|
|
#define SFRAME_SIZE ((EFRAME_SIZE * DAHDI_CHUNKSIZE) + (EFRAME_GAP * (DAHDI_CHUNKSIZE - 1)))
|
|
|
|
|
|
|
|
#define MAX_ALARMS 10
|
|
|
|
|
|
|
|
#define MINPEGTIME 10 * 8 /* 30 ms peak to peak gets us no more than 100 Hz */
|
|
|
|
#define PEGTIME 50 * 8 /* 50ms peak to peak gets us rings of 10 Hz or more */
|
|
|
|
#define PEGCOUNT 5 /* 5 cycles of pegging means RING */
|
|
|
|
|
|
|
|
#define SDI_CLK (0x00010000)
|
|
|
|
#define SDI_DOUT (0x00020000)
|
|
|
|
#define SDI_DREAD (0x00040000)
|
|
|
|
#define SDI_DIN (0x00080000)
|
|
|
|
|
|
|
|
#define __CMD_RD (1 << 20) /* Read Operation */
|
|
|
|
#define __CMD_WR (1 << 21) /* Write Operation */
|
|
|
|
#define __CMD_FIN (1 << 22) /* Has finished receive */
|
|
|
|
#define __CMD_TX (1 << 23) /* Has been transmitted */
|
|
|
|
|
|
|
|
#define CMD_WR(a,b) (((a) << 8) | (b) | __CMD_WR)
|
|
|
|
#define CMD_RD(a) (((a) << 8) | __CMD_RD)
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define CMD_BYTE(card,bit,altcs) (((((card) & 0x3) * 3 + (bit)) * 7) \
|
|
|
|
+ ((card) >> 2) + (altcs) + ((altcs) ? -21 : 0))
|
|
|
|
#endif
|
|
|
|
#define NUM_MODULES 24
|
|
|
|
#define NUM_SLOTS 6
|
|
|
|
#define MAX_SPANS 9
|
|
|
|
|
|
|
|
#define NUM_CAL_REGS 12
|
|
|
|
|
|
|
|
#define QRV_DEBOUNCETIME 20
|
|
|
|
|
|
|
|
#define VPM150M_HPI_CONTROL 0x00
|
|
|
|
#define VPM150M_HPI_ADDRESS 0x02
|
|
|
|
#define VPM150M_HPI_DATA 0x03
|
|
|
|
|
|
|
|
#define VPM_SUPPORT
|
|
|
|
#define VPM150M_SUPPORT
|
|
|
|
|
|
|
|
#ifdef VPM150M_SUPPORT
|
|
|
|
#include "voicebus/GpakCust.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-29 06:28:53 +08:00
|
|
|
#include "voicebus/vpmoct.h"
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
struct calregs {
|
|
|
|
unsigned char vals[NUM_CAL_REGS];
|
|
|
|
};
|
|
|
|
|
|
|
|
enum battery_state {
|
|
|
|
BATTERY_UNKNOWN = 0,
|
2011-08-31 00:38:36 +08:00
|
|
|
BATTERY_DEBOUNCING_PRESENT,
|
2013-05-09 21:32:17 +08:00
|
|
|
BATTERY_DEBOUNCING_PRESENT_FROM_LOST_ALARM,
|
2011-08-31 00:38:36 +08:00
|
|
|
BATTERY_DEBOUNCING_PRESENT_ALARM,
|
2010-08-28 05:59:27 +08:00
|
|
|
BATTERY_PRESENT,
|
2011-08-31 00:38:36 +08:00
|
|
|
BATTERY_DEBOUNCING_LOST,
|
2013-05-09 21:32:17 +08:00
|
|
|
BATTERY_DEBOUNCING_LOST_FROM_PRESENT_ALARM,
|
2011-08-31 00:38:36 +08:00
|
|
|
BATTERY_DEBOUNCING_LOST_ALARM,
|
2010-08-28 05:59:27 +08:00
|
|
|
BATTERY_LOST,
|
|
|
|
};
|
|
|
|
|
2011-08-31 00:38:32 +08:00
|
|
|
enum ring_detector_state {
|
|
|
|
RINGOFF = 0,
|
|
|
|
DEBOUNCING_RINGING_POSITIVE,
|
|
|
|
DEBOUNCING_RINGING_NEGATIVE,
|
|
|
|
RINGING,
|
|
|
|
DEBOUNCING_RINGOFF,
|
|
|
|
};
|
|
|
|
|
2011-08-31 00:38:41 +08:00
|
|
|
enum polarity_state {
|
|
|
|
UNKNOWN_POLARITY = 0,
|
|
|
|
POLARITY_DEBOUNCE_POSITIVE,
|
|
|
|
POLARITY_POSITIVE,
|
|
|
|
POLARITY_DEBOUNCE_NEGATIVE,
|
|
|
|
POLARITY_NEGATIVE,
|
|
|
|
};
|
|
|
|
|
2011-06-03 04:03:38 +08:00
|
|
|
struct wctdm_cmd {
|
|
|
|
struct list_head node;
|
|
|
|
struct completion *complete;
|
|
|
|
u32 cmd;
|
|
|
|
u8 ident;
|
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/**
|
|
|
|
* struct wctdm_span -
|
|
|
|
* @span: dahdi_span to register.
|
|
|
|
* @timing_priority: What the priority of this span is relative to the other
|
|
|
|
* spans.
|
|
|
|
* @spanno: Which span on the card this is.
|
|
|
|
*
|
|
|
|
* NOTE: spanno would normally be taken care of by dahdi_span.offset, but
|
|
|
|
* appears to have meaning in xhfc.c, and that needs to be audited before
|
|
|
|
* changing. !!!TODO!!!
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct wctdm_span {
|
|
|
|
struct dahdi_span span;
|
|
|
|
int timing_priority;
|
|
|
|
int spanno;
|
|
|
|
struct wctdm *wc;
|
|
|
|
struct b400m_span *bspan;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wctdm_chan {
|
|
|
|
struct dahdi_chan chan;
|
|
|
|
struct dahdi_echocan_state ec;
|
|
|
|
int timeslot;
|
2011-06-29 06:28:53 +08:00
|
|
|
unsigned int hwpreec_enabled:1;
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2011-06-03 04:02:51 +08:00
|
|
|
struct fxo {
|
2011-08-31 00:38:32 +08:00
|
|
|
enum ring_detector_state ring_state:4;
|
|
|
|
enum battery_state battery_state:4;
|
2011-08-31 00:38:41 +08:00
|
|
|
enum polarity_state polarity_state:4;
|
2011-08-31 00:38:32 +08:00
|
|
|
u8 ring_polarity_change_count:4;
|
|
|
|
u8 hook_ring_shadow;
|
|
|
|
s8 line_voltage_status;
|
2011-06-03 04:02:51 +08:00
|
|
|
int offhook;
|
|
|
|
int neonmwi_state;
|
|
|
|
int neonmwi_last_voltage;
|
|
|
|
unsigned int neonmwi_debounce;
|
|
|
|
unsigned int neonmwi_offcounter;
|
2011-08-31 00:38:14 +08:00
|
|
|
unsigned long display_fxovoltage;
|
2011-08-31 00:38:32 +08:00
|
|
|
unsigned long ringdebounce_timer;
|
2011-08-31 00:38:36 +08:00
|
|
|
unsigned long battdebounce_timer;
|
2011-08-31 00:38:41 +08:00
|
|
|
unsigned long poldebounce_timer;
|
2011-06-03 04:02:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fxs {
|
2011-08-31 00:38:27 +08:00
|
|
|
u8 oht_active:1;
|
|
|
|
u8 off_hook:1;
|
2011-06-03 04:02:51 +08:00
|
|
|
int idletxhookstate; /* IDLE changing hook state */
|
|
|
|
/* lasttxhook reflects the last value written to the proslic's reg
|
|
|
|
* 64 (LINEFEED_CONTROL) in bits 0-2. Bit 4 indicates if the last
|
|
|
|
* write is pending i.e. it is in process of being written to the
|
|
|
|
* register
|
|
|
|
* NOTE: in order for this value to actually be written to the
|
|
|
|
* proslic, the appropriate matching value must be written into the
|
|
|
|
* sethook variable so that it gets queued and handled by the
|
|
|
|
* voicebus ISR.
|
|
|
|
*/
|
|
|
|
int lasttxhook;
|
2011-08-31 00:38:19 +08:00
|
|
|
u8 linefeed_control_shadow;
|
|
|
|
u8 hook_state_shadow;
|
2011-06-03 04:02:51 +08:00
|
|
|
int palarms;
|
|
|
|
struct dahdi_vmwi_info vmwisetting;
|
|
|
|
int vmwi_active_messages;
|
|
|
|
int vmwi_linereverse;
|
|
|
|
int reversepolarity; /* polarity reversal */
|
|
|
|
struct calregs calregs;
|
2011-08-31 00:38:14 +08:00
|
|
|
unsigned long check_alarm;
|
|
|
|
unsigned long check_proslic;
|
2011-08-31 00:38:23 +08:00
|
|
|
unsigned long oppending_timeout;
|
2011-08-31 00:38:27 +08:00
|
|
|
unsigned long ohttimer;
|
2011-06-03 04:02:51 +08:00
|
|
|
};
|
|
|
|
|
2011-06-03 04:02:56 +08:00
|
|
|
struct qrv {
|
|
|
|
#define RADMODE_INVERTCOR 1
|
|
|
|
#define RADMODE_IGNORECOR 2
|
|
|
|
#define RADMODE_EXTTONE 4
|
|
|
|
#define RADMODE_EXTINVERT 8
|
|
|
|
#define RADMODE_IGNORECT 16
|
|
|
|
#define RADMODE_PREEMP 32
|
|
|
|
#define RADMODE_DEEMP 64
|
|
|
|
char hook;
|
|
|
|
unsigned short debouncetime;
|
|
|
|
unsigned short debtime;
|
|
|
|
int radmode;
|
|
|
|
signed short rxgain;
|
|
|
|
signed short txgain;
|
2011-08-31 00:38:19 +08:00
|
|
|
u8 isrshadow[3];
|
2011-06-03 04:02:56 +08:00
|
|
|
};
|
|
|
|
|
2011-06-03 04:03:01 +08:00
|
|
|
enum module_type {
|
|
|
|
NONE = 0,
|
|
|
|
FXS,
|
|
|
|
FXO,
|
|
|
|
FXSINIT,
|
|
|
|
QRV,
|
|
|
|
BRI,
|
|
|
|
};
|
|
|
|
|
2011-06-03 04:02:51 +08:00
|
|
|
struct wctdm_module {
|
2011-08-31 00:38:32 +08:00
|
|
|
union modtypes {
|
2011-06-03 04:02:51 +08:00
|
|
|
struct fxo fxo;
|
|
|
|
struct fxs fxs;
|
2011-06-03 04:02:56 +08:00
|
|
|
struct qrv qrv;
|
2011-06-03 04:02:51 +08:00
|
|
|
struct b400m *bri;
|
|
|
|
} mod;
|
2011-06-03 04:02:56 +08:00
|
|
|
|
2011-06-03 04:03:38 +08:00
|
|
|
/* Protected by wctdm.reglock */
|
|
|
|
struct list_head pending_cmds;
|
|
|
|
struct list_head active_cmds;
|
2011-06-03 04:03:57 +08:00
|
|
|
u8 offsets[3];
|
|
|
|
u8 subaddr;
|
|
|
|
u8 card;
|
2011-06-03 04:02:51 +08:00
|
|
|
|
2011-06-03 04:03:01 +08:00
|
|
|
enum module_type type;
|
2011-06-03 04:02:51 +08:00
|
|
|
int sethook; /* pending hook state command */
|
|
|
|
int dacssrc;
|
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
struct wctdm {
|
|
|
|
const struct wctdm_desc *desc;
|
2011-06-03 04:02:47 +08:00
|
|
|
const char *board_name;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
spinlock_t frame_list_lock;
|
|
|
|
struct list_head frame_list;
|
|
|
|
|
2011-08-31 00:38:14 +08:00
|
|
|
unsigned long framecount;
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned char txident;
|
|
|
|
unsigned char rxident;
|
|
|
|
|
2011-03-16 03:06:05 +08:00
|
|
|
u8 ctlreg;
|
|
|
|
u8 tdm410leds;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int mods_per_board; /* maximum number of modules for this board */
|
|
|
|
int digi_mods; /* number of digital modules present */
|
|
|
|
int avchannels; /* active "voice" (voice, B and D) channels */
|
|
|
|
|
|
|
|
spinlock_t reglock; /* held when accessing anything affecting the module array */
|
2010-11-05 00:40:53 +08:00
|
|
|
wait_queue_head_t regq;
|
2011-08-19 03:21:44 +08:00
|
|
|
struct list_head free_isr_commands;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-06-03 04:02:51 +08:00
|
|
|
struct wctdm_module mods[NUM_MODULES];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
struct vpmadt032 *vpmadt032;
|
2011-06-29 06:28:53 +08:00
|
|
|
struct vpmoct *vpmoct;
|
2010-08-28 05:59:27 +08:00
|
|
|
struct voicebus vb;
|
|
|
|
struct wctdm_span *aspan; /* pointer to the spans[] holding the analog span */
|
|
|
|
struct wctdm_span *spans[MAX_SPANS];
|
|
|
|
struct wctdm_chan *chans[NUM_MODULES];
|
|
|
|
#ifdef CONFIG_VOICEBUS_ECREFERENCE
|
|
|
|
struct dahdi_fifo *ec_reference[NUM_MODULES];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Only care about digital spans here */
|
|
|
|
/* int span_timing_prio[MAX_SPANS - 1]; */
|
|
|
|
struct semaphore syncsem;
|
|
|
|
int oldsync;
|
|
|
|
|
2011-06-29 06:29:00 +08:00
|
|
|
int not_ready; /* 0 when the entire card is ready to go */
|
2011-06-29 06:28:53 +08:00
|
|
|
unsigned long checkflag; /* Internal state flags and task bits */
|
2010-08-28 05:59:27 +08:00
|
|
|
int companding;
|
2011-10-27 02:58:14 +08:00
|
|
|
struct dahdi_device *ddev;
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2011-06-29 06:29:00 +08:00
|
|
|
static inline bool is_initialized(struct wctdm *wc)
|
|
|
|
{
|
|
|
|
WARN_ON(wc->not_ready < 0);
|
|
|
|
return (wc->not_ready == 0);
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Atomic flag bits for checkflag field */
|
|
|
|
#define WCTDM_CHECK_TIMING 0
|
|
|
|
|
2011-06-03 04:03:15 +08:00
|
|
|
int wctdm_getreg(struct wctdm *wc, struct wctdm_module *const mod, int addr);
|
|
|
|
int wctdm_setreg(struct wctdm *wc, struct wctdm_module *const mod,
|
|
|
|
int addr, int val);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-06-29 06:28:53 +08:00
|
|
|
int wctdm_wait_for_ready(struct wctdm *wc);
|
2011-06-03 04:01:54 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
extern struct semaphore ifacelock;
|
|
|
|
extern struct wctdm *ifaces[WC_MAX_IFACES];
|
|
|
|
|
|
|
|
#endif
|