patch-2.3.24 linux/drivers/net/irda/pc87108.c

Next file: linux/drivers/net/irda/smc-ircc.c
Previous file: linux/drivers/net/irda/litelink.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.23/linux/drivers/net/irda/pc87108.c linux/drivers/net/irda/pc87108.c
@@ -6,7 +6,7 @@
  * Status:        Experimental.
  * Author:        Dag Brattli <dagb@cs.uit.no>
  * Created at:    Sat Nov  7 21:43:15 1998
- * Modified at:   Wed Aug 11 09:26:26 1999
+ * Modified at:   Wed Oct 20 00:08:41 1999
  * Modified by:   Dag Brattli <dagb@cs.uit.no>
  * 
  *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>
@@ -29,11 +29,11 @@
  *
  *         __u8 bank;
  *     
- *         bank = inb( iobase+BSR);
+ *         bank = inb(iobase+BSR);
  *  
  *         do_your_stuff_here();
  *
- *         outb( bank, iobase+BSR);
+ *         outb(bank, iobase+BSR);
  *
  *    If you find bugs in this file, its very likely that the same bug
  *    will also be in w83977af_ir.c since the implementations is quite
@@ -51,6 +51,7 @@
 #include <linux/delay.h>
 #include <linux/malloc.h>
 #include <linux/init.h>
+#include <linux/rtnetlink.h>
 
 #include <asm/io.h>
 #include <asm/dma.h>
@@ -101,19 +102,19 @@
 static int  pc87108_open(int i, unsigned int iobase, unsigned int board_addr, 
 			 unsigned int irq, unsigned int dma);
 #ifdef MODULE
-static int  pc87108_close(struct irda_device *idev);
+static int  pc87108_close(struct pc87108 *self);
 #endif /* MODULE */
 static int  pc87108_probe(int iobase, int board_addr, int irq, int dma);
-static void pc87108_pio_receive(struct irda_device *idev);
-static int  pc87108_dma_receive(struct irda_device *idev); 
-static int  pc87108_dma_receive_complete(struct irda_device *idev, int iobase);
+static void pc87108_pio_receive(struct pc87108 *self);
+static int  pc87108_dma_receive(struct pc87108 *self); 
+static int  pc87108_dma_receive_complete(struct pc87108 *self, int iobase);
 static int  pc87108_hard_xmit(struct sk_buff *skb, struct net_device *dev);
 static int  pc87108_pio_write(int iobase, __u8 *buf, int len, int fifo_size);
-static void pc87108_dma_write(struct irda_device *idev, int iobase);
-static void pc87108_change_speed(struct irda_device *idev, __u32 baud);
+static void pc87108_dma_write(struct pc87108 *self, int iobase);
+static void pc87108_change_speed(struct pc87108 *self, __u32 baud);
 static void pc87108_interrupt(int irq, void *dev_id, struct pt_regs *regs);
-static void pc87108_wait_until_sent(struct irda_device *idev);
-static int  pc87108_is_receiving(struct irda_device *idev);
+static void pc87108_wait_until_sent(struct pc87108 *self);
+static int  pc87108_is_receiving(struct pc87108 *self);
 static int  pc87108_read_dongle_id (int iobase);
 static void pc87108_init_dongle_interface (int iobase, int dongle_id);
 
@@ -152,11 +153,11 @@
 {
 	int i;
 
-        DEBUG(4, __FUNCTION__ "()\n");
+        IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	for (i=0; i < 4; i++) {
 		if (dev_self[i])
-			pc87108_close(&(dev_self[i]->idev));
+			pc87108_close(dev_self[i]);
 	}
 }
 #endif /* MODULE */
@@ -170,12 +171,13 @@
 static int pc87108_open(int i, unsigned int iobase, unsigned int board_addr, 
 			unsigned int irq, unsigned int dma)
 {
+	struct net_device *dev;
 	struct pc87108 *self;
-	struct irda_device *idev;
-	int ret;
 	int dongle_id;
+	int ret;
+	int err;
 
-	DEBUG(0, __FUNCTION__ "()\n");
+	IRDA_DEBUG(0, __FUNCTION__ "()\n");
 
 	if ((dongle_id = pc87108_probe(iobase, board_addr, irq, dma)) == -1)
 		return -1;
@@ -194,90 +196,127 @@
 	/* Need to store self somewhere */
 	dev_self[i] = self;
 
-	idev = &self->idev;
-
 	/* Initialize IO */
-	idev->io.iobase    = iobase;
-        idev->io.irq       = irq;
-        idev->io.io_ext    = CHIP_IO_EXTENT;
-        idev->io.dma       = dma;
-        idev->io.fifo_size = 32;
+	self->io.iobase    = iobase;
+        self->io.irq       = irq;
+        self->io.io_ext    = CHIP_IO_EXTENT;
+        self->io.dma       = dma;
+        self->io.fifo_size = 32;
 
 	/* Lock the port that we need */
-	ret = check_region(idev->io.iobase, idev->io.io_ext);
+	ret = check_region(self->io.iobase, self->io.io_ext);
 	if (ret < 0) { 
-		DEBUG(0, __FUNCTION__ "(), can't get iobase of 0x%03x\n",
-		      idev->io.iobase);
-		/* pc87108_cleanup( self->idev);  */
+		IRDA_DEBUG(0, __FUNCTION__ "(), can't get iobase of 0x%03x\n",
+		      self->io.iobase);
+		/* pc87108_cleanup(self->self);  */
 		return -ENODEV;
 	}
-	request_region(idev->io.iobase, idev->io.io_ext, idev->name);
+	request_region(self->io.iobase, self->io.io_ext, driver_name);
 
 	/* Initialize QoS for this device */
-	irda_init_max_qos_capabilies(&idev->qos);
+	irda_init_max_qos_capabilies(&self->qos);
 	
 	/* The only value we must override it the baudrate */
-	idev->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
+	self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
 		IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
 	
-	idev->qos.min_turn_time.bits = qos_mtt_bits;
-	irda_qos_bits_to_value(&idev->qos);
+	self->qos.min_turn_time.bits = qos_mtt_bits;
+	irda_qos_bits_to_value(&self->qos);
 	
-	idev->flags = IFF_FIR|IFF_MIR|IFF_SIR|IFF_DMA|IFF_PIO|IFF_DONGLE;
-
-	/* Specify which buffer allocation policy we need */
-	idev->rx_buff.flags = GFP_KERNEL | GFP_DMA;
-	idev->tx_buff.flags = GFP_KERNEL | GFP_DMA;
+	self->flags = IFF_FIR|IFF_MIR|IFF_SIR|IFF_DMA|IFF_PIO|IFF_DONGLE;
 
 	/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
-	idev->rx_buff.truesize = 14384; 
-	idev->tx_buff.truesize = 4000;
+	self->rx_buff.truesize = 14384; 
+	self->tx_buff.truesize = 4000;
+
+	/* Allocate memory if needed */
+	if (self->rx_buff.truesize > 0) {
+		self->rx_buff.head = (__u8 *) kmalloc(self->rx_buff.truesize,
+						      GFP_KERNEL|GFP_DMA);
+		if (self->rx_buff.head == NULL)
+			return -ENOMEM;
+		memset(self->rx_buff.head, 0, self->rx_buff.truesize);
+	}
+	if (self->tx_buff.truesize > 0) {
+		self->tx_buff.head = (__u8 *) kmalloc(self->tx_buff.truesize, 
+						      GFP_KERNEL|GFP_DMA);
+		if (self->tx_buff.head == NULL) {
+			kfree(self->rx_buff.head);
+			return -ENOMEM;
+		}
+		memset(self->tx_buff.head, 0, self->tx_buff.truesize);
+	}
+
+	self->rx_buff.in_frame = FALSE;
+	self->rx_buff.state = OUTSIDE_FRAME;
+	self->tx_buff.data = self->tx_buff.head;
+	self->rx_buff.data = self->rx_buff.head;
 	
-	/* Initialize callbacks */
-	idev->change_speed    = pc87108_change_speed;
-	idev->wait_until_sent = pc87108_wait_until_sent;
-	idev->is_receiving    = pc87108_is_receiving;
-     
+	if (!(dev = dev_alloc("irda%d", &err))) {
+		ERROR(__FUNCTION__ "(), dev_alloc() failed!\n");
+		return -ENOMEM;
+	}
+	/* dev_alloc doesn't clear the struct, so lets do a little hack */
+	memset(((__u8*)dev)+sizeof(char*),0,sizeof(struct net_device)-sizeof(char*));
+
+	dev->priv = (void *) self;
+	self->netdev = dev;
+
 	/* Override the network functions we need to use */
-	idev->netdev.init            = pc87108_net_init;
-	idev->netdev.hard_start_xmit = pc87108_hard_xmit;
-	idev->netdev.open            = pc87108_net_open;
-	idev->netdev.stop            = pc87108_net_close;
+	dev->init            = pc87108_net_init;
+	dev->hard_start_xmit = pc87108_hard_xmit;
+	dev->open            = pc87108_net_open;
+	dev->stop            = pc87108_net_close;
+
+	rtnl_lock();
+	err = register_netdevice(dev);
+	rtnl_unlock();
+	if (err) {
+		ERROR(__FUNCTION__ "(), register_netdev() failed!\n");
+		return -1;
+	}
 
-	idev->io.dongle_id = dongle_id;
+	MESSAGE("IrDA: Registered device %s\n", dev->name);
+	
+	self->io.dongle_id = dongle_id;
 	pc87108_init_dongle_interface(iobase, dongle_id);
 
-	/* Open the IrDA device */
-	irda_device_open(idev, driver_name, self);
-	
 	return 0;
 }
 
 #ifdef MODULE
 /*
- * Function pc87108_close (idev)
+ * Function pc87108_close (self)
  *
  *    Close driver instance
  *
  */
-static int pc87108_close(struct irda_device *idev)
+static int pc87108_close(struct pc87108 *self)
 {
-	struct pc87108 *self;
 	int iobase;
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
-	ASSERT(idev != NULL, return -1;);
-	ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return -1;);
+	ASSERT(self != NULL, return -1;);
 
-        iobase = idev->io.iobase;
-	self = (struct pc87108 *) idev->priv;
+        iobase = self->io.iobase;
+
+	/* Remove netdevice */
+	if (self->netdev) {
+		rtnl_lock();
+		unregister_netdev(self->netdev);
+		rtnl_unlock();
+	}
 
 	/* Release the PORT that this driver is using */
-	DEBUG(4, __FUNCTION__ "(), Releasing Region %03x\n", idev->io.iobase);
-	release_region(idev->io.iobase, idev->io.io_ext);
+	IRDA_DEBUG(4, __FUNCTION__ "(), Releasing Region %03x\n", self->io.iobase);
+	release_region(self->io.iobase, self->io.io_ext);
 
-	irda_device_close(idev);
+	if (self->tx_buff.head)
+		kfree(self->tx_buff.head);
+	
+	if (self->rx_buff.head)
+		kfree(self->rx_buff.head);
 
 	kfree(self);
 
@@ -297,7 +336,7 @@
 	__u8 temp=0;
 	int dongle_id;
 	
-	DEBUG(4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	/* Base Address and Interrupt Control Register BAIC */
 	outb(0, board_addr);
@@ -326,7 +365,7 @@
 	case 0: outb(0x08+temp, board_addr+1); break;
 	case 1: outb(0x10+temp, board_addr+1); break;
 	case 3: outb(0x18+temp, board_addr+1); break;
-	default: DEBUG( 0, __FUNCTION__ "(), invalid dma");
+	default: IRDA_DEBUG(0, __FUNCTION__ "(), invalid dma");
 	}
 
 	/* Mode Control Register MCTL */
@@ -344,13 +383,13 @@
 	}
 	
 	/* Switch to advanced mode */
-	switch_bank( iobase, BANK2);
+	switch_bank(iobase, BANK2);
 	outb(ECR1_EXT_SL, iobase+ECR1);
 	switch_bank(iobase, BANK0);
 
 	dongle_id = pc87108_read_dongle_id(iobase);
-	DEBUG(0, __FUNCTION__ "(), Found dongle: %s\n", 
-	      dongle_types[ dongle_id]);
+	IRDA_DEBUG(0, __FUNCTION__ "(), Found dongle: %s\n", 
+	      dongle_types[dongle_id]);
 	
 	/* Set FIFO threshold to TX17, RX16, reset and enable FIFO's */
 	switch_bank(iobase, BANK0);	
@@ -380,7 +419,7 @@
 	outb(2048 & 0xff, iobase+4);
 	outb((2048 >> 8) & 0x1f, iobase+5);
 	
-	DEBUG(0, "PC87108 driver loaded. Version: 0x%02x\n", version);
+	IRDA_DEBUG(0, "PC87108 driver loaded. Version: 0x%02x\n", version);
 
 	/* Enable receive interrupts */
 	switch_bank(iobase, BANK0);
@@ -397,14 +436,14 @@
  * that the user may have plugged/unplugged the IrDA Dongle.
  * 
  */
-static int pc87108_read_dongle_id ( int iobase)
+static int pc87108_read_dongle_id (int iobase)
 {
 	int dongle_id;
 	__u8 bank;
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Select Bank 7 */
 	switch_bank(iobase, BANK7);
@@ -416,7 +455,7 @@
 	udelay(50);
 	
 	/* IRCFG1: read the ID bits */
-	dongle_id = inb( iobase+4) & 0x0f;
+	dongle_id = inb(iobase+4) & 0x0f;
 
 #ifdef BROKEN_DONGLE_ID
 	if (dongle_id == 0x0a)
@@ -426,7 +465,7 @@
 	/* Go back to  bank 0 before returning */
 	switch_bank(iobase, BANK0);
 
-	DEBUG(0, __FUNCTION__ "(), Dongle = %#x\n", dongle_id);
+	IRDA_DEBUG(0, __FUNCTION__ "(), Dongle = %#x\n", dongle_id);
 
 	outb(bank, iobase+BSR);
 
@@ -446,49 +485,49 @@
 	int bank;
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Select Bank 7 */
-	switch_bank( iobase, BANK7);
+	switch_bank(iobase, BANK7);
 	
 	/* IRCFG4: set according to dongle_id */
 	switch (dongle_id) {
 	case 0x00: /* same as */
 	case 0x01: /* Differential serial interface */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x02: /* same as */
 	case 0x03: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x04: /* Sharp RY5HD01 */
-		DEBUG( 0, __FUNCTION__ "(), %s not supported yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not supported yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x05: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x06: /* Single-ended serial interface */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x07: /* Consumer-IR only */
-		DEBUG( 0, __FUNCTION__ "(), %s is not for IrDA mode\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s is not for IrDA mode\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
-		DEBUG( 0, __FUNCTION__ "(), %s not supported yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not supported yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
-		outb_p( 0x28, iobase+7); /* Set irsl[0-2] as output */
+		outb_p(0x28, iobase+7); /* Set irsl[0-2] as output */
 		break;
 	case 0x0A: /* same as */
 	case 0x0B: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x0C: /* same as */
@@ -497,28 +536,28 @@
 		 * Set irsl0 as input, irsl[1-2] as output, and separate 
 		 * inputs are used for SIR and MIR/FIR 
 		 */
-		outb( 0x48, iobase+7); 
+		outb(0x48, iobase+7); 
 		break;
 	case 0x0E: /* Supports SIR Mode only */
-		outb( 0x28, iobase+7); /* Set irsl[0-2] as output */
+		outb(0x28, iobase+7); /* Set irsl[0-2] as output */
 		break;
 	case 0x0F: /* No dongle connected */
-		DEBUG( 0, __FUNCTION__ "(), %s\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s\n",
 		       dongle_types[dongle_id]); 
-		DEBUG( 0, "***\n");
+		IRDA_DEBUG(0, "***\n");
 
-		switch_bank( iobase, BANK0);
-		outb( 0x62, iobase+MCR);
+		switch_bank(iobase, BANK0);
+		outb(0x62, iobase+MCR);
 		break;
 	default: 
-		DEBUG( 0, __FUNCTION__ "(), invalid dongle_id %#x", dongle_id);
+		IRDA_DEBUG(0, __FUNCTION__ "(), invalid dongle_id %#x", dongle_id);
 	}
 	
 	/* IRCFG1: IRSL1 and 2 are set to IrDA mode */
-	outb( 0x00, iobase+4);
+	outb(0x00, iobase+4);
 
 	/* Restore bank register */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 	
 } /* set_up_dongle_interface */
 
@@ -528,66 +567,66 @@
  *    Change speed of the attach dongle
  *
  */
-static void pc87108_change_dongle_speed( int iobase, int speed, int dongle_id)
+static void pc87108_change_dongle_speed(int iobase, int speed, int dongle_id)
 {
 	unsigned long flags;
 	__u8 bank;
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Select Bank 7 */
-	switch_bank( iobase, BANK7);
+	switch_bank(iobase, BANK7);
 	
 	/* IRCFG1: set according to dongle_id */
 	switch (dongle_id) {
 	case 0x00: /* same as */
 	case 0x01: /* Differential serial interface */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x02: /* same as */
 	case 0x03: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x04: /* Sharp RY5HD01 */
-		DEBUG( 0, __FUNCTION__ "(), %s not supported yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not supported yet\n",
 		       dongle_types[dongle_id]); 
 	case 0x05: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x06: /* Single-ended serial interface */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x07: /* Consumer-IR only */
-		DEBUG( 0, __FUNCTION__ "(), %s is not for IrDA mode\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s is not for IrDA mode\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
-		DEBUG( 0, __FUNCTION__ "(), %s not supported yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not supported yet\n",
 		       dongle_types[dongle_id]); 
 	case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
-		switch_bank( iobase, BANK7);
-		outb_p( 0x01, iobase+4);
+		switch_bank(iobase, BANK7);
+		outb_p(0x01, iobase+4);
 
-		if ( speed == 4000000) {
+		if (speed == 4000000) {
 			save_flags(flags);
 			cli();
-			outb( 0x81, iobase+4);
-			outb( 0x80, iobase+4);
+			outb(0x81, iobase+4);
+			outb(0x80, iobase+4);
 			restore_flags(flags);
 		}
 		else
-			outb_p( 0x00, iobase+4);
+			outb_p(0x00, iobase+4);
 		break;
 	case 0x0A: /* same as */
 	case 0x0B: /* Reserved */
-		DEBUG( 0, __FUNCTION__ "(), %s not defined by irda yet\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s not defined by irda yet\n",
 		       dongle_types[dongle_id]); 
 		break;
 	case 0x0C: /* same as */
@@ -596,78 +635,77 @@
 	case 0x0E: /* Supports SIR Mode only */
 		break;
 	case 0x0F: /* No dongle connected */
-		DEBUG( 0, __FUNCTION__ "(), %s is not for IrDA mode\n",
+		IRDA_DEBUG(0, __FUNCTION__ "(), %s is not for IrDA mode\n",
 		       dongle_types[dongle_id]);
 
-		switch_bank( iobase, BANK0); 
-		outb( 0x62, iobase+MCR);
+		switch_bank(iobase, BANK0); 
+		outb(0x62, iobase+MCR);
 		break;
 	default: 
-		DEBUG( 0, __FUNCTION__ "(), invalid data_rate\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), invalid data_rate\n");
 	}
 	/* Restore bank register */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 }
 
 /*
- * Function pc87108_change_speed (idev, baud)
+ * Function pc87108_change_speed (self, baud)
  *
  *    Change the speed of the device
  *
  */
-static void pc87108_change_speed(struct irda_device *idev, __u32 speed)
+static void pc87108_change_speed(struct pc87108 *self, __u32 speed)
 {
 	__u8 mcr = MCR_SIR;
 	__u8 bank;
 	int iobase; 
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
-	ASSERT( idev != NULL, return;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return;);
+	ASSERT(self != NULL, return;);
 
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
 	/* Update accounting for new speed */
-	idev->io.baudrate = speed;
+	self->io.speed = speed;
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Disable interrupts */
-	switch_bank( iobase, BANK0);
-	outb( 0, iobase+IER);
+	switch_bank(iobase, BANK0);
+	outb(0, iobase+IER);
 
 	  /* Select Bank 2 */
-	switch_bank( iobase, BANK2);
+	switch_bank(iobase, BANK2);
 
-	outb( 0x00, iobase+BGDH);
-	switch ( speed) {
-	case 9600:   outb( 0x0c, iobase+BGDL); break;
-	case 19200:  outb( 0x06, iobase+BGDL); break;
-	case 37600:  outb( 0x03, iobase+BGDL); break;
-	case 57600:  outb( 0x02, iobase+BGDL); break;
-	case 115200: outb( 0x01, iobase+BGDL); break;
+	outb(0x00, iobase+BGDH);
+	switch (speed) {
+	case 9600:   outb(0x0c, iobase+BGDL); break;
+	case 19200:  outb(0x06, iobase+BGDL); break;
+	case 37600:  outb(0x03, iobase+BGDL); break;
+	case 57600:  outb(0x02, iobase+BGDL); break;
+	case 115200: outb(0x01, iobase+BGDL); break;
 	case 576000:
-		switch_bank( iobase, BANK5);
+		switch_bank(iobase, BANK5);
 		
 		/* IRCR2: MDRS is set */
-		outb( inb( iobase+4) | 0x04, iobase+4);
+		outb(inb(iobase+4) | 0x04, iobase+4);
 	       
 		mcr = MCR_MIR;
-		DEBUG(0, __FUNCTION__ "(), handling baud of 576000\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 576000\n");
 		break;
 	case 1152000:
 		mcr = MCR_MIR;
-		DEBUG(0, __FUNCTION__ "(), handling baud of 1152000\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 1152000\n");
 		break;
 	case 4000000:
 		mcr = MCR_FIR;
-		DEBUG(0, __FUNCTION__ "(), handling baud of 4000000\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 4000000\n");
 		break;
 	default:
 		mcr = MCR_FIR;
-		DEBUG( 0, __FUNCTION__ "(), unknown baud rate of %d\n", speed);
+		IRDA_DEBUG(0, __FUNCTION__ "(), unknown baud rate of %d\n", speed);
 		break;
 	}
 
@@ -676,34 +714,34 @@
 	outb(mcr | MCR_TX_DFR, iobase+MCR);
 
 	/* Give some hits to the transceiver */
-	pc87108_change_dongle_speed( iobase, speed, idev->io.dongle_id);
+	pc87108_change_dongle_speed(iobase, speed, self->io.dongle_id);
 
 	/* Set FIFO threshold to TX17, RX16 */
-	switch_bank( iobase, BANK0);
-	outb( FCR_RXTH|     /* Set Rx FIFO threshold */
+	switch_bank(iobase, BANK0);
+	outb(FCR_RXTH|     /* Set Rx FIFO threshold */
 	      FCR_TXTH|     /* Set Tx FIFO threshold */
 	      FCR_TXSR|     /* Reset Tx FIFO */
 	      FCR_RXSR|     /* Reset Rx FIFO */
 	      FCR_FIFO_EN,  /* Enable FIFOs */
 	      iobase+FCR);
-	/* outb( 0xa7, iobase+FCR); */
+	/* outb(0xa7, iobase+FCR); */
 	
 	/* Set FIFO size to 32 */
-	switch_bank( iobase, BANK2);
-	outb( EXCR2_RFSIZ|EXCR2_TFSIZ, iobase+EXCR2);	
+	switch_bank(iobase, BANK2);
+	outb(EXCR2_RFSIZ|EXCR2_TFSIZ, iobase+EXCR2);	
 	
-	idev->netdev.tbusy = 0;
+	self->netdev->tbusy = 0;
 	
 	/* Enable some interrupts so we can receive frames */
-	switch_bank( iobase, BANK0); 
-	if ( speed > 115200) {
-		outb( IER_SFIF_IE, iobase+IER);
-		pc87108_dma_receive( idev);
+	switch_bank(iobase, BANK0); 
+	if (speed > 115200) {
+		outb(IER_SFIF_IE, iobase+IER);
+		pc87108_dma_receive(self);
 	} else
-		outb( IER_RXHDL_IE, iobase+IER);
+		outb(IER_RXHDL_IE, iobase+IER);
     	
 	/* Restore BSR */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 }
 
 /*
@@ -712,107 +750,106 @@
  *    Transmit the frame!
  *
  */
-static int pc87108_hard_xmit( struct sk_buff *skb, struct net_device *dev)
+static int pc87108_hard_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-	struct irda_device *idev;
+	struct pc87108 *self;
 	int iobase;
 	__u8 bank;
 	int mtt;
 	
-	idev = (struct irda_device *) dev->priv;
+	self = (struct pc87108 *) dev->priv;
 
-	ASSERT( idev != NULL, return 0;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return 0;);
+	ASSERT(self != NULL, return 0;);
 
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
-	DEBUG(4, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies, (int) skb->len);
+	IRDA_DEBUG(4, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies, (int) skb->len);
 	
 	/* Lock transmit buffer */
-	if ( irda_lock( (void *) &dev->tbusy) == FALSE)
+	if (irda_lock((void *) &dev->tbusy) == FALSE)
 		return -EBUSY;
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Decide if we should use PIO or DMA transfer */
-	if ( idev->io.baudrate > 115200) {
-		idev->tx_buff.data = idev->tx_buff.head;
-		memcpy(idev->tx_buff.data, skb->data, skb->len);
-		idev->tx_buff.len = skb->len;
+	if (self->io.speed > 115200) {
+		self->tx_buff.data = self->tx_buff.head;
+		memcpy(self->tx_buff.data, skb->data, skb->len);
+		self->tx_buff.len = skb->len;
 
-		mtt = irda_get_mtt( skb);
-	        if ( mtt > 50) {
+		mtt = irda_get_mtt(skb);
+	        if (mtt > 50) {
 			/* Adjust for timer resolution */
 			mtt = mtt / 125 + 1;
 
 			/* Setup timer */
-			switch_bank( iobase, BANK4);
-			outb( mtt & 0xff, iobase+TMRL);
-			outb(( mtt >> 8) & 0x0f, iobase+TMRH);
+			switch_bank(iobase, BANK4);
+			outb(mtt & 0xff, iobase+TMRL);
+			outb((mtt >> 8) & 0x0f, iobase+TMRH);
 			
 			/* Start timer */
-			outb( IRCR1_TMR_EN, iobase+IRCR1);
-			idev->io.direction = IO_XMIT;
+			outb(IRCR1_TMR_EN, iobase+IRCR1);
+			self->io.direction = IO_XMIT;
 			
 			/* Enable timer interrupt */
-			switch_bank( iobase, BANK0);
-			outb( IER_TMR_IE, iobase+IER);
+			switch_bank(iobase, BANK0);
+			outb(IER_TMR_IE, iobase+IER);
 		} else {
 			/* Use udelay for delays less than 50 us. */
 			if (mtt)
-				udelay( mtt);
+				udelay(mtt);
 
 			/* Enable DMA interrupt */
-			switch_bank( iobase, BANK0);
-	 		outb( IER_DMA_IE, iobase+IER);
-	     		pc87108_dma_write( idev, iobase);
+			switch_bank(iobase, BANK0);
+	 		outb(IER_DMA_IE, iobase+IER);
+	     		pc87108_dma_write(self, iobase);
 		}
         } else {
-	        idev->tx_buff.len = async_wrap_skb(skb, idev->tx_buff.data, 
-						   idev->tx_buff.truesize);
+	        self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data, 
+						   self->tx_buff.truesize);
 		
-		idev->tx_buff.data = idev->tx_buff.head;
+		self->tx_buff.data = self->tx_buff.head;
 		
 		/* Add interrupt on tx low level (will fire immediately) */
-		switch_bank( iobase, BANK0);
-		outb( IER_TXLDL_IE, iobase+IER);
+		switch_bank(iobase, BANK0);
+		outb(IER_TXLDL_IE, iobase+IER);
 	}
-	dev_kfree_skb( skb);
+	dev_kfree_skb(skb);
 
 	/* Restore bank register */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 
 	return 0;
 }
 
 /*
- * Function pc87108_dma_xmit (idev, iobase)
+ * Function pc87108_dma_xmit (self, iobase)
  *
  *    Transmit data using DMA
  *
  */
-static void pc87108_dma_write( struct irda_device *idev, int iobase)
+static void pc87108_dma_write(struct pc87108 *self, int iobase)
 {
 	int bsr;
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	/* Save current bank */
-	bsr = inb( iobase+BSR);
+	bsr = inb(iobase+BSR);
 
 	/* Disable DMA */
 	switch_bank(iobase, BANK0);
-	outb( inb( iobase+MCR) & ~MCR_DMA_EN, iobase+MCR);
+	outb(inb(iobase+MCR) & ~MCR_DMA_EN, iobase+MCR);
 
-	setup_dma(idev->io.dma, idev->tx_buff.data, idev->tx_buff.len, 
+	setup_dma(self->io.dma, self->tx_buff.data, self->tx_buff.len, 
 		  DMA_MODE_WRITE);
 	
-	idev->io.direction = IO_XMIT;
+	self->io.direction = IO_XMIT;
 	
 	/* Choose transmit DMA channel  */ 
 	switch_bank(iobase, BANK2);
-	outb( inb( iobase+ECR1) | ECR1_DMASWP|ECR1_DMANF|ECR1_EXT_SL, 
+	outb(inb(iobase+ECR1) | ECR1_DMASWP|ECR1_DMANF|ECR1_EXT_SL, 
 	      iobase+ECR1);
 	
 	/* Enable DMA */
@@ -824,7 +861,7 @@
 }
 
 /*
- * Function pc87108_pio_xmit (idev, iobase)
+ * Function pc87108_pio_xmit (self, iobase)
  *
  *    Transmit data using PIO. Returns the number of bytes that actually
  *    got transfered
@@ -835,17 +872,17 @@
 	int actual = 0;
 	__u8 bank;
 	
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
-	switch_bank( iobase, BANK0);
-	if (!(inb_p( iobase+LSR) & LSR_TXEMP)) {
-		DEBUG( 4, __FUNCTION__ "(), warning, FIFO not empty yet!\n");
+	switch_bank(iobase, BANK0);
+	if (!(inb_p(iobase+LSR) & LSR_TXEMP)) {
+		IRDA_DEBUG(4, __FUNCTION__ "(), warning, FIFO not empty yet!\n");
 
 		fifo_size -= 17;
-		DEBUG( 4, __FUNCTION__ "%d bytes left in tx fifo\n", fifo_size);
+		IRDA_DEBUG(4, __FUNCTION__ "%d bytes left in tx fifo\n", fifo_size);
 	}
 
 	/* Fill FIFO with current frame */
@@ -854,7 +891,7 @@
 		outb(buf[actual++], iobase+TXD);
 	}
         
-	DEBUG(4, __FUNCTION__ "(), fifo_size %d ; %d sent of %d\n", 
+	IRDA_DEBUG(4, __FUNCTION__ "(), fifo_size %d ; %d sent of %d\n", 
 	      fifo_size, actual, len);
 
 	/* Restore bank */
@@ -864,74 +901,69 @@
 }
 
 /*
- * Function pc87108_dma_xmit_complete (idev)
+ * Function pc87108_dma_xmit_complete (self)
  *
  *    The transfer of a frame in finished. This function will only be called 
  *    by the interrupt handler
  *
  */
-static void pc87108_dma_xmit_complete( struct irda_device *idev)
+static void pc87108_dma_xmit_complete(struct pc87108 *self)
 {
 	int iobase;
 	__u8 bank;
 
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
-	ASSERT( idev != NULL, return;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return;);
+	ASSERT(self != NULL, return;);
 
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 
 	/* Disable DMA */
-	switch_bank( iobase, BANK0);
-	outb( inb(iobase+MCR) & ~MCR_DMA_EN, iobase+MCR);
+	switch_bank(iobase, BANK0);
+	outb(inb(iobase+MCR) & ~MCR_DMA_EN, iobase+MCR);
 	
 	/* Check for underrrun! */
-	if ( inb( iobase+ASCR) & ASCR_TXUR) {
-		idev->stats.tx_errors++;
-		idev->stats.tx_fifo_errors++;
+	if (inb(iobase+ASCR) & ASCR_TXUR) {
+		self->stats.tx_errors++;
+		self->stats.tx_fifo_errors++;
 		
 		/* Clear bit, by writing 1 into it */
-		outb( ASCR_TXUR, iobase+ASCR);
+		outb(ASCR_TXUR, iobase+ASCR);
 	} else {
-		idev->stats.tx_packets++;
-		idev->stats.tx_bytes +=  idev->tx_buff.len;
+		self->stats.tx_packets++;
+		self->stats.tx_bytes +=  self->tx_buff.len;
 	}
 	
 	/* Unlock tx_buff and request another frame */
-	idev->netdev.tbusy = 0; /* Unlock */
-	idev->media_busy = FALSE;
+	self->netdev->tbusy = 0; /* Unlock */
 	
 	/* Tell the network layer, that we can accept more frames */
-	mark_bh( NET_BH);
+	mark_bh(NET_BH);
 
 	/* Restore bank */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 }
 
 /*
- * Function pc87108_dma_receive (idev)
+ * Function pc87108_dma_receive (self)
  *
  *    Get ready for receiving a frame. The device will initiate a DMA
  *    if it starts to receive a frame.
  *
  */
-static int pc87108_dma_receive(struct irda_device *idev) 
+static int pc87108_dma_receive(struct pc87108 *self) 
 {
-	struct pc87108 *self;
 	int iobase;
 	__u8 bsr;
 
-	ASSERT(idev != NULL, return -1;);
-	ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return -1;);
+	ASSERT(self != NULL, return -1;);
 
-	DEBUG(4, __FUNCTION__ "\n");
+	IRDA_DEBUG(4, __FUNCTION__ "\n");
 
-	self = idev->priv;
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
 	/* Save current bank */
 	bsr = inb(iobase+BSR);
@@ -940,12 +972,12 @@
 	switch_bank(iobase, BANK0);
 	outb(inb(iobase+MCR) & ~MCR_DMA_EN, iobase+MCR);
 
-	setup_dma(idev->io.dma, idev->rx_buff.data, 
-		  idev->rx_buff.truesize, DMA_MODE_READ);
+	setup_dma(self->io.dma, self->rx_buff.data, 
+		  self->rx_buff.truesize, DMA_MODE_READ);
 	
 	/* driver->media_busy = FALSE; */
-	idev->io.direction = IO_RECV;
-	idev->rx_buff.data = idev->rx_buff.head;
+	self->io.direction = IO_RECV;
+	self->rx_buff.data = self->rx_buff.head;
 
 	/* Reset Rx FIFO. This will also flush the ST_FIFO */
 	outb(FCR_RXTH|FCR_TXTH|FCR_RXSR|FCR_FIFO_EN, iobase+FCR);
@@ -953,7 +985,7 @@
 
 	/* Choose DMA Rx, DMA Fairness, and Advanced mode */
 	switch_bank(iobase, BANK2);
-	outb((inb( iobase+ECR1) & ~ECR1_DMASWP)|ECR1_DMANF|ECR1_EXT_SL, 
+	outb((inb(iobase+ECR1) & ~ECR1_DMASWP)|ECR1_DMANF|ECR1_EXT_SL, 
 	     iobase+ECR1);
 	
 	/* enable DMA */
@@ -963,40 +995,38 @@
 	/* Restore bank register */
 	outb(bsr, iobase+BSR);
 	
-	DEBUG(4, __FUNCTION__ "(), done!\n");	
+	IRDA_DEBUG(4, __FUNCTION__ "(), done!\n");	
 	
 	return 0;
 }
 
 /*
- * Function pc87108_dma_receive_complete (idev)
+ * Function pc87108_dma_receive_complete (self)
  *
  *    Finished with receiving frames
  *
  *    
  */
-static int pc87108_dma_receive_complete(struct irda_device *idev, int iobase)
+static int pc87108_dma_receive_complete(struct pc87108 *self, int iobase)
 {
 	struct sk_buff *skb;
-	struct pc87108 *self;
 	struct st_fifo *st_fifo;
-	int len;
 	__u8 bank;
 	__u8 status;
+	int len;
 
-	self = idev->priv;
 	st_fifo = &self->st_fifo;
 
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 	
 	/* Read status FIFO */
 	switch_bank(iobase, BANK5);
-	while (( status = inb( iobase+FRM_ST)) & FRM_ST_VLD) {
-		st_fifo->entries[ st_fifo->tail].status = status;
+	while ((status = inb(iobase+FRM_ST)) & FRM_ST_VLD) {
+		st_fifo->entries[st_fifo->tail].status = status;
 
-		st_fifo->entries[ st_fifo->tail].len  = inb(iobase+RFLFL);
-		st_fifo->entries[ st_fifo->tail].len |= inb(iobase+RFLFH) << 8;
+		st_fifo->entries[st_fifo->tail].len  = inb(iobase+RFLFL);
+		st_fifo->entries[st_fifo->tail].len |= inb(iobase+RFLFH) << 8;
 		
 		st_fifo->tail++;
 		st_fifo->len++;
@@ -1016,28 +1046,28 @@
 		if (status & FRM_ST_ERR_MSK) {
 			if (status & FRM_ST_LOST_FR) {
 				/* Add number of lost frames to stats */
-				idev->stats.rx_errors += len;	
+				self->stats.rx_errors += len;	
 			} else {
 				/* Skip frame */
-				idev->stats.rx_errors++;
+				self->stats.rx_errors++;
 				
-				idev->rx_buff.data += len;
+				self->rx_buff.data += len;
 			
 				if (status & FRM_ST_MAX_LEN)
-					idev->stats.rx_length_errors++;
+					self->stats.rx_length_errors++;
 				
 				if (status & FRM_ST_PHY_ERR) 
-					idev->stats.rx_frame_errors++;
+					self->stats.rx_frame_errors++;
 				
 				if (status & FRM_ST_BAD_CRC) 
-					idev->stats.rx_crc_errors++;
+					self->stats.rx_crc_errors++;
 			}
 			/* The errors below can be reported in both cases */
 			if (status & FRM_ST_OVR1)
-				idev->stats.rx_fifo_errors++;
+				self->stats.rx_fifo_errors++;
 			
 			if (status & FRM_ST_OVR2)
-				idev->stats.rx_fifo_errors++;
+				self->stats.rx_fifo_errors++;
 			
 		} else {
 			/* Check if we have transfered all data to memory */
@@ -1057,10 +1087,10 @@
 			/* Should be OK then */			
 			skb = dev_alloc_skb(len+1);
 			if (skb == NULL)  {
-				printk( KERN_INFO __FUNCTION__ 
+				printk(KERN_INFO __FUNCTION__ 
 					"(), memory squeeze, dropping frame.\n");
 				/* Restore bank register */
-				outb( bank, iobase+BSR);
+				outb(bank, iobase+BSR);
 
 				return FALSE;
 			}
@@ -1069,22 +1099,22 @@
 			skb_reserve(skb, 1); 
 
 			/* Copy frame without CRC */
-			if (idev->io.baudrate < 4000000) {
+			if (self->io.speed < 4000000) {
 				skb_put(skb, len-2);
-				memcpy(skb->data, idev->rx_buff.data, len-2);
+				memcpy(skb->data, self->rx_buff.data, len-2);
 			} else {
 				skb_put(skb, len-4);
-				memcpy(skb->data, idev->rx_buff.data, len-4);
+				memcpy(skb->data, self->rx_buff.data, len-4);
 			}
 
 			/* Move to next frame */
-			idev->rx_buff.data += len;
-			idev->stats.rx_packets++;
+			self->rx_buff.data += len;
+			self->stats.rx_packets++;
 
-			skb->dev = &idev->netdev;
+			skb->dev = self->netdev;
 			skb->mac.raw  = skb->data;
 			skb->protocol = htons(ETH_P_IRDA);
-			netif_rx( skb);
+			netif_rx(skb);
 		}
 	}
 	/* Restore bank register */
@@ -1094,60 +1124,59 @@
 }
 
 /*
- * Function pc87108_pio_receive (idev)
+ * Function pc87108_pio_receive (self)
  *
  *    Receive all data in receiver FIFO
  *
  */
-static void pc87108_pio_receive( struct irda_device *idev) 
+static void pc87108_pio_receive(struct pc87108 *self) 
 {
 	__u8 byte = 0x00;
 	int iobase;
 
-	DEBUG(4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
-	ASSERT(idev != NULL, return;);
-	ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
+	ASSERT(self != NULL, return;);
 	
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 	
 	/*  Receive all characters in Rx FIFO */
 	do {
 		byte = inb(iobase+RXD);
-		async_unwrap_char(idev, byte);
+		async_unwrap_char(self->netdev, &self->rx_buff, byte);
 
 	} while (inb(iobase+LSR) & LSR_RXDA); /* Data available */	
 }
 
 /*
- * Function pc87108_sir_interrupt (idev, eir)
+ * Function pc87108_sir_interrupt (self, eir)
  *
  *    Handle SIR interrupt
  *
  */
-static __u8 pc87108_sir_interrupt(struct irda_device *idev, int eir)
+static __u8 pc87108_sir_interrupt(struct pc87108 *self, int eir)
 {
 	int actual;
 	__u8 new_ier = 0;
 
 	/* Transmit FIFO low on data */
-	if ( eir & EIR_TXLDL_EV) {
+	if (eir & EIR_TXLDL_EV) {
 		/* Write data left in transmit buffer */
-		actual = pc87108_pio_write(idev->io.iobase, 
-					   idev->tx_buff.data, 
-					   idev->tx_buff.len, 
-					   idev->io.fifo_size);
-		idev->tx_buff.data += actual;
-		idev->tx_buff.len  -= actual;
+		actual = pc87108_pio_write(self->io.iobase, 
+					   self->tx_buff.data, 
+					   self->tx_buff.len, 
+					   self->io.fifo_size);
+		self->tx_buff.data += actual;
+		self->tx_buff.len  -= actual;
 		
-		idev->io.direction = IO_XMIT;
+		self->io.direction = IO_XMIT;
 
 		/* Check if finished */
-		if (idev->tx_buff.len > 0)
+		if (self->tx_buff.len > 0)
 			new_ier |= IER_TXLDL_IE;
 		else { 
-			idev->netdev.tbusy = 0; /* Unlock */
-			idev->stats.tx_packets++;
+			self->netdev->tbusy = 0; /* Unlock */
+			self->stats.tx_packets++;
 			
 		        mark_bh(NET_BH);	
 
@@ -1156,16 +1185,16 @@
 			
 	}
 	/* Check if transmission has completed */
-	if ( eir & EIR_TXEMP_EV) {
+	if (eir & EIR_TXEMP_EV) {
 		
 		/* Turn around and get ready to receive some data */
-		idev->io.direction = IO_RECV;
+		self->io.direction = IO_RECV;
 		new_ier |= IER_RXHDL_IE;
 	}
 
 	/* Rx FIFO threshold or timeout */
-	if ( eir & EIR_RXHDL_EV) {
-		pc87108_pio_receive( idev);
+	if (eir & EIR_RXHDL_EV) {
+		pc87108_pio_receive(self);
 
 		/* Keep receiving */
 		new_ier |= IER_RXHDL_IE;
@@ -1174,22 +1203,22 @@
 }
 
 /*
- * Function pc87108_fir_interrupt (idev, eir)
+ * Function pc87108_fir_interrupt (self, eir)
  *
  *    Handle MIR/FIR interrupt
  *
  */
-static __u8 pc87108_fir_interrupt( struct irda_device *idev, int iobase,
-				   int eir)
+static __u8 pc87108_fir_interrupt(struct pc87108 *self, int iobase,
+				  int eir)
 {
 	__u8 new_ier = 0;
 	__u8 bank;
 
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 	
 	/* Status event, or end of frame detected in FIFO */
 	if (eir & (EIR_SFIF_EV|EIR_LS_EV)) {
-		if (pc87108_dma_receive_complete( idev, iobase)) {
+		if (pc87108_dma_receive_complete(self, iobase)) {
 
 			/* Wait for next status FIFO interrupt */
 			new_ier |= IER_SFIF_IE;
@@ -1197,52 +1226,52 @@
 			/* DMA not finished yet */
 
 			/* Set timer value, resolution 125 us */
-			switch_bank( iobase, BANK4);
-			outb( 0x0f, iobase+TMRL); /* 125 us */
-			outb( 0x00, iobase+TMRH);
+			switch_bank(iobase, BANK4);
+			outb(0x0f, iobase+TMRL); /* 125 us */
+			outb(0x00, iobase+TMRH);
 
 			/* Start timer */
-			outb( IRCR1_TMR_EN, iobase+IRCR1);
+			outb(IRCR1_TMR_EN, iobase+IRCR1);
 
 			new_ier |= IER_TMR_IE;
 		}
 	}
 	/* Timer finished */
-	if ( eir & EIR_TMR_EV) {
+	if (eir & EIR_TMR_EV) {
 		/* Disable timer */
-		switch_bank( iobase, BANK4);
-		outb( 0, iobase+IRCR1);
+		switch_bank(iobase, BANK4);
+		outb(0, iobase+IRCR1);
 
 		/* Clear timer event */
 		switch_bank(iobase, BANK0);
-		outb( ASCR_CTE, iobase+ASCR);
+		outb(ASCR_CTE, iobase+ASCR);
 
 		/* Check if this is a TX timer interrupt */
-		if ( idev->io.direction == IO_XMIT) {
-			pc87108_dma_write( idev, iobase);
+		if (self->io.direction == IO_XMIT) {
+			pc87108_dma_write(self, iobase);
 
 			/*  Interrupt on DMA */
 			new_ier |= IER_DMA_IE;
 		} else {
 			/* Check if DMA has now finished */
-			pc87108_dma_receive_complete( idev, iobase);
+			pc87108_dma_receive_complete(self, iobase);
 
 			new_ier |= IER_SFIF_IE;
 		}
 	}	
 	/* Finished with transmission */
-	if ( eir & EIR_DMA_EV) {
-		pc87108_dma_xmit_complete( idev);
+	if (eir & EIR_DMA_EV) {
+		pc87108_dma_xmit_complete(self);
 		
 		/* Check if there are more frames to be transmitted */
-		if ( irda_device_txqueue_empty( idev)) {
+		if (irda_device_txqueue_empty(self->netdev)) {
 			/* Prepare for receive */
-			pc87108_dma_receive( idev);
+			pc87108_dma_receive(self);
 			
 			new_ier = IER_LS_IE|IER_SFIF_IE;
 		}
 	}
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 
 	return new_ier;
 }
@@ -1255,51 +1284,52 @@
  */
 static void pc87108_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
+	struct net_device *dev = (struct net_device *) dev_id;
+	struct pc87108 *self;
 	__u8 bsr, eir, ier;
 	int iobase;
 
-	struct irda_device *idev = (struct irda_device *) dev_id;
-
-	if (idev == NULL) {
-		printk( KERN_WARNING "%s: irq %d for unknown device.\n", 
+	if (!dev) {
+		printk(KERN_WARNING "%s: irq %d for unknown device.\n", 
 			driver_name, irq);
 		return;
 	}
+	self = (struct pc87108 *) dev->priv;
 
-	idev->netdev.interrupt = 1;
+	dev->interrupt = 1;
 
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
 	/* Save current bank */
-	bsr = inb( iobase+BSR);
+	bsr = inb(iobase+BSR);
 
-	switch_bank( iobase, BANK0);	
-	ier = inb( iobase+IER); 
-	eir = inb( iobase+EIR) & ier; /* Mask out the interesting ones */ 
+	switch_bank(iobase, BANK0);	
+	ier = inb(iobase+IER); 
+	eir = inb(iobase+EIR) & ier; /* Mask out the interesting ones */ 
 
-	outb( 0, iobase+IER); /* Disable interrupts */
+	outb(0, iobase+IER); /* Disable interrupts */
 	
-	if ( eir) {
+	if (eir) {
 		/* Dispatch interrupt handler for the current speed */
-		if ( idev->io.baudrate > 115200)
-			ier = pc87108_fir_interrupt( idev, iobase, eir);
+		if (self->io.speed > 115200)
+			ier = pc87108_fir_interrupt(self, iobase, eir);
 		else
-			ier = pc87108_sir_interrupt( idev, eir);
+			ier = pc87108_sir_interrupt(self, eir);
 	}
 
-	outb( ier, iobase+IER);   /* Restore interrupts */
-	outb( bsr, iobase+BSR);   /* Restore bank register */
+	outb(ier, iobase+IER);   /* Restore interrupts */
+	outb(bsr, iobase+BSR);   /* Restore bank register */
 
-	idev->netdev.interrupt = 0;
+	dev->interrupt = 0;
 }
 
 /*
- * Function pc87108_wait_until_sent (idev)
+ * Function pc87108_wait_until_sent (self)
  *
  *    This function should put the current thread to sleep until all data 
  *    have been sent, so it is safe to f.eks. change the speed.
  */
-static void pc87108_wait_until_sent( struct irda_device *idev)
+static void pc87108_wait_until_sent(struct pc87108 *self)
 {
 	/* Just delay 60 ms */
 	current->state = TASK_INTERRUPTIBLE;
@@ -1307,33 +1337,32 @@
 }
 
 /*
- * Function pc87108_is_receiving (idev)
+ * Function pc87108_is_receiving (self)
  *
  *    Return TRUE is we are currently receiving a frame
  *
  */
-static int pc87108_is_receiving( struct irda_device *idev)
+static int pc87108_is_receiving(struct pc87108 *self)
 {
 	int status = FALSE;
 	int iobase;
 	__u8 bank;
 
-	ASSERT( idev != NULL, return FALSE;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return FALSE;);
+	ASSERT(self != NULL, return FALSE;);
 
-	if ( idev->io.baudrate > 115200) {
-		iobase = idev->io.iobase;
+	if (self->io.speed > 115200) {
+		iobase = self->io.iobase;
 
 		/* Check if rx FIFO is not empty */
-		bank = inb( iobase+BSR);
-		switch_bank( iobase, BANK2);
-		if (( inb( iobase+RXFLV) & 0x3f) != 0) {
+		bank = inb(iobase+BSR);
+		switch_bank(iobase, BANK2);
+		if ((inb(iobase+RXFLV) & 0x3f) != 0) {
 			/* We are receiving something */
 			status =  TRUE;
 		}
-		outb( bank, iobase+BSR);
+		outb(bank, iobase+BSR);
 	} else 
-		status = ( idev->rx_buff.state != OUTSIDE_FRAME);
+		status = (self->rx_buff.state != OUTSIDE_FRAME);
 	
 	return status;
 }
@@ -1344,12 +1373,12 @@
  *    Initialize network device
  *
  */
-static int pc87108_net_init( struct net_device *dev)
+static int pc87108_net_init(struct net_device *dev)
 {
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	/* Setup to be a normal IrDA network device driver */
-	irda_device_setup( dev);
+	irda_device_setup(dev);
 
 	/* Insert overrides below this line! */
 
@@ -1363,46 +1392,54 @@
  *    Start the device
  *
  */
-static int pc87108_net_open( struct net_device *dev)
+static int pc87108_net_open(struct net_device *dev)
 {
-	struct irda_device *idev;
+	struct pc87108 *self;
 	int iobase;
 	__u8 bank;
 	
-	DEBUG( 4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 	
-	ASSERT( dev != NULL, return -1;);
-	idev = (struct irda_device *) dev->priv;
+	ASSERT(dev != NULL, return -1;);
+	self = (struct pc87108 *) dev->priv;
 	
-	ASSERT( idev != NULL, return 0;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return 0;);
+	ASSERT(self != NULL, return 0;);
 	
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
-	if (request_irq( idev->io.irq, pc87108_interrupt, 0, idev->name, 
-			 (void *) idev)) {
+	if (request_irq(self->io.irq, pc87108_interrupt, 0, dev->name, 
+			 (void *) dev)) {
 		return -EAGAIN;
 	}
 	/*
 	 * Always allocate the DMA channel after the IRQ,
 	 * and clean up on failure.
 	 */
-	if (request_dma(idev->io.dma, idev->name)) {
-		free_irq( idev->io.irq, idev);
+	if (request_dma(self->io.dma, dev->name)) {
+		free_irq(self->io.irq, self);
 		return -EAGAIN;
 	}
 	
 	/* Save current bank */
-	bank = inb( iobase+BSR);
+	bank = inb(iobase+BSR);
 	
 	/* turn on interrupts */
-	switch_bank( iobase, BANK0);
-	outb( IER_LS_IE | IER_RXHDL_IE, iobase+IER);
+	switch_bank(iobase, BANK0);
+	outb(IER_LS_IE | IER_RXHDL_IE, iobase+IER);
 
 	/* Restore bank register */
-	outb( bank, iobase+BSR);
+	outb(bank, iobase+BSR);
 
-	irda_device_net_open(dev);
+	/* Ready to play! */
+	dev->tbusy = 0;
+	dev->interrupt = 0;
+	dev->start = 1;
+
+	/* 
+	 * Open new IrLAP layer instance, now that everything should be
+	 * initialized properly 
+	 */
+	self->irlap = irlap_open(dev, &self->qos);
 
 	MOD_INC_USE_COUNT;
 
@@ -1417,23 +1454,29 @@
  */
 static int pc87108_net_close(struct net_device *dev)
 {
-	struct irda_device *idev;
+	struct pc87108 *self;
 	int iobase;
 	__u8 bank;
 
-	DEBUG(4, __FUNCTION__ "()\n");
+	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 	
-	irda_device_net_close(dev);
-
 	ASSERT(dev != NULL, return -1;);
-	idev = (struct irda_device *) dev->priv;
+	self = (struct pc87108 *) dev->priv;
 	
-	ASSERT(idev != NULL, return 0;);
-	ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return 0;);
+	ASSERT(self != NULL, return 0;);
+
+	/* Stop device */
+	dev->tbusy = 1;
+	dev->start = 0;
+
+	/* Stop and remove instance of IrLAP */
+	if (self->irlap)
+		irlap_close(self->irlap);
+	self->irlap = NULL;
 	
-	iobase = idev->io.iobase;
+	iobase = self->io.iobase;
 
-	disable_dma(idev->io.dma);
+	disable_dma(self->io.dma);
 
 	/* Save current bank */
 	bank = inb(iobase+BSR);
@@ -1442,8 +1485,8 @@
 	switch_bank(iobase, BANK0);
 	outb(0, iobase+IER); 
        
-	free_irq(idev->io.irq, idev);
-	free_dma(idev->io.dma);
+	free_irq(self->io.irq, self);
+	free_dma(self->io.dma);
 
 	/* Restore bank register */
 	outb(bank, iobase+BSR);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)