1 /*********************************************************************
 
   5  * Description:   Driver for the ALI M1535D and M1543C FIR Controller
 
   6  * Status:        Experimental.
 
   7  * Author:        Benjamin Kong <benjamin_kong@ali.com.tw>
 
   8  * Created at:    2000/10/16 03:46PM
 
   9  * Modified at:   2001/1/3 02:55PM
 
  10  * Modified by:   Benjamin Kong <benjamin_kong@ali.com.tw>
 
  11  * Modified at:   2003/11/6 and support for ALi south-bridge chipsets M1563
 
  12  * Modified by:   Clear Zhang <clear_zhang@ali.com.tw>
 
  14  *     Copyright (c) 2000 Benjamin Kong <benjamin_kong@ali.com.tw>
 
  17  *     This program is free software; you can redistribute it and/or 
 
  18  *     modify it under the terms of the GNU General Public License as 
 
  19  *     published by the Free Software Foundation; either version 2 of 
 
  20  *     the License, or (at your option) any later version.
 
  22  ********************************************************************/
 
  24 #include <linux/module.h>
 
  26 #include <linux/kernel.h>
 
  27 #include <linux/types.h>
 
  28 #include <linux/skbuff.h>
 
  29 #include <linux/netdevice.h>
 
  30 #include <linux/ioport.h>
 
  31 #include <linux/delay.h>
 
  32 #include <linux/slab.h>
 
  33 #include <linux/init.h>
 
  34 #include <linux/rtnetlink.h>
 
  35 #include <linux/serial_reg.h>
 
  36 #include <linux/dma-mapping.h>
 
  40 #include <asm/byteorder.h>
 
  43 #include <linux/pm_legacy.h>
 
  45 #include <net/irda/wrapper.h>
 
  46 #include <net/irda/irda.h>
 
  47 #include <net/irda/irda_device.h>
 
  51 #define CHIP_IO_EXTENT 8
 
  52 #define BROKEN_DONGLE_ID
 
  54 static char *driver_name = "ali-ircc";
 
  56 /* Module parameters */
 
  57 static int qos_mtt_bits = 0x07;  /* 1 ms or more */
 
  59 /* Use BIOS settions by default, but user may supply module parameters */
 
  60 static unsigned int io[]  = { ~0, ~0, ~0, ~0 };
 
  61 static unsigned int irq[] = { 0, 0, 0, 0 };
 
  62 static unsigned int dma[] = { 0, 0, 0, 0 };
 
  64 static int  ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info);
 
  65 static int  ali_ircc_init_43(ali_chip_t *chip, chipio_t *info);
 
  66 static int  ali_ircc_init_53(ali_chip_t *chip, chipio_t *info);
 
  68 /* These are the currently known ALi sourth-bridge chipsets, the only one difference
 
  69  * is that M1543C doesn't support HP HDSL-3600
 
  71 static ali_chip_t chips[] =
 
  73         { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53, ali_ircc_init_43 },
 
  74         { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53, ali_ircc_init_53 },
 
  75         { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53, ali_ircc_init_53 },
 
  79 /* Max 4 instances for now */
 
  80 static struct ali_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
 
  83 static char *dongle_types[] = {
 
  87         "No dongle connected",
 
  91 static int  ali_ircc_open(int i, chipio_t *info);
 
  93 static int  ali_ircc_close(struct ali_ircc_cb *self);
 
  95 static int  ali_ircc_setup(chipio_t *info);
 
  96 static int  ali_ircc_is_receiving(struct ali_ircc_cb *self);
 
  97 static int  ali_ircc_net_open(struct net_device *dev);
 
  98 static int  ali_ircc_net_close(struct net_device *dev);
 
  99 static int  ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 
 100 static int  ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
 
 101 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
 
 102 static void ali_ircc_suspend(struct ali_ircc_cb *self);
 
 103 static void ali_ircc_wakeup(struct ali_ircc_cb *self);
 
 104 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev);
 
 107 static int  ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
 
 108 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self);
 
 109 static void ali_ircc_sir_receive(struct ali_ircc_cb *self);
 
 110 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self);
 
 111 static int  ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
 
 112 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
 
 115 static int  ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
 
 116 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
 
 117 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self);
 
 118 static int  ali_ircc_dma_receive(struct ali_ircc_cb *self); 
 
 119 static int  ali_ircc_dma_receive_complete(struct ali_ircc_cb *self);
 
 120 static int  ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self);
 
 121 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self);
 
 124 static int  ali_ircc_read_dongle_id (int i, chipio_t *info);
 
 125 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed);
 
 127 /* ALi chip function */
 
 128 static void SIR2FIR(int iobase);
 
 129 static void FIR2SIR(int iobase);
 
 130 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable);
 
 133  * Function ali_ircc_init ()
 
 135  *    Initialize chip. Find out whay kinds of chips we are dealing with
 
 136  *    and their configuation registers address
 
 138 static int __init ali_ircc_init(void)
 
 147         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 149         /* Probe for all the ALi chipsets we know about */
 
 150         for (chip= chips; chip->name; chip++, i++) 
 
 152                 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__, chip->name);
 
 154                 /* Try all config registers for this chip */
 
 155                 for (cfg=0; cfg<2; cfg++)
 
 157                         cfg_base = chip->cfg[cfg];
 
 161                         memset(&info, 0, sizeof(chipio_t));
 
 162                         info.cfg_base = cfg_base;
 
 163                         info.fir_base = io[i];
 
 168                         /* Enter Configuration */
 
 169                         outb(chip->entr1, cfg_base);
 
 170                         outb(chip->entr2, cfg_base);
 
 172                         /* Select Logical Device 5 Registers (UART2) */
 
 173                         outb(0x07, cfg_base);
 
 174                         outb(0x05, cfg_base+1);
 
 176                         /* Read Chip Identification Register */
 
 177                         outb(chip->cid_index, cfg_base);        
 
 178                         reg = inb(cfg_base+1);  
 
 180                         if (reg == chip->cid_value)
 
 182                                 IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __FUNCTION__, cfg_base);
 
 184                                 outb(0x1F, cfg_base);
 
 185                                 revision = inb(cfg_base+1);
 
 186                                 IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __FUNCTION__,
 
 187                                            chip->name, revision);                                       
 
 190                                  * If the user supplies the base address, then
 
 191                                  * we init the chip, if not we probe the values
 
 196                                         chip->init(chip, &info);
 
 200                                         chip->probe(chip, &info);       
 
 203                                 if (ali_ircc_open(i, &info) == 0)
 
 209                                 IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __FUNCTION__, chip->name, cfg_base);
 
 211                         /* Exit configuration */
 
 212                         outb(0xbb, cfg_base);
 
 216         IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);                                                 
 
 221  * Function ali_ircc_cleanup ()
 
 223  *    Close all configured chips
 
 226 static void __exit ali_ircc_cleanup(void)
 
 230         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 
 
 232         pm_unregister_all(ali_ircc_pmproc);
 
 234         for (i=0; i < 4; i++) {
 
 236                         ali_ircc_close(dev_self[i]);
 
 239         IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
 
 243  * Function ali_ircc_open (int i, chipio_t *inf)
 
 245  *    Open driver instance
 
 248 static int ali_ircc_open(int i, chipio_t *info)
 
 250         struct net_device *dev;
 
 251         struct ali_ircc_cb *self;
 
 252         struct pm_dev *pmdev;
 
 256         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 
 
 258         /* Set FIR FIFO and DMA Threshold */
 
 259         if ((ali_ircc_setup(info)) == -1)
 
 262         dev = alloc_irdadev(sizeof(*self));
 
 264                 IRDA_ERROR("%s(), can't allocate memory for control block!\n",
 
 271         spin_lock_init(&self->lock);
 
 273         /* Need to store self somewhere */
 
 278         self->io.cfg_base  = info->cfg_base;    /* In ali_ircc_probe_53 assign          */
 
 279         self->io.fir_base  = info->fir_base;    /* info->sir_base = info->fir_base      */
 
 280         self->io.sir_base  = info->sir_base;    /* ALi SIR and FIR use the same address */
 
 281         self->io.irq       = info->irq;
 
 282         self->io.fir_ext   = CHIP_IO_EXTENT;
 
 283         self->io.dma       = info->dma;
 
 284         self->io.fifo_size = 16;                /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
 
 286         /* Reserve the ioports that we need */
 
 287         if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) {
 
 288                 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
 
 294         /* Initialize QoS for this device */
 
 295         irda_init_max_qos_capabilies(&self->qos);
 
 297         /* The only value we must override it the baudrate */
 
 298         self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
 
 299                 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); // benjamin 2000/11/8 05:27PM
 
 301         self->qos.min_turn_time.bits = qos_mtt_bits;
 
 303         irda_qos_bits_to_value(&self->qos);
 
 305         /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
 
 306         self->rx_buff.truesize = 14384; 
 
 307         self->tx_buff.truesize = 14384;
 
 309         /* Allocate memory if needed */
 
 311                 dma_alloc_coherent(NULL, self->rx_buff.truesize,
 
 312                                    &self->rx_buff_dma, GFP_KERNEL);
 
 313         if (self->rx_buff.head == NULL) {
 
 317         memset(self->rx_buff.head, 0, self->rx_buff.truesize);
 
 320                 dma_alloc_coherent(NULL, self->tx_buff.truesize,
 
 321                                    &self->tx_buff_dma, GFP_KERNEL);
 
 322         if (self->tx_buff.head == NULL) {
 
 326         memset(self->tx_buff.head, 0, self->tx_buff.truesize);
 
 328         self->rx_buff.in_frame = FALSE;
 
 329         self->rx_buff.state = OUTSIDE_FRAME;
 
 330         self->tx_buff.data = self->tx_buff.head;
 
 331         self->rx_buff.data = self->rx_buff.head;
 
 333         /* Reset Tx queue info */
 
 334         self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
 
 335         self->tx_fifo.tail = self->tx_buff.head;
 
 338         /* Keep track of module usage */
 
 339         SET_MODULE_OWNER(dev);
 
 341         /* Override the network functions we need to use */
 
 342         dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
 
 343         dev->open            = ali_ircc_net_open;
 
 344         dev->stop            = ali_ircc_net_close;
 
 345         dev->do_ioctl        = ali_ircc_net_ioctl;
 
 346         dev->get_stats       = ali_ircc_net_get_stats;
 
 348         err = register_netdev(dev);
 
 350                 IRDA_ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
 
 353         IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
 
 355         /* Check dongle id */
 
 356         dongle_id = ali_ircc_read_dongle_id(i, info);
 
 357         IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]);
 
 359         self->io.dongle_id = dongle_id;
 
 361         pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, ali_ircc_pmproc);
 
 365         IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
 
 370         dma_free_coherent(NULL, self->tx_buff.truesize,
 
 371                           self->tx_buff.head, self->tx_buff_dma);
 
 373         dma_free_coherent(NULL, self->rx_buff.truesize,
 
 374                           self->rx_buff.head, self->rx_buff_dma);
 
 376         release_region(self->io.fir_base, self->io.fir_ext);
 
 385  * Function ali_ircc_close (self)
 
 387  *    Close driver instance
 
 390 static int __exit ali_ircc_close(struct ali_ircc_cb *self)
 
 394         IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 396         IRDA_ASSERT(self != NULL, return -1;);
 
 398         iobase = self->io.fir_base;
 
 400         /* Remove netdevice */
 
 401         unregister_netdev(self->netdev);
 
 403         /* Release the PORT that this driver is using */
 
 404         IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __FUNCTION__, self->io.fir_base);
 
 405         release_region(self->io.fir_base, self->io.fir_ext);
 
 407         if (self->tx_buff.head)
 
 408                 dma_free_coherent(NULL, self->tx_buff.truesize,
 
 409                                   self->tx_buff.head, self->tx_buff_dma);
 
 411         if (self->rx_buff.head)
 
 412                 dma_free_coherent(NULL, self->rx_buff.truesize,
 
 413                                   self->rx_buff.head, self->rx_buff_dma);
 
 415         dev_self[self->index] = NULL;
 
 416         free_netdev(self->netdev);
 
 418         IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
 
 424  * Function ali_ircc_init_43 (chip, info)
 
 426  *    Initialize the ALi M1543 chip. 
 
 428 static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info) 
 
 430         /* All controller information like I/O address, DMA channel, IRQ
 
 438  * Function ali_ircc_init_53 (chip, info)
 
 440  *    Initialize the ALi M1535 chip. 
 
 442 static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info) 
 
 444         /* All controller information like I/O address, DMA channel, IRQ
 
 452  * Function ali_ircc_probe_53 (chip, info)
 
 454  *      Probes for the ALi M1535D or M1535
 
 456 static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info)
 
 458         int cfg_base = info->cfg_base;
 
 461         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 463         /* Enter Configuration */
 
 464         outb(chip->entr1, cfg_base);
 
 465         outb(chip->entr2, cfg_base);
 
 467         /* Select Logical Device 5 Registers (UART2) */
 
 468         outb(0x07, cfg_base);
 
 469         outb(0x05, cfg_base+1);
 
 471         /* Read address control register */
 
 472         outb(0x60, cfg_base);
 
 473         hi = inb(cfg_base+1);   
 
 474         outb(0x61, cfg_base);
 
 475         low = inb(cfg_base+1);
 
 476         info->fir_base = (hi<<8) + low;
 
 478         info->sir_base = info->fir_base;
 
 480         IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __FUNCTION__, info->fir_base);
 
 482         /* Read IRQ control register */
 
 483         outb(0x70, cfg_base);
 
 484         reg = inb(cfg_base+1);
 
 485         info->irq = reg & 0x0f;
 
 486         IRDA_DEBUG(2, "%s(), probing irq=%d\n", __FUNCTION__, info->irq);
 
 488         /* Read DMA channel */
 
 489         outb(0x74, cfg_base);
 
 490         reg = inb(cfg_base+1);
 
 491         info->dma = reg & 0x07;
 
 493         if(info->dma == 0x04)
 
 494                 IRDA_WARNING("%s(), No DMA channel assigned !\n", __FUNCTION__);
 
 496                 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __FUNCTION__, info->dma);
 
 498         /* Read Enabled Status */
 
 499         outb(0x30, cfg_base);
 
 500         reg = inb(cfg_base+1);
 
 501         info->enabled = (reg & 0x80) && (reg & 0x01);
 
 502         IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __FUNCTION__, info->enabled);
 
 504         /* Read Power Status */
 
 505         outb(0x22, cfg_base);
 
 506         reg = inb(cfg_base+1);
 
 507         info->suspended = (reg & 0x20);
 
 508         IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __FUNCTION__, info->suspended);
 
 510         /* Exit configuration */
 
 511         outb(0xbb, cfg_base);
 
 513         IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 
 
 519  * Function ali_ircc_setup (info)
 
 521  *      Set FIR FIFO and DMA Threshold
 
 522  *      Returns non-negative on success.
 
 525 static int ali_ircc_setup(chipio_t *info)
 
 529         int iobase = info->fir_base;
 
 531         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 533         /* Locking comments :
 
 534          * Most operations here need to be protected. We are called before
 
 535          * the device instance is created in ali_ircc_open(), therefore 
 
 536          * nobody can bother us - Jean II */
 
 538         /* Switch to FIR space */
 
 542         outb(0x40, iobase+FIR_MCR); // benjamin 2000/11/30 11:45AM
 
 544         /* Read FIR ID Version Register */
 
 545         switch_bank(iobase, BANK3);
 
 546         version = inb(iobase+FIR_ID_VR);
 
 548         /* Should be 0x00 in the M1535/M1535D */
 
 551                 IRDA_ERROR("%s, Wrong chip version %02x\n", driver_name, version);
 
 555         // IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
 
 557         /* Set FIR FIFO Threshold Register */
 
 558         switch_bank(iobase, BANK1);
 
 559         outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
 
 561         /* Set FIR DMA Threshold Register */
 
 562         outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
 
 565         switch_bank(iobase, BANK2);
 
 566         outb(inb(iobase+FIR_IRDA_CR) | IRDA_CR_CRC, iobase+FIR_IRDA_CR);
 
 568         /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
 
 570         /* Switch to Bank 0 */
 
 571         switch_bank(iobase, BANK0);
 
 573         tmp = inb(iobase+FIR_LCR_B);
 
 574         tmp &=~0x20; // disable SIP
 
 575         tmp |= 0x80; // these two steps make RX mode
 
 577         outb(tmp, iobase+FIR_LCR_B);
 
 579         /* Disable Interrupt */
 
 580         outb(0x00, iobase+FIR_IER);
 
 583         /* Switch to SIR space */
 
 586         IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name);
 
 588         /* Enable receive interrupts */ 
 
 589         // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
 
 590         // Turn on the interrupts in ali_ircc_net_open
 
 592         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);        
 
 598  * Function ali_ircc_read_dongle_id (int index, info)
 
 600  * Try to read dongle indentification. This procedure needs to be executed
 
 601  * once after power-on/reset. It also needs to be used whenever you suspect
 
 602  * that the user may have plugged/unplugged the IrDA Dongle.
 
 604 static int ali_ircc_read_dongle_id (int i, chipio_t *info)
 
 607         int cfg_base = info->cfg_base;
 
 609         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 611         /* Enter Configuration */
 
 612         outb(chips[i].entr1, cfg_base);
 
 613         outb(chips[i].entr2, cfg_base);
 
 615         /* Select Logical Device 5 Registers (UART2) */
 
 616         outb(0x07, cfg_base);
 
 617         outb(0x05, cfg_base+1);
 
 620         outb(0xf0, cfg_base);
 
 621         reg = inb(cfg_base+1);  
 
 622         dongle_id = ((reg>>6)&0x02) | ((reg>>5)&0x01);
 
 623         IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __FUNCTION__, 
 
 624                 dongle_id, dongle_types[dongle_id]);
 
 626         /* Exit configuration */
 
 627         outb(0xbb, cfg_base);
 
 629         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);        
 
 635  * Function ali_ircc_interrupt (irq, dev_id, regs)
 
 637  *    An interrupt from the chip has arrived. Time to do some work
 
 640 static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id,
 
 641                                         struct pt_regs *regs)
 
 643         struct net_device *dev = (struct net_device *) dev_id;
 
 644         struct ali_ircc_cb *self;
 
 647         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 650                 IRDA_WARNING("%s: irq %d for unknown device.\n", driver_name, irq);
 
 654         self = (struct ali_ircc_cb *) dev->priv;
 
 656         spin_lock(&self->lock);
 
 658         /* Dispatch interrupt handler for the current speed */
 
 659         if (self->io.speed > 115200)
 
 660                 ret = ali_ircc_fir_interrupt(self);
 
 662                 ret = ali_ircc_sir_interrupt(self);
 
 664         spin_unlock(&self->lock);
 
 666         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
 
 670  * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
 
 672  *    Handle MIR/FIR interrupt
 
 675 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self)
 
 677         __u8 eir, OldMessageCount;
 
 680         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 682         iobase = self->io.fir_base;
 
 684         switch_bank(iobase, BANK0);     
 
 685         self->InterruptID = inb(iobase+FIR_IIR);                
 
 686         self->BusStatus = inb(iobase+FIR_BSR);  
 
 688         OldMessageCount = (self->LineStatus + 1) & 0x07;
 
 689         self->LineStatus = inb(iobase+FIR_LSR); 
 
 690         //self->ier = inb(iobase+FIR_IER);              2000/12/1 04:32PM
 
 691         eir = self->InterruptID & self->ier; /* Mask out the interesting ones */ 
 
 693         IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __FUNCTION__,self->InterruptID);
 
 694         IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __FUNCTION__,self->LineStatus);
 
 695         IRDA_DEBUG(1, "%s(), self->ier = %x\n", __FUNCTION__,self->ier);
 
 696         IRDA_DEBUG(1, "%s(), eir = %x\n", __FUNCTION__,eir);
 
 698         /* Disable interrupts */
 
 699          SetCOMInterrupts(self, FALSE);
 
 701         /* Tx or Rx Interrupt */
 
 705                 if (self->io.direction == IO_XMIT) /* TX */
 
 707                         IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __FUNCTION__);
 
 709                         if(ali_ircc_dma_xmit_complete(self))
 
 711                                 if (irda_device_txqueue_empty(self->netdev)) 
 
 713                                         /* Prepare for receive */
 
 714                                         ali_ircc_dma_receive(self);                                     
 
 726                         IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __FUNCTION__);
 
 728                         if(OldMessageCount > ((self->LineStatus+1) & 0x07))
 
 730                                 self->rcvFramesOverflow = TRUE; 
 
 731                                 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******** \n", __FUNCTION__);
 
 734                         if (ali_ircc_dma_receive_complete(self))
 
 736                                 IRDA_DEBUG(1, "%s(), ******* receive complete ******** \n", __FUNCTION__);
 
 742                                 IRDA_DEBUG(1, "%s(), ******* Not receive complete ******** \n", __FUNCTION__);
 
 744                                 self->ier = IER_EOM | IER_TIMER;                                                                
 
 749         /* Timer Interrupt */
 
 750         else if (eir & IIR_TIMER)
 
 752                 if(OldMessageCount > ((self->LineStatus+1) & 0x07))
 
 754                         self->rcvFramesOverflow = TRUE; 
 
 755                         IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******* \n", __FUNCTION__);
 
 758                 switch_bank(iobase, BANK1);
 
 759                 tmp = inb(iobase+FIR_CR);
 
 760                 outb( tmp& ~CR_TIMER_EN, iobase+FIR_CR);
 
 762                 /* Check if this is a Tx timer interrupt */
 
 763                 if (self->io.direction == IO_XMIT)
 
 765                         ali_ircc_dma_xmit(self);
 
 767                         /* Interrupt on EOM */
 
 773                         if(ali_ircc_dma_receive_complete(self)) 
 
 779                                 self->ier = IER_EOM | IER_TIMER;
 
 784         /* Restore Interrupt */ 
 
 785         SetCOMInterrupts(self, TRUE);   
 
 787         IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __FUNCTION__);
 
 788         return IRQ_RETVAL(eir);
 
 792  * Function ali_ircc_sir_interrupt (irq, self, eir)
 
 794  *    Handle SIR interrupt
 
 797 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self)
 
 802         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 804         iobase = self->io.sir_base;
 
 806         iir = inb(iobase+UART_IIR) & UART_IIR_ID;
 
 808                 /* Clear interrupt */
 
 809                 lsr = inb(iobase+UART_LSR);
 
 811                 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __FUNCTION__, 
 
 817                                 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
 
 820                                 /* Receive interrupt */
 
 821                                 ali_ircc_sir_receive(self);
 
 824                                 if (lsr & UART_LSR_THRE)
 
 826                                         /* Transmitter ready for data */
 
 827                                         ali_ircc_sir_write_wakeup(self);                                
 
 831                                 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __FUNCTION__, iir);
 
 838         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);        
 
 840         return IRQ_RETVAL(iir);
 
 845  * Function ali_ircc_sir_receive (self)
 
 847  *    Receive one frame from the infrared port
 
 850 static void ali_ircc_sir_receive(struct ali_ircc_cb *self) 
 
 855         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
 856         IRDA_ASSERT(self != NULL, return;);
 
 858         iobase = self->io.sir_base;
 
 861          * Receive all characters in Rx FIFO, unwrap and unstuff them. 
 
 862          * async_unwrap_char will deliver all found frames  
 
 865                 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff, 
 
 866                                   inb(iobase+UART_RX));
 
 868                 /* Make sure we don't stay here too long */
 
 869                 if (boguscount++ > 32) {
 
 870                         IRDA_DEBUG(2,"%s(), breaking!\n", __FUNCTION__);
 
 873         } while (inb(iobase+UART_LSR) & UART_LSR_DR);   
 
 875         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
 879  * Function ali_ircc_sir_write_wakeup (tty)
 
 881  *    Called by the driver when there's room for more data.  If we have
 
 882  *    more packets to send, we send them here.
 
 885 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self)
 
 890         IRDA_ASSERT(self != NULL, return;);
 
 892         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
 894         iobase = self->io.sir_base;
 
 896         /* Finished with frame?  */
 
 897         if (self->tx_buff.len > 0)  
 
 899                 /* Write data left in transmit buffer */
 
 900                 actual = ali_ircc_sir_write(iobase, self->io.fifo_size, 
 
 901                                       self->tx_buff.data, self->tx_buff.len);
 
 902                 self->tx_buff.data += actual;
 
 903                 self->tx_buff.len  -= actual;
 
 909                         /* We must wait until all data are gone */
 
 910                         while(!(inb(iobase+UART_LSR) & UART_LSR_TEMT))
 
 911                                 IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __FUNCTION__ );
 
 913                         IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __FUNCTION__ , self->new_speed);
 
 914                         ali_ircc_change_speed(self, self->new_speed);
 
 917                         // benjamin 2000/11/10 06:32PM
 
 918                         if (self->io.speed > 115200)
 
 920                                 IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT \n", __FUNCTION__ );                              
 
 923                                 // SetCOMInterrupts(self, TRUE);                                                        
 
 929                         netif_wake_queue(self->netdev); 
 
 932                 self->stats.tx_packets++;
 
 934                 /* Turn on receive interrupts */
 
 935                 outb(UART_IER_RDI, iobase+UART_IER);
 
 938         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
 941 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud)
 
 943         struct net_device *dev = self->netdev;
 
 946         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
 948         IRDA_DEBUG(2, "%s(), setting speed = %d \n", __FUNCTION__ , baud);
 
 950         /* This function *must* be called with irq off and spin-lock.
 
 953         iobase = self->io.fir_base;
 
 955         SetCOMInterrupts(self, FALSE); // 2000/11/24 11:43AM
 
 957         /* Go to MIR, FIR Speed */
 
 962                 ali_ircc_fir_change_speed(self, baud);                  
 
 964                 /* Install FIR xmit handler*/
 
 965                 dev->hard_start_xmit = ali_ircc_fir_hard_xmit;          
 
 967                 /* Enable Interuupt */
 
 968                 self->ier = IER_EOM; // benjamin 2000/11/20 07:24PM                                     
 
 970                 /* Be ready for incomming frames */
 
 971                 ali_ircc_dma_receive(self);     // benajmin 2000/11/8 07:46PM not complete
 
 973         /* Go to SIR Speed */
 
 976                 ali_ircc_sir_change_speed(self, baud);
 
 978                 /* Install SIR xmit handler*/
 
 979                 dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
 
 983         SetCOMInterrupts(self, TRUE);   // 2000/11/24 11:43AM
 
 985         netif_wake_queue(self->netdev); 
 
 987         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
 990 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 baud)
 
 994         struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
 
 995         struct net_device *dev;
 
 997         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
 999         IRDA_ASSERT(self != NULL, return;);
 
1002         iobase = self->io.fir_base;
 
1004         IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __FUNCTION__ ,self->io.speed,baud);
 
1006         /* Come from SIR speed */
 
1007         if(self->io.speed <=115200)
 
1012         /* Update accounting for new speed */
 
1013         self->io.speed = baud;
 
1015         // Set Dongle Speed mode
 
1016         ali_ircc_change_dongle_speed(self, baud);
 
1018         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1022  * Function ali_sir_change_speed (self, speed)
 
1024  *    Set speed of IrDA port to specified baudrate
 
1027 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed)
 
1029         struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
 
1030         unsigned long flags;
 
1032         int fcr;    /* FIFO control reg */
 
1033         int lcr;    /* Line control reg */
 
1036         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
1038         IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __FUNCTION__ , speed);
 
1040         IRDA_ASSERT(self != NULL, return;);
 
1042         iobase = self->io.sir_base;
 
1044         /* Come from MIR or FIR speed */
 
1045         if(self->io.speed >115200)
 
1047                 // Set Dongle Speed mode first
 
1048                 ali_ircc_change_dongle_speed(self, speed);
 
1053         // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
 
1055         inb(iobase+UART_LSR);
 
1056         inb(iobase+UART_SCR);
 
1058         /* Update accounting for new speed */
 
1059         self->io.speed = speed;
 
1061         spin_lock_irqsave(&self->lock, flags);
 
1063         divisor = 115200/speed;
 
1065         fcr = UART_FCR_ENABLE_FIFO;
 
1068          * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
 
1069          * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
 
1070          * about this timeout since it will always be fast enough. 
 
1072         if (self->io.speed < 38400)
 
1073                 fcr |= UART_FCR_TRIGGER_1;
 
1075                 fcr |= UART_FCR_TRIGGER_14;
 
1077         /* IrDA ports use 8N1 */
 
1078         lcr = UART_LCR_WLEN8;
 
1080         outb(UART_LCR_DLAB | lcr, iobase+UART_LCR); /* Set DLAB */
 
1081         outb(divisor & 0xff,      iobase+UART_DLL); /* Set speed */
 
1082         outb(divisor >> 8,        iobase+UART_DLM);
 
1083         outb(lcr,                 iobase+UART_LCR); /* Set 8N1  */
 
1084         outb(fcr,                 iobase+UART_FCR); /* Enable FIFO's */
 
1086         /* without this, the conection will be broken after come back from FIR speed,
 
1087            but with this, the SIR connection is harder to established */
 
1088         outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase+UART_MCR);
 
1090         spin_unlock_irqrestore(&self->lock, flags);
 
1092         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1095 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed)
 
1098         struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
 
1099         int iobase,dongle_id;
 
1102         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );        
 
1104         iobase = self->io.fir_base;     /* or iobase = self->io.sir_base; */
 
1105         dongle_id = self->io.dongle_id;
 
1107         /* We are already locked, no need to do it again */
 
1109         IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __FUNCTION__ , dongle_types[dongle_id], speed);          
 
1111         switch_bank(iobase, BANK2);
 
1112         tmp = inb(iobase+FIR_IRDA_CR);
 
1114         /* IBM type dongle */
 
1117                 if(speed == 4000000)
 
1120                         // SD/MODE __|     |__ __
 
1125                         tmp &=  ~IRDA_CR_HDLC;          // HDLC=0
 
1126                         tmp |= IRDA_CR_CRC;             // CRC=1
 
1128                         switch_bank(iobase, BANK2);
 
1129                         outb(tmp, iobase+FIR_IRDA_CR);
 
1131                         // T1 -> SD/MODE:0 IRTX:0
 
1134                         outb(tmp, iobase+FIR_IRDA_CR);
 
1137                         // T2 -> SD/MODE:1 IRTX:0
 
1140                         outb(tmp, iobase+FIR_IRDA_CR);
 
1143                         // T3 -> SD/MODE:1 IRTX:1
 
1145                         outb(tmp, iobase+FIR_IRDA_CR);
 
1148                         // T4 -> SD/MODE:0 IRTX:1
 
1151                         outb(tmp, iobase+FIR_IRDA_CR);
 
1154                         // T5 -> SD/MODE:0 IRTX:0
 
1157                         outb(tmp, iobase+FIR_IRDA_CR);
 
1160                         // reset -> Normal TX output Signal
 
1161                         outb(tmp & ~0x02, iobase+FIR_IRDA_CR);                          
 
1163                 else /* speed <=1152000 */
 
1171                         /* MIR 115200, 57600 */
 
1174                                 tmp |= 0xA0;       //HDLC=1, 1.152Mbps=1
 
1178                                 tmp &=~0x80;       //HDLC 0.576Mbps
 
1179                                 tmp |= 0x20;       //HDLC=1,
 
1182                         tmp |= IRDA_CR_CRC;             // CRC=1
 
1184                         switch_bank(iobase, BANK2);
 
1185                         outb(tmp, iobase+FIR_IRDA_CR);
 
1187                         /* MIR 115200, 57600 */ 
 
1189                         //switch_bank(iobase, BANK2);                   
 
1190                         // T1 -> SD/MODE:0 IRTX:0
 
1193                         outb(tmp, iobase+FIR_IRDA_CR);
 
1196                         // T2 -> SD/MODE:1 IRTX:0
 
1199                         outb(tmp, iobase+FIR_IRDA_CR);
 
1201                         // T3 -> SD/MODE:0 IRTX:0
 
1204                         outb(tmp, iobase+FIR_IRDA_CR);
 
1207                         // reset -> Normal TX output Signal
 
1208                         outb(tmp & ~0x02, iobase+FIR_IRDA_CR);                                                  
 
1211         else if (dongle_id == 1) /* HP HDSL-3600 */
 
1216                         tmp &=  ~IRDA_CR_HDLC;  // HDLC=0
 
1220                         tmp |= 0xA0;            // HDLC=1, 1.152Mbps=1
 
1224                         tmp &=~0x80;            // HDLC 0.576Mbps
 
1225                         tmp |= 0x20;            // HDLC=1,
 
1229                 tmp |= IRDA_CR_CRC;             // CRC=1
 
1231                 switch_bank(iobase, BANK2);
 
1232                 outb(tmp, iobase+FIR_IRDA_CR);          
 
1234         else /* HP HDSL-1100 */
 
1236                 if(speed <= 115200) /* SIR */
 
1239                         tmp &= ~IRDA_CR_FIR_SIN;        // HP sin select = 0
 
1241                         switch_bank(iobase, BANK2);
 
1242                         outb(tmp, iobase+FIR_IRDA_CR);                  
 
1250                                 tmp &=  ~IRDA_CR_HDLC;  // HDLC=0
 
1254                                 tmp |= 0xA0;            // HDLC=1, 1.152Mbps=1
 
1258                                 tmp &=~0x80;            // HDLC 0.576Mbps
 
1259                                 tmp |= 0x20;            // HDLC=1,
 
1263                         tmp |= IRDA_CR_CRC;             // CRC=1
 
1264                         tmp |= IRDA_CR_FIR_SIN;         // HP sin select = 1
 
1266                         switch_bank(iobase, BANK2);
 
1267                         outb(tmp, iobase+FIR_IRDA_CR);                  
 
1271         switch_bank(iobase, BANK0);
 
1273         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );               
 
1277  * Function ali_ircc_sir_write (driver)
 
1279  *    Fill Tx FIFO with transmit data
 
1282 static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
 
1286         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
1288         /* Tx FIFO should be empty! */
 
1289         if (!(inb(iobase+UART_LSR) & UART_LSR_THRE)) {
 
1290                 IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __FUNCTION__ );
 
1294         /* Fill FIFO with current frame */
 
1295         while ((fifo_size-- > 0) && (actual < len)) {
 
1296                 /* Transmit next byte */
 
1297                 outb(buf[actual], iobase+UART_TX);
 
1302         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1307  * Function ali_ircc_net_open (dev)
 
1312 static int ali_ircc_net_open(struct net_device *dev)
 
1314         struct ali_ircc_cb *self;
 
1318         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
1320         IRDA_ASSERT(dev != NULL, return -1;);
 
1322         self = (struct ali_ircc_cb *) dev->priv;
 
1324         IRDA_ASSERT(self != NULL, return 0;);
 
1326         iobase = self->io.fir_base;
 
1328         /* Request IRQ and install Interrupt Handler */
 
1329         if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev)) 
 
1331                 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name,
 
1337          * Always allocate the DMA channel after the IRQ, and clean up on 
 
1340         if (request_dma(self->io.dma, dev->name)) {
 
1341                 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name,
 
1343                 free_irq(self->io.irq, self);
 
1347         /* Turn on interrups */
 
1348         outb(UART_IER_RDI , iobase+UART_IER);
 
1350         /* Ready to play! */
 
1351         netif_start_queue(dev); //benjamin by irport
 
1353         /* Give self a hardware name */
 
1354         sprintf(hwname, "ALI-FIR @ 0x%03x", self->io.fir_base);
 
1357          * Open new IrLAP layer instance, now that everything should be
 
1358          * initialized properly 
 
1360         self->irlap = irlap_open(dev, &self->qos, hwname);
 
1362         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1368  * Function ali_ircc_net_close (dev)
 
1373 static int ali_ircc_net_close(struct net_device *dev)
 
1376         struct ali_ircc_cb *self;
 
1379         IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
1381         IRDA_ASSERT(dev != NULL, return -1;);
 
1383         self = (struct ali_ircc_cb *) dev->priv;
 
1384         IRDA_ASSERT(self != NULL, return 0;);
 
1387         netif_stop_queue(dev);
 
1389         /* Stop and remove instance of IrLAP */
 
1391                 irlap_close(self->irlap);
 
1394         disable_dma(self->io.dma);
 
1396         /* Disable interrupts */
 
1397         SetCOMInterrupts(self, FALSE);
 
1399         free_irq(self->io.irq, dev);
 
1400         free_dma(self->io.dma);
 
1402         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1408  * Function ali_ircc_fir_hard_xmit (skb, dev)
 
1410  *    Transmit the frame
 
1413 static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
 
1415         struct ali_ircc_cb *self;
 
1416         unsigned long flags;
 
1421         IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );       
 
1423         self = (struct ali_ircc_cb *) dev->priv;
 
1424         iobase = self->io.fir_base;
 
1426         netif_stop_queue(dev);
 
1428         /* Make sure tests *& speed change are atomic */
 
1429         spin_lock_irqsave(&self->lock, flags);
 
1431         /* Note : you should make sure that speed changes are not going
 
1432          * to corrupt any outgoing frame. Look at nsc-ircc for the gory
 
1433          * details - Jean II */
 
1435         /* Check if we need to change the speed */
 
1436         speed = irda_get_next_speed(skb);
 
1437         if ((speed != self->io.speed) && (speed != -1)) {
 
1438                 /* Check for empty frame */
 
1440                         ali_ircc_change_speed(self, speed); 
 
1441                         dev->trans_start = jiffies;
 
1442                         spin_unlock_irqrestore(&self->lock, flags);
 
1446                         self->new_speed = speed;
 
1449         /* Register and copy this frame to DMA memory */
 
1450         self->tx_fifo.queue[self->tx_fifo.free].start = self->tx_fifo.tail;
 
1451         self->tx_fifo.queue[self->tx_fifo.free].len = skb->len;
 
1452         self->tx_fifo.tail += skb->len;
 
1454         self->stats.tx_bytes += skb->len;
 
1456         memcpy(self->tx_fifo.queue[self->tx_fifo.free].start, skb->data, 
 
1459         self->tx_fifo.len++;
 
1460         self->tx_fifo.free++;
 
1462         /* Start transmit only if there is currently no transmit going on */
 
1463         if (self->tx_fifo.len == 1) 
 
1465                 /* Check if we must wait the min turn time or not */
 
1466                 mtt = irda_get_mtt(skb);
 
1470                         /* Check how much time we have used already */
 
1471                         do_gettimeofday(&self->now);
 
1473                         diff = self->now.tv_usec - self->stamp.tv_usec;
 
1474                         /* self->stamp is set from ali_ircc_dma_receive_complete() */
 
1476                         IRDA_DEBUG(1, "%s(), ******* diff = %d ******* \n", __FUNCTION__ , diff);       
 
1481                         /* Check if the mtt is larger than the time we have
 
1482                          * already used by all the protocol processing
 
1489                                  * Use timer if delay larger than 1000 us, and
 
1490                                  * use udelay for smaller values which should
 
1495                                         /* Adjust for timer resolution */
 
1496                                         mtt = (mtt+250) / 500;  /* 4 discard, 5 get advanced, Let's round off */
 
1498                                         IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __FUNCTION__ , mtt);       
 
1501                                         if (mtt == 1) /* 500 us */
 
1503                                                 switch_bank(iobase, BANK1);
 
1504                                                 outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR);
 
1506                                         else if (mtt == 2) /* 1 ms */
 
1508                                                 switch_bank(iobase, BANK1);
 
1509                                                 outb(TIMER_IIR_1ms, iobase+FIR_TIMER_IIR);
 
1511                                         else /* > 2ms -> 4ms */
 
1513                                                 switch_bank(iobase, BANK1);
 
1514                                                 outb(TIMER_IIR_2ms, iobase+FIR_TIMER_IIR);
 
1519                                         outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
 
1520                                         self->io.direction = IO_XMIT;
 
1522                                         /* Enable timer interrupt */
 
1523                                         self->ier = IER_TIMER;
 
1524                                         SetCOMInterrupts(self, TRUE);                                   
 
1526                                         /* Timer will take care of the rest */
 
1531                         } // if (if (mtt > diff)
 
1534                 /* Enable EOM interrupt */
 
1535                 self->ier = IER_EOM;
 
1536                 SetCOMInterrupts(self, TRUE);
 
1538                 /* Transmit frame */
 
1539                 ali_ircc_dma_xmit(self);
 
1540         } // if (self->tx_fifo.len == 1) 
 
1544         /* Not busy transmitting anymore if window is not full */
 
1545         if (self->tx_fifo.free < MAX_TX_WINDOW)
 
1546                 netif_wake_queue(self->netdev);
 
1548         /* Restore bank register */
 
1549         switch_bank(iobase, BANK0);
 
1551         dev->trans_start = jiffies;
 
1552         spin_unlock_irqrestore(&self->lock, flags);
 
1555         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1560 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self)
 
1563         unsigned char FIFO_OPTI, Hi, Lo;
 
1566         IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );       
 
1568         iobase = self->io.fir_base;
 
1570         /* FIFO threshold , this method comes from NDIS5 code */
 
1572         if(self->tx_fifo.queue[self->tx_fifo.ptr].len < TX_FIFO_Threshold)
 
1573                 FIFO_OPTI = self->tx_fifo.queue[self->tx_fifo.ptr].len-1;
 
1575                 FIFO_OPTI = TX_FIFO_Threshold;
 
1578         switch_bank(iobase, BANK1);
 
1579         outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
 
1581         self->io.direction = IO_XMIT;
 
1583         irda_setup_dma(self->io.dma, 
 
1584                        ((u8 *)self->tx_fifo.queue[self->tx_fifo.ptr].start -
 
1585                         self->tx_buff.head) + self->tx_buff_dma,
 
1586                        self->tx_fifo.queue[self->tx_fifo.ptr].len, 
 
1590         switch_bank(iobase, BANK0);
 
1591         outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
 
1593         /* Set Tx FIFO threshold */
 
1594         if (self->fifo_opti_buf!=FIFO_OPTI) 
 
1596                 switch_bank(iobase, BANK1);
 
1597                 outb(FIFO_OPTI, iobase+FIR_FIFO_TR) ;
 
1598                 self->fifo_opti_buf=FIFO_OPTI;
 
1601         /* Set Tx DMA threshold */
 
1602         switch_bank(iobase, BANK1);
 
1603         outb(TX_DMA_Threshold, iobase+FIR_DMA_TR);
 
1605         /* Set max Tx frame size */
 
1606         Hi = (self->tx_fifo.queue[self->tx_fifo.ptr].len >> 8) & 0x0f;
 
1607         Lo = self->tx_fifo.queue[self->tx_fifo.ptr].len & 0xff;
 
1608         switch_bank(iobase, BANK2);
 
1609         outb(Hi, iobase+FIR_TX_DSR_HI);
 
1610         outb(Lo, iobase+FIR_TX_DSR_LO);
 
1612         /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
 
1613         switch_bank(iobase, BANK0);     
 
1614         tmp = inb(iobase+FIR_LCR_B);
 
1615         tmp &= ~0x20; // Disable SIP
 
1616         outb(((unsigned char)(tmp & 0x3f) | LCR_B_TX_MODE) & ~LCR_B_BW, iobase+FIR_LCR_B);
 
1617         IRDA_DEBUG(1, "%s(), ******* Change to TX mode: FIR_LCR_B = 0x%x ******* \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
 
1619         outb(0, iobase+FIR_LSR);
 
1621         /* Enable DMA and Burst Mode */
 
1622         switch_bank(iobase, BANK1);
 
1623         outb(inb(iobase+FIR_CR) | CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
 
1625         switch_bank(iobase, BANK0); 
 
1627         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
 
1630 static int  ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self)
 
1635         IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );       
 
1637         iobase = self->io.fir_base;
 
1640         switch_bank(iobase, BANK1);
 
1641         outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
 
1643         /* Check for underrun! */
 
1644         switch_bank(iobase, BANK0);
 
1645         if((inb(iobase+FIR_LSR) & LSR_FRAME_ABORT) == LSR_FRAME_ABORT)
 
1648                 IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __FUNCTION__);        
 
1649                 self->stats.tx_errors++;
 
1650                 self->stats.tx_fifo_errors++;           
 
1654                 self->stats.tx_packets++;
 
1657         /* Check if we need to change the speed */
 
1658         if (self->new_speed) 
 
1660                 ali_ircc_change_speed(self, self->new_speed);
 
1661                 self->new_speed = 0;
 
1664         /* Finished with this frame, so prepare for next */
 
1665         self->tx_fifo.ptr++;
 
1666         self->tx_fifo.len--;
 
1668         /* Any frames to be sent back-to-back? */
 
1669         if (self->tx_fifo.len) 
 
1671                 ali_ircc_dma_xmit(self);
 
1673                 /* Not finished yet! */
 
1677         {       /* Reset Tx FIFO info */
 
1678                 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
 
1679                 self->tx_fifo.tail = self->tx_buff.head;
 
1682         /* Make sure we have room for more frames */
 
1683         if (self->tx_fifo.free < MAX_TX_WINDOW) {
 
1684                 /* Not busy transmitting anymore */
 
1685                 /* Tell the network layer, that we can accept more frames */
 
1686                 netif_wake_queue(self->netdev);
 
1689         switch_bank(iobase, BANK0); 
 
1691         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1696  * Function ali_ircc_dma_receive (self)
 
1698  *    Get ready for receiving a frame. The device will initiate a DMA
 
1699  *    if it starts to receive a frame.
 
1702 static int ali_ircc_dma_receive(struct ali_ircc_cb *self) 
 
1706         IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );       
 
1708         iobase = self->io.fir_base;
 
1710         /* Reset Tx FIFO info */
 
1711         self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
 
1712         self->tx_fifo.tail = self->tx_buff.head;
 
1715         switch_bank(iobase, BANK1);
 
1716         outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
 
1718         /* Reset Message Count */
 
1719         switch_bank(iobase, BANK0);
 
1720         outb(0x07, iobase+FIR_LSR);
 
1722         self->rcvFramesOverflow = FALSE;        
 
1724         self->LineStatus = inb(iobase+FIR_LSR) ;
 
1726         /* Reset Rx FIFO info */
 
1727         self->io.direction = IO_RECV;
 
1728         self->rx_buff.data = self->rx_buff.head;
 
1731         // switch_bank(iobase, BANK0);
 
1732         outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A); 
 
1734         self->st_fifo.len = self->st_fifo.pending_bytes = 0;
 
1735         self->st_fifo.tail = self->st_fifo.head = 0;
 
1737         irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
 
1740         /* Set Receive Mode,Brick Wall */
 
1741         //switch_bank(iobase, BANK0);
 
1742         tmp = inb(iobase+FIR_LCR_B);
 
1743         outb((unsigned char)(tmp &0x3f) | LCR_B_RX_MODE | LCR_B_BW , iobase + FIR_LCR_B); // 2000/12/1 05:16PM
 
1744         IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x *** \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
 
1746         /* Set Rx Threshold */
 
1747         switch_bank(iobase, BANK1);
 
1748         outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
 
1749         outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
 
1751         /* Enable DMA and Burst Mode */
 
1752         // switch_bank(iobase, BANK1);
 
1753         outb(CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
 
1755         switch_bank(iobase, BANK0); 
 
1756         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1760 static int  ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)
 
1762         struct st_fifo *st_fifo;
 
1763         struct sk_buff *skb;
 
1764         __u8 status, MessageCount;
 
1765         int len, i, iobase, val;        
 
1767         IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );       
 
1769         st_fifo = &self->st_fifo;               
 
1770         iobase = self->io.fir_base;     
 
1772         switch_bank(iobase, BANK0);
 
1773         MessageCount = inb(iobase+ FIR_LSR)&0x07;
 
1775         if (MessageCount > 0)   
 
1776                 IRDA_DEBUG(0, "%s(), Messsage count = %d,\n", __FUNCTION__ , MessageCount);     
 
1778         for (i=0; i<=MessageCount; i++)
 
1781                 switch_bank(iobase, BANK0);
 
1782                 status = inb(iobase+FIR_LSR);
 
1784                 switch_bank(iobase, BANK2);
 
1785                 len = inb(iobase+FIR_RX_DSR_HI) & 0x0f;
 
1787                 len |= inb(iobase+FIR_RX_DSR_LO);
 
1789                 IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __FUNCTION__ , len);       
 
1790                 IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __FUNCTION__ , status);
 
1792                 if (st_fifo->tail >= MAX_RX_WINDOW) {
 
1793                         IRDA_DEBUG(0, "%s(), window is full!\n", __FUNCTION__ );
 
1797                 st_fifo->entries[st_fifo->tail].status = status;
 
1798                 st_fifo->entries[st_fifo->tail].len = len;
 
1799                 st_fifo->pending_bytes += len;
 
1804         for (i=0; i<=MessageCount; i++)
 
1806                 /* Get first entry */
 
1807                 status = st_fifo->entries[st_fifo->head].status;
 
1808                 len    = st_fifo->entries[st_fifo->head].len;
 
1809                 st_fifo->pending_bytes -= len;
 
1813                 /* Check for errors */
 
1814                 if ((status & 0xd8) || self->rcvFramesOverflow || (len==0))             
 
1816                         IRDA_DEBUG(0,"%s(), ************* RX Errors ************ \n", __FUNCTION__ );   
 
1819                         self->stats.rx_errors++;
 
1821                         self->rx_buff.data += len;
 
1823                         if (status & LSR_FIFO_UR) 
 
1825                                 self->stats.rx_frame_errors++;
 
1826                                 IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************ \n", __FUNCTION__ );
 
1828                         if (status & LSR_FRAME_ERROR)
 
1830                                 self->stats.rx_frame_errors++;
 
1831                                 IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************ \n", __FUNCTION__ );
 
1834                         if (status & LSR_CRC_ERROR) 
 
1836                                 self->stats.rx_crc_errors++;
 
1837                                 IRDA_DEBUG(0,"%s(), ************* CRC Errors ************ \n", __FUNCTION__ );
 
1840                         if(self->rcvFramesOverflow)
 
1842                                 self->stats.rx_frame_errors++;
 
1843                                 IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************ \n", __FUNCTION__ );                                                          
 
1847                                 self->stats.rx_frame_errors++;
 
1848                                 IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 ********* \n", __FUNCTION__ );
 
1854                         if (st_fifo->pending_bytes < 32) 
 
1856                                 switch_bank(iobase, BANK0);
 
1857                                 val = inb(iobase+FIR_BSR);      
 
1858                                 if ((val& BSR_FIFO_NOT_EMPTY)== 0x80) 
 
1860                                         IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************ \n", __FUNCTION__ );
 
1862                                         /* Put this entry back in fifo */
 
1865                                         st_fifo->pending_bytes += len;
 
1866                                         st_fifo->entries[st_fifo->head].status = status;
 
1867                                         st_fifo->entries[st_fifo->head].len = len;
 
1870                                         * DMA not finished yet, so try again 
 
1871                                         * later, set timer value, resolution 
 
1875                                         switch_bank(iobase, BANK1);
 
1876                                         outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR); // 2001/1/2 05:07PM
 
1879                                         outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
 
1881                                         return FALSE; /* I'll be back! */
 
1886                          * Remember the time we received this frame, so we can
 
1887                          * reduce the min turn time a bit since we will know
 
1888                          * how much time we have used for protocol processing
 
1890                         do_gettimeofday(&self->stamp);
 
1892                         skb = dev_alloc_skb(len+1);
 
1895                                 IRDA_WARNING("%s(), memory squeeze, "
 
1896                                              "dropping frame.\n",
 
1898                                 self->stats.rx_dropped++;
 
1903                         /* Make sure IP header gets aligned */
 
1904                         skb_reserve(skb, 1); 
 
1906                         /* Copy frame without CRC, CRC is removed by hardware*/
 
1908                         memcpy(skb->data, self->rx_buff.data, len);
 
1910                         /* Move to next frame */
 
1911                         self->rx_buff.data += len;
 
1912                         self->stats.rx_bytes += len;
 
1913                         self->stats.rx_packets++;
 
1915                         skb->dev = self->netdev;
 
1916                         skb->mac.raw  = skb->data;
 
1917                         skb->protocol = htons(ETH_P_IRDA);
 
1919                         self->netdev->last_rx = jiffies;
 
1923         switch_bank(iobase, BANK0);     
 
1925         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
1932  * Function ali_ircc_sir_hard_xmit (skb, dev)
 
1934  *    Transmit the frame!
 
1937 static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
 
1939         struct ali_ircc_cb *self;
 
1940         unsigned long flags;
 
1944         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
1946         IRDA_ASSERT(dev != NULL, return 0;);
 
1948         self = (struct ali_ircc_cb *) dev->priv;
 
1949         IRDA_ASSERT(self != NULL, return 0;);
 
1951         iobase = self->io.sir_base;
 
1953         netif_stop_queue(dev);
 
1955         /* Make sure tests *& speed change are atomic */
 
1956         spin_lock_irqsave(&self->lock, flags);
 
1958         /* Note : you should make sure that speed changes are not going
 
1959          * to corrupt any outgoing frame. Look at nsc-ircc for the gory
 
1960          * details - Jean II */
 
1962         /* Check if we need to change the speed */
 
1963         speed = irda_get_next_speed(skb);
 
1964         if ((speed != self->io.speed) && (speed != -1)) {
 
1965                 /* Check for empty frame */
 
1967                         ali_ircc_change_speed(self, speed); 
 
1968                         dev->trans_start = jiffies;
 
1969                         spin_unlock_irqrestore(&self->lock, flags);
 
1973                         self->new_speed = speed;
 
1976         /* Init tx buffer */
 
1977         self->tx_buff.data = self->tx_buff.head;
 
1979         /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
 
1980         self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data, 
 
1981                                            self->tx_buff.truesize);
 
1983         self->stats.tx_bytes += self->tx_buff.len;
 
1985         /* Turn on transmit finished interrupt. Will fire immediately!  */
 
1986         outb(UART_IER_THRI, iobase+UART_IER); 
 
1988         dev->trans_start = jiffies;
 
1989         spin_unlock_irqrestore(&self->lock, flags);
 
1993         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2000  * Function ali_ircc_net_ioctl (dev, rq, cmd)
 
2002  *    Process IOCTL commands for this device
 
2005 static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
2007         struct if_irda_req *irq = (struct if_irda_req *) rq;
 
2008         struct ali_ircc_cb *self;
 
2009         unsigned long flags;
 
2012         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2014         IRDA_ASSERT(dev != NULL, return -1;);
 
2018         IRDA_ASSERT(self != NULL, return -1;);
 
2020         IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__ , dev->name, cmd);
 
2023         case SIOCSBANDWIDTH: /* Set bandwidth */
 
2024                 IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __FUNCTION__ );
 
2026                  * This function will also be used by IrLAP to change the
 
2027                  * speed, so we still must allow for speed change within
 
2028                  * interrupt context.
 
2030                 if (!in_interrupt() && !capable(CAP_NET_ADMIN))
 
2033                 spin_lock_irqsave(&self->lock, flags);
 
2034                 ali_ircc_change_speed(self, irq->ifr_baudrate);         
 
2035                 spin_unlock_irqrestore(&self->lock, flags);
 
2037         case SIOCSMEDIABUSY: /* Set media busy */
 
2038                 IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __FUNCTION__ );
 
2039                 if (!capable(CAP_NET_ADMIN))
 
2041                 irda_device_set_media_busy(self->netdev, TRUE);
 
2043         case SIOCGRECEIVING: /* Check if we are receiving right now */
 
2044                 IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __FUNCTION__ );
 
2045                 /* This is protected */
 
2046                 irq->ifr_receiving = ali_ircc_is_receiving(self);
 
2052         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2058  * Function ali_ircc_is_receiving (self)
 
2060  *    Return TRUE is we are currently receiving a frame
 
2063 static int ali_ircc_is_receiving(struct ali_ircc_cb *self)
 
2065         unsigned long flags;
 
2069         IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
 
2071         IRDA_ASSERT(self != NULL, return FALSE;);
 
2073         spin_lock_irqsave(&self->lock, flags);
 
2075         if (self->io.speed > 115200) 
 
2077                 iobase = self->io.fir_base;
 
2079                 switch_bank(iobase, BANK1);
 
2080                 if((inb(iobase+FIR_FIFO_FR) & 0x3f) != 0)               
 
2082                         /* We are receiving something */
 
2083                         IRDA_DEBUG(1, "%s(), We are receiving something\n", __FUNCTION__ );
 
2086                 switch_bank(iobase, BANK0);             
 
2090                 status = (self->rx_buff.state != OUTSIDE_FRAME);
 
2093         spin_unlock_irqrestore(&self->lock, flags);
 
2095         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
 
2100 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev)
 
2102         struct ali_ircc_cb *self = (struct ali_ircc_cb *) dev->priv;
 
2104         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2106         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2108         return &self->stats;
 
2111 static void ali_ircc_suspend(struct ali_ircc_cb *self)
 
2113         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2115         IRDA_MESSAGE("%s, Suspending\n", driver_name);
 
2117         if (self->io.suspended)
 
2120         ali_ircc_net_close(self->netdev);
 
2122         self->io.suspended = 1;
 
2124         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2127 static void ali_ircc_wakeup(struct ali_ircc_cb *self)
 
2129         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2131         if (!self->io.suspended)
 
2134         ali_ircc_net_open(self->netdev);
 
2136         IRDA_MESSAGE("%s, Waking up\n", driver_name);
 
2138         self->io.suspended = 0;
 
2140         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2143 static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
 
2145         struct ali_ircc_cb *self = (struct ali_ircc_cb*) dev->data;
 
2147         IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2152                         ali_ircc_suspend(self);
 
2155                         ali_ircc_wakeup(self);
 
2160         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2166 /* ALi Chip Function */
 
2168 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)
 
2171         unsigned char newMask;
 
2173         int iobase = self->io.fir_base; /* or sir_base */
 
2175         IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __FUNCTION__ , enable);        
 
2177         /* Enable the interrupt which we wish to */
 
2179                 if (self->io.direction == IO_XMIT)
 
2181                         if (self->io.speed > 115200) /* FIR, MIR */
 
2183                                 newMask = self->ier;
 
2187                                 newMask = UART_IER_THRI | UART_IER_RDI;
 
2191                         if (self->io.speed > 115200) /* FIR, MIR */
 
2193                                 newMask = self->ier;
 
2197                                 newMask = UART_IER_RDI;
 
2201         else /* Disable all the interrupts */
 
2207         //SIR and FIR has different registers
 
2208         if (self->io.speed > 115200)
 
2210                 switch_bank(iobase, BANK0);
 
2211                 outb(newMask, iobase+FIR_IER);
 
2214                 outb(newMask, iobase+UART_IER);
 
2216         IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2219 static void SIR2FIR(int iobase)
 
2221         //unsigned char tmp;
 
2223         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2225         /* Already protected (change_speed() or setup()), no need to lock.
 
2228         outb(0x28, iobase+UART_MCR);
 
2229         outb(0x68, iobase+UART_MCR);
 
2230         outb(0x88, iobase+UART_MCR);            
 
2232         outb(0x60, iobase+FIR_MCR);     /*  Master Reset */
 
2233         outb(0x20, iobase+FIR_MCR);     /*  Master Interrupt Enable */
 
2235         //tmp = inb(iobase+FIR_LCR_B);  /* SIP enable */
 
2237         //outb(tmp, iobase+FIR_LCR_B);  
 
2239         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );       
 
2242 static void FIR2SIR(int iobase)
 
2246         IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
 
2248         /* Already protected (change_speed() or setup()), no need to lock.
 
2251         outb(0x20, iobase+FIR_MCR);     /* IRQ to low */
 
2252         outb(0x00, iobase+UART_IER);    
 
2254         outb(0xA0, iobase+FIR_MCR);     /* Don't set master reset */
 
2255         outb(0x00, iobase+UART_FCR);
 
2256         outb(0x07, iobase+UART_FCR);            
 
2258         val = inb(iobase+UART_RX);
 
2259         val = inb(iobase+UART_LSR);
 
2260         val = inb(iobase+UART_MSR);
 
2262         IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
 
2265 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
 
2266 MODULE_DESCRIPTION("ALi FIR Controller Driver");
 
2267 MODULE_LICENSE("GPL");
 
2270 module_param_array(io, int, NULL, 0);
 
2271 MODULE_PARM_DESC(io, "Base I/O addresses");
 
2272 module_param_array(irq, int, NULL, 0);
 
2273 MODULE_PARM_DESC(irq, "IRQ lines");
 
2274 module_param_array(dma, int, NULL, 0);
 
2275 MODULE_PARM_DESC(dma, "DMA channels");
 
2277 module_init(ali_ircc_init);
 
2278 module_exit(ali_ircc_cleanup);