wctdm24xxp.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_3215 (1 << 0)
  43. #define FLAG_EXPRESS (1 << 1)
  44. #define EFRAME_SIZE 108L
  45. #define EFRAME_GAP 20L
  46. #define SFRAME_SIZE ((EFRAME_SIZE * DAHDI_CHUNKSIZE) + (EFRAME_GAP * (DAHDI_CHUNKSIZE - 1)))
  47. #define MAX_ALARMS 10
  48. #define MOD_TYPE_NONE 0
  49. #define MOD_TYPE_FXS 1
  50. #define MOD_TYPE_FXO 2
  51. #define MOD_TYPE_FXSINIT 3
  52. #define MOD_TYPE_QRV 5
  53. #define MOD_TYPE_BRI 7
  54. #define MINPEGTIME 10 * 8 /* 30 ms peak to peak gets us no more than 100 Hz */
  55. #define PEGTIME 50 * 8 /* 50ms peak to peak gets us rings of 10 Hz or more */
  56. #define PEGCOUNT 5 /* 5 cycles of pegging means RING */
  57. #define SDI_CLK (0x00010000)
  58. #define SDI_DOUT (0x00020000)
  59. #define SDI_DREAD (0x00040000)
  60. #define SDI_DIN (0x00080000)
  61. #define __CMD_RD (1 << 20) /* Read Operation */
  62. #define __CMD_WR (1 << 21) /* Write Operation */
  63. #define __CMD_FIN (1 << 22) /* Has finished receive */
  64. #define __CMD_TX (1 << 23) /* Has been transmitted */
  65. #define CMD_WR(a,b) (((a) << 8) | (b) | __CMD_WR)
  66. #define CMD_RD(a) (((a) << 8) | __CMD_RD)
  67. #if 0
  68. #define CMD_BYTE(card,bit,altcs) (((((card) & 0x3) * 3 + (bit)) * 7) \
  69. + ((card) >> 2) + (altcs) + ((altcs) ? -21 : 0))
  70. #endif
  71. #define NUM_MODULES 24
  72. #define NUM_SLOTS 6
  73. #define MAX_SPANS 9
  74. #define NUM_CAL_REGS 12
  75. #define USER_COMMANDS 8
  76. #define ISR_COMMANDS 2
  77. #define QRV_DEBOUNCETIME 20
  78. #define MAX_COMMANDS (USER_COMMANDS + ISR_COMMANDS)
  79. #define VPM150M_HPI_CONTROL 0x00
  80. #define VPM150M_HPI_ADDRESS 0x02
  81. #define VPM150M_HPI_DATA 0x03
  82. #define VPM_SUPPORT
  83. #define VPM150M_SUPPORT
  84. #ifdef VPM150M_SUPPORT
  85. #include "voicebus/GpakCust.h"
  86. #endif
  87. struct calregs {
  88. unsigned char vals[NUM_CAL_REGS];
  89. };
  90. struct cmdq {
  91. unsigned int cmds[MAX_COMMANDS];
  92. unsigned char isrshadow[ISR_COMMANDS];
  93. };
  94. enum battery_state {
  95. BATTERY_UNKNOWN = 0,
  96. BATTERY_PRESENT,
  97. BATTERY_LOST,
  98. };
  99. /**
  100. * struct wctdm_span -
  101. * @span: dahdi_span to register.
  102. * @timing_priority: What the priority of this span is relative to the other
  103. * spans.
  104. * @spanno: Which span on the card this is.
  105. *
  106. * NOTE: spanno would normally be taken care of by dahdi_span.offset, but
  107. * appears to have meaning in xhfc.c, and that needs to be audited before
  108. * changing. !!!TODO!!!
  109. *
  110. */
  111. struct wctdm_span {
  112. struct dahdi_span span;
  113. int timing_priority;
  114. int spanno;
  115. struct wctdm *wc;
  116. struct b400m_span *bspan;
  117. };
  118. struct wctdm_chan {
  119. struct dahdi_chan chan;
  120. struct dahdi_echocan_state ec;
  121. int timeslot;
  122. };
  123. struct wctdm {
  124. const struct wctdm_desc *desc;
  125. char board_name[80];
  126. int usecount;
  127. int pos; /* card number in system */
  128. spinlock_t frame_list_lock;
  129. struct list_head frame_list;
  130. unsigned int intcount;
  131. unsigned char txident;
  132. unsigned char rxident;
  133. int flags[NUM_MODULES]; /* bitmap of board-specific + module-specific flags */
  134. u8 ctlreg;
  135. u8 tdm410leds;
  136. int mods_per_board; /* maximum number of modules for this board */
  137. int digi_mods; /* number of digital modules present */
  138. int avchannels; /* active "voice" (voice, B and D) channels */
  139. int modmap; /* Bit-map of present cards (1=present) */
  140. int altcs[NUM_MODULES];
  141. /* FIXME: why are all of these QRV-only members part of the main card structure? */
  142. char qrvhook[NUM_MODULES];
  143. unsigned short qrvdebtime[NUM_MODULES];
  144. int radmode[NUM_MODULES];
  145. #define RADMODE_INVERTCOR 1
  146. #define RADMODE_IGNORECOR 2
  147. #define RADMODE_EXTTONE 4
  148. #define RADMODE_EXTINVERT 8
  149. #define RADMODE_IGNORECT 16
  150. #define RADMODE_PREEMP 32
  151. #define RADMODE_DEEMP 64
  152. unsigned short debouncetime[NUM_MODULES];
  153. signed short rxgain[NUM_MODULES];
  154. signed short txgain[NUM_MODULES];
  155. spinlock_t reglock; /* held when accessing anything affecting the module array */
  156. wait_queue_head_t regq; /* for schluffen() */
  157. union {
  158. struct fxo {
  159. int wasringing;
  160. int lastrdtx;
  161. int lastrdtx_count;
  162. int ringdebounce;
  163. int offhook;
  164. int battdebounce;
  165. int battalarm;
  166. enum battery_state battery;
  167. int lastpol;
  168. int polarity;
  169. int polaritydebounce;
  170. int neonmwi_state;
  171. int neonmwi_last_voltage;
  172. unsigned int neonmwi_debounce;
  173. unsigned int neonmwi_offcounter;
  174. } fxo;
  175. struct fxs {
  176. int oldrxhook;
  177. int debouncehook;
  178. int lastrxhook;
  179. int debounce;
  180. int ohttimer;
  181. int idletxhookstate; /* IDLE changing hook state */
  182. /* lasttxhook reflects the last value written to the proslic's reg
  183. * 64 (LINEFEED_CONTROL) in bits 0-2. Bit 4 indicates if the last
  184. * write is pending i.e. it is in process of being written to the
  185. * register
  186. * NOTE: in order for this value to actually be written to the
  187. * proslic, the appropriate matching value must be written into the
  188. * sethook variable so that it gets queued and handled by the
  189. * voicebus ISR.
  190. */
  191. int lasttxhook;
  192. int oppending_ms;
  193. spinlock_t lasttxhooklock;
  194. int palarms;
  195. struct dahdi_vmwi_info vmwisetting;
  196. int vmwi_active_messages;
  197. int vmwi_linereverse;
  198. int reversepolarity; /* polarity reversal */
  199. struct calregs calregs;
  200. } fxs;
  201. struct b400m *bri;
  202. } mods[NUM_MODULES];
  203. struct cmdq cmdq[NUM_MODULES];
  204. int modtype[NUM_MODULES]; /* type of module (FXO/FXS/QRV/etc.) */
  205. int sethook[NUM_MODULES]; /* pending hook state command */
  206. int dacssrc[NUM_MODULES];
  207. struct vpmadt032 *vpmadt032;
  208. struct voicebus vb;
  209. struct wctdm_span *aspan; /* pointer to the spans[] holding the analog span */
  210. struct wctdm_span *spans[MAX_SPANS];
  211. struct wctdm_chan *chans[NUM_MODULES];
  212. #ifdef CONFIG_VOICEBUS_ECREFERENCE
  213. struct dahdi_fifo *ec_reference[NUM_MODULES];
  214. #endif
  215. /* Only care about digital spans here */
  216. /* int span_timing_prio[MAX_SPANS - 1]; */
  217. struct semaphore syncsem;
  218. int oldsync;
  219. int initialized; /* =1 when the entire card is ready to go */
  220. unsigned long checkflag; /* Internal state flags and task bits */
  221. int companding;
  222. };
  223. /* Atomic flag bits for checkflag field */
  224. #define WCTDM_CHECK_TIMING 0
  225. int schluffen(wait_queue_head_t *q);
  226. void wait_just_a_bit(int foo);
  227. int wctdm_getreg(struct wctdm *wc, int card, int addr);
  228. int wctdm_setreg(struct wctdm *wc, int card, int addr, int val);
  229. extern struct semaphore ifacelock;
  230. extern struct wctdm *ifaces[WC_MAX_IFACES];
  231. #endif