| 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 | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 5 | * | 
|  | 6 | * Copyright 2000-2003 by Armin Schindler (mac@melware.de) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright 2000-2003 Cytronics & Melware (info@melware.de) | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 8 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> | 
|  | 16 | #include <asm/uaccess.h> | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 17 | #include <linux/seq_file.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/skbuff.h> | 
|  | 19 |  | 
|  | 20 | #include "os_capi.h" | 
|  | 21 |  | 
|  | 22 | #include "platform.h" | 
|  | 23 | #include "di_defs.h" | 
|  | 24 | #include "capi20.h" | 
|  | 25 | #include "divacapi.h" | 
|  | 26 | #include "cp_vers.h" | 
|  | 27 | #include "capifunc.h" | 
|  | 28 |  | 
|  | 29 | static char *main_revision = "$Revision: 1.24 $"; | 
|  | 30 | static char *DRIVERNAME = | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 31 | "Eicon DIVA - CAPI Interface driver (http://www.melware.net)"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static char *DRIVERLNAME = "divacapi"; | 
|  | 33 |  | 
|  | 34 | MODULE_DESCRIPTION("CAPI driver for Eicon DIVA cards"); | 
|  | 35 | MODULE_AUTHOR("Cytronics & Melware, Eicon Networks"); | 
|  | 36 | MODULE_SUPPORTED_DEVICE("CAPI and DIVA card drivers"); | 
|  | 37 | MODULE_LICENSE("GPL"); | 
|  | 38 |  | 
|  | 39 | /* | 
|  | 40 | * get revision number from revision string | 
|  | 41 | */ | 
|  | 42 | static char *getrev(const char *revision) | 
|  | 43 | { | 
|  | 44 | char *rev; | 
|  | 45 | char *p; | 
|  | 46 | if ((p = strchr(revision, ':'))) { | 
|  | 47 | rev = p + 2; | 
|  | 48 | p = strchr(rev, '$'); | 
|  | 49 | *--p = 0; | 
|  | 50 | } else | 
|  | 51 | rev = "1.0"; | 
|  | 52 | return rev; | 
|  | 53 |  | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | /* | 
|  | 57 | * alloc a message buffer | 
|  | 58 | */ | 
|  | 59 | diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, | 
|  | 60 | void **data_buf) | 
|  | 61 | { | 
|  | 62 | diva_os_message_buffer_s *dmb = alloc_skb(size, GFP_ATOMIC); | 
|  | 63 | if (dmb) { | 
|  | 64 | *data_buf = skb_put(dmb, size); | 
|  | 65 | } | 
|  | 66 | return (dmb); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | /* | 
|  | 70 | * free a message buffer | 
|  | 71 | */ | 
| Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | void diva_os_free_message_buffer(diva_os_message_buffer_s *dmb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { | 
|  | 74 | kfree_skb(dmb); | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | /* | 
|  | 78 | * proc function for controller info | 
|  | 79 | */ | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 80 | static int diva_ctl_proc_show(struct seq_file *m, void *v) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 82 | struct capi_ctr *ctrl = m->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | diva_card *card = (diva_card *) ctrl->driverdata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 85 | seq_printf(m, "%s\n", ctrl->name); | 
|  | 86 | seq_printf(m, "Serial No. : %s\n", ctrl->serial); | 
|  | 87 | seq_printf(m, "Id         : %d\n", card->Id); | 
|  | 88 | seq_printf(m, "Channels   : %d\n", card->d.channels); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 |  | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 90 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 93 | static int diva_ctl_proc_open(struct inode *inode, struct file *file) | 
|  | 94 | { | 
|  | 95 | return single_open(file, diva_ctl_proc_show, NULL); | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | static const struct file_operations diva_ctl_proc_fops = { | 
|  | 99 | .owner		= THIS_MODULE, | 
|  | 100 | .open		= diva_ctl_proc_open, | 
|  | 101 | .read		= seq_read, | 
|  | 102 | .llseek		= seq_lseek, | 
|  | 103 | .release	= single_release, | 
|  | 104 | }; | 
|  | 105 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* | 
|  | 107 | * set additional os settings in capi_ctr struct | 
|  | 108 | */ | 
|  | 109 | void diva_os_set_controller_struct(struct capi_ctr *ctrl) | 
|  | 110 | { | 
|  | 111 | ctrl->driver_name = DRIVERLNAME; | 
|  | 112 | ctrl->load_firmware = NULL; | 
|  | 113 | ctrl->reset_ctr = NULL; | 
| Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 114 | ctrl->proc_fops = &diva_ctl_proc_fops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | ctrl->owner = THIS_MODULE; | 
|  | 116 | } | 
|  | 117 |  | 
|  | 118 | /* | 
|  | 119 | * module init | 
|  | 120 | */ | 
| hartleys | d739889 | 2012-04-24 12:56:03 +0000 | [diff] [blame] | 121 | static int __init divacapi_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { | 
|  | 123 | char tmprev[32]; | 
|  | 124 | int ret = 0; | 
|  | 125 |  | 
|  | 126 | sprintf(DRIVERRELEASE_CAPI, "%d.%d%s", DRRELMAJOR, DRRELMINOR, | 
|  | 127 | DRRELEXTRA); | 
|  | 128 |  | 
|  | 129 | printk(KERN_INFO "%s\n", DRIVERNAME); | 
|  | 130 | printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_CAPI); | 
|  | 131 | strcpy(tmprev, main_revision); | 
|  | 132 | printk("%s  Build: %s(%s)\n", getrev(tmprev), | 
|  | 133 | diva_capi_common_code_build, DIVA_BUILD); | 
|  | 134 |  | 
|  | 135 | if (!(init_capifunc())) { | 
|  | 136 | printk(KERN_ERR "%s: failed init capi_driver.\n", | 
|  | 137 | DRIVERLNAME); | 
|  | 138 | ret = -EIO; | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | return ret; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | /* | 
|  | 145 | * module exit | 
|  | 146 | */ | 
| hartleys | d739889 | 2012-04-24 12:56:03 +0000 | [diff] [blame] | 147 | static void __exit divacapi_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { | 
|  | 149 | finit_capifunc(); | 
|  | 150 | printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME); | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | module_init(divacapi_init); | 
|  | 154 | module_exit(divacapi_exit); |