oct612x-user.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Octasic OCT6100 Interface
  3. *
  4. * Copyright (C) 2013 Digium, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. */
  9. /*
  10. * See http://www.asterisk.org for more information about
  11. * the Asterisk project. Please do not directly contact
  12. * any of the maintainers of this project for assistance;
  13. * the project provides a web site, mailing lists and IRC
  14. * channels for your use.
  15. *
  16. * This program is free software, distributed under the terms of
  17. * the GNU General Public License Version 2 as published by the
  18. * Free Software Foundation. See the LICENSE file included with
  19. * this program for more details.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <dahdi/kernel.h>
  24. #include "oct612x.h"
  25. UINT32 Oct6100UserGetTime(tPOCT6100_GET_TIME f_pTime)
  26. {
  27. /* Why couldn't they just take a timeval like everyone else? */
  28. struct timeval tv;
  29. unsigned long long total_usecs;
  30. unsigned int mask = ~0;
  31. do_gettimeofday(&tv);
  32. total_usecs = (((unsigned long long)(tv.tv_sec)) * 1000000) +
  33. (((unsigned long long)(tv.tv_usec)));
  34. f_pTime->aulWallTimeUs[0] = (total_usecs & mask);
  35. f_pTime->aulWallTimeUs[1] = (total_usecs >> 32);
  36. return cOCT6100_ERR_OK;
  37. }
  38. UINT32 Oct6100UserMemSet(PVOID f_pAddress, UINT32 f_ulPattern,
  39. UINT32 f_ulLength)
  40. {
  41. memset(f_pAddress, f_ulPattern, f_ulLength);
  42. return cOCT6100_ERR_OK;
  43. }
  44. UINT32 Oct6100UserMemCopy(PVOID f_pDestination, const void *f_pSource,
  45. UINT32 f_ulLength)
  46. {
  47. memcpy(f_pDestination, f_pSource, f_ulLength);
  48. return cOCT6100_ERR_OK;
  49. }
  50. UINT32 Oct6100UserCreateSerializeObject(
  51. tPOCT6100_CREATE_SERIALIZE_OBJECT f_pCreate)
  52. {
  53. struct oct612x_context *context = f_pCreate->pProcessContext;
  54. struct mutex *lock = kzalloc(sizeof(*lock), GFP_KERNEL);
  55. if (!lock) {
  56. dev_err(context->dev, "Out of memory in %s.\n", __func__);
  57. return cOCT6100_ERR_BASE;
  58. }
  59. mutex_init(lock);
  60. f_pCreate->ulSerialObjHndl = lock;
  61. return cOCT6100_ERR_OK;
  62. }
  63. UINT32 Oct6100UserDestroySerializeObject(
  64. tPOCT6100_DESTROY_SERIALIZE_OBJECT f_pDestroy)
  65. {
  66. struct mutex *lock = f_pDestroy->ulSerialObjHndl;
  67. kfree(lock);
  68. return cOCT6100_ERR_OK;
  69. }
  70. UINT32 Oct6100UserSeizeSerializeObject(
  71. tPOCT6100_SEIZE_SERIALIZE_OBJECT f_pSeize)
  72. {
  73. struct mutex *lock = f_pSeize->ulSerialObjHndl;
  74. mutex_lock(lock);
  75. return cOCT6100_ERR_OK;
  76. }
  77. UINT32 Oct6100UserReleaseSerializeObject(
  78. tPOCT6100_RELEASE_SERIALIZE_OBJECT f_pRelease)
  79. {
  80. struct mutex *lock = f_pRelease->ulSerialObjHndl;
  81. mutex_unlock(lock);
  82. return cOCT6100_ERR_OK;
  83. }
  84. UINT32 Oct6100UserDriverWriteApi(tPOCT6100_WRITE_PARAMS f_pWriteParams)
  85. {
  86. struct oct612x_context *context = f_pWriteParams->pProcessContext;
  87. #ifdef OCTASIC_DEBUG
  88. if (!context || !context->ops || !context->ops->write) {
  89. pr_debug("Invalid call to %s\n", __func__);
  90. return cOCT6100_ERR_BASE;
  91. }
  92. #endif
  93. context->ops->write(context, f_pWriteParams->ulWriteAddress,
  94. f_pWriteParams->usWriteData);
  95. return cOCT6100_ERR_OK;
  96. }
  97. UINT32 Oct6100UserDriverWriteSmearApi(tPOCT6100_WRITE_SMEAR_PARAMS f_pSmearParams)
  98. {
  99. struct oct612x_context *context = f_pSmearParams->pProcessContext;
  100. #ifdef OCTASIC_DEBUG
  101. if (!context || !context->ops || !context->ops->write_smear) {
  102. pr_debug("Invalid call to %s\n", __func__);
  103. return cOCT6100_ERR_BASE;
  104. }
  105. #endif
  106. context->ops->write_smear(context, f_pSmearParams->ulWriteAddress,
  107. f_pSmearParams->usWriteData,
  108. f_pSmearParams->ulWriteLength);
  109. return cOCT6100_ERR_OK;
  110. }
  111. UINT32 Oct6100UserDriverWriteBurstApi(
  112. tPOCT6100_WRITE_BURST_PARAMS f_pBurstParams)
  113. {
  114. struct oct612x_context *context = f_pBurstParams->pProcessContext;
  115. #ifdef OCTASIC_DEBUG
  116. if (!context || !context->ops || !context->ops->write_burst) {
  117. pr_debug("Invalid call to %s\n", __func__);
  118. return cOCT6100_ERR_BASE;
  119. }
  120. #endif
  121. context->ops->write_burst(context, f_pBurstParams->ulWriteAddress,
  122. f_pBurstParams->pusWriteData,
  123. f_pBurstParams->ulWriteLength);
  124. return cOCT6100_ERR_OK;
  125. }
  126. UINT32 Oct6100UserDriverReadApi(tPOCT6100_READ_PARAMS f_pReadParams)
  127. {
  128. struct oct612x_context *context = f_pReadParams->pProcessContext;
  129. #ifdef OCTASIC_DEBUG
  130. if (!context || !context->ops || !context->ops->read) {
  131. pr_debug("Invalid call to %s\n", __func__);
  132. return cOCT6100_ERR_BASE;
  133. }
  134. #endif
  135. context->ops->read(context, f_pReadParams->ulReadAddress,
  136. f_pReadParams->pusReadData);
  137. return cOCT6100_ERR_OK;
  138. }
  139. UINT32 Oct6100UserDriverReadBurstApi(tPOCT6100_READ_BURST_PARAMS f_pBurstParams)
  140. {
  141. struct oct612x_context *context = f_pBurstParams->pProcessContext;
  142. #ifdef OCTASIC_DEBUG
  143. if (!context || !context->ops || !context->ops->read_burst) {
  144. pr_debug("Invalid call to %s\n", __func__);
  145. return cOCT6100_ERR_BASE;
  146. }
  147. #endif
  148. context->ops->read_burst(context, f_pBurstParams->ulReadAddress,
  149. f_pBurstParams->pusReadData,
  150. f_pBurstParams->ulReadLength);
  151. return cOCT6100_ERR_OK;
  152. }
  153. EXPORT_SYMBOL(Oct6100ChipOpen);
  154. EXPORT_SYMBOL(Oct6100ChipClose);
  155. EXPORT_SYMBOL(Oct6100ChipCloseDef);
  156. EXPORT_SYMBOL(Oct6100GetInstanceSize);
  157. EXPORT_SYMBOL(Oct6100GetInstanceSizeDef);
  158. EXPORT_SYMBOL(Oct6100ChipOpenDef);
  159. EXPORT_SYMBOL(Oct6100ChannelModify);
  160. EXPORT_SYMBOL(Oct6100ToneDetectionEnableDef);
  161. EXPORT_SYMBOL(Oct6100InterruptServiceRoutine);
  162. EXPORT_SYMBOL(Oct6100InterruptServiceRoutineDef);
  163. EXPORT_SYMBOL(Oct6100ApiGetCapacityPins);
  164. EXPORT_SYMBOL(Oct6100ToneDetectionEnable);
  165. EXPORT_SYMBOL(Oct6100EventGetToneDef);
  166. EXPORT_SYMBOL(Oct6100EventGetTone);
  167. EXPORT_SYMBOL(Oct6100ApiGetCapacityPinsDef);
  168. EXPORT_SYMBOL(Oct6100ChannelOpen);
  169. EXPORT_SYMBOL(Oct6100ChannelOpenDef);
  170. EXPORT_SYMBOL(Oct6100ChannelModifyDef);
  171. static int __init oct612x_module_init(void)
  172. {
  173. /* This registration with dahdi.ko will fail since the span is not
  174. * defined, but it will make sure that this module is a dependency of
  175. * dahdi.ko, so that when it is being unloded, this module will be
  176. * unloaded as well. */
  177. dahdi_register_device(NULL, NULL);
  178. return 0;
  179. }
  180. module_init(oct612x_module_init);
  181. static void __exit oct612x_module_cleanup(void)
  182. {
  183. /* Nothing to do */;
  184. }
  185. module_exit(oct612x_module_cleanup);
  186. MODULE_AUTHOR("Digium Incorporated <support@digium.com>");
  187. MODULE_DESCRIPTION("Octasic OCT6100 Hardware Echocan Library");
  188. MODULE_LICENSE("GPL v2");