GpakCust.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2005, Adaptive Digital Technologies, Inc.
  3. *
  4. * File Name: GpakCust.h
  5. *
  6. * Description:
  7. * This file contains host system dependent definitions and prototypes of
  8. * functions to support generic G.PAK API functions. The file is used when
  9. * integrating G.PAK API functions in a specific host processor environment.
  10. *
  11. * Note: This file may need to be modified by the G.PAK system integrator.
  12. *
  13. * Version: 1.0
  14. *
  15. * Revision History:
  16. * 06/15/05 - Initial release.
  17. *
  18. * This program has been released under the terms of the GPL version 2 by
  19. * permission of Adaptive Digital Technologies, Inc.
  20. *
  21. */
  22. /*
  23. * See http://www.asterisk.org for more information about
  24. * the Asterisk project. Please do not directly contact
  25. * any of the maintainers of this project for assistance;
  26. * the project provides a web site, mailing lists and IRC
  27. * channels for your use.
  28. *
  29. * This program is free software, distributed under the terms of
  30. * the GNU General Public License Version 2 as published by the
  31. * Free Software Foundation. See the LICENSE file included with
  32. * this program for more details.
  33. */
  34. #ifndef _GPAKCUST_H /* prevent multiple inclusion */
  35. #define _GPAKCUST_H
  36. #include <linux/module.h>
  37. #include <linux/device.h>
  38. #include <linux/completion.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/delay.h>
  41. #include <linux/version.h>
  42. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
  43. #include <linux/semaphore.h>
  44. #endif
  45. #include "gpakenum.h"
  46. #include "adt_lec.h"
  47. #define DEBUG_VPMADT032_ECHOCAN (1 << 4)
  48. /* Host and DSP system dependent related definitions. */
  49. #define MAX_DSP_CORES 128 /* maximum number of DSP cores */
  50. #define MAX_CHANNELS 32 /* maximum number of channels */
  51. #define MAX_WAIT_LOOPS 50 /* max number of wait delay loops */
  52. #define DSP_IFBLK_ADDRESS 0x0100 /* DSP address of I/F block pointer */
  53. #define DOWNLOAD_BLOCK_SIZE 512 /* download block size (DSP words) */
  54. #define VPM150M_MAX_COMMANDS 8
  55. #define __VPM150M_RWPAGE (1 << 4)
  56. #define __VPM150M_RD (1 << 3)
  57. #define __VPM150M_WR (1 << 2)
  58. #define __VPM150M_FIN (1 << 1)
  59. #define __VPM150M_TX (1 << 0)
  60. #define __VPM150M_RWPAGE (1 << 4)
  61. #define __VPM150M_RD (1 << 3)
  62. #define __VPM150M_WR (1 << 2)
  63. #define __VPM150M_FIN (1 << 1)
  64. #define __VPM150M_TX (1 << 0)
  65. /* Some Bit ops for different operations */
  66. #define VPM150M_HPIRESET 1
  67. #define VPM150M_SWRESET 2
  68. #define VPM150M_ACTIVE 4
  69. #define NLPTYPE_NONE 0
  70. #define NLPTYPE_MUTE 1
  71. #define NLPTYPE_RANDOM_NOISE 2
  72. #define HOTH_NOISE_NLPTYPE 3
  73. #define NLPTYPE_SUPPRESS 4
  74. #define NLPTYPE_RESERVED 5
  75. #define NLPTYPE_AUTOSUPPRESS 6
  76. #define DEFAULT_NLPTYPE NLPTYPE_AUTOSUPPRESS
  77. /* This is the threshold (in dB) for enabling and disabling of the NLP */
  78. #define DEFAULT_NLPTHRESH 22
  79. #define DEFAULT_NLPMAXSUPP 10
  80. struct vpmadt032_cmd {
  81. struct list_head node;
  82. __le32 address;
  83. __le16 data;
  84. u8 desc;
  85. u8 txident;
  86. struct completion complete;
  87. };
  88. /* Contains the options used when initializing the vpmadt032 module */
  89. struct vpmadt032_options {
  90. int vpmnlptype;
  91. int vpmnlpthresh;
  92. int vpmnlpmaxsupp;
  93. u32 debug;
  94. u32 channels;
  95. };
  96. struct GpakChannelConfig;
  97. struct vpmadt032 {
  98. struct voicebus *vb;
  99. struct work_struct work;
  100. struct workqueue_struct *wq;
  101. int dspid;
  102. struct semaphore sem;
  103. unsigned long control;
  104. unsigned char curpage;
  105. unsigned short version;
  106. struct adt_lec_params curecstate[MAX_CHANNELS];
  107. spinlock_t change_list_lock;
  108. struct list_head change_list;
  109. spinlock_t list_lock;
  110. /* Commands that are waiting to be processed. */
  111. struct list_head pending_cmds;
  112. /* Commands that are currently in progress by the VPM module */
  113. struct list_head active_cmds;
  114. struct vpmadt032_options options;
  115. void (*setchanconfig_from_state)(struct vpmadt032 *vpm, int channel, struct GpakChannelConfig *chanconfig);
  116. };
  117. struct voicebus;
  118. struct dahdi_chan;
  119. struct dahdi_echocanparams;
  120. struct dahdi_echocanparam;
  121. struct dahdi_echocan_state;
  122. char vpmadt032tone_to_zaptone(GpakToneCodes_t tone);
  123. int vpmadt032_test(struct vpmadt032 *vpm, struct voicebus *vb);
  124. int vpmadt032_init(struct vpmadt032 *vpm);
  125. int vpmadt032_reset(struct vpmadt032 *vpm);
  126. struct vpmadt032 *vpmadt032_alloc(struct vpmadt032_options *options);
  127. void vpmadt032_free(struct vpmadt032 *vpm);
  128. int vpmadt032_echocan_create(struct vpmadt032 *vpm, int channo,
  129. enum adt_companding companding,
  130. struct dahdi_echocanparams *ecp,
  131. struct dahdi_echocanparam *p);
  132. void vpmadt032_echocan_free(struct vpmadt032 *vpm, int channo,
  133. struct dahdi_echocan_state *ec);
  134. struct GpakEcanParms;
  135. void vpmadt032_get_default_parameters(struct GpakEcanParms *p);
  136. /* If there is a command ready to go to the VPMADT032, return it, otherwise
  137. * NULL. Call with local interrupts disabled. */
  138. static inline struct vpmadt032_cmd *vpmadt032_get_ready_cmd(struct vpmadt032 *vpm)
  139. {
  140. struct vpmadt032_cmd *cmd;
  141. spin_lock(&vpm->list_lock);
  142. if (list_empty(&vpm->pending_cmds)) {
  143. spin_unlock(&vpm->list_lock);
  144. return NULL;
  145. }
  146. cmd = list_entry(vpm->pending_cmds.next, struct vpmadt032_cmd, node);
  147. list_move_tail(&cmd->node, &vpm->active_cmds);
  148. spin_unlock(&vpm->list_lock);
  149. return cmd;
  150. }
  151. /**
  152. * call with local interrupts disabled.
  153. */
  154. static inline void vpmadt032_resend(struct vpmadt032 *vpm)
  155. {
  156. struct vpmadt032_cmd *cmd, *temp;
  157. /* By moving the commands back to the pending list, they will be
  158. * transmitted when room is available */
  159. spin_lock(&vpm->list_lock);
  160. list_for_each_entry_safe(cmd, temp, &vpm->active_cmds, node) {
  161. cmd->desc &= ~(__VPM150M_TX);
  162. list_move_tail(&cmd->node, &vpm->pending_cmds);
  163. }
  164. spin_unlock(&vpm->list_lock);
  165. }
  166. typedef __u16 DSP_WORD; /* 16 bit DSP word */
  167. typedef __u32 DSP_ADDRESS; /* 32 bit DSP address */
  168. typedef __u32 GPAK_FILE_ID; /* G.PAK Download file identifier */
  169. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  170. * gpakReadDspMemory - Read DSP memory.
  171. *
  172. * FUNCTION
  173. * This function reads a contiguous block of words from DSP memory starting at
  174. * the specified address.
  175. *
  176. * RETURNS
  177. * nothing
  178. *
  179. */
  180. extern void gpakReadDspMemory(
  181. unsigned short int DspId, /* DSP Identifier (0 to MAX_DSP_CORES-1) */
  182. DSP_ADDRESS DspAddress, /* DSP's memory address of first word */
  183. unsigned int NumWords, /* number of contiguous words to read */
  184. DSP_WORD *pWordValues /* pointer to array of word values variable */
  185. );
  186. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  187. * gpakWriteDspMemory - Write DSP memory.
  188. *
  189. * FUNCTION
  190. * This function writes a contiguous block of words to DSP memory starting at
  191. * the specified address.
  192. *
  193. * RETURNS
  194. * nothing
  195. *
  196. */
  197. extern void gpakWriteDspMemory(
  198. unsigned short int DspId, /* DSP Identifier (0 to MAX_DSP_CORES-1) */
  199. DSP_ADDRESS DspAddress, /* DSP's memory address of first word */
  200. unsigned int NumWords, /* number of contiguous words to write */
  201. DSP_WORD *pWordValues /* pointer to array of word values to write */
  202. );
  203. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  204. * gpakHostDelay - Delay for a fixed time interval.
  205. *
  206. * FUNCTION
  207. * This function delays for a fixed time interval before returning. The time
  208. * interval is the Host Port Interface sampling period when polling a DSP for
  209. * replies to command messages.
  210. *
  211. * RETURNS
  212. * nothing
  213. *
  214. */
  215. extern void gpakHostDelay(void);
  216. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  217. * gpakLockAccess - Lock access to the specified DSP.
  218. *
  219. * FUNCTION
  220. * This function aquires exclusive access to the specified DSP.
  221. *
  222. * RETURNS
  223. * nothing
  224. *
  225. */
  226. extern void gpakLockAccess(
  227. unsigned short int DspId /* DSP Identifier (0 to MAX_DSP_CORES-1) */
  228. );
  229. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  230. * gpakUnlockAccess - Unlock access to the specified DSP.
  231. *
  232. * FUNCTION
  233. * This function releases exclusive access to the specified DSP.
  234. *
  235. * RETURNS
  236. * nothing
  237. *
  238. */
  239. extern void gpakUnlockAccess(
  240. unsigned short int DspId /* DSP Identifier (0 to MAX_DSP_CORES-1) */
  241. );
  242. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  243. * gpakReadFile - Read a block of bytes from a G.PAK Download file.
  244. *
  245. * FUNCTION
  246. * This function reads a contiguous block of bytes from a G.PAK Download file
  247. * starting at the current file position.
  248. *
  249. * RETURNS
  250. * The number of bytes read from the file.
  251. * -1 indicates an error occurred.
  252. * 0 indicates all bytes have been read (end of file)
  253. *
  254. */
  255. extern int gpakReadFile(
  256. GPAK_FILE_ID FileId, /* G.PAK Download File Identifier */
  257. unsigned char *pBuffer, /* pointer to buffer for storing bytes */
  258. unsigned int NumBytes /* number of bytes to read */
  259. );
  260. #endif /* prevent multiple inclusion */