Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / isdn / hardware / eicon / capimain.c
1 /* $Id: capimain.c,v 1.24 2003/09/09 06:51:05 schindler Exp $
2  *
3  * ISDN interface module for Eicon active cards DIVA.
4  * CAPI Interface
5  * 
6  * Copyright 2000-2003 by Armin Schindler (mac@melware.de) 
7  * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
8  * 
9  * This software may be used and distributed according to the terms
10  * of the GNU General Public License, incorporated herein by reference.
11  */
12
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <asm/uaccess.h>
16 #include <linux/smp_lock.h>
17 #include <linux/skbuff.h>
18
19 #include "os_capi.h"
20
21 #include "platform.h"
22 #include "di_defs.h"
23 #include "capi20.h"
24 #include "divacapi.h"
25 #include "cp_vers.h"
26 #include "capifunc.h"
27
28 static char *main_revision = "$Revision: 1.24 $";
29 static char *DRIVERNAME =
30     "Eicon DIVA - CAPI Interface driver (http://www.melware.net)";
31 static char *DRIVERLNAME = "divacapi";
32
33 MODULE_DESCRIPTION("CAPI driver for Eicon DIVA cards");
34 MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
35 MODULE_SUPPORTED_DEVICE("CAPI and DIVA card drivers");
36 MODULE_LICENSE("GPL");
37
38 /*
39  * get revision number from revision string
40  */
41 static char *getrev(const char *revision)
42 {
43         char *rev;
44         char *p;
45         if ((p = strchr(revision, ':'))) {
46                 rev = p + 2;
47                 p = strchr(rev, '$');
48                 *--p = 0;
49         } else
50                 rev = "1.0";
51         return rev;
52
53 }
54
55 /*
56  * alloc a message buffer
57  */
58 diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size,
59                                                        void **data_buf)
60 {
61         diva_os_message_buffer_s *dmb = alloc_skb(size, GFP_ATOMIC);
62         if (dmb) {
63                 *data_buf = skb_put(dmb, size);
64         }
65         return (dmb);
66 }
67
68 /*
69  * free a message buffer
70  */
71 void diva_os_free_message_buffer(diva_os_message_buffer_s * dmb)
72 {
73         kfree_skb(dmb);
74 }
75
76 /*
77  * proc function for controller info
78  */
79 static int diva_ctl_read_proc(char *page, char **start, off_t off,
80                               int count, int *eof, struct capi_ctr *ctrl)
81 {
82         diva_card *card = (diva_card *) ctrl->driverdata;
83         int len = 0;
84
85         len += sprintf(page + len, "%s\n", ctrl->name);
86         len += sprintf(page + len, "Serial No. : %s\n", ctrl->serial);
87         len += sprintf(page + len, "Id         : %d\n", card->Id);
88         len += sprintf(page + len, "Channels   : %d\n", card->d.channels);
89
90         if (off + count >= len)
91                 *eof = 1;
92         if (len < off)
93                 return 0;
94         *start = page + off;
95         return ((count < len - off) ? count : len - off);
96 }
97
98 /*
99  * set additional os settings in capi_ctr struct
100  */
101 void diva_os_set_controller_struct(struct capi_ctr *ctrl)
102 {
103         ctrl->driver_name = DRIVERLNAME;
104         ctrl->load_firmware = NULL;
105         ctrl->reset_ctr = NULL;
106         ctrl->ctr_read_proc = diva_ctl_read_proc;
107         ctrl->owner = THIS_MODULE;
108 }
109
110 /*
111  * module init
112  */
113 static int DIVA_INIT_FUNCTION divacapi_init(void)
114 {
115         char tmprev[32];
116         int ret = 0;
117
118         sprintf(DRIVERRELEASE_CAPI, "%d.%d%s", DRRELMAJOR, DRRELMINOR,
119                 DRRELEXTRA);
120
121         printk(KERN_INFO "%s\n", DRIVERNAME);
122         printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_CAPI);
123         strcpy(tmprev, main_revision);
124         printk("%s  Build: %s(%s)\n", getrev(tmprev),
125                diva_capi_common_code_build, DIVA_BUILD);
126
127         if (!(init_capifunc())) {
128                 printk(KERN_ERR "%s: failed init capi_driver.\n",
129                        DRIVERLNAME);
130                 ret = -EIO;
131         }
132
133         return ret;
134 }
135
136 /*
137  * module exit
138  */
139 static void DIVA_EXIT_FUNCTION divacapi_exit(void)
140 {
141         finit_capifunc();
142         printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);
143 }
144
145 module_init(divacapi_init);
146 module_exit(divacapi_exit);