wctdm24xxp.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Wildcard TDM2400P TDM FXS/FXO Interface Driver for DAHDI Telephony interface
  3. *
  4. * Written by Mark Spencer <markster@digium.com>
  5. * Support for TDM800P and VPM150M by Matthew Fredrickson <creslin@digium.com>
  6. *
  7. * Copyright (C) 2005-2010 Digium, Inc.
  8. *
  9. * All rights reserved.
  10. *
  11. */
  12. /*
  13. * See http://www.asterisk.org for more information about
  14. * the Asterisk project. Please do not directly contact
  15. * any of the maintainers of this project for assistance;
  16. * the project provides a web site, mailing lists and IRC
  17. * channels for your use.
  18. *
  19. * This program is free software, distributed under the terms of
  20. * the GNU General Public License Version 2 as published by the
  21. * Free Software Foundation. See the LICENSE file included with
  22. * this program for more details.
  23. */
  24. #ifndef _WCTDM24XXP_H
  25. #define _WCTDM24XXP_H
  26. #include <dahdi/kernel.h>
  27. #include <linux/version.h>
  28. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
  29. #include <linux/semaphore.h>
  30. #else
  31. #include <asm/semaphore.h>
  32. #endif
  33. #include "voicebus/voicebus.h"
  34. #define NUM_FXO_REGS 60
  35. #define WC_MAX_IFACES 128
  36. /*!
  37. * \brief Default ringer debounce (in ms)
  38. */
  39. #define DEFAULT_RING_DEBOUNCE 1024
  40. #define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
  41. #define OHT_TIMER 6000 /* How long after RING to retain OHT */
  42. #define FLAG_EXPRESS (1 << 0)
  43. #define EFRAME_SIZE 108L
  44. #define EFRAME_GAP 20L
  45. #define SFRAME_SIZE ((EFRAME_SIZE * DAHDI_CHUNKSIZE) + (EFRAME_GAP * (DAHDI_CHUNKSIZE - 1)))
  46. #define MAX_ALARMS 10
  47. #define MINPEGTIME 10 * 8 /* 30 ms peak to peak gets us no more than 100 Hz */
  48. #define PEGTIME 50 * 8 /* 50ms peak to peak gets us rings of 10 Hz or more */
  49. #define PEGCOUNT 5 /* 5 cycles of pegging means RING */
  50. #define SDI_CLK (0x00010000)
  51. #define SDI_DOUT (0x00020000)
  52. #define SDI_DREAD (0x00040000)
  53. #define SDI_DIN (0x00080000)
  54. #define __CMD_RD (1 << 20) /* Read Operation */
  55. #define __CMD_WR (1 << 21) /* Write Operation */
  56. #define __CMD_FIN (1 << 22) /* Has finished receive */
  57. #define __CMD_TX (1 << 23) /* Has been transmitted */
  58. #define CMD_WR(a,b) (((a) << 8) | (b) | __CMD_WR)
  59. #define CMD_RD(a) (((a) << 8) | __CMD_RD)
  60. #if 0
  61. #define CMD_BYTE(card,bit,altcs) (((((card) & 0x3) * 3 + (bit)) * 7) \
  62. + ((card) >> 2) + (altcs) + ((altcs) ? -21 : 0))
  63. #endif
  64. #define NUM_MODULES 24
  65. #define NUM_SLOTS 6
  66. #define MAX_SPANS 9
  67. #define NUM_CAL_REGS 12
  68. #define QRV_DEBOUNCETIME 20
  69. #define VPM150M_HPI_CONTROL 0x00
  70. #define VPM150M_HPI_ADDRESS 0x02
  71. #define VPM150M_HPI_DATA 0x03
  72. #define VPM_SUPPORT
  73. #define VPM150M_SUPPORT
  74. #ifdef VPM150M_SUPPORT
  75. #include "voicebus/GpakCust.h"
  76. #endif
  77. #include "voicebus/vpmoct.h"
  78. struct calregs {
  79. unsigned char vals[NUM_CAL_REGS];
  80. };
  81. enum battery_state {
  82. BATTERY_UNKNOWN = 0,
  83. BATTERY_DEBOUNCING_PRESENT,
  84. BATTERY_DEBOUNCING_PRESENT_FROM_LOST_ALARM,
  85. BATTERY_DEBOUNCING_PRESENT_ALARM,
  86. BATTERY_PRESENT,
  87. BATTERY_DEBOUNCING_LOST,
  88. BATTERY_DEBOUNCING_LOST_FROM_PRESENT_ALARM,
  89. BATTERY_DEBOUNCING_LOST_ALARM,
  90. BATTERY_LOST,
  91. };
  92. enum ring_detector_state {
  93. RINGOFF = 0,
  94. DEBOUNCING_RINGING_POSITIVE,
  95. DEBOUNCING_RINGING_NEGATIVE,
  96. RINGING,
  97. DEBOUNCING_RINGOFF,
  98. };
  99. enum polarity_state {
  100. UNKNOWN_POLARITY = 0,
  101. POLARITY_DEBOUNCE_POSITIVE,
  102. POLARITY_POSITIVE,
  103. POLARITY_DEBOUNCE_NEGATIVE,
  104. POLARITY_NEGATIVE,
  105. };
  106. struct wctdm_cmd {
  107. struct list_head node;
  108. struct completion *complete;
  109. u32 cmd;
  110. u8 ident;
  111. };
  112. /**
  113. * struct wctdm_span -
  114. * @span: dahdi_span to register.
  115. * @timing_priority: What the priority of this span is relative to the other
  116. * spans.
  117. * @spanno: Which span on the card this is.
  118. *
  119. * NOTE: spanno would normally be taken care of by dahdi_span.offset, but
  120. * appears to have meaning in xhfc.c, and that needs to be audited before
  121. * changing. !!!TODO!!!
  122. *
  123. */
  124. struct wctdm_span {
  125. struct dahdi_span span;
  126. int timing_priority;
  127. int spanno;
  128. struct wctdm *wc;
  129. struct b400m_span *bspan;
  130. };
  131. struct wctdm_chan {
  132. struct dahdi_chan chan;
  133. struct dahdi_echocan_state ec;
  134. int timeslot;
  135. unsigned int hwpreec_enabled:1;
  136. };
  137. struct fxo {
  138. enum ring_detector_state ring_state:4;
  139. enum battery_state battery_state:4;
  140. enum polarity_state polarity_state:4;
  141. u8 ring_polarity_change_count:4;
  142. u8 hook_ring_shadow;
  143. s8 line_voltage_status;
  144. int offhook;
  145. int neonmwi_state;
  146. int neonmwi_last_voltage;
  147. unsigned int neonmwi_debounce;
  148. unsigned int neonmwi_offcounter;
  149. unsigned long display_fxovoltage;
  150. unsigned long ringdebounce_timer;
  151. unsigned long battdebounce_timer;
  152. unsigned long poldebounce_timer;
  153. };
  154. struct fxs {
  155. u8 oht_active:1;
  156. u8 off_hook:1;
  157. int idletxhookstate; /* IDLE changing hook state */
  158. /* lasttxhook reflects the last value written to the proslic's reg
  159. * 64 (LINEFEED_CONTROL) in bits 0-2. Bit 4 indicates if the last
  160. * write is pending i.e. it is in process of being written to the
  161. * register
  162. * NOTE: in order for this value to actually be written to the
  163. * proslic, the appropriate matching value must be written into the
  164. * sethook variable so that it gets queued and handled by the
  165. * voicebus ISR.
  166. */
  167. int lasttxhook;
  168. u8 linefeed_control_shadow;
  169. u8 hook_state_shadow;
  170. int palarms;
  171. struct dahdi_vmwi_info vmwisetting;
  172. int vmwi_active_messages;
  173. int vmwi_linereverse;
  174. int reversepolarity; /* polarity reversal */
  175. struct calregs calregs;
  176. unsigned long check_alarm;
  177. unsigned long check_proslic;
  178. unsigned long oppending_timeout;
  179. unsigned long ohttimer;
  180. };
  181. struct qrv {
  182. #define RADMODE_INVERTCOR 1
  183. #define RADMODE_IGNORECOR 2
  184. #define RADMODE_EXTTONE 4
  185. #define RADMODE_EXTINVERT 8
  186. #define RADMODE_IGNORECT 16
  187. #define RADMODE_PREEMP 32
  188. #define RADMODE_DEEMP 64
  189. char hook;
  190. unsigned short debouncetime;
  191. unsigned short debtime;
  192. int radmode;
  193. signed short rxgain;
  194. signed short txgain;
  195. u8 isrshadow[3];
  196. };
  197. enum module_type {
  198. NONE = 0,
  199. FXS,
  200. FXO,
  201. FXSINIT,
  202. QRV,
  203. BRI,
  204. };
  205. struct wctdm_module {
  206. union modtypes {
  207. struct fxo fxo;
  208. struct fxs fxs;
  209. struct qrv qrv;
  210. struct b400m *bri;
  211. } mod;
  212. /* Protected by wctdm.reglock */
  213. struct list_head pending_cmds;
  214. struct list_head active_cmds;
  215. u8 offsets[3];
  216. u8 subaddr;
  217. u8 card;
  218. enum module_type type;
  219. int sethook; /* pending hook state command */
  220. int dacssrc;
  221. };
  222. struct wctdm {
  223. const struct wctdm_desc *desc;
  224. const char *board_name;
  225. spinlock_t frame_list_lock;
  226. struct list_head frame_list;
  227. unsigned long framecount;
  228. unsigned char txident;
  229. unsigned char rxident;
  230. u8 ctlreg;
  231. u8 tdm410leds;
  232. int mods_per_board; /* maximum number of modules for this board */
  233. int digi_mods; /* number of digital modules present */
  234. int avchannels; /* active "voice" (voice, B and D) channels */
  235. spinlock_t reglock; /* held when accessing anything affecting the module array */
  236. wait_queue_head_t regq;
  237. struct list_head free_isr_commands;
  238. struct wctdm_module mods[NUM_MODULES];
  239. struct vpmadt032 *vpmadt032;
  240. struct vpmoct *vpmoct;
  241. struct voicebus vb;
  242. struct wctdm_span *aspan; /* pointer to the spans[] holding the analog span */
  243. struct wctdm_span *spans[MAX_SPANS];
  244. struct wctdm_chan *chans[NUM_MODULES];
  245. #ifdef CONFIG_VOICEBUS_ECREFERENCE
  246. struct dahdi_fifo *ec_reference[NUM_MODULES];
  247. #endif
  248. /* Only care about digital spans here */
  249. /* int span_timing_prio[MAX_SPANS - 1]; */
  250. struct semaphore syncsem;
  251. int oldsync;
  252. int not_ready; /* 0 when the entire card is ready to go */
  253. unsigned long checkflag; /* Internal state flags and task bits */
  254. int companding;
  255. struct dahdi_device *ddev;
  256. };
  257. static inline bool is_initialized(struct wctdm *wc)
  258. {
  259. WARN_ON(wc->not_ready < 0);
  260. return (wc->not_ready == 0);
  261. }
  262. /* Atomic flag bits for checkflag field */
  263. #define WCTDM_CHECK_TIMING 0
  264. int wctdm_getreg(struct wctdm *wc, struct wctdm_module *const mod, int addr);
  265. int wctdm_setreg(struct wctdm *wc, struct wctdm_module *const mod,
  266. int addr, int val);
  267. int wctdm_wait_for_ready(struct wctdm *wc);
  268. extern struct semaphore ifacelock;
  269. extern struct wctdm *ifaces[WC_MAX_IFACES];
  270. #endif