dsp_hwec.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * dsp_hwec.c:
  3. * builtin mISDN dsp pipeline element for enabling the hw echocanceller
  4. *
  5. * Copyright (C) 2007, Nadi Sarrar
  6. *
  7. * Nadi Sarrar <nadi@beronet.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * The full GNU General Public License is included in this distribution in the
  24. * file called LICENSE.
  25. *
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/string.h>
  29. #include <linux/mISDNdsp.h>
  30. #include <linux/mISDNif.h>
  31. #include "core.h"
  32. #include "dsp.h"
  33. #include "dsp_hwec.h"
  34. static struct mISDN_dsp_element_arg args[] = {
  35. { "deftaps", "128", "Set the number of taps of cancellation." },
  36. };
  37. static struct mISDN_dsp_element dsp_hwec_p = {
  38. .name = "hwec",
  39. .new = NULL,
  40. .free = NULL,
  41. .process_tx = NULL,
  42. .process_rx = NULL,
  43. .num_args = ARRAY_SIZE(args),
  44. .args = args,
  45. };
  46. struct mISDN_dsp_element *dsp_hwec = &dsp_hwec_p;
  47. void dsp_hwec_enable(struct dsp *dsp, const char *arg)
  48. {
  49. int deftaps = 128,
  50. len;
  51. struct mISDN_ctrl_req cq;
  52. if (!dsp) {
  53. printk(KERN_ERR "%s: failed to enable hwec: dsp is NULL\n",
  54. __func__);
  55. return;
  56. }
  57. if (!arg)
  58. goto _do;
  59. len = strlen(arg);
  60. if (!len)
  61. goto _do;
  62. {
  63. char _dup[len + 1];
  64. char *dup, *tok, *name, *val;
  65. int tmp;
  66. strcpy(_dup, arg);
  67. dup = _dup;
  68. while ((tok = strsep(&dup, ","))) {
  69. if (!strlen(tok))
  70. continue;
  71. name = strsep(&tok, "=");
  72. val = tok;
  73. if (!val)
  74. continue;
  75. if (!strcmp(name, "deftaps")) {
  76. if (sscanf(val, "%d", &tmp) == 1)
  77. deftaps = tmp;
  78. }
  79. }
  80. }
  81. _do:
  82. printk(KERN_DEBUG "%s: enabling hwec with deftaps=%d\n",
  83. __func__, deftaps);
  84. memset(&cq, 0, sizeof(cq));
  85. cq.op = MISDN_CTRL_HFC_ECHOCAN_ON;
  86. cq.p1 = deftaps;
  87. if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
  88. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  89. __func__);
  90. return;
  91. }
  92. }
  93. void dsp_hwec_disable(struct dsp *dsp)
  94. {
  95. struct mISDN_ctrl_req cq;
  96. if (!dsp) {
  97. printk(KERN_ERR "%s: failed to disable hwec: dsp is NULL\n",
  98. __func__);
  99. return;
  100. }
  101. printk(KERN_DEBUG "%s: disabling hwec\n", __func__);
  102. memset(&cq, 0, sizeof(cq));
  103. cq.op = MISDN_CTRL_HFC_ECHOCAN_OFF;
  104. if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
  105. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  106. __func__);
  107. return;
  108. }
  109. }
  110. int dsp_hwec_init(void)
  111. {
  112. mISDN_dsp_element_register(dsp_hwec);
  113. return 0;
  114. }
  115. void dsp_hwec_exit(void)
  116. {
  117. mISDN_dsp_element_unregister(dsp_hwec);
  118. }