[Asterisk-cvs] zaptel ztdummy.c,1.3,1.4

markster at lists.digium.com markster at lists.digium.com
Sat Jun 26 16:06:12 CDT 2004


Update of /usr/cvsroot/zaptel
In directory mongoose.digium.com:/tmp/cvs-serv19427

Modified Files:
	ztdummy.c 
Log Message:
Merge 2.6 and 2.4 versions of ztdummy (no longer needs UHCI for kernel > 2.6.0)


Index: ztdummy.c
===================================================================
RCS file: /usr/cvsroot/zaptel/ztdummy.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ztdummy.c	27 Oct 2003 15:09:58 -0000	1.3
+++ ztdummy.c	26 Jun 2004 19:52:06 -0000	1.4
@@ -1,11 +1,14 @@
 /*
  * Dummy Zaptel Driver for Zapata Telephony interface
  *
- * Required: usb-uhci module and kernel > 2.4.4
+ * Required: usb-uhci module and kernel > 2.4.4 OR kernel > 2.6.0
  *
  * Written by Robert Pleh <robert.pleh at hermes.si>
+ * 2.6 version by Tony Hoyle
+ * Unified by Mark Spencer <markster at digium.com>
  *
  * Copyright (C) 2002, Hermes Softlab
+ * Copyright (C) 2004, Digium, Inc.
  *
  * All rights reserved.
  *
@@ -24,15 +27,27 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
-#include <asm/io.h>
+#include <linux/version.h>
+
+#ifndef VERSION_CODE
+#  define VERSION_CODE(vers,rel,seq) ( ((vers)<<16) | ((rel)<<8) | (seq) )
+#endif
+
+
+#if LINUX_VERSION_CODE < VERSION_CODE(2,4,5)
+#  error "This kernel is too old: not supported by this file"
+#endif
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/errno.h>
+#ifndef LINUX26
 #include <linux/usb.h>
 #include <linux/pci.h>
-#include <linux/errno.h>
 #include <asm/io.h>
+#endif
 #ifdef STANDALONE_ZAPATA
 #include "zaptel.h"
 #else
@@ -54,15 +69,21 @@
 #  error "This kernel is too old: not supported by this file"
 #endif
 
+static struct ztdummy *ztd;
 
+static int debug = 0;
 
-static struct ztdummy *ztd;
+#ifdef LINUX26
+/* New 2.6 kernel timer stuff */
+static struct timer_list timer;
+#else
+#if LINUX_VERSION_CODE < VERSION_CODE(2,4,5)
+#  error "This kernel is too old: not supported by this file"
+#endif
+/* Old UCHI stuff */
 static    uhci_desc_t  *td;
 static    uhci_t *s;
 static int check_int = 0;
-
-
-static int debug = 0;
 static int monitor = 0;
 
 /* exported kernel symbols */
@@ -75,7 +96,18 @@
 extern int delete_desc (uhci_t *s, uhci_desc_t *element);
 extern uhci_t **uhci_devices;
 
+#endif
+
 
+#ifdef LINUX26
+static void ztdummy_timer(unsigned long param)
+{
+    zt_receive(&ztd->span);
+    zt_transmit(&ztd->span);
+    timer.expires = jiffies + 1;
+    add_timer(&timer);
+}
+#else
 static void ztdummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
     unsigned short status;
@@ -92,6 +124,7 @@
      }
 	return;
 }
+#endif
 
 static int ztdummy_initialize(struct ztdummy *ztd)
 {
@@ -112,14 +145,12 @@
 	return 0;
 }
 
-
-
-
 int init_module(void)
 {
+#ifndef LINUX26
     int irq;
     spinlock_t mylock = SPIN_LOCK_UNLOCKED;
-
+	
     if (uhci_devices==NULL){
         printk ("ztdummy: Uhci_devices pointer error.\n");
 	    return -ENODEV;
@@ -129,12 +160,14 @@
         printk ("ztdummy: No uhci_device found.\n");
 	    return -ENODEV;
     }
+#endif
 
     ztd = kmalloc(sizeof(struct ztdummy), GFP_KERNEL);
     if (ztd == NULL) {
 	    printk("ztdummy: Unable to allocate memory\n");
 	    return -ENOMEM;
     }
+
     memset(ztd, 0x0, sizeof(struct ztdummy));
 
     if (ztdummy_initialize(ztd)) {
@@ -143,6 +176,12 @@
 	return -ENODEV;
     }
 
+#ifdef LINUX26
+    init_timer(&timer);
+    timer.function = ztdummy_timer;
+    timer.expires = jiffies + 1;
+    add_timer(&timer);
+#else
     irq=s->irq;
     spin_lock_irq(&mylock);
     free_irq(s->irq, s);	/* remove uhci_interrupt temporaly */
@@ -161,6 +200,8 @@
     alloc_td(s, &td, 0);
     fill_td(td, TD_CTRL_IOC, 0, 0);
     insert_td_horizontal(s, s->int_chain[0], td);	/* use int_chain[0] to get 1ms interrupts */
+#endif	
+
     if (debug)
         printk("ztdummy: init() finished\n");
     return 0;
@@ -169,11 +210,17 @@
 
 void cleanup_module(void)
 {
-    zt_unregister(&ztd->span);
+#ifdef LINUX26
+    del_timer(&timer);
+#else
     free_irq(s->irq, ztd);  /* disable interrupts */
+#endif
+    zt_unregister(&ztd->span);
     kfree(ztd);
-    unlink_td (s, td, 1);   /* unlink and delete td */
-    delete_desc (s, td);
+#ifndef LINUX26
+	unlink_td(s, td, 1);
+	delete_desc(s, td);
+#endif
     if (debug)
         printk("ztdummy: cleanup() finished\n");
 }
@@ -181,11 +228,11 @@
 
 
 MODULE_PARM(debug, "i");
+#ifndef LINUX26
 MODULE_PARM(monitor, "i");
+#endif
 MODULE_DESCRIPTION("Dummy Zaptel Driver");
 MODULE_AUTHOR("Robert Pleh <robert.pleh at hermes.si>");
 #ifdef MODULE_LICENSE
 MODULE_LICENSE("GPL");
 #endif
-
-




More information about the svn-commits mailing list