dsp_hwec.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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, *tok, *name, *val;
  64. int tmp;
  65. dup = kstrdup(arg, GFP_ATOMIC);
  66. if (!dup)
  67. return;
  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. kfree(dup);
  81. }
  82. _do:
  83. printk(KERN_DEBUG "%s: enabling hwec with deftaps=%d\n",
  84. __func__, deftaps);
  85. memset(&cq, 0, sizeof(cq));
  86. cq.op = MISDN_CTRL_HFC_ECHOCAN_ON;
  87. cq.p1 = deftaps;
  88. if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
  89. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  90. __func__);
  91. return;
  92. }
  93. }
  94. void dsp_hwec_disable(struct dsp *dsp)
  95. {
  96. struct mISDN_ctrl_req cq;
  97. if (!dsp) {
  98. printk(KERN_ERR "%s: failed to disable hwec: dsp is NULL\n",
  99. __func__);
  100. return;
  101. }
  102. printk(KERN_DEBUG "%s: disabling hwec\n", __func__);
  103. memset(&cq, 0, sizeof(cq));
  104. cq.op = MISDN_CTRL_HFC_ECHOCAN_OFF;
  105. if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
  106. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  107. __func__);
  108. return;
  109. }
  110. }
  111. int dsp_hwec_init(void)
  112. {
  113. mISDN_dsp_element_register(dsp_hwec);
  114. return 0;
  115. }
  116. void dsp_hwec_exit(void)
  117. {
  118. mISDN_dsp_element_unregister(dsp_hwec);
  119. }