2
* DAHDI Telephony Interface to VPMADT032 Firmware Loader
4
* Copyright (C) 2008-2009 Digium, Inc. All rights reserved.
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.
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.
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.
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>
27
#include <dahdi/kernel.h>
31
#define module_printk(level, fmt, args...) \
32
printk(level "%s: " fmt, THIS_MODULE->name, ## args)
33
#define debug_printk(level, fmt, args...) if (debug >= level) \
34
printk(KERN_DEBUG "%s (%s): " fmt, THIS_MODULE->name, \
37
#include "voicebus/voicebus.h"
38
#include "voicebus/vpmadtreg.h"
39
#include "vpmadt032_loader.h"
41
vpmlinkage static int __attribute__((format (printf, 1, 2)))
42
logger(const char *format, ...)
47
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
48
va_start(args, format);
49
res = vprintk(format, args);
54
va_start(args, format);
55
res = vsnprintf(buf, sizeof(buf), format, args);
57
printk(KERN_INFO "%s" buf);
63
vpmlinkage static void *memalloc(size_t len)
65
return kmalloc(len, GFP_KERNEL);
68
vpmlinkage static void memfree(void *ptr)
73
struct private_context {
79
struct completion done;
82
static void init_private_context(struct private_context *ctx)
84
memset(ctx, 0, sizeof(ctx));
85
init_completion(&ctx->done);
88
static void handle_receive(void *vbb, void *context)
90
struct private_context *ctx = context;
91
__vpmadt032_receive(ctx->pvt, vbb);
92
if (__vpmadt032_done(ctx->pvt))
96
static void handle_transmit(void *vbb, void *context)
98
struct private_context *ctx = context;
99
__vpmadt032_transmit(ctx->pvt, vbb);
100
voicebus_transmit(ctx->vb, vbb);
103
static int vpmadt032_load_firmware(struct voicebus *vb)
106
struct private_context *ctx;
107
struct pci_dev *pdev = voicebus_get_pci_dev(vb);
109
ctx = kmalloc(sizeof(struct private_context), GFP_KERNEL);
112
init_private_context(ctx);
114
ret = __vpmadt032_start_load(
115
0, pdev->vendor << 16 | pdev->device,
119
voicebus_get_handlers(vb, &ctx->old_rx, &ctx->old_tx,
121
voicebus_set_handlers(vb, handle_receive, handle_transmit, ctx);
122
wait_for_completion(&ctx->done);
123
voicebus_set_handlers(vb, ctx->old_rx, ctx->old_tx, ctx->old_context);
124
__vpmadt032_cleanup(ctx->pvt);
130
static struct vpmadt_loader loader = {
131
.owner = THIS_MODULE,
132
.load = vpmadt032_load_firmware,
135
static int __init vpmadt032_loader_init(void)
137
__vpmadt032_init(logger, debug, memalloc, memfree);
138
vpmadtreg_register(&loader);
142
static void __exit vpmadt032_loader_exit(void)
144
vpmadtreg_unregister(&loader);
148
module_param(debug, int, S_IRUGO | S_IWUSR);
149
MODULE_DESCRIPTION("DAHDI VPMADT032 (Hardware Echo Canceller) Firmware Loader");
150
MODULE_AUTHOR("Digium Incorporated <support@digium.com>");
151
MODULE_LICENSE("Digium Commercial");
153
module_init(vpmadt032_loader_init);
154
module_exit(vpmadt032_loader_exit);