ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / isdn / hardware / eicon / diva_didd.c
1 /* $Id: diva_didd.c,v 1.13 2003/08/27 10:11:21 schindler Exp $
2  *
3  * DIDD Interface module for Eicon active cards.
4  * 
5  * Functions are in dadapter.c 
6  * 
7  * Copyright 2002-2003 by Armin Schindler (mac@melware.de) 
8  * Copyright 2002-2003 Cytronics & Melware (info@melware.de)
9  * 
10  * This software may be used and distributed according to the terms
11  * of the GNU General Public License, incorporated herein by reference.
12  */
13
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/proc_fs.h>
19
20 #include "platform.h"
21 #include "di_defs.h"
22 #include "dadapter.h"
23 #include "divasync.h"
24 #include "did_vers.h"
25
26 static char *main_revision = "$Revision: 1.13 $";
27
28 static char *DRIVERNAME =
29     "Eicon DIVA - DIDD table (http://www.melware.net)";
30 static char *DRIVERLNAME = "divadidd";
31 char *DRIVERRELEASE_DIDD = "2.0";
32
33 static char *main_proc_dir = "eicon";
34
35 MODULE_DESCRIPTION("DIDD table driver for diva drivers");
36 MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
37 MODULE_SUPPORTED_DEVICE("Eicon diva drivers");
38 MODULE_LICENSE("GPL");
39
40 #define MAX_DESCRIPTORS  32
41
42 #define DBG_MINIMUM  (DL_LOG + DL_FTL + DL_ERR)
43 #define DBG_DEFAULT  (DBG_MINIMUM + DL_XLOG + DL_REG)
44
45 extern int diddfunc_init(void);
46 extern void diddfunc_finit(void);
47
48 extern void DIVA_DIDD_Read(void *, int);
49
50 static struct proc_dir_entry *proc_didd;
51 struct proc_dir_entry *proc_net_eicon = NULL;
52
53 EXPORT_SYMBOL_NOVERS(DIVA_DIDD_Read);
54 EXPORT_SYMBOL_NOVERS(proc_net_eicon);
55
56 static char *getrev(const char *revision)
57 {
58         char *rev;
59         char *p;
60         if ((p = strchr(revision, ':'))) {
61                 rev = p + 2;
62                 p = strchr(rev, '$');
63                 *--p = 0;
64         } else
65                 rev = "1.0";
66         return rev;
67 }
68
69 static int
70 proc_read(char *page, char **start, off_t off, int count, int *eof,
71           void *data)
72 {
73         int len = 0;
74         char tmprev[32];
75
76         strcpy(tmprev, main_revision);
77         len += sprintf(page + len, "%s\n", DRIVERNAME);
78         len += sprintf(page + len, "name     : %s\n", DRIVERLNAME);
79         len += sprintf(page + len, "release  : %s\n", DRIVERRELEASE_DIDD);
80         len += sprintf(page + len, "build    : %s(%s)\n",
81                        diva_didd_common_code_build, DIVA_BUILD);
82         len += sprintf(page + len, "revision : %s\n", getrev(tmprev));
83
84         if (off + count >= len)
85                 *eof = 1;
86         if (len < off)
87                 return 0;
88         *start = page + off;
89         return ((count < len - off) ? count : len - off);
90 }
91
92 static int DIVA_INIT_FUNCTION create_proc(void)
93 {
94         proc_net_eicon = create_proc_entry(main_proc_dir, S_IFDIR, proc_net);
95
96         if (proc_net_eicon) {
97                 if ((proc_didd =
98                      create_proc_entry(DRIVERLNAME, S_IFREG | S_IRUGO,
99                                        proc_net_eicon))) {
100                         proc_didd->read_proc = proc_read;
101                 }
102                 return (1);
103         }
104         return (0);
105 }
106
107 static void DIVA_EXIT_FUNCTION remove_proc(void)
108 {
109         remove_proc_entry(DRIVERLNAME, proc_net_eicon);
110         remove_proc_entry(main_proc_dir, proc_net);
111 }
112
113 static int DIVA_INIT_FUNCTION divadidd_init(void)
114 {
115         char tmprev[32];
116         int ret = 0;
117
118         printk(KERN_INFO "%s\n", DRIVERNAME);
119         printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_DIDD);
120         strcpy(tmprev, main_revision);
121         printk("%s  Build:%s(%s)\n", getrev(tmprev),
122                diva_didd_common_code_build, DIVA_BUILD);
123
124         if (!create_proc()) {
125                 printk(KERN_ERR "%s: could not create proc entry\n",
126                        DRIVERLNAME);
127                 ret = -EIO;
128                 goto out;
129         }
130
131         if (!diddfunc_init()) {
132                 printk(KERN_ERR "%s: failed to connect to DIDD.\n",
133                        DRIVERLNAME);
134 #ifdef MODULE
135                 remove_proc();
136 #endif
137                 ret = -EIO;
138                 goto out;
139         }
140
141       out:
142         return (ret);
143 }
144
145 void DIVA_EXIT_FUNCTION divadidd_exit(void)
146 {
147         diddfunc_finit();
148         remove_proc();
149         printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);
150 }
151
152 module_init(divadidd_init);
153 module_exit(divadidd_exit);