patch-2.3.38 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 --recursive --new-file v2.3.37/linux/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.3
+ * Description:   Driver for the SMC Infrared Communications Controller
  * Status:        Experimental.
  * Author:        Thomas Davis (tadavis@jps.net)
  * Created at:    
- * Modified at:   Sat Dec 11 14:38:26 1999
+ * Modified at:   Wed Jan  5 12:38:06 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
+ *     Applicable Models : Fujitsu Lifebook 635t, Sony PCG-505TX
  *
  ********************************************************************/
 
@@ -53,8 +62,8 @@
 
 #define CHIP_IO_EXTENT 8
 
-static unsigned int io[]  = { 0x2e8, 0x140, 0x118, ~0 }; 
-static unsigned int io2[] = { 0x2f8, 0x3e8, 0x2e8, 0};
+static unsigned int io[]  = { 0x2e8, 0x140, 0x118, 0x240 }; 
+static unsigned int io2[] = { 0x2f8, 0x3e8, 0x2e8, 0x3e8 };
 
 static struct ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL};
 
@@ -64,10 +73,11 @@
 static int  ircc_close(struct ircc_cb *self);
 #endif /* MODULE */
 static int  ircc_probe(int iobase, int board_addr);
+static int  ircc_probe_smc(int *ioaddr, int *ioaddr2);
 static int  ircc_dma_receive(struct ircc_cb *self); 
 static int  ircc_dma_receive_complete(struct ircc_cb *self, int iobase);
 static int  ircc_hard_xmit(struct sk_buff *skb, struct net_device *dev);
-static void ircc_dma_write(struct ircc_cb *self, int iobase);
+static void ircc_dma_xmit(struct ircc_cb *self, int iobase);
 static void ircc_change_speed(void *priv, __u32 speed);
 static void ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 static int  ircc_is_receiving(struct ircc_cb *self);
@@ -75,24 +85,13 @@
 static int  ircc_net_open(struct net_device *dev);
 static int  ircc_net_close(struct net_device *dev);
 
-static int ircc_debug=3;
 static int ircc_irq=255;
 static int ircc_dma=255;
 
-static inline void register_bank(int port, int bank)
-{
-        outb(((inb(port+UART_MASTER) & 0xF0) | (bank & 0x07)),
-             port+UART_MASTER);
-}
-
-static inline unsigned int serial_in(int port, int offset)
+static inline void register_bank(int iobase, int bank)
 {
-        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);
 }
 
 /*
@@ -103,9 +102,10 @@
  */
 int __init ircc_init(void)
 {
+	int ioaddr, ioaddr2;
 	int i;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 	for (i=0; (io[i] < 2000) && (i < 4); i++) {
 		int ioaddr = io[i];
 		if (check_region(ioaddr, CHIP_IO_EXTENT))
@@ -113,7 +113,13 @@
 		if (ircc_open(i, io[i], io2[i]) == 0)
 			return 0;
 	}
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
+
+	/* last chance saloon, see what the controller says */
+	if (ircc_probe_smc(&ioaddr, &ioaddr2) == 0) {
+                  if (check_region(ioaddr, CHIP_IO_EXTENT) == 0)
+                          if (ircc_open(0, ioaddr, ioaddr2) == 0)
+                                  return 0; 
+	}
 
 	return -ENODEV;
 }
@@ -129,13 +135,12 @@
 {
 	int i;
 
-	IRDA_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]);
 	}
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 }
 #endif /* MODULE */
 
@@ -152,11 +157,11 @@
 	int config;
 	int ret;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
 	if ((config = ircc_probe(iobase, iobase2)) == -1) {
-	        IRDA_DEBUG(ircc_debug, 
-		      __FUNCTION__ ": addr 0x%04x - no device found!\n", iobase);
+	        IRDA_DEBUG(0, __FUNCTION__ 
+			   "(), addr 0x%04x - no device found!\n", iobase);
 		return -1;
 	}
 	
@@ -165,11 +170,12 @@
 	 */
 	self = kmalloc(sizeof(struct ircc_cb), GFP_KERNEL);
 	if (self == NULL) {
-		printk(KERN_ERR "IrDA: Can't allocate memory for "
-			"IrDA control block!\n");
+		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;
@@ -188,16 +194,16 @@
         self->io.iobase2   = iobase2; /* Used by irport */
         self->io.irq       = config >> 4 & 0x0f;
 	if (ircc_irq < 255) {
-	        MESSAGE("smc_ircc: Overriding IRQ - chip says %d, using %d\n",
-			self->io.irq, ircc_irq);
+	        MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
+			driver_name, self->io.irq, ircc_irq);
 		self->io.irq = ircc_irq;
 	}
         self->io.io_ext    = CHIP_IO_EXTENT;
         self->io.io_ext2   = 8;       /* Used by irport */
         self->io.dma       = config & 0x0f;
 	if (ircc_dma < 255) {
-	        MESSAGE("smc: Overriding DMA - chip says %d, using %d\n",
-			self->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;
 	}
         self->io.fifo_size = 16;
@@ -206,7 +212,7 @@
 	ret = check_region(self->io.iobase, self->io.io_ext);
 	if (ret < 0) { 
 		IRDA_DEBUG(0, __FUNCTION__ ": can't get iobase of 0x%03x\n",
-		       self->io.iobase);
+			   self->io.iobase);
 		/* ircc_cleanup(self->self);  */
 		return -ENODEV;
 	}
@@ -214,17 +220,11 @@
 	request_region(self->io.iobase, self->io.io_ext, driver_name);
 
 	/* Initialize QoS for this device */
-	irda_init_max_qos_capabilies(&self->qos);
+	irda_init_max_qos_capabilies(&irport->qos);
 	
-#if 1
 	/* The only value we must override it the baudrate */
-	self->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 */
-	self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
-		IR_115200;
-#endif
 
 	irport->qos.min_turn_time.bits = 0x07;
 	irda_qos_bits_to_value(&irport->qos);
@@ -235,23 +235,19 @@
 	self->rx_buff.truesize = 4000; 
 	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.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);
+	
+	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;
@@ -260,12 +256,11 @@
 	
 	/* Override the speed change function, since we must control it now */
 	irport->change_speed = &ircc_change_speed;
-	self->netdev->open  = &ircc_net_open;
-	self->netdev->stop = &ircc_net_close;
+	self->netdev->open   = &ircc_net_open;
+	self->netdev->stop   = &ircc_net_close;
 
 	irport_start(self->irport);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
@@ -280,7 +275,7 @@
 {
 	int iobase;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return -1;);
 
@@ -289,18 +284,16 @@
 	irport_close(self->irport);
 
 	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);
 
 	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);
  
 	/* Release the PORT that this driver is using */
-	IRDA_DEBUG(ircc_debug, 
-	       __FUNCTION__ ": releasing 0x%03x\n", self->io.iobase);
+	IRDA_DEBUG(0, __FUNCTION__ "(), releasing 0x%03x\n", self->io.iobase);
 
 	release_region(self->io.iobase, self->io.io_ext);
 
@@ -312,13 +305,67 @@
 
 	kfree(self);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
-
 	return 0;
 }
 #endif /* MODULE */
 
 /*
+ * Function ircc_probe_smc (ioaddr, ioaddr2)
+ *
+ *    Probe the SMC Chip for an IrDA port
+ *
+ */
+static int ircc_probe_smc(int *ioaddr, int *ioaddr2)
+{
+        static int smcreg[] = { 0x3f0, 0x370 };
+	__u8 devid, mode;
+	__u8 conf_reg;
+	int ret = -1;
+	int fir_io;
+        int i;
+	
+	IRDA_DEBUG(0, __FUNCTION__ "()\n");
+
+        for (i = 0; i < 2 && ret == -1; i++) {
+		conf_reg = smcreg[i];
+        
+		/* Enter configuration */
+                outb(0x55, conf_reg);
+                outb(0x55, conf_reg);
+    
+		outb(0x0d, conf_reg);
+		devid = inb(conf_reg+1);
+		IRDA_DEBUG(0, __FUNCTION__ "(), devid=0x%02x\n",devid);
+		
+		/* Check for expected device ID; are there others? */
+		if (devid == 0x29) {    
+			outb(0x0c, conf_reg);
+			mode = inb(conf_reg+1);
+			mode = (mode & 0x38) >> 3;
+
+			/* Value for IR port */
+			if (mode && mode < 4) {
+				/* SIR iobase */
+				outb(0x25, conf_reg);
+				*ioaddr2 = inb(conf_reg+1) << 2;
+
+				/* FIR iobase */
+				outb(0x2b, conf_reg);
+				fir_io = inb(conf_reg+1) << 3;
+				if (fir_io) {
+					ret = 0;
+					*ioaddr = fir_io;
+				}
+			}
+		}
+
+		/* Exit configuration */
+		outb(0xaa, conf_reg);
+        }
+	return ret;
+}
+
+/*
  * Function ircc_probe (iobase, board_addr, irq, dma)
  *
  *    Returns non-negative on success.
@@ -329,14 +376,18 @@
 	int version = 1;
 	int low, high, chip, config, dma, irq;
 	
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
+
+	/* Power on device */
+	outb(inb(iobase+IRCC_MASTER) & ~IRCC_MASTER_POWERDOWN, 
+	     iobase+IRCC_MASTER);
 
 	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);
+	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;
 
@@ -344,13 +395,10 @@
                 IRDA_DEBUG(0, "SMC IrDA Controller found; IrCC version %d.%d, "
 		      "port 0x%04x, dma %d, interrupt %d\n",
                       chip & 0x0f, version, iobase, dma, irq);
-	} else {
+	} else
 		return -1;
-	}
-
-	serial_out(iobase, UART_MASTER, 0);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
+	outb(0, iobase+IRCC_MASTER);
 
 	return config;
 }
@@ -367,7 +415,7 @@
 	struct ircc_cb *self = (struct ircc_cb *) priv;
 	struct net_device *dev;
 
-	IRDA_DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return;);
 
@@ -380,16 +428,16 @@
 	switch (speed) {
 	case 9600:
 	case 19200:
-	case 37600:
+	case 38400:
 	case 57600:
 	case 115200:
-	        IRDA_DEBUG(ircc_debug+1, 
-		      __FUNCTION__ ": using irport to change speed to %d\n",
-		      speed);
+	        IRDA_DEBUG(0, __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);
+		outb(0, iobase+IRCC_IER);
+		outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER);
+		outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER);
 
 		dev->hard_start_xmit = &irport_hard_xmit;
 
@@ -400,27 +448,23 @@
 		irport_change_speed(self->irport, speed);
 		return;
 		break;
-
 	case 576000:		
-		ir_mode = UART_CFGA_IRDA_HDLC;
+		ir_mode = IRCC_CFGA_IRDA_HDLC;
 		select = 0;
 		fast = 0;
-		IRDA_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;
+		select = IRCC_1152;
 		fast = 0;
-		IRDA_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;
+		ir_mode = IRCC_CFGA_IRDA_4PPM;
 		select = 0;
-		fast = UART_LCR_A_FAST;
-		IRDA_DEBUG(ircc_debug, __FUNCTION__ 
-			   "(), handling baud of 4000000\n");
+		fast = IRCC_LCR_A_FAST;
+		IRDA_DEBUG(0, __FUNCTION__ "(), handling baud of 4000000\n");
 		break;
 	default:
 		IRDA_DEBUG(0, __FUNCTION__ "(), unknown baud rate of %d\n", 
@@ -428,14 +472,10 @@
 		return;
 	}
 
-#if 0
-	serial_out(self->io.iobase2, 4, 0x08);
-#endif
-
-	serial_out(iobase, UART_MASTER, UART_MASTER_RESET);
+	outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER);
 
 	register_bank(iobase, 0);
-	serial_out(iobase, UART_IER, 0);
+	outb(0, iobase+IRCC_IER);
 	
        	irport_stop(self->irport);	
 
@@ -448,27 +488,23 @@
 	dev->tbusy = 0;
 	
 	register_bank(iobase, 1);
+	outb(((inb(iobase+IRCC_SCE_CFGA) & 0x87) | ir_mode), 
+	     iobase+IRCC_SCE_CFGA);
+	
+	outb(((inb(iobase+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_IR), 
+	     iobase+IRCC_SCE_CFGB);
 
-	serial_out(iobase, UART_SCE_CFGA, 
-		   ((serial_in(iobase, UART_SCE_CFGA) & 0x87) | ir_mode));
-
-	serial_out(iobase, UART_SCE_CFGB,
-		   ((serial_in(iobase, UART_SCE_CFGB) & 0x3f) | UART_CFGB_IR));
-
-	(void) serial_in(iobase, UART_FIFO_THRESHOLD);
-	serial_out(iobase, UART_FIFO_THRESHOLD, 64);
+	(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) | select | IRCC_CRC, 
+	     iobase+IRCC_CONTROL);
 
 	register_bank(iobase, 0);
 
-	serial_out(iobase, UART_LCR_A, fast);
-
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
+	outb(fast, iobase+IRCC_LCR_A);
 }
 
 /*
@@ -485,7 +521,6 @@
 	int mtt;
 	__u32 speed;
 
-	IRDA_DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
 	irport = (struct irport_cb *) dev->priv;
 	self = (struct ircc_cb *) irport->priv;
 
@@ -493,15 +528,13 @@
 
 	iobase = self->io.iobase;
 
-	IRDA_DEBUG(ircc_debug+1, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies,
+	IRDA_DEBUG(2, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies,
 		   (int) skb->len);
 
 	/* Check if we need to change the speed */
 	if ((speed = irda_get_speed(skb)) != self->io.speed)
 		self->new_speed = speed;
 	
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": using dma; len=%d\n", skb->len);
-
 	/* Lock transmit buffer */
 	if (irda_lock((void *) &dev->tbusy) == FALSE)
 		return -EBUSY;
@@ -514,21 +547,15 @@
 
 	self->tx_buff.len = skb->len;
 	self->tx_buff.data = self->tx_buff.head;
-#if 0
-	self->tx_buff.offset = 0;
-#endif
-	
-	mtt = irda_get_mtt(skb);
 	
-	/* Use udelay for delays less than 50 us. */
+	mtt = irda_get_mtt(skb);	
 	if (mtt)
 		udelay(mtt);
 	
-	ircc_dma_write(self, iobase);
+	ircc_dma_xmit(self, iobase);
 	
 	dev_kfree_skb(skb);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
@@ -538,48 +565,44 @@
  *    Transmit data using DMA
  *
  */
-static void ircc_dma_write(struct ircc_cb *self, int iobase)
+static void ircc_dma_xmit(struct ircc_cb *self, int iobase)
 {
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return;);
 
 	iobase = self->io.iobase;
 
 	setup_dma(self->io.dma, self->tx_buff.data, self->tx_buff.len, 
-		   DMA_MODE_WRITE);
+		  DMA_TX_MODE);
 	
 	self->io.direction = IO_XMIT;
 
-	serial_out(self->io.iobase2, 4, 0x08);
-
+	outb(0x08, self->io.iobase2+4);
+	
 	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);
+	outb((inb(iobase+IRCC_CONTROL) & 0xf0), iobase+IRCC_CONTROL);
+	
+	outb(2, iobase+IRCC_BOF_COUNT_LO);
+	outb(0, iobase+IRCC_BRICKWALL_CNT_LO);
 #if 1
-	serial_out(iobase, UART_BRICKWALL_TX_CNT_HI, self->tx_buff.len >> 8);
-	serial_out(iobase, UART_TX_SIZE_LO, self->tx_buff.len & 0xff);
+	outb(self->tx_buff.len >> 8, iobase+IRCC_BRICKWALL_TX_CNT_HI);
+	outb(self->tx_buff.len & 0xff, iobase+IRCC_TX_SIZE_LO);
 #else
-	serial_out(iobase, UART_BRICKWALL_TX_CNT_HI, 0);
-	serial_out(iobase, UART_TX_SIZE_LO, 0);
+	outb(0, iobase+IRCC_BRICKWALL_TX_CNT_HI);
+	outb(0, iobase+IRCC_TX_SIZE_LO);
 #endif
 
 	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,
+	     iobase+IRCC_SCE_CFGB);
 
 	register_bank(iobase, 0);
 
-	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);
+	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase+IRCC_IER);
+	outb(IRCC_LCR_B_SCE_TRANSMIT|IRCC_LCR_B_SIP_ENABLE, iobase+IRCC_LCR_B);
 
-	serial_out(iobase, UART_MASTER, UART_MASTER_INT_EN);
-
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
+	outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER);
 }
 
 /*
@@ -593,20 +616,20 @@
 {
 	int iobase, d;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return;);
 
 	register_bank(self->io.iobase, 1);
 
-	serial_out(self->io.iobase, UART_SCE_CFGB,
-		   serial_in(self->io.iobase, UART_SCE_CFGB) &
-		   ~UART_CFGB_DMA_ENABLE);
+	outb(inb(self->io.iobase+IRCC_SCE_CFGB) & IRCC_CFGB_DMA_ENABLE,
+	     self->io.iobase+IRCC_SCE_CFGB);
 
 	d = get_dma_residue(self->io.dma);
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": dma residue = %d, len=%d, sent=%d\n", 
-	      d, self->tx_buff.len, self->tx_buff.len - d);
+	IRDA_DEBUG(0, __FUNCTION__ 
+		   ": dma residue = %d, len=%d, sent=%d\n", 
+		   d, self->tx_buff.len, self->tx_buff.len - d);
 
 	iobase = self->io.iobase;
 
@@ -630,8 +653,6 @@
 	
 	/* Tell the network layer, that we can accept more frames */
 	mark_bh(NET_BH);
-
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 }
 
 /*
@@ -645,14 +666,14 @@
 {
 	int iobase;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return -1;);
 
 	iobase= self->io.iobase;
 
 	setup_dma(self->io.dma, self->rx_buff.data, self->rx_buff.truesize, 
-		   DMA_MODE_READ);
+		   DMA_RX_MODE);
 	
 	/* driver->media_busy = FALSE; */
 	self->io.direction = IO_RECV;
@@ -662,25 +683,22 @@
 #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);
+	outb(inb(iobase+IRCC_CONTROL) & 0xf0, iobase+IRCC_CONTROL);
+	outb(2, iobase+IRCC_BOF_COUNT_LO);
+	outb(0, iobase+IRCC_BRICKWALL_CNT_LO);
+	outb(0, iobase+IRCC_BRICKWALL_TX_CNT_HI);
+	outb(0, iobase+IRCC_TX_SIZE_LO);
+	outb(0, iobase+IRCC_RX_SIZE_HI);
+	outb(0, iobase+IRCC_RX_SIZE_LO);
 
 	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);
 	
 	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);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
@@ -696,22 +714,20 @@
 	struct sk_buff *skb;
 	int len, msgcnt;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(2, __FUNCTION__ "\n");
 
-	msgcnt = serial_in(self->io.iobase, UART_LCR_B) & 0x08;
+	msgcnt = inb(self->io.iobase+IRCC_LCR_B) & 0x08;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": dma count = %d\n",
-	      get_dma_residue(self->io.dma));
+	IRDA_DEBUG(0, __FUNCTION__ ": dma count = %d\n",
+		   get_dma_residue(self->io.dma));
 
 	len = self->rx_buff.truesize - get_dma_residue(self->io.dma) - 4;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": msgcnt = %d, len=%d\n", msgcnt, len);
+	IRDA_DEBUG(0, __FUNCTION__ ": msgcnt = %d, len=%d\n", msgcnt, len);
 
 	skb = dev_alloc_skb(len+1);
-
-	if (skb == NULL)  {
-		printk(KERN_INFO __FUNCTION__ 
-			": memory squeeze, dropping frame.\n");
+	if (!skb)  {
+		WARNING(__FUNCTION__ "(), memory squeeze, dropping frame.\n");
 		return FALSE;
 	}
 			
@@ -728,11 +744,9 @@
 	netif_rx(skb);
 
 	register_bank(self->io.iobase, 1);
-	serial_out(self->io.iobase, UART_SCE_CFGB,
-		   serial_in(self->io.iobase, UART_SCE_CFGB) &
-		   ~UART_CFGB_DMA_ENABLE);
+	outb(inb(self->io.iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 
+	     self->io.iobase+IRCC_SCE_CFGB);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return TRUE;
 }
 
@@ -748,11 +762,9 @@
 	struct net_device *dev = (struct net_device *) dev_id;
 	struct ircc_cb *self;
 
-	IRDA_DEBUG(ircc_debug+1, __FUNCTION__ " -->\n");
-
 	if (dev == NULL) {
 		printk(KERN_WARNING "%s: irq %d for unknown device.\n", 
-			driver_name, irq);
+		       driver_name, irq);
 		return;
 	}
 	
@@ -762,45 +774,42 @@
 
 	dev->interrupt = 1;
 
-	serial_out(iobase, UART_MASTER, 0);
+	outb(0, iobase+IRCC_MASTER);
 
 	register_bank(iobase, 0);
+	iir = inb(iobase+IRCC_IIR);
 
-	iir = serial_in(iobase, UART_IIR);
+	/* Disable interrupts */
+	outb(0, iobase+IRCC_IER);
 
-	serial_out(iobase, UART_IER, 0);
+	IRDA_DEBUG(0, __FUNCTION__ "(), iir = 0x%02x\n", iir);
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": iir = 0x%02x\n", iir);
+	if (iir & IRCC_IIR_EOM) {
+	        IRDA_DEBUG(0, __FUNCTION__ "(), IRCC_IIR_EOM\n");
 
-	if (iir & UART_IIR_EOM) {
-	        IRDA_DEBUG(ircc_debug, __FUNCTION__ ": UART_IIR_EOM\n");
-		if (self->io.direction == IO_RECV) {
+		if (self->io.direction == IO_RECV)
 			ircc_dma_receive_complete(self, iobase);
-		} else {
+		else
 			ircc_dma_xmit_complete(self, iobase);
-		}
+		
 		ircc_dma_receive(self);
 	}
-
-	if (iir & UART_IIR_ACTIVE_FRAME) {
-	        IRDA_DEBUG(ircc_debug, __FUNCTION__ ": UART_IIR_ACTIVE_FRAME\n");
+	if (iir & IRCC_IIR_ACTIVE_FRAME) {
+	        IRDA_DEBUG(0, __FUNCTION__ "(), IRCC_IIR_ACTIVE_FRAME\n");
 		self->rx_buff.state = INSIDE_FRAME;
 #if 0
 		ircc_dma_receive(self);
 #endif
 	}
-
-	if (iir & UART_IIR_RAW_MODE) {
-		IRDA_DEBUG(ircc_debug, __FUNCTION__ ": IIR RAW mode interrupt.\n");
+	if (iir & IRCC_IIR_RAW_MODE) {
+		IRDA_DEBUG(0, __FUNCTION__ "(), IIR RAW mode interrupt.\n");
 	}
 
-	dev->interrupt = 0;
-
 	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);
+	outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, iobase+IRCC_IER);
+	outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER);
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
+	dev->interrupt = 0;
 }
 
 /*
@@ -814,17 +823,15 @@
 	int status = FALSE;
 	/* int iobase; */
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 
 	ASSERT(self != NULL, return FALSE;);
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ ": dma count = %d\n",
-	      get_dma_residue(self->io.dma));
+	IRDA_DEBUG(0, __FUNCTION__ ": dma count = %d\n",
+		   get_dma_residue(self->io.dma));
 
 	status = (self->rx_buff.state != OUTSIDE_FRAME);
 	
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
-
 	return status;
 }
 
@@ -840,7 +847,7 @@
 	struct ircc_cb *self;
 	int iobase;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 	
 	ASSERT(dev != NULL, return -1;);
 	irport = (struct irport_cb *) dev->priv;
@@ -850,20 +857,20 @@
 	
 	iobase = self->io.iobase;
 
-	irport_net_open(dev);
+	irport_net_open(dev); /* irport allocates the irq */
 
 	/*
 	 * Always allocate the DMA channel after the IRQ,
 	 * and clean up on failure.
 	 */
 	if (request_dma(self->io.dma, dev->name)) {
-		free_irq(self->io.irq, dev);
+		irport_net_close(dev);
+
 		return -EAGAIN;
 	}
 	
 	MOD_INC_USE_COUNT;
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
@@ -879,7 +886,7 @@
 	struct ircc_cb *self;
 	int iobase;
 
-	IRDA_DEBUG(ircc_debug, __FUNCTION__ " -->\n");
+	IRDA_DEBUG(0, __FUNCTION__ "\n");
 	
 	ASSERT(dev != NULL, return -1;);
 	irport = (struct irport_cb *) dev->priv;
@@ -897,15 +904,12 @@
 
 	MOD_DEC_USE_COUNT;
 
-	IRDA_DEBUG(ircc_debug, "--> " __FUNCTION__ "\n");
 	return 0;
 }
 
 #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");
 
@@ -919,4 +923,4 @@
 	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)