| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> | 
|  | 14 | #include <linux/init.h> | 
|  | 15 | #include <asm/uaccess.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/skbuff.h> | 
|  | 17 |  | 
|  | 18 | #include "os_capi.h" | 
|  | 19 |  | 
|  | 20 | #include "platform.h" | 
|  | 21 | #include "di_defs.h" | 
|  | 22 | #include "capi20.h" | 
|  | 23 | #include "divacapi.h" | 
|  | 24 | #include "cp_vers.h" | 
|  | 25 | #include "capifunc.h" | 
|  | 26 |  | 
|  | 27 | static char *main_revision = "$Revision: 1.24 $"; | 
|  | 28 | static char *DRIVERNAME = | 
|  | 29 | "Eicon DIVA - CAPI Interface driver (http://www.melware.net)"; | 
|  | 30 | static char *DRIVERLNAME = "divacapi"; | 
|  | 31 |  | 
|  | 32 | MODULE_DESCRIPTION("CAPI driver for Eicon DIVA cards"); | 
|  | 33 | MODULE_AUTHOR("Cytronics & Melware, Eicon Networks"); | 
|  | 34 | MODULE_SUPPORTED_DEVICE("CAPI and DIVA card drivers"); | 
|  | 35 | MODULE_LICENSE("GPL"); | 
|  | 36 |  | 
|  | 37 | /* | 
|  | 38 | * get revision number from revision string | 
|  | 39 | */ | 
|  | 40 | static char *getrev(const char *revision) | 
|  | 41 | { | 
|  | 42 | char *rev; | 
|  | 43 | char *p; | 
|  | 44 | if ((p = strchr(revision, ':'))) { | 
|  | 45 | rev = p + 2; | 
|  | 46 | p = strchr(rev, '$'); | 
|  | 47 | *--p = 0; | 
|  | 48 | } else | 
|  | 49 | rev = "1.0"; | 
|  | 50 | return rev; | 
|  | 51 |  | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | /* | 
|  | 55 | * alloc a message buffer | 
|  | 56 | */ | 
|  | 57 | diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, | 
|  | 58 | void **data_buf) | 
|  | 59 | { | 
|  | 60 | diva_os_message_buffer_s *dmb = alloc_skb(size, GFP_ATOMIC); | 
|  | 61 | if (dmb) { | 
|  | 62 | *data_buf = skb_put(dmb, size); | 
|  | 63 | } | 
|  | 64 | return (dmb); | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | /* | 
|  | 68 | * free a message buffer | 
|  | 69 | */ | 
|  | 70 | void diva_os_free_message_buffer(diva_os_message_buffer_s * dmb) | 
|  | 71 | { | 
|  | 72 | kfree_skb(dmb); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | /* | 
|  | 76 | * proc function for controller info | 
|  | 77 | */ | 
|  | 78 | static int diva_ctl_read_proc(char *page, char **start, off_t off, | 
|  | 79 | int count, int *eof, struct capi_ctr *ctrl) | 
|  | 80 | { | 
|  | 81 | diva_card *card = (diva_card *) ctrl->driverdata; | 
|  | 82 | int len = 0; | 
|  | 83 |  | 
|  | 84 | len += sprintf(page + len, "%s\n", ctrl->name); | 
|  | 85 | len += sprintf(page + len, "Serial No. : %s\n", ctrl->serial); | 
|  | 86 | len += sprintf(page + len, "Id         : %d\n", card->Id); | 
|  | 87 | len += sprintf(page + len, "Channels   : %d\n", card->d.channels); | 
|  | 88 |  | 
|  | 89 | if (off + count >= len) | 
|  | 90 | *eof = 1; | 
|  | 91 | if (len < off) | 
|  | 92 | return 0; | 
|  | 93 | *start = page + off; | 
|  | 94 | return ((count < len - off) ? count : len - off); | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | /* | 
|  | 98 | * set additional os settings in capi_ctr struct | 
|  | 99 | */ | 
|  | 100 | void diva_os_set_controller_struct(struct capi_ctr *ctrl) | 
|  | 101 | { | 
|  | 102 | ctrl->driver_name = DRIVERLNAME; | 
|  | 103 | ctrl->load_firmware = NULL; | 
|  | 104 | ctrl->reset_ctr = NULL; | 
|  | 105 | ctrl->ctr_read_proc = diva_ctl_read_proc; | 
|  | 106 | ctrl->owner = THIS_MODULE; | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | /* | 
|  | 110 | * module init | 
|  | 111 | */ | 
|  | 112 | static int DIVA_INIT_FUNCTION divacapi_init(void) | 
|  | 113 | { | 
|  | 114 | char tmprev[32]; | 
|  | 115 | int ret = 0; | 
|  | 116 |  | 
|  | 117 | sprintf(DRIVERRELEASE_CAPI, "%d.%d%s", DRRELMAJOR, DRRELMINOR, | 
|  | 118 | DRRELEXTRA); | 
|  | 119 |  | 
|  | 120 | printk(KERN_INFO "%s\n", DRIVERNAME); | 
|  | 121 | printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_CAPI); | 
|  | 122 | strcpy(tmprev, main_revision); | 
|  | 123 | printk("%s  Build: %s(%s)\n", getrev(tmprev), | 
|  | 124 | diva_capi_common_code_build, DIVA_BUILD); | 
|  | 125 |  | 
|  | 126 | if (!(init_capifunc())) { | 
|  | 127 | printk(KERN_ERR "%s: failed init capi_driver.\n", | 
|  | 128 | DRIVERLNAME); | 
|  | 129 | ret = -EIO; | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | return ret; | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 | /* | 
|  | 136 | * module exit | 
|  | 137 | */ | 
|  | 138 | static void DIVA_EXIT_FUNCTION divacapi_exit(void) | 
|  | 139 | { | 
|  | 140 | finit_capifunc(); | 
|  | 141 | printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | module_init(divacapi_init); | 
|  | 145 | module_exit(divacapi_exit); |