Debian Codegraph @

drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c

raw symbols SCIP
1 /*
2 * DAHDI Telephony Interface to VPMADT032 Firmware Loader
3 *
4 * Copyright (C) 2008-2012 Digium, Inc. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/ctype.h>
24 #include <linux/moduleparam.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27
28 #include <dahdi/kernel.h>
29
30 static int debug;
31
32 #include "voicebus/voicebus.h"
33 #include "voicebus/vpmadtreg.h"
34 #include "vpmadt032_loader.h"
35
36 vpmlinkage static int __attribute__((format (printf, 1, 2)))
37 logger(const char *format, ...)
38 {
39 int res;
40 va_list args;
41
42 va_start(args, format);
43 res = vprintk(format, args);
44 va_end(args);
45
46 return res;
47 }
48
49 vpmlinkage static void *memalloc(size_t len)
50 {
51 return kmalloc(len, GFP_KERNEL);
52 }
53
54 vpmlinkage static void memfree(void *ptr)
55 {
56 kfree(ptr);
57 }
58
59 struct private_context {
60 struct voicebus *vb;
61 void *pvt;
62 struct completion done;
63 struct voicebus_operations ops;
64 };
65
66 static void handle_receive(struct voicebus *vb, struct list_head *buffers)
67 {
68 struct vbb *vbb;
69 struct private_context *ctx = container_of(vb->ops,
70 struct private_context, ops);
71 list_for_each_entry(vbb, buffers, entry) {
72 __vpmadt032_receive(ctx->pvt, vbb->data);
73 if (__vpmadt032_done(ctx->pvt))
74 complete(&ctx->done);
75 }
76 }
77
78 static void handle_transmit(struct voicebus *vb, struct list_head *buffers)
79 {
80 struct vbb *vbb;
81 struct private_context *ctx = container_of(vb->ops,
82 struct private_context, ops);
83 list_for_each_entry(vbb, buffers, entry)
84 __vpmadt032_transmit(ctx->pvt, vbb->data);
85 }
86
87 static void init_private_context(struct private_context *ctx)
88 {
89 init_completion(&ctx->done);
90 ctx->ops.handle_receive = handle_receive;
91 ctx->ops.handle_transmit = handle_transmit;
92 }
93
94 static int vpmadt032_load_firmware(struct voicebus *vb)
95 {
96 int ret = 0;
97 struct private_context *ctx;
98 const struct voicebus_operations *old;
99 int id;
100 might_sleep();
101 ctx = kzalloc(sizeof(struct private_context), GFP_KERNEL);
102 if (!ctx)
103 return -ENOMEM;
104 init_private_context(ctx);
105 ctx->vb = vb;
106
107 if (0x8007 == vb->pdev->device || 0x8008 == vb->pdev->device)
108 id = vb->pdev->vendor << 16 | 0x2400;
109 else
110 id = vb->pdev->vendor << 16 | vb->pdev->device;
111
112 ret = __vpmadt032_start_load(0, id, &ctx->pvt);
113 if (ret)
114 goto error_exit;
115 old = vb->ops;
116 vb->ops = &ctx->ops;
117 if (!wait_for_completion_timeout(&ctx->done, HZ*20))
118 ret = -EIO;
119 vb->ops = old;
120 __vpmadt032_cleanup(ctx->pvt);
121 error_exit:
122 kfree(ctx);
123 return ret;
124 }
125
126 static struct vpmadt_loader loader = {
127 .owner = THIS_MODULE,
128 .load = vpmadt032_load_firmware,
129 };
130
131 static int __init vpmadt032_loader_init(void)
132 {
133 __vpmadt032_init(logger, debug, memalloc, memfree);
134 vpmadtreg_register(&loader);
135 return 0;
136 }
137
138 static void __exit vpmadt032_loader_exit(void)
139 {
140 vpmadtreg_unregister(&loader);
141 return;
142 }
143
144 module_param(debug, int, S_IRUGO | S_IWUSR);
145 MODULE_DESCRIPTION("DAHDI VPMADT032 (Hardware Echo Canceller) Firmware Loader");
146 MODULE_AUTHOR("Digium Incorporated <[email protected]>");
147 MODULE_LICENSE("Digium Commercial");
148
149 module_init(vpmadt032_loader_init);
150 module_exit(vpmadt032_loader_exit);