patch-2.2.15 linux/drivers/net/irda/smc-ircc.c

Next file: linux/drivers/net/irda/tekram.c
Previous file: linux/drivers/net/irda/pc87108.c
Back to the patch index
Back to the overall index

diff -u --new-file --recursive --exclude-from ../../exclude v2.2.14/drivers/net/irda/smc-ircc.c linux/drivers/net/irda/smc-ircc.c
@@ -1,26 +1,35 @@
 /*********************************************************************
  *                
  * Filename:      smc-ircc.c
- * Version:       0.1
- * Description:   Driver for the SMC Infrared Communications Controller (SMC)
+ * Version:       0.4
+ * Description:   Driver for the SMC Infrared Communications Controller
  * Status:        Experimental.
  * Author:        Thomas Davis (tadavis@jps.net)
  * Created at:    
- * Modified at:   Wed May 19 15:30:08 1999
+ * Modified at:   Fri Jan 21 09:41:08 2000
  * Modified by:   Dag Brattli <dagb@cs.uit.no>
  * 
- *     Copyright (c) 1998-1999 Thomas Davis, All Rights Reserved.
+ *     Copyright (c) 1999-2000 Dag Brattli
+ *     Copyright (c) 1998-1999 Thomas Davis, 
+ *     All Rights Reserved.
  *      
  *     This program is free software; you can redistribute it and/or 
  *     modify it under the terms of the GNU General Public License as 
  *     published by the Free Software Foundation; either version 2 of 
  *     the License, or (at your option) any later version.
- *  
- *     I, Thomas Davis, admit no liability nor provide warranty for any
- *     of this software. This material is provided "AS-IS" and at no charge.
+ * 
+ *     This program is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *     GNU General Public License for more details.
+ * 
+ *     You should have received a copy of the GNU General Public License 
+ *     along with this program; if not, write to the Free Software 
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
+ *     MA 02111-1307 USA
  *
- *     Applicable Models : Fujitsu Lifebook 635t
- *			   Sony PCG-505TX (gets DMA wrong.)
+ *     SIO's: SMC FDC37N869, FDC37C669, FDC37N958
+ *     Applicable Models : Fujitsu Lifebook 635t, Sony PCG-505TX
  *
  ********************************************************************/
 
@@ -33,14 +42,18 @@
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/malloc.h>
-#include <linux/delay.h>
-#include <linux/init.h>
 #include <linux/init.h>
+#include <linux/rtnetlink.h>
+#include <linux/serial_reg.h>
 
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/byteorder.h>
 
+#ifdef CONFIG_APM
+#include <linux/apm_bios.h>
+#endif
+
 #include <net/irda/wrapper.h>
 #include <net/irda/irda.h>
 #include <net/irda/irmod.h>
@@ -54,46 +67,49 @@
 
 #define CHIP_IO_EXTENT 8
 
-static unsigned int io[]  = { 0x2e8, 0x140, ~0, ~0 };
-static unsigned int io2[] = { 0x2f8, 0x3e8, 0, 0};
+static unsigned int io[]  = { ~0, ~0 }; 
+static unsigned int io2[] = { 0, 0 };
 
-static struct ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL};
+static struct ircc_cb *dev_self[] = { NULL, NULL};
 
 /* Some prototypes */
-static int  ircc_open( int i, unsigned int iobase, unsigned int board_addr);
-static int  ircc_close( struct irda_device *idev);
-static int  ircc_probe( int iobase, int board_addr);
-static int  ircc_dma_receive( struct irda_device *idev); 
-static int  ircc_dma_receive_complete(struct irda_device *idev, int iobase);
-static int  ircc_hard_xmit( struct sk_buff *skb, struct device *dev);
-static void ircc_dma_write( struct irda_device *idev, int iobase);
-static void ircc_change_speed( struct irda_device *idev, int baud);
+static int  ircc_open(int i, unsigned int iobase, unsigned int board_addr);
+#ifdef MODULE
+static int  ircc_close(struct ircc_cb *self);
+#endif /* MODULE */
+static int  ircc_probe(int iobase, int board_addr);
+static int  ircc_probe_58(smc_chip_t *chip, chipio_t *info);
+static int  ircc_probe_69(smc_chip_t *chip, chipio_t *info);
+static int  ircc_dma_receive(struct ircc_cb *self, int iobase); 
+static void ircc_dma_receive_complete(struct ircc_cb *self, int iobase);
+static int  ircc_hard_xmit(struct sk_buff *skb, struct device *dev);
+static void ircc_dma_xmit(struct ircc_cb *self, int iobase, int bofs);
+static void ircc_change_speed(void *priv, __u32 speed);
 static void ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
-static void ircc_wait_until_sent( struct irda_device *idev);
-static int  ircc_is_receiving( struct irda_device *idev);
+static int  ircc_is_receiving(struct ircc_cb *self);
 
-static int  ircc_net_init( struct device *dev);
-static int  ircc_net_open( struct device *dev);
-static int  ircc_net_close( struct device *dev);
+static int  ircc_net_open(struct device *dev);
+static int  ircc_net_close(struct device *dev);
+#ifdef CONFIG_APM
+static int  ircc_apmproc(apm_event_t event);
+#endif /* CONFIG_APM */
+
+/* These are the currently known SMC chipsets */
+static smc_chip_t chips[] =
+{
+	{ "FDC37C669", 0x55, 0x55, 0x0d, 0x04, ircc_probe_69 },
+	{ "FDC37N869", 0x55, 0x00, 0x0d, 0x29, ircc_probe_69 },
+	{ "FDC37N958", 0x55, 0x55, 0x20, 0x09, ircc_probe_58 },
+	{ NULL }
+};
 
-static int ircc_debug=3;
 static int ircc_irq=255;
 static int ircc_dma=255;
 
-static inline void register_bank(int port, int bank)
+static inline void register_bank(int iobase, int bank)
 {
-        outb(((inb(port+UART_MASTER) & 0xF0) | (bank & 0x07)),
-             port+UART_MASTER);
-}
-
-static inline unsigned int serial_in(int port, int offset)
-{
-        return inb(port+offset);
-}
-
-static inline void serial_out(int port, int offset, int value)
-{
-        outb(value, port+offset);
+        outb(((inb(iobase+IRCC_MASTER) & 0xf0) | (bank & 0x07)),
+               iobase+IRCC_MASTER);
 }
 
 /*
@@ -102,21 +118,40 @@
  *    Initialize chip. Just try to find out how many chips we are dealing with
  *    and where they are
  */
-__initfunc(int ircc_init(void))
+int __init ircc_init(void)
 {
+	static int smcreg[] = { 0x3f0, 0x370 };
+	smc_chip_t *chip;
+	chipio_t info;
+	int ret = -ENODEV;
 	int i;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-	for ( i=0; (io[i] < 2000) && (i < 4); i++) {
-		int ioaddr = io[i];
-		if (check_region(ioaddr, CHIP_IO_EXTENT))
-			continue;
-		if (ircc_open( i, io[i], io2[i]) == 0)
-			return 0;
-	}
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	return -ENODEV;
+	/* Probe for all the NSC chipsets we know about */
+	for (chip=chips; chip->name ; chip++,i++) {
+		for (i=0; i<2; i++) {
+			info.cfg_base = smcreg[i];
+			
+			/* 
+			 * First we check if the user has supplied any
+                         * parameters which we should use instead of probed
+			 * values
+			 */
+			if (io[i] < 2000) {
+				info.fir_base = io[i];
+				info.sir_base = io2[i];
+			} else if (chip->probe(chip, &info) < 0)
+				continue;
+			if (check_region(info.fir_base, CHIP_IO_EXTENT) < 0)
+				continue;
+			if (check_region(info.sir_base, CHIP_IO_EXTENT) < 0)
+				continue;
+			if (ircc_open(i, info.fir_base, info.sir_base) == 0)
+				ret = 0; 
+		}
+	}
+	return ret;
 }
 
 /*
@@ -130,13 +165,12 @@
 {
 	int i;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	for ( i=0; i < 4; i++) {
-		if ( dev_self[i])
-			ircc_close( &(dev_self[i]->idev));
+	for (i=0; i < 2; i++) {
+		if (dev_self[i])
+			ircc_close(dev_self[i]);
 	}
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 }
 #endif /* MODULE */
 
@@ -146,166 +180,270 @@
  *    Open driver instance
  *
  */
-static int ircc_open( int i, unsigned int iobase, unsigned int iobase2)
+static int ircc_open(int i, unsigned int fir_base, unsigned int sir_base)
 {
 	struct ircc_cb *self;
-	struct irda_device *idev;
-	int ret;
+        struct irport_cb *irport;
 	int config;
+	int ret;
 
-	DEBUG( ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	if ((config = ircc_probe( iobase, iobase2)) == -1) {
-	        DEBUG(ircc_debug, 
-		      __FUNCTION__ ": addr 0x%04x - no device found!\n", iobase);
+	if ((config = ircc_probe(fir_base, sir_base)) == -1) {
+	        IRDA_DEBUG(0, __FUNCTION__ 
+			   "(), addr 0x%04x - no device found!\n", fir_base);
 		return -1;
 	}
 	
 	/*
 	 *  Allocate new instance of the driver
 	 */
-	self = kmalloc( sizeof(struct ircc_cb), GFP_KERNEL);
-	if ( self == NULL) {
-		printk( KERN_ERR "IrDA: Can't allocate memory for "
-			"IrDA control block!\n");
+	self = kmalloc(sizeof(struct ircc_cb), GFP_KERNEL);
+	if (self == NULL) {
+		ERROR("%s, Can't allocate memory for control block!\n",
+                      driver_name);
 		return -ENOMEM;
 	}
 	memset(self, 0, sizeof(struct ircc_cb));
+	spin_lock_init(&self->lock);
    
 	/* Need to store self somewhere */
 	dev_self[i] = self;
 
-	idev = &self->idev;
+	irport = irport_open(i, sir_base, config >> 4 & 0x0f);
+	if (!irport)
+		return -ENODEV;
+
+	/* Steal the network device from irport */
+	self->netdev = irport->netdev;
+	self->irport = irport;
+	irport->priv = self;
 
 	/* Initialize IO */
-	idev->io.iobase    = iobase;
-        idev->io.iobase2   = iobase2; /* Used by irport */
-        idev->io.irq       = config >> 4 & 0x0f;
+	self->io.fir_base  = fir_base;
+        self->io.sir_base  = sir_base; /* Used by irport */
+        self->io.irq       = config >> 4 & 0x0f;
 	if (ircc_irq < 255) {
-	        printk(KERN_INFO "smc: Overriding IRQ - chip says %d, using %d\n",
-		      idev->io.irq, ircc_irq);
-		idev->io.irq = ircc_irq;
-	}
-        idev->io.io_ext    = CHIP_IO_EXTENT;
-        idev->io.io_ext2   = 8;       /* Used by irport */
-        idev->io.dma       = config & 0x0f;
+	        MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
+			driver_name, self->io.irq, ircc_irq);
+		self->io.irq = ircc_irq;
+	}
+        self->io.fir_ext   = CHIP_IO_EXTENT;
+        self->io.sir_ext   = 8;       /* Used by irport */
+        self->io.dma       = config & 0x0f;
 	if (ircc_dma < 255) {
-	        printk(KERN_INFO "smc: Overriding DMA - chip says %d, using %d\n",
-		      idev->io.dma, ircc_dma);
-		idev->io.dma = ircc_dma;
+	        MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
+			driver_name, self->io.dma, ircc_dma);
+		self->io.dma = ircc_dma;
 	}
-        idev->io.fifo_size = 16;
 
 	/* Lock the port that we need */
-	ret = check_region( idev->io.iobase, idev->io.io_ext);
-	if ( ret < 0) { 
-		DEBUG( 0, __FUNCTION__ ": can't get iobase of 0x%03x\n",
-		       idev->io.iobase);
-		/* ircc_cleanup( self->idev);  */
+	ret = check_region(self->io.fir_base, self->io.fir_ext);
+	if (ret < 0) { 
+		IRDA_DEBUG(0, __FUNCTION__ ": can't get fir_base of 0x%03x\n",
+			   self->io.fir_base);
+                kfree(self);
 		return -ENODEV;
 	}
-	ret = check_region( idev->io.iobase2, idev->io.io_ext2);
-	if ( ret < 0) { 
-		DEBUG( 0, __FUNCTION__ ": can't get iobase of 0x%03x\n",
-		       idev->io.iobase2);
-		/* ircc_cleanup( self->idev);  */
-		return -ENODEV;
-	}
-	request_region( idev->io.iobase, idev->io.io_ext, idev->name);
-        request_region( idev->io.iobase2, idev->io.io_ext2, idev->name);
+	request_region(self->io.fir_base, self->io.fir_ext, driver_name);
 
 	/* Initialize QoS for this device */
-	irda_init_max_qos_capabilies( &idev->qos);
+	irda_init_max_qos_capabilies(&irport->qos);
 	
-#if 1
 	/* The only value we must override it the baudrate */
-	idev->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
+	irport->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
 		IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
-#else
-	/* The only value we must override it the baudrate */
-	idev->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
-		IR_115200;
-#endif
 
-	idev->qos.min_turn_time.bits = 0x07;
-	irda_qos_bits_to_value( &idev->qos);
+	irport->qos.min_turn_time.bits = 0x07;
+	irda_qos_bits_to_value(&irport->qos);
 
-	idev->flags = IFF_FIR|IFF_SIR|IFF_DMA|IFF_PIO;
+	irport->flags = IFF_FIR|IFF_MIR|IFF_SIR|IFF_DMA|IFF_PIO;
 	
-	/* Specify which buffer allocation policy we need */
-	idev->rx_buff.flags = GFP_KERNEL | GFP_DMA;
-	idev->tx_buff.flags = GFP_KERNEL | GFP_DMA;
-
 	/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
-	idev->rx_buff.truesize = 4000; 
-	idev->tx_buff.truesize = 4000;
+	self->rx_buff.truesize = 4000; 
+	self->tx_buff.truesize = 4000;
+
+	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);
 	
-	/* Initialize callbacks */
-	idev->change_speed    = ircc_change_speed;
-	idev->wait_until_sent = ircc_wait_until_sent;
-	idev->is_receiving    = ircc_is_receiving;
-     
-	/* Override the network functions we need to use */
-	idev->netdev.init            = ircc_net_init;
-	idev->netdev.hard_start_xmit = ircc_hard_xmit;
-	idev->netdev.open            = ircc_net_open;
-	idev->netdev.stop            = ircc_net_close;
+	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);
 
-	irport_start(idev, iobase2);
+	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;
+	
+	/* Override the speed change function, since we must control it now */
+	irport->change_speed = &ircc_change_speed;
+	irport->interrupt    = &ircc_interrupt;
+	self->netdev->open   = &ircc_net_open;
+	self->netdev->stop   = &ircc_net_close;
+
+	irport_start(self->irport);
 
-	/* Open the IrDA device */
-	irda_device_open( idev, driver_name, self);
-	
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
 /*
- * Function ircc_close (idev)
+ * Function ircc_close (self)
  *
  *    Close driver instance
  *
  */
-static int ircc_close( struct irda_device *idev)
+#ifdef MODULE
+static int ircc_close(struct ircc_cb *self)
 {
 	int iobase;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	ASSERT( idev != NULL, return -1;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return -1;);
+	ASSERT(self != NULL, return -1;);
 
-        iobase = idev->io.iobase;
+        iobase = self->io.fir_base;
 
-	irport_stop(idev, idev->io.iobase2);
+	irport_close(self->irport);
 
+	/* Stop interrupts */
 	register_bank(iobase, 0);
-	serial_out(iobase, UART_IER, 0);
-	serial_out(iobase, UART_MASTER, UART_MASTER_RESET);
-
+	outb(0, iobase+IRCC_IER);
+	outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER);
+	outb(0x00, iobase+IRCC_MASTER);
+#if 0
+	/* Reset to SIR mode */
 	register_bank(iobase, 1);
-
-        serial_out(iobase, UART_SCE_CFGA, 
-		   UART_CFGA_IRDA_SIR_A | UART_CFGA_TX_POLARITY);
-        serial_out(iobase, UART_SCE_CFGB, UART_CFGB_IR);
- 
+        outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase+IRCC_SCE_CFGA);
+        outb(IRCC_CFGB_IR, iobase+IRCC_SCE_CFGB);
+#endif
 	/* Release the PORT that this driver is using */
-	DEBUG( ircc_debug, 
-	       __FUNCTION__ ": releasing 0x%03x\n", idev->io.iobase);
+	IRDA_DEBUG(0, __FUNCTION__ "(), releasing 0x%03x\n", 
+		   self->io.fir_base);
 
-	release_region( idev->io.iobase, idev->io.io_ext);
+	release_region(self->io.fir_base, self->io.fir_ext);
 
-	if ( idev->io.iobase2) {
-		DEBUG( ircc_debug, __FUNCTION__ ": releasing 0x%03x\n", 
-		       idev->io.iobase2);
-		release_region( idev->io.iobase2, idev->io.io_ext2);
-	}
+	if (self->tx_buff.head)
+		kfree(self->tx_buff.head);
+	
+	if (self->rx_buff.head)
+		kfree(self->rx_buff.head);
 
-	irda_device_close( idev);
+	kfree(self);
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
+#endif /* MODULE */
+
+/*
+ * Function ircc_probe_69 (chip, info)
+ *
+ *    Probes for the SMC FDC37C669 and FDC37N869
+ *
+ */
+static int ircc_probe_69(smc_chip_t *chip, chipio_t *info)
+{
+	int cfg_base = info->cfg_base;
+	__u8 devid, mode;
+	int ret = -ENODEV;
+	int fir_io;
+	
+	IRDA_DEBUG(0, __FUNCTION__ "()\n");
+
+	/* Enter configuration */
+	outb(chip->entr1, cfg_base);
+	outb(chip->entr2, cfg_base);
+	
+	outb(chip->cid_index, cfg_base);
+	devid = inb(cfg_base+1);
+	IRDA_DEBUG(0, __FUNCTION__ "(), devid=0x%02x\n",devid);
+	
+	/* Check for expected device ID; are there others? */
+	if (devid == chip->cid_value) {
+		outb(0x0c, cfg_base);
+		mode = inb(cfg_base+1);
+		mode = (mode & 0x38) >> 3;
+		
+		/* Value for IR port */
+		if (mode && mode < 4) {
+			/* SIR iobase */
+			outb(0x25, cfg_base);
+			info->sir_base = inb(cfg_base+1) << 2;
+
+		       	/* FIR iobase */
+			outb(0x2b, cfg_base);
+			fir_io = inb(cfg_base+1) << 3;
+			if (fir_io) {
+				ret = 0;
+				info->fir_base = fir_io;
+			}
+		}
+	}
+	
+	/* Exit configuration */
+	outb(0xaa, cfg_base);
+
+	return ret;
+}
+
+/*
+ * Function ircc_probe_58 (chip, info)
+ *
+ *    Probes for the SMC FDC37N958
+ *
+ */
+static int ircc_probe_58(smc_chip_t *chip, chipio_t *info)
+{
+	int cfg_base = info->cfg_base;
+	__u8 devid;
+	int ret = -ENODEV;
+	int fir_io;
+	
+	IRDA_DEBUG(0, __FUNCTION__ "()\n");
+
+	/* Enter configuration */
+	outb(chip->entr1, cfg_base);
+	outb(chip->entr2, cfg_base);
+	
+	outb(chip->cid_index, cfg_base);
+	devid = inb(cfg_base+1);
+	IRDA_DEBUG(0, __FUNCTION__ "(), devid=0x%02x\n",devid);
+	
+	/* Check for expected device ID; are there others? */
+	if (devid == chip->cid_value) {
+		/* Select logical device (UART2) */
+		outb(0x07, cfg_base);
+		outb(0x05, cfg_base + 1);
+		
+		/* SIR iobase */
+		outb(0x60, cfg_base);
+		info->sir_base = inb(cfg_base + 1) << 8;
+		outb(0x61, cfg_base);
+		info->sir_base |= inb(cfg_base + 1);
+		
+		/* Read FIR base */
+		outb(0x62, cfg_base);
+		fir_io = inb(cfg_base + 1) << 8;
+		outb(0x63, cfg_base);
+		fir_io |= inb(cfg_base + 1);
+		outb(0x2b, cfg_base);
+		if (fir_io) {
+			ret = 0;
+			info->fir_base = fir_io;
+		}
+	}
+	
+	/* Exit configuration */
+	outb(0xaa, cfg_base);
+
+	return ret;
+}
 
 /*
  * Function ircc_probe (iobase, board_addr, irq, dma)
@@ -313,135 +451,144 @@
  *    Returns non-negative on success.
  *
  */
-static int ircc_probe( int iobase, int iobase2) 
+static int ircc_probe(int fir_base, int sir_base) 
 {
-	int version = 1;
 	int low, high, chip, config, dma, irq;
-	
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	int iobase = fir_base;
+	int version = 1;
 
-	register_bank(iobase, 3);
-	high = serial_in(iobase, UART_ID_HIGH);
-	low = serial_in(iobase, UART_ID_LOW);
-	chip = serial_in(iobase, UART_CHIP_ID);
-	version = serial_in(iobase, UART_VERSION);
-	config = serial_in(iobase, UART_INTERFACE);
-	irq = config >> 4 & 0x0f;
-	dma = config & 0x0f;
-
-	if (high == 0x10 && low == 0xb8 && chip == 0xf1) {
-		DEBUG(0, "SMC IrDA Controller found; version = %d, "
-		      "port 0x%04x, dma %d, interrupt %d\n",
-		      version, iobase, dma, irq);
-	} else {
-		return -1;
-	}
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	serial_out(iobase, UART_MASTER, 0);
+	register_bank(iobase, 3);
+	high    = inb(iobase+IRCC_ID_HIGH);
+	low     = inb(iobase+IRCC_ID_LOW);
+	chip    = inb(iobase+IRCC_CHIP_ID);
+	version = inb(iobase+IRCC_VERSION);
+	config  = inb(iobase+IRCC_INTERFACE);
+	irq     = config >> 4 & 0x0f;
+	dma     = config & 0x0f;
+
+        if (high == 0x10 && low == 0xb8 && (chip == 0xf1 || chip == 0xf2)) { 
+                MESSAGE("SMC IrDA Controller found; IrCC version %d.%d, "
+			"port 0x%03x, dma=%d, irq=%d\n",
+			chip & 0x0f, version, iobase, dma, irq);
+	} else
+		return -ENODEV;
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	/* Power on device */
+	outb(0x00, iobase+IRCC_MASTER);
 
 	return config;
 }
 
 /*
- * Function ircc_change_speed (idev, baud)
+ * Function ircc_change_speed (self, baud)
  *
  *    Change the speed of the device
  *
  */
-static void ircc_change_speed( struct irda_device *idev, int speed)
+static void ircc_change_speed(void *priv, __u32 speed)
 {
-	struct ircc_cb *self;
-	int iobase, ir_mode, select, fast; 
+	int iobase, ir_mode, ctrl, fast; 
+	struct ircc_cb *self = (struct ircc_cb *) priv;
+	struct device *dev;
 
-	DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	ASSERT(idev != NULL, return;);
-	ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
+	ASSERT(self != NULL, return;);
 
-	self = idev->priv;
-	iobase = idev->io.iobase;
+	dev = self->netdev;
+	iobase = self->io.fir_base;
 
 	/* Update accounting for new speed */
-	idev->io.baudrate = speed;
+	self->io.speed = speed;
 
-	switch ( speed) {
+	outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER);
+	outb(0x00, iobase+IRCC_MASTER);
+
+	switch (speed) {
 	case 9600:
 	case 19200:
-	case 37600:
+	case 38400:
 	case 57600:
-	case 115200:
-	        DEBUG(ircc_debug+1, 
-		      __FUNCTION__ ": using irport to change speed to %d\n",
-		      speed);
-		register_bank(iobase, 0);
-		serial_out(iobase, UART_IER, 0);
-		serial_out(iobase, UART_MASTER, UART_MASTER_RESET);
-		serial_out(iobase, UART_MASTER, UART_MASTER_INT_EN);
-		irport_start(idev, idev->io.iobase2);
-		irport_change_speed( idev, speed);
-		return;
+	case 115200:		
+		ir_mode = IRCC_CFGA_IRDA_SIR_A;
+		ctrl = 0;
+		fast = 0;
 		break;
-
 	case 576000:		
-		ir_mode = UART_CFGA_IRDA_HDLC;
-		select = 0;
+		ir_mode = IRCC_CFGA_IRDA_HDLC;
+		ctrl = IRCC_CRC;
 		fast = 0;
-		DEBUG( ircc_debug, __FUNCTION__ ": handling baud of 576000\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 576000\n");
 		break;
 	case 1152000:
-		ir_mode = UART_CFGA_IRDA_HDLC;
-		select = UART_1152;
+		ir_mode = IRCC_CFGA_IRDA_HDLC;
+		ctrl = IRCC_1152 | IRCC_CRC;
 		fast = 0;
-		DEBUG(ircc_debug, __FUNCTION__ ": handling baud of 1152000\n");
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 1152000\n");
 		break;
 	case 4000000:
-		ir_mode = UART_CFGA_IRDA_4PPM;
-		select = 0;
-		fast = UART_LCR_A_FAST;
-		DEBUG(ircc_debug, __FUNCTION__ ": handling baud of 4000000\n");
+		ir_mode = IRCC_CFGA_IRDA_4PPM;
+		ctrl = IRCC_CRC;
+		fast = IRCC_LCR_A_FAST;
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 4000000\n");
 		break;
 	default:
-		DEBUG( 0, __FUNCTION__ ": unknown baud rate of %d\n", speed);
+		IRDA_DEBUG(0, __FUNCTION__ "(), unknown baud rate of %d\n", 
+			   speed);
 		return;
 	}
-
-#if 0
-	serial_out(idev->io.iobase2, 4, 0x08);
-#endif
-
-	serial_out(iobase, UART_MASTER, UART_MASTER_RESET);
-
-	register_bank(iobase, 0);
-	serial_out(iobase, UART_IER, 0);
-	
-       	irport_stop(idev, idev->io.iobase2);
-
-	idev->netdev.tbusy = 0;
 	
-	register_bank(iobase, 1);
+	register_bank(iobase, 0);
+	outb(0, iobase+IRCC_IER);
+	outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER);
 
-	serial_out(iobase, UART_SCE_CFGA, 
-		   ((serial_in(iobase, UART_SCE_CFGA) & 0x87) | ir_mode));
+	/* Make special FIR init if necessary */
+	if (speed > 115200) {
+		irport_stop(self->irport);
+
+		/* Install FIR transmit handler */
+		dev->hard_start_xmit = &ircc_hard_xmit;
+
+		/* 
+		 * Don't know why we have to do this, but FIR interrupts 
+		 * stops working if we remove it.
+		 */
+		/* outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR); */
 
-	serial_out(iobase, UART_SCE_CFGB,
-		   ((serial_in(iobase, UART_SCE_CFGB) & 0x3f) | UART_CFGB_IR));
+		/* Be ready for incomming frames */
+		ircc_dma_receive(self, iobase);
+	} else {
+		/* Install SIR transmit handler */
+		dev->hard_start_xmit = &irport_hard_xmit;
+		irport_start(self->irport);
+		
+	        IRDA_DEBUG(0, __FUNCTION__ 
+			   "(), using irport to change speed to %d\n", speed);
+		irport_change_speed(self->irport, speed);
+	}	
+	dev->tbusy = 0;
 
-	(void) serial_in(iobase, UART_FIFO_THRESHOLD);
-	serial_out(iobase, UART_FIFO_THRESHOLD, 64);
+	register_bank(iobase, 1);
+	outb(((inb(iobase+IRCC_SCE_CFGA) & 0x87) | ir_mode), 
+	     iobase+IRCC_SCE_CFGA);
 
+#ifdef SMC_669 /* Uses pin 88/89 for Rx/Tx */
+	outb(((inb(iobase+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM), 
+	     iobase+IRCC_SCE_CFGB);
+#else	
+	outb(((inb(iobase+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
+	     iobase+IRCC_SCE_CFGB);
+#endif	
+	(void) inb(iobase+IRCC_FIFO_THRESHOLD);
+	outb(64, iobase+IRCC_FIFO_THRESHOLD);
+	
 	register_bank(iobase, 4);
-
-	serial_out(iobase, UART_CONTROL,
-		   (serial_in(iobase, UART_CONTROL) & 0x30) 
-		   | select | UART_CRC );
-
+	outb((inb(iobase+IRCC_CONTROL) & 0x30) | ctrl, iobase+IRCC_CONTROL);
+	
 	register_bank(iobase, 0);
-
-	serial_out(iobase, UART_LCR_A, fast);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	outb(fast, iobase+IRCC_LCR_A);
 }
 
 /*
@@ -450,271 +597,252 @@
  *    Transmit the frame!
  *
  */
-static int ircc_hard_xmit( struct sk_buff *skb, struct device *dev)
+static int ircc_hard_xmit(struct sk_buff *skb, struct device *dev)
 {
-	struct irda_device *idev;
+	struct irport_cb *irport;
+	struct ircc_cb *self;
+	unsigned long flags;
+	__u32 speed;
 	int iobase;
 	int mtt;
 
-	DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
-	idev = (struct irda_device *) dev->priv;
-
-	ASSERT( idev != NULL, return 0;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return 0;);
+	irport = (struct irport_cb *) dev->priv;
+	self = (struct ircc_cb *) irport->priv;
+	ASSERT(self != NULL, return 0;);
 
-	iobase = idev->io.iobase;
+	iobase = self->io.fir_base;
 
-	DEBUG(ircc_debug+1, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies, (int) skb->len);
+	spin_lock_irqsave(&self->lock, flags);
 
-	/* Use irport for SIR speeds */
-	if (idev->io.baudrate <= 115200) {
-		DEBUG(ircc_debug+1, __FUNCTION__ ": calling irport_hard_xmit\n");
-		return irport_hard_xmit(skb, dev);
-	}
+	/* Check if we need to change the speed after this frame */
+	if ((speed = irda_get_speed(skb)) != self->io.speed)
+		self->new_speed = speed;
 	
-	DEBUG(ircc_debug, __FUNCTION__ ": using dma; len=%d\n", skb->len);
-
 	/* Lock transmit buffer */
 	if (irda_lock((void *) &dev->tbusy) == FALSE)
 		return -EBUSY;
 
-	memcpy( idev->tx_buff.head, skb->data, skb->len);
-
-	/* Make sure that the length is a multiple of 16 bits */
-	if ( skb->len & 0x01)
-		skb->len++;
+	memcpy(self->tx_buff.head, skb->data, skb->len);
 
-	idev->tx_buff.len = skb->len;
-	idev->tx_buff.data = idev->tx_buff.head;
-#if 0
-	idev->tx_buff.offset = 0;
-#endif
-	
-	mtt = irda_get_mtt( skb);
-	
-	/* Use udelay for delays less than 50 us. */
-	if (mtt)
-		udelay( mtt);
+	self->tx_buff.len = skb->len;
+	self->tx_buff.data = self->tx_buff.head;
 	
-	ircc_dma_write( idev, iobase);
+	mtt = irda_get_mtt(skb);	
+	if (mtt) {
+		int bofs;
+
+		/* 
+		 * Compute who many BOFS (STA or PA's) we need to waste the
+		 * min turn time given the speed of the link.
+		 */
+		bofs = mtt * (self->io.speed / 1000) / 8000;
+		if (bofs > 4095)
+			bofs = 4095;
+
+		ircc_dma_xmit(self, iobase, bofs);
+	} else {
+		/* Transmit frame */
+		ircc_dma_xmit(self, iobase, 0);
+	}
 	
-	dev_kfree_skb( skb);
+	spin_unlock_irqrestore(&self->lock, flags);
+	dev_kfree_skb(skb);
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
 /*
- * Function ircc_dma_xmit (idev, iobase)
+ * Function ircc_dma_xmit (self, iobase)
  *
  *    Transmit data using DMA
  *
  */
-static void ircc_dma_write( struct irda_device *idev, int iobase)
+static void ircc_dma_xmit(struct ircc_cb *self, int iobase, int bofs)
 {
-	struct ircc_cb *self;
+	__u8 ctrl;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-
-	ASSERT( idev != NULL, return;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return;);
-
-	self = idev->priv;
-	iobase = idev->io.iobase;
-
-	setup_dma( idev->io.dma, idev->tx_buff.data, idev->tx_buff.len, 
-		   DMA_MODE_WRITE);
-	
-	idev->io.direction = IO_XMIT;
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
+#if 0	
+	/* Disable Rx */
+	register_bank(iobase, 0);
+	outb(0x00, iobase+IRCC_LCR_B);
+#endif
+	register_bank(iobase, 1);
+	outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 
+	     iobase+IRCC_SCE_CFGB);
 
-	serial_out(idev->io.iobase2, 4, 0x08);
+	self->io.direction = IO_XMIT;
 
+	/* Set BOF additional count for generating the min turn time */
 	register_bank(iobase, 4);
-	serial_out(iobase, UART_CONTROL, 
-		   (serial_in(iobase, UART_CONTROL) & 0xF0));
-
-	serial_out(iobase, UART_BOF_COUNT_LO, 2);
-	serial_out(iobase, UART_BRICKWALL_CNT_LO, 0);
-#if 1
-	serial_out(iobase, UART_BRICKWALL_TX_CNT_HI, idev->tx_buff.len >> 8);
-	serial_out(iobase, UART_TX_SIZE_LO, idev->tx_buff.len & 0xff);
-#else
-	serial_out(iobase, UART_BRICKWALL_TX_CNT_HI, 0);
-	serial_out(iobase, UART_TX_SIZE_LO, 0);
-#endif
+	outb(bofs & 0xff, iobase+IRCC_BOF_COUNT_LO);
+	ctrl = inb(iobase+IRCC_CONTROL) & 0xf0;
+	outb(ctrl | ((bofs >> 8) & 0x0f), iobase+IRCC_BOF_COUNT_HI);
+
+	/* Set max Tx frame size */
+	outb(self->tx_buff.len >> 8, iobase+IRCC_TX_SIZE_HI);
+	outb(self->tx_buff.len & 0xff, iobase+IRCC_TX_SIZE_LO);
+
+	/* Setup DMA controller (must be done after enabling chip DMA) */
+	setup_dma(self->io.dma, self->tx_buff.data, self->tx_buff.len, 
+		  DMA_TX_MODE);
 
+	outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);
+	/* Enable burst mode chip Tx DMA */
 	register_bank(iobase, 1);
-	serial_out(iobase, UART_SCE_CFGB,
-		   serial_in(iobase, UART_SCE_CFGB) | UART_CFGB_DMA_ENABLE);
+	outb(inb(iobase+IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
+	     IRCC_CFGB_DMA_BURST, iobase+IRCC_SCE_CFGB);
 
+	/* Enable interrupt */
+	outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER);
 	register_bank(iobase, 0);
+	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase+IRCC_IER);
 
-	serial_out(iobase, UART_IER, UART_IER_ACTIVE_FRAME | UART_IER_EOM);
-	serial_out(iobase, UART_LCR_B,
-		   UART_LCR_B_SCE_TRANSMIT|UART_LCR_B_SIP_ENABLE);
-
-	serial_out(iobase, UART_MASTER, UART_MASTER_INT_EN);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	/* Enable transmit */
+	outb(IRCC_LCR_B_SCE_TRANSMIT|IRCC_LCR_B_SIP_ENABLE, iobase+IRCC_LCR_B);
 }
 
 /*
- * Function ircc_dma_xmit_complete (idev)
+ * Function ircc_dma_xmit_complete (self)
  *
  *    The transfer of a frame in finished. This function will only be called 
  *    by the interrupt handler
  *
  */
-static void ircc_dma_xmit_complete( struct irda_device *idev, int underrun)
+static void ircc_dma_xmit_complete(struct ircc_cb *self, int iobase)
 {
-	struct ircc_cb *self;
-	int iobase, d;
-
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-
-	ASSERT( idev != NULL, return;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return;);
-
-	register_bank(idev->io.iobase, 1);
-
-	serial_out(idev->io.iobase, UART_SCE_CFGB,
-		   serial_in(idev->io.iobase, UART_SCE_CFGB) &
-		   ~UART_CFGB_DMA_ENABLE);
-
-	d = get_dma_residue(idev->io.dma);
-
-	DEBUG(ircc_debug, __FUNCTION__ ": dma residue = %d, len=%d, sent=%d\n", 
-	      d, idev->tx_buff.len, idev->tx_buff.len - d);
-
-	self = idev->priv;
-
-	iobase = idev->io.iobase;
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
+#if 0
+	/* Disable Tx */
+	register_bank(iobase, 0);
+	outb(0x00, iobase+IRCC_LCR_B);
+#endif
+	register_bank(self->io.fir_base, 1);
+	outb(inb(self->io.fir_base+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
+	     self->io.fir_base+IRCC_SCE_CFGB);
 
 	/* Check for underrrun! */
-	if ( underrun) {
-		idev->stats.tx_errors++;
-		idev->stats.tx_fifo_errors++;		
+	register_bank(iobase, 0);
+	if (inb(iobase+IRCC_LSR) & IRCC_LSR_UNDERRUN) {
+		self->irport->stats.tx_errors++;
+		self->irport->stats.tx_fifo_errors++;
+
+		/* Reset error condition */
+		register_bank(iobase, 0);
+		outb(IRCC_MASTER_ERROR_RESET, iobase+IRCC_MASTER);
+		outb(0x00, iobase+IRCC_MASTER);
 	} else {
-		idev->stats.tx_packets++;
-		idev->stats.tx_bytes +=  idev->tx_buff.len;
+		self->irport->stats.tx_packets++;
+		self->irport->stats.tx_bytes +=  self->tx_buff.len;
+	}
+
+	/* Check if it's time to change the speed */
+	if (self->new_speed) {
+		ircc_change_speed(self, self->new_speed);		
+		self->new_speed = 0;
 	}
 
 	/* 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);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	mark_bh(NET_BH);
 }
 
 /*
- * Function ircc_dma_receive (idev)
+ * Function ircc_dma_receive (self)
  *
  *    Get ready for receiving a frame. The device will initiate a DMA
  *    if it starts to receive a frame.
  *
  */
-static int ircc_dma_receive( struct irda_device *idev) 
-{
-	struct ircc_cb *self;
-	int iobase;
-
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-
-	ASSERT( idev != NULL, return -1;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return -1;);
+static int ircc_dma_receive(struct ircc_cb *self, int iobase) 
+{	
+	/* Turn off chip DMA */
+	//register_bank(iobase, 1);
+	//outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 
+	//     iobase+IRCC_SCE_CFGB);
+
+	setup_dma(self->io.dma, self->rx_buff.data, self->rx_buff.truesize, 
+		  DMA_RX_MODE);
+	/* Set max Rx frame size */
+	register_bank(iobase, 4);
+	outb((2050 >> 8) & 0x0f, iobase+IRCC_RX_SIZE_HI);
+	outb(2050 & 0xff, iobase+IRCC_RX_SIZE_LO);
 
-	self = idev->priv;
-	iobase= idev->io.iobase;
+	self->io.direction = IO_RECV;
+	self->rx_buff.data = self->rx_buff.head;
 
-	setup_dma( idev->io.dma, idev->rx_buff.data, idev->rx_buff.truesize, 
-		   DMA_MODE_READ);
+	/* Setup DMA controller */
 	
-	/* driver->media_busy = FALSE; */
-	idev->io.direction = IO_RECV;
-	idev->rx_buff.data = idev->rx_buff.head;
-#if 0
-	idev->rx_buff.offset = 0;
-#endif
-
-	register_bank(iobase, 4);
-	serial_out(iobase, UART_CONTROL, 
-		   (serial_in(iobase, UART_CONTROL) &0xF0));
-	serial_out(iobase, UART_BOF_COUNT_LO, 2);
-	serial_out(iobase, UART_BRICKWALL_CNT_LO, 0);
-	serial_out(iobase, UART_BRICKWALL_TX_CNT_HI, 0);
-	serial_out(iobase, UART_TX_SIZE_LO, 0);
-	serial_out(iobase, UART_RX_SIZE_HI, 0);
-	serial_out(iobase, UART_RX_SIZE_LO, 0);
-
+	/* Enable receiver */
 	register_bank(iobase, 0);
-	serial_out(iobase, 
-		   UART_LCR_B, UART_LCR_B_SCE_RECEIVE | UART_LCR_B_SIP_ENABLE);
+	outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE, 
+	     iobase+IRCC_LCR_B);
 	
+	/* Enable burst mode chip Rx DMA */
 	register_bank(iobase, 1);
-	serial_out(iobase, UART_SCE_CFGB,
-		   serial_in(iobase, UART_SCE_CFGB) | 
-		   UART_CFGB_DMA_ENABLE | UART_CFGB_DMA_BURST);
+	outb(inb(iobase+IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE | 
+	     IRCC_CFGB_DMA_BURST, iobase+IRCC_SCE_CFGB);
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
 /*
- * Function ircc_dma_receive_complete (idev)
+ * Function ircc_dma_receive_complete (self)
  *
  *    Finished with receiving frames
  *
  *    
  */
-static int ircc_dma_receive_complete( struct irda_device *idev, int iobase)
+static void ircc_dma_receive_complete(struct ircc_cb *self, int iobase)
 {
+	unsigned long flags;
 	struct sk_buff *skb;
-	struct ircc_cb *self;
 	int len, msgcnt;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-
-	self = idev->priv;
-
-	msgcnt = serial_in(idev->io.iobase, UART_LCR_B) & 0x08;
-
-	DEBUG(ircc_debug, __FUNCTION__ ": dma count = %d\n",
-	      get_dma_residue(idev->io.dma));
-
-	len = idev->rx_buff.truesize - get_dma_residue(idev->io.dma) - 4;
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
+#if 0
+	/* Disable Rx */
+	register_bank(iobase, 0);
+	outb(0x00, iobase+IRCC_LCR_B);
+#endif
+	register_bank(iobase, 0);
+	msgcnt = inb(iobase+IRCC_LCR_B) & 0x08;
 
-	DEBUG(ircc_debug, __FUNCTION__ ": msgcnt = %d, len=%d\n", msgcnt, len);
+	IRDA_DEBUG(2, __FUNCTION__ ": dma count = %d\n",
+		   get_dma_residue(self->io.dma));
 
-	skb = dev_alloc_skb( len+1);
+	len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
+	
+	/* Remove CRC */
+	if (self->io.speed < 4000000)
+		len -= 2;
+	else
+		len -= 4;
 
-	if (skb == NULL)  {
-		printk( KERN_INFO __FUNCTION__ 
-			": memory squeeze, dropping frame.\n");
-		return FALSE;
+	if ((len < 2) && (len > 2050)) {
+		WARNING(__FUNCTION__ "(), bogus len=%d\n", len);
+		return;
 	}
-			
+	IRDA_DEBUG(2, __FUNCTION__ ": msgcnt = %d, len=%d\n", msgcnt, len);
+
+	skb = dev_alloc_skb(len+1);
+	if (!skb)  {
+		WARNING(__FUNCTION__ "(), memory squeeze, dropping frame.\n");
+		return;
+	}			
 	/* Make sure IP header gets aligned */
-	skb_reserve( skb, 1); 
-	skb_put( skb, len);
+	skb_reserve(skb, 1); 
 
-	memcpy(skb->data, idev->rx_buff.data, len);
-	idev->stats.rx_packets++;
+	memcpy(skb_put(skb, len), self->rx_buff.data, len);
+	self->irport->stats.rx_packets++;
+	self->irport->stats.rx_bytes += len;
 
-	skb->dev = &idev->netdev;
+	skb->dev = self->netdev;
 	skb->mac.raw  = skb->data;
 	skb->protocol = htons(ETH_P_IRDA);
-	netif_rx( skb);
-
-	register_bank(idev->io.iobase, 1);
-	serial_out(idev->io.iobase, UART_SCE_CFGB,
-		   serial_in(idev->io.iobase, UART_SCE_CFGB) &
-		   ~UART_CFGB_DMA_ENABLE);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
-	return TRUE;
+	netif_rx(skb);
 }
 
 /*
@@ -725,176 +853,115 @@
  */
 static void ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
+	struct device *dev = (struct device *) dev_id;
+	struct irport_cb *irport;
+	struct ircc_cb *self;
 	int iobase, iir;
 
-	struct irda_device *idev = (struct irda_device *) dev_id;
-
-	DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
-
-	if (idev == NULL) {
-		printk( KERN_WARNING "%s: irq %d for unknown device.\n", 
-			driver_name, irq);
+	if (dev == NULL) {
+		printk(KERN_WARNING "%s: irq %d for unknown device.\n", 
+		       driver_name, irq);
 		return;
 	}
-	
-	if (idev->io.baudrate <= 115200) {
-		DEBUG(ircc_debug+1, __FUNCTION__ 
-		      ": routing interrupt to irport_interrupt\n");
-		return irport_interrupt( irq, dev_id, regs);
+	irport = (struct irport_cb *) dev->priv;
+	ASSERT(irport != NULL, return;);
+	self = (struct ircc_cb *) irport->priv;
+	ASSERT(self != NULL, return;);
+
+	/* Check if we should use the SIR interrupt handler */
+	if (self->io.speed < 576000) {
+		irport_interrupt(irq, dev_id, regs);
+		return;
 	}
+	iobase = self->io.fir_base;
 
-	iobase = idev->io.iobase;
-
-	idev->netdev.interrupt = 1;
-
-	serial_out(iobase, UART_MASTER, 0);
+	spin_lock(&self->lock);	
+	dev->interrupt = 1;
 
 	register_bank(iobase, 0);
+	iir = inb(iobase+IRCC_IIR);
 
-	iir = serial_in(iobase, UART_IIR);
-
-	serial_out(iobase, UART_IER, 0);
-
-	DEBUG(ircc_debug, __FUNCTION__ ": iir = 0x%02x\n", iir);
+	/* Disable interrupts */
+	outb(0, iobase+IRCC_IER);
 
-	if (iir & UART_IIR_EOM) {
-	        DEBUG(ircc_debug, __FUNCTION__ ": UART_IIR_EOM\n");
-		if (idev->io.direction == IO_RECV) {
-			ircc_dma_receive_complete(idev, iobase);
-		} else {
-			ircc_dma_xmit_complete(idev, iobase);
-		}
-		ircc_dma_receive(idev);
-	}
+	IRDA_DEBUG(2, __FUNCTION__ "(), iir = 0x%02x\n", iir);
 
-	if (iir & UART_IIR_ACTIVE_FRAME) {
-	        DEBUG(ircc_debug, __FUNCTION__ ": UART_IIR_ACTIVE_FRAME\n");
-		idev->rx_buff.state = INSIDE_FRAME;
-#if 0
-		ircc_dma_receive(idev);
-#endif
-	}
-
-	if (iir & UART_IIR_RAW_MODE) {
-		DEBUG(ircc_debug, __FUNCTION__ ": IIR RAW mode interrupt.\n");
+	if (iir & IRCC_IIR_EOM) {
+		if (self->io.direction == IO_RECV)
+			ircc_dma_receive_complete(self, iobase);
+		else
+			ircc_dma_xmit_complete(self, iobase);
+		
+		ircc_dma_receive(self, iobase);
 	}
 
-	idev->netdev.interrupt = 0;
-
+	/* Enable interrupts again */
 	register_bank(iobase, 0);
-	serial_out(iobase, UART_IER, UART_IER_ACTIVE_FRAME|UART_IER_EOM);
-	serial_out(iobase, UART_MASTER, UART_MASTER_INT_EN);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
-}
-
-/*
- * Function ircc_wait_until_sent (idev)
- *
- *    This function should put the current thread to sleep until all data 
- *    have been sent, so it is safe to change the speed.
- */
-static void ircc_wait_until_sent( struct irda_device *idev)
-{
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, iobase+IRCC_IER);
 
-	/* Just delay 60 ms */
-	current->state = TASK_INTERRUPTIBLE;
-	schedule_timeout(6);
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
+	dev->interrupt = 0;
+	spin_unlock(&self->lock);
 }
 
 /*
- * Function ircc_is_receiving (idev)
+ * Function ircc_is_receiving (self)
  *
  *    Return TRUE is we are currently receiving a frame
  *
  */
-static int ircc_is_receiving( struct irda_device *idev)
+static int ircc_is_receiving(struct ircc_cb *self)
 {
 	int status = FALSE;
 	/* int iobase; */
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
-	ASSERT( idev != NULL, return FALSE;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return FALSE;);
+	ASSERT(self != NULL, return FALSE;);
 
-	DEBUG(ircc_debug, __FUNCTION__ ": dma count = %d\n",
-	      get_dma_residue(idev->io.dma));
+	IRDA_DEBUG(0, __FUNCTION__ ": dma count = %d\n",
+		   get_dma_residue(self->io.dma));
 
-	status = ( idev->rx_buff.state != OUTSIDE_FRAME);
+	status = (self->rx_buff.state != OUTSIDE_FRAME);
 	
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
-
 	return status;
 }
 
 /*
- * Function ircc_net_init (dev)
- *
- *    Initialize network device
- *
- */
-static int ircc_net_init( struct device *dev)
-{
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-
-	/* Setup to be a normal IrDA network device driver */
-	irda_device_setup( dev);
-
-	/* Insert overrides below this line! */
-
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
-	return 0;
-}
-
-
-/*
  * Function ircc_net_open (dev)
  *
  *    Start the device
  *
  */
-static int ircc_net_open( struct device *dev)
+static int ircc_net_open(struct device *dev)
 {
-	struct irda_device *idev;
+	struct irport_cb *irport;
+	struct ircc_cb *self;
 	int iobase;
+
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 	
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
-	
-	ASSERT( dev != NULL, return -1;);
-	idev = (struct irda_device *) dev->priv;
-	
-	ASSERT( idev != NULL, return 0;);
-	ASSERT( idev->magic == IRDA_DEVICE_MAGIC, return 0;);
+	ASSERT(dev != NULL, return -1;);
+	irport = (struct irport_cb *) dev->priv;
+	self = (struct ircc_cb *) irport->priv;
+
+	ASSERT(self != NULL, return 0;);
 	
-	iobase = idev->io.iobase;
+	iobase = self->io.fir_base;
+
+	irport_net_open(dev); /* irport allocates the irq */
 
-	if (request_irq( idev->io.irq, ircc_interrupt, 0, idev->name, 
-			 (void *) idev)) {
-		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)) {
+		irport_net_close(dev);
+
 		return -EAGAIN;
 	}
-		
-	/* Ready to play! */
-	dev->tbusy = 0;
-	dev->interrupt = 0;
-	dev->start = 1;
-
-	/* turn on interrupts */
 	
 	MOD_INC_USE_COUNT;
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
@@ -906,64 +973,108 @@
  */
 static int ircc_net_close(struct device *dev)
 {
-	struct irda_device *idev;
+	struct irport_cb *irport;
+	struct ircc_cb *self;
 	int iobase;
 
-	DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 	
-	/* Stop device */
-	dev->tbusy = 1;
-	dev->start = 0;
-
-	ASSERT( dev != NULL, return -1;);
-	idev = (struct irda_device *) dev->priv;
+	ASSERT(dev != NULL, return -1;);
+	irport = (struct irport_cb *) dev->priv;
+	self = (struct ircc_cb *) irport->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.fir_base;
 
-	disable_dma( idev->io.dma);
+	irport_net_close(dev);
 
-	/* Disable interrupts */
-       
-	free_irq( idev->io.irq, idev);
-	free_dma( idev->io.dma);
+	disable_dma(self->io.dma);
+
+	free_dma(self->io.dma);
 
 	MOD_DEC_USE_COUNT;
 
-	DEBUG( ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
-#ifdef MODULE
+#ifdef CONFIG_APM
+static void ircc_suspend(struct ircc_cb *self)
+{
+	int i = 10;
+
+	MESSAGE("%s, Suspending\n", driver_name);
+
+	if (self->io.suspended)
+		return;
+
+	ircc_net_close(self->netdev);
+
+	self->io.suspended = 1;
+}
+
+static void ircc_wakeup(struct ircc_cb *self)
+{
+	struct device *dev = self->netdev;
+	unsigned long flags;
+
+	if (!self->io.suspended)
+		return;
+
+	save_flags(flags);
+	cli();
+
+	ircc_net_open(self->netdev);
+	
+	restore_flags(flags);
+	MESSAGE("%s, Waking up\n", driver_name);
+}
 
+static int ircc_apmproc(apm_event_t event)
+{
+	static int down = 0;          /* Filter out double events */
+	int i;
+
+	switch (event) {
+	case APM_SYS_SUSPEND:
+	case APM_USER_SUSPEND:
+		if (!down) {			
+			for (i=0; i<4; i++) {
+				if (dev_self[i])
+					ircc_suspend(dev_self[i]);
+			}
+		}
+		down = 1;
+		break;
+	case APM_NORMAL_RESUME:
+	case APM_CRITICAL_RESUME:
+		if (down) {
+			for (i=0; i<4; i++) {
+				if (dev_self[i])
+					ircc_wakeup(dev_self[i]);
+			}
+		}
+		down = 0;
+		break;
+	}
+	return 0;
+}
+#endif /* CONFIG_APM */
+
+#ifdef MODULE
 MODULE_AUTHOR("Thomas Davis <tadavis@jps.net>");
 MODULE_DESCRIPTION("SMC IrCC controller driver");
-MODULE_PARM(ircc_debug,"1i");
 MODULE_PARM(ircc_dma, "1i");
 MODULE_PARM(ircc_irq, "1i");
 
-/*
- * Function init_module (void)
- *
- *    
- *
- */
 int init_module(void)
 {
 	return ircc_init();
 }
 
-/*
- * Function cleanup_module (void)
- *
- *    
- *
- */
 void cleanup_module(void)
 {
 	ircc_cleanup();
 }
 
-#endif
+#endif /* MODULE */

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