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
28 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/mISDNdsp.h>
31 #include <linux/mISDNif.h>
32 #include "core.h"
33 #include "dsp.h"
34 #include "dsp_hwec.h"
35
36 static struct mISDN_dsp_element_arg args[] = {
37 { "deftaps", "128", "Set the number of taps of cancellation." },
38 };
39
40 static struct mISDN_dsp_element dsp_hwec_p = {
41 .name = "hwec",
42 .new = NULL,
43 .free = NULL,
44 .process_tx = NULL,
45 .process_rx = NULL,
46 .num_args = ARRAY_SIZE(args),
47 .args = args,
48 };
49 struct mISDN_dsp_element *dsp_hwec = &dsp_hwec_p;
50
dsp_hwec_enable(struct dsp * dsp,const char * arg)51 void dsp_hwec_enable(struct dsp *dsp, const char *arg)
52 {
53 int deftaps = 128,
54 len;
55 struct mISDN_ctrl_req cq;
56
57 if (!dsp) {
58 printk(KERN_ERR "%s: failed to enable hwec: dsp is NULL\n",
59 __func__);
60 return;
61 }
62
63 if (!arg)
64 goto _do;
65
66 len = strlen(arg);
67 if (!len)
68 goto _do;
69
70 {
71 char *dup, *tok, *name, *val;
72 int tmp;
73
74 dup = kstrdup(arg, GFP_ATOMIC);
75 if (!dup)
76 return;
77
78 while ((tok = strsep(&dup, ","))) {
79 if (!strlen(tok))
80 continue;
81 name = strsep(&tok, "=");
82 val = tok;
83
84 if (!val)
85 continue;
86
87 if (!strcmp(name, "deftaps")) {
88 if (sscanf(val, "%d", &tmp) == 1)
89 deftaps = tmp;
90 }
91 }
92
93 kfree(dup);
94 }
95
96 _do:
97 printk(KERN_DEBUG "%s: enabling hwec with deftaps=%d\n",
98 __func__, deftaps);
99 memset(&cq, 0, sizeof(cq));
100 cq.op = MISDN_CTRL_HFC_ECHOCAN_ON;
101 cq.p1 = deftaps;
102 if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
103 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
104 __func__);
105 return;
106 }
107 }
108
dsp_hwec_disable(struct dsp * dsp)109 void dsp_hwec_disable(struct dsp *dsp)
110 {
111 struct mISDN_ctrl_req cq;
112
113 if (!dsp) {
114 printk(KERN_ERR "%s: failed to disable hwec: dsp is NULL\n",
115 __func__);
116 return;
117 }
118
119 printk(KERN_DEBUG "%s: disabling hwec\n", __func__);
120 memset(&cq, 0, sizeof(cq));
121 cq.op = MISDN_CTRL_HFC_ECHOCAN_OFF;
122 if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
123 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
124 __func__);
125 return;
126 }
127 }
128
dsp_hwec_init(void)129 int dsp_hwec_init(void)
130 {
131 mISDN_dsp_element_register(dsp_hwec);
132
133 return 0;
134 }
135
dsp_hwec_exit(void)136 void dsp_hwec_exit(void)
137 {
138 mISDN_dsp_element_unregister(dsp_hwec);
139 }
140