From ea509b8f268d9dd6a7e0dccd1a5e1bc15a1aef64 Mon Sep 17 00:00:00 2001 From: markster Date: Sat, 26 Jun 2004 19:52:06 +0000 Subject: Merge 2.6 and 2.4 versions of ztdummy (no longer needs UHCI for kernel > 2.6.0) git-svn-id: http://svn.digium.com/svn/zaptel/trunk@424 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- ztdummy.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/ztdummy.c b/ztdummy.c index eb21332..f849ac5 100755 --- a/ztdummy.c +++ b/ztdummy.c @@ -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 + * 2.6 version by Tony Hoyle + * Unified by Mark Spencer * * 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 +#include + +#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 #include #include #include +#include +#ifndef LINUX26 #include #include -#include #include +#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 void uhci_interrupt (int irq, void *__uhci, struct pt_regs *regs); 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 @@ static void ztdummy_interrupt(int irq, void *dev_id, struct pt_regs *regs) } return; } +#endif static int ztdummy_initialize(struct ztdummy *ztd) { @@ -112,14 +145,12 @@ static int ztdummy_initialize(struct ztdummy *ztd) 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 @@ int init_module(void) 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 @@ int init_module(void) 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 @@ int init_module(void) 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 @@ int init_module(void) 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 @@ void cleanup_module(void) MODULE_PARM(debug, "i"); +#ifndef LINUX26 MODULE_PARM(monitor, "i"); +#endif MODULE_DESCRIPTION("Dummy Zaptel Driver"); MODULE_AUTHOR("Robert Pleh "); #ifdef MODULE_LICENSE MODULE_LICENSE("GPL"); #endif - - -- cgit v1.2.3