~xnox/debian/sid/dahdi-linux/nmu-659818

« back to all changes in this revision

Viewing changes to drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell, Tzafrir Cohen, Victor Seva
  • Date: 2009-05-20 07:22:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090520072246-y1ba8ofc81ykgf8z
Tags: 1:2.2.0~dfsg~rc4-1
* New upstream release

[ Tzafrir Cohen ]
* NOT RELEASED YET
* Dropped qozap as wcb4xxp provides that functionality.
* New upstream RC.
* Actually build OpenVox drivers.
* opvxa1200.c: rev. 1.4.12.4 (battery fixes and such)
* Fix '${match}' in udev rules file (hardwire).
* no_firmware_download: Disable downloading a binary kernel module at 
  build time.

[ Victor Seva ]
* fix debian/watch. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DAHDI Telephony Interface to VPMADT032 Firmware Loader
 
3
 *
 
4
 * Copyright (C) 2008-2009 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
 
 
27
#include <dahdi/kernel.h>
 
28
 
 
29
static int debug;
 
30
 
 
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, \
 
35
        __func__, ## args)
 
36
 
 
37
#include "voicebus/voicebus.h"
 
38
#include "voicebus/vpmadtreg.h"
 
39
#include "vpmadt032_loader.h"
 
40
 
 
41
vpmlinkage static int __attribute__((format (printf, 1, 2)))
 
42
logger(const char *format, ...)
 
43
{
 
44
        int res;
 
45
        va_list args;
 
46
 
 
47
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
 
48
        va_start(args, format);
 
49
        res = vprintk(format, args);
 
50
        va_end(args);
 
51
#else
 
52
        char buf[256];
 
53
 
 
54
        va_start(args, format);
 
55
        res = vsnprintf(buf, sizeof(buf), format, args);
 
56
        va_end(args);
 
57
        printk(KERN_INFO "%s" buf);
 
58
#endif
 
59
 
 
60
        return res;
 
61
}
 
62
 
 
63
vpmlinkage static void *memalloc(size_t len)
 
64
{
 
65
        return kmalloc(len, GFP_KERNEL);
 
66
}
 
67
 
 
68
vpmlinkage static void memfree(void *ptr)
 
69
{
 
70
        kfree(ptr);
 
71
}
 
72
 
 
73
struct private_context {
 
74
        struct voicebus *vb;
 
75
        void *old_rx;
 
76
        void *old_tx;
 
77
        void *old_context;
 
78
        void *pvt;
 
79
        struct completion done;
 
80
};
 
81
 
 
82
static void init_private_context(struct private_context *ctx)
 
83
{
 
84
        memset(ctx, 0, sizeof(ctx));
 
85
        init_completion(&ctx->done);
 
86
}
 
87
 
 
88
static void handle_receive(void *vbb, void *context)
 
89
{
 
90
        struct private_context *ctx = context;
 
91
        __vpmadt032_receive(ctx->pvt, vbb);
 
92
        if (__vpmadt032_done(ctx->pvt))
 
93
                complete(&ctx->done);
 
94
}
 
95
 
 
96
static void handle_transmit(void *vbb, void *context)
 
97
{
 
98
        struct private_context *ctx = context;
 
99
        __vpmadt032_transmit(ctx->pvt, vbb);
 
100
        voicebus_transmit(ctx->vb, vbb);
 
101
}
 
102
 
 
103
static int vpmadt032_load_firmware(struct voicebus *vb)
 
104
{
 
105
        int ret = 0;
 
106
        struct private_context *ctx;
 
107
        struct pci_dev *pdev = voicebus_get_pci_dev(vb);
 
108
        might_sleep();
 
109
        ctx = kmalloc(sizeof(struct private_context), GFP_KERNEL);
 
110
        if (!ctx)
 
111
                return -ENOMEM;
 
112
        init_private_context(ctx);
 
113
        ctx->vb = vb;
 
114
        ret = __vpmadt032_start_load(
 
115
                        0, pdev->vendor << 16 | pdev->device,
 
116
                        &ctx->pvt);
 
117
        if (ret)
 
118
                goto error_exit;
 
119
        voicebus_get_handlers(vb, &ctx->old_rx, &ctx->old_tx,
 
120
                &ctx->old_context);
 
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);
 
125
error_exit:
 
126
        kfree(ctx);
 
127
        return 0;
 
128
}
 
129
 
 
130
static struct vpmadt_loader loader = {
 
131
        .owner = THIS_MODULE,
 
132
        .load = vpmadt032_load_firmware,
 
133
};
 
134
 
 
135
static int __init vpmadt032_loader_init(void)
 
136
{
 
137
        __vpmadt032_init(logger, debug, memalloc, memfree);
 
138
        vpmadtreg_register(&loader);
 
139
        return 0;
 
140
}
 
141
 
 
142
static void __exit vpmadt032_loader_exit(void)
 
143
{
 
144
        vpmadtreg_unregister(&loader);
 
145
        return;
 
146
}
 
147
 
 
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");
 
152
 
 
153
module_init(vpmadt032_loader_init);
 
154
module_exit(vpmadt032_loader_exit);