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>
44 #include <net/irda/wrapper.h>
45 #include <net/irda/irda.h>
46 #include <net/irda/irda_device.h>
50 #define CHIP_IO_EXTENT 8
51 #define BROKEN_DONGLE_ID
53 static char *driver_name = "ali-ircc";
55 /* Module parameters */
56 static int qos_mtt_bits = 0x07; /* 1 ms or more */
58 /* Use BIOS settions by default, but user may supply module parameters */
59 static unsigned int io[] = { ~0, ~0, ~0, ~0 };
60 static unsigned int irq[] = { 0, 0, 0, 0 };
61 static unsigned int dma[] = { 0, 0, 0, 0 };
63 static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info);
64 static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info);
65 static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info);
67 /* These are the currently known ALi sourth-bridge chipsets, the only one difference
68 * is that M1543C doesn't support HP HDSL-3600
70 static ali_chip_t chips[] =
72 { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53, ali_ircc_init_43 },
73 { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53, ali_ircc_init_53 },
74 { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53, ali_ircc_init_53 },
78 /* Max 4 instances for now */
79 static struct ali_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
82 static char *dongle_types[] = {
86 "No dongle connected",
90 static int ali_ircc_open(int i, chipio_t *info);
92 static int ali_ircc_close(struct ali_ircc_cb *self);
94 static int ali_ircc_setup(chipio_t *info);
95 static int ali_ircc_is_receiving(struct ali_ircc_cb *self);
96 static int ali_ircc_net_open(struct net_device *dev);
97 static int ali_ircc_net_close(struct net_device *dev);
98 static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
99 static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
100 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
101 static void ali_ircc_suspend(struct ali_ircc_cb *self);
102 static void ali_ircc_wakeup(struct ali_ircc_cb *self);
103 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev);
106 static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
107 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self);
108 static void ali_ircc_sir_receive(struct ali_ircc_cb *self);
109 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self);
110 static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
111 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
114 static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
115 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
116 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self);
117 static int ali_ircc_dma_receive(struct ali_ircc_cb *self);
118 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self);
119 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self);
120 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self);
123 static int ali_ircc_read_dongle_id (int i, chipio_t *info);
124 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed);
126 /* ALi chip function */
127 static void SIR2FIR(int iobase);
128 static void FIR2SIR(int iobase);
129 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable);
132 * Function ali_ircc_init ()
134 * Initialize chip. Find out whay kinds of chips we are dealing with
135 * and their configuation registers address
137 static int __init ali_ircc_init(void)
146 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
148 /* Probe for all the ALi chipsets we know about */
149 for (chip= chips; chip->name; chip++, i++)
151 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__, chip->name);
153 /* Try all config registers for this chip */
154 for (cfg=0; cfg<2; cfg++)
156 cfg_base = chip->cfg[cfg];
160 memset(&info, 0, sizeof(chipio_t));
161 info.cfg_base = cfg_base;
162 info.fir_base = io[i];
167 /* Enter Configuration */
168 outb(chip->entr1, cfg_base);
169 outb(chip->entr2, cfg_base);
171 /* Select Logical Device 5 Registers (UART2) */
172 outb(0x07, cfg_base);
173 outb(0x05, cfg_base+1);
175 /* Read Chip Identification Register */
176 outb(chip->cid_index, cfg_base);
177 reg = inb(cfg_base+1);
179 if (reg == chip->cid_value)
181 IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __FUNCTION__, cfg_base);
183 outb(0x1F, cfg_base);
184 revision = inb(cfg_base+1);
185 IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __FUNCTION__,
186 chip->name, revision);
189 * If the user supplies the base address, then
190 * we init the chip, if not we probe the values
195 chip->init(chip, &info);
199 chip->probe(chip, &info);
202 if (ali_ircc_open(i, &info) == 0)
208 IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __FUNCTION__, chip->name, cfg_base);
210 /* Exit configuration */
211 outb(0xbb, cfg_base);
215 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
220 * Function ali_ircc_cleanup ()
222 * Close all configured chips
225 static void __exit ali_ircc_cleanup(void)
229 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
231 pm_unregister_all(ali_ircc_pmproc);
233 for (i=0; i < 4; i++) {
235 ali_ircc_close(dev_self[i]);
238 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
242 * Function ali_ircc_open (int i, chipio_t *inf)
244 * Open driver instance
247 static int ali_ircc_open(int i, chipio_t *info)
249 struct net_device *dev;
250 struct ali_ircc_cb *self;
251 struct pm_dev *pmdev;
255 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
257 /* Set FIR FIFO and DMA Threshold */
258 if ((ali_ircc_setup(info)) == -1)
261 dev = alloc_irdadev(sizeof(*self));
263 ERROR("%s(), can't allocate memory for control block!\n", __FUNCTION__);
269 spin_lock_init(&self->lock);
271 /* Need to store self somewhere */
276 self->io.cfg_base = info->cfg_base; /* In ali_ircc_probe_53 assign */
277 self->io.fir_base = info->fir_base; /* info->sir_base = info->fir_base */
278 self->io.sir_base = info->sir_base; /* ALi SIR and FIR use the same address */
279 self->io.irq = info->irq;
280 self->io.fir_ext = CHIP_IO_EXTENT;
281 self->io.dma = info->dma;
282 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
284 /* Reserve the ioports that we need */
285 if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) {
286 WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
292 /* Initialize QoS for this device */
293 irda_init_max_qos_capabilies(&self->qos);
295 /* The only value we must override it the baudrate */
296 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
297 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); // benjamin 2000/11/8 05:27PM
299 self->qos.min_turn_time.bits = qos_mtt_bits;
301 irda_qos_bits_to_value(&self->qos);
303 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
304 self->rx_buff.truesize = 14384;
305 self->tx_buff.truesize = 14384;
307 /* Allocate memory if needed */
309 dma_alloc_coherent(NULL, self->rx_buff.truesize,
310 &self->rx_buff_dma, GFP_KERNEL);
311 if (self->rx_buff.head == NULL) {
315 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
318 dma_alloc_coherent(NULL, self->tx_buff.truesize,
319 &self->tx_buff_dma, GFP_KERNEL);
320 if (self->tx_buff.head == NULL) {
324 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
326 self->rx_buff.in_frame = FALSE;
327 self->rx_buff.state = OUTSIDE_FRAME;
328 self->tx_buff.data = self->tx_buff.head;
329 self->rx_buff.data = self->rx_buff.head;
331 /* Reset Tx queue info */
332 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
333 self->tx_fifo.tail = self->tx_buff.head;
336 /* Keep track of module usage */
337 SET_MODULE_OWNER(dev);
339 /* Override the network functions we need to use */
340 dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
341 dev->open = ali_ircc_net_open;
342 dev->stop = ali_ircc_net_close;
343 dev->do_ioctl = ali_ircc_net_ioctl;
344 dev->get_stats = ali_ircc_net_get_stats;
346 err = register_netdev(dev);
348 ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
351 MESSAGE("IrDA: Registered device %s\n", dev->name);
353 /* Check dongle id */
354 dongle_id = ali_ircc_read_dongle_id(i, info);
355 MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]);
357 self->io.dongle_id = dongle_id;
359 pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, ali_ircc_pmproc);
363 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
368 dma_free_coherent(NULL, self->tx_buff.truesize,
369 self->tx_buff.head, self->tx_buff_dma);
371 dma_free_coherent(NULL, self->rx_buff.truesize,
372 self->rx_buff.head, self->rx_buff_dma);
374 release_region(self->io.fir_base, self->io.fir_ext);
383 * Function ali_ircc_close (self)
385 * Close driver instance
388 static int __exit ali_ircc_close(struct ali_ircc_cb *self)
392 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
394 ASSERT(self != NULL, return -1;);
396 iobase = self->io.fir_base;
398 /* Remove netdevice */
399 unregister_netdev(self->netdev);
401 /* Release the PORT that this driver is using */
402 IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __FUNCTION__, self->io.fir_base);
403 release_region(self->io.fir_base, self->io.fir_ext);
405 if (self->tx_buff.head)
406 dma_free_coherent(NULL, self->tx_buff.truesize,
407 self->tx_buff.head, self->tx_buff_dma);
409 if (self->rx_buff.head)
410 dma_free_coherent(NULL, self->rx_buff.truesize,
411 self->rx_buff.head, self->rx_buff_dma);
413 dev_self[self->index] = NULL;
414 free_netdev(self->netdev);
416 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
422 * Function ali_ircc_init_43 (chip, info)
424 * Initialize the ALi M1543 chip.
426 static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info)
428 /* All controller information like I/O address, DMA channel, IRQ
436 * Function ali_ircc_init_53 (chip, info)
438 * Initialize the ALi M1535 chip.
440 static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info)
442 /* All controller information like I/O address, DMA channel, IRQ
450 * Function ali_ircc_probe_53 (chip, info)
452 * Probes for the ALi M1535D or M1535
454 static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info)
456 int cfg_base = info->cfg_base;
459 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
461 /* Enter Configuration */
462 outb(chip->entr1, cfg_base);
463 outb(chip->entr2, cfg_base);
465 /* Select Logical Device 5 Registers (UART2) */
466 outb(0x07, cfg_base);
467 outb(0x05, cfg_base+1);
469 /* Read address control register */
470 outb(0x60, cfg_base);
471 hi = inb(cfg_base+1);
472 outb(0x61, cfg_base);
473 low = inb(cfg_base+1);
474 info->fir_base = (hi<<8) + low;
476 info->sir_base = info->fir_base;
478 IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __FUNCTION__, info->fir_base);
480 /* Read IRQ control register */
481 outb(0x70, cfg_base);
482 reg = inb(cfg_base+1);
483 info->irq = reg & 0x0f;
484 IRDA_DEBUG(2, "%s(), probing irq=%d\n", __FUNCTION__, info->irq);
486 /* Read DMA channel */
487 outb(0x74, cfg_base);
488 reg = inb(cfg_base+1);
489 info->dma = reg & 0x07;
491 if(info->dma == 0x04)
492 WARNING("%s(), No DMA channel assigned !\n", __FUNCTION__);
494 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __FUNCTION__, info->dma);
496 /* Read Enabled Status */
497 outb(0x30, cfg_base);
498 reg = inb(cfg_base+1);
499 info->enabled = (reg & 0x80) && (reg & 0x01);
500 IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __FUNCTION__, info->enabled);
502 /* Read Power Status */
503 outb(0x22, cfg_base);
504 reg = inb(cfg_base+1);
505 info->suspended = (reg & 0x20);
506 IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __FUNCTION__, info->suspended);
508 /* Exit configuration */
509 outb(0xbb, cfg_base);
511 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
517 * Function ali_ircc_setup (info)
519 * Set FIR FIFO and DMA Threshold
520 * Returns non-negative on success.
523 static int ali_ircc_setup(chipio_t *info)
527 int iobase = info->fir_base;
529 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
531 /* Locking comments :
532 * Most operations here need to be protected. We are called before
533 * the device instance is created in ali_ircc_open(), therefore
534 * nobody can bother us - Jean II */
536 /* Switch to FIR space */
540 outb(0x40, iobase+FIR_MCR); // benjamin 2000/11/30 11:45AM
542 /* Read FIR ID Version Register */
543 switch_bank(iobase, BANK3);
544 version = inb(iobase+FIR_ID_VR);
546 /* Should be 0x00 in the M1535/M1535D */
549 ERROR("%s, Wrong chip version %02x\n", driver_name, version);
553 // MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
555 /* Set FIR FIFO Threshold Register */
556 switch_bank(iobase, BANK1);
557 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
559 /* Set FIR DMA Threshold Register */
560 outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
563 switch_bank(iobase, BANK2);
564 outb(inb(iobase+FIR_IRDA_CR) | IRDA_CR_CRC, iobase+FIR_IRDA_CR);
566 /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
568 /* Switch to Bank 0 */
569 switch_bank(iobase, BANK0);
571 tmp = inb(iobase+FIR_LCR_B);
572 tmp &=~0x20; // disable SIP
573 tmp |= 0x80; // these two steps make RX mode
575 outb(tmp, iobase+FIR_LCR_B);
577 /* Disable Interrupt */
578 outb(0x00, iobase+FIR_IER);
581 /* Switch to SIR space */
584 MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name);
586 /* Enable receive interrupts */
587 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
588 // Turn on the interrupts in ali_ircc_net_open
590 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
596 * Function ali_ircc_read_dongle_id (int index, info)
598 * Try to read dongle indentification. This procedure needs to be executed
599 * once after power-on/reset. It also needs to be used whenever you suspect
600 * that the user may have plugged/unplugged the IrDA Dongle.
602 static int ali_ircc_read_dongle_id (int i, chipio_t *info)
605 int cfg_base = info->cfg_base;
607 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
609 /* Enter Configuration */
610 outb(chips[i].entr1, cfg_base);
611 outb(chips[i].entr2, cfg_base);
613 /* Select Logical Device 5 Registers (UART2) */
614 outb(0x07, cfg_base);
615 outb(0x05, cfg_base+1);
618 outb(0xf0, cfg_base);
619 reg = inb(cfg_base+1);
620 dongle_id = ((reg>>6)&0x02) | ((reg>>5)&0x01);
621 IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __FUNCTION__,
622 dongle_id, dongle_types[dongle_id]);
624 /* Exit configuration */
625 outb(0xbb, cfg_base);
627 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
633 * Function ali_ircc_interrupt (irq, dev_id, regs)
635 * An interrupt from the chip has arrived. Time to do some work
638 static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id,
639 struct pt_regs *regs)
641 struct net_device *dev = (struct net_device *) dev_id;
642 struct ali_ircc_cb *self;
645 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
648 WARNING("%s: irq %d for unknown device.\n", driver_name, irq);
652 self = (struct ali_ircc_cb *) dev->priv;
654 spin_lock(&self->lock);
656 /* Dispatch interrupt handler for the current speed */
657 if (self->io.speed > 115200)
658 ret = ali_ircc_fir_interrupt(self);
660 ret = ali_ircc_sir_interrupt(self);
662 spin_unlock(&self->lock);
664 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
668 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
670 * Handle MIR/FIR interrupt
673 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self)
675 __u8 eir, OldMessageCount;
678 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
680 iobase = self->io.fir_base;
682 switch_bank(iobase, BANK0);
683 self->InterruptID = inb(iobase+FIR_IIR);
684 self->BusStatus = inb(iobase+FIR_BSR);
686 OldMessageCount = (self->LineStatus + 1) & 0x07;
687 self->LineStatus = inb(iobase+FIR_LSR);
688 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
689 eir = self->InterruptID & self->ier; /* Mask out the interesting ones */
691 IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __FUNCTION__,self->InterruptID);
692 IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __FUNCTION__,self->LineStatus);
693 IRDA_DEBUG(1, "%s(), self->ier = %x\n", __FUNCTION__,self->ier);
694 IRDA_DEBUG(1, "%s(), eir = %x\n", __FUNCTION__,eir);
696 /* Disable interrupts */
697 SetCOMInterrupts(self, FALSE);
699 /* Tx or Rx Interrupt */
703 if (self->io.direction == IO_XMIT) /* TX */
705 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __FUNCTION__);
707 if(ali_ircc_dma_xmit_complete(self))
709 if (irda_device_txqueue_empty(self->netdev))
711 /* Prepare for receive */
712 ali_ircc_dma_receive(self);
724 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __FUNCTION__);
726 if(OldMessageCount > ((self->LineStatus+1) & 0x07))
728 self->rcvFramesOverflow = TRUE;
729 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******** \n", __FUNCTION__);
732 if (ali_ircc_dma_receive_complete(self))
734 IRDA_DEBUG(1, "%s(), ******* receive complete ******** \n", __FUNCTION__);
740 IRDA_DEBUG(1, "%s(), ******* Not receive complete ******** \n", __FUNCTION__);
742 self->ier = IER_EOM | IER_TIMER;
747 /* Timer Interrupt */
748 else if (eir & IIR_TIMER)
750 if(OldMessageCount > ((self->LineStatus+1) & 0x07))
752 self->rcvFramesOverflow = TRUE;
753 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******* \n", __FUNCTION__);
756 switch_bank(iobase, BANK1);
757 tmp = inb(iobase+FIR_CR);
758 outb( tmp& ~CR_TIMER_EN, iobase+FIR_CR);
760 /* Check if this is a Tx timer interrupt */
761 if (self->io.direction == IO_XMIT)
763 ali_ircc_dma_xmit(self);
765 /* Interrupt on EOM */
771 if(ali_ircc_dma_receive_complete(self))
777 self->ier = IER_EOM | IER_TIMER;
782 /* Restore Interrupt */
783 SetCOMInterrupts(self, TRUE);
785 IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __FUNCTION__);
786 return IRQ_RETVAL(eir);
790 * Function ali_ircc_sir_interrupt (irq, self, eir)
792 * Handle SIR interrupt
795 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self)
800 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
802 iobase = self->io.sir_base;
804 iir = inb(iobase+UART_IIR) & UART_IIR_ID;
806 /* Clear interrupt */
807 lsr = inb(iobase+UART_LSR);
809 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __FUNCTION__,
815 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
818 /* Receive interrupt */
819 ali_ircc_sir_receive(self);
822 if (lsr & UART_LSR_THRE)
824 /* Transmitter ready for data */
825 ali_ircc_sir_write_wakeup(self);
829 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __FUNCTION__, iir);
836 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
838 return IRQ_RETVAL(iir);
843 * Function ali_ircc_sir_receive (self)
845 * Receive one frame from the infrared port
848 static void ali_ircc_sir_receive(struct ali_ircc_cb *self)
853 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
854 ASSERT(self != NULL, return;);
856 iobase = self->io.sir_base;
859 * Receive all characters in Rx FIFO, unwrap and unstuff them.
860 * async_unwrap_char will deliver all found frames
863 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
864 inb(iobase+UART_RX));
866 /* Make sure we don't stay here too long */
867 if (boguscount++ > 32) {
868 IRDA_DEBUG(2,"%s(), breaking!\n", __FUNCTION__);
871 } while (inb(iobase+UART_LSR) & UART_LSR_DR);
873 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
877 * Function ali_ircc_sir_write_wakeup (tty)
879 * Called by the driver when there's room for more data. If we have
880 * more packets to send, we send them here.
883 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self)
888 ASSERT(self != NULL, return;);
890 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
892 iobase = self->io.sir_base;
894 /* Finished with frame? */
895 if (self->tx_buff.len > 0)
897 /* Write data left in transmit buffer */
898 actual = ali_ircc_sir_write(iobase, self->io.fifo_size,
899 self->tx_buff.data, self->tx_buff.len);
900 self->tx_buff.data += actual;
901 self->tx_buff.len -= actual;
907 /* We must wait until all data are gone */
908 while(!(inb(iobase+UART_LSR) & UART_LSR_TEMT))
909 IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __FUNCTION__ );
911 IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __FUNCTION__ , self->new_speed);
912 ali_ircc_change_speed(self, self->new_speed);
915 // benjamin 2000/11/10 06:32PM
916 if (self->io.speed > 115200)
918 IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT \n", __FUNCTION__ );
921 // SetCOMInterrupts(self, TRUE);
927 netif_wake_queue(self->netdev);
930 self->stats.tx_packets++;
932 /* Turn on receive interrupts */
933 outb(UART_IER_RDI, iobase+UART_IER);
936 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
939 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud)
941 struct net_device *dev = self->netdev;
944 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
946 IRDA_DEBUG(2, "%s(), setting speed = %d \n", __FUNCTION__ , baud);
948 /* This function *must* be called with irq off and spin-lock.
951 iobase = self->io.fir_base;
953 SetCOMInterrupts(self, FALSE); // 2000/11/24 11:43AM
955 /* Go to MIR, FIR Speed */
960 ali_ircc_fir_change_speed(self, baud);
962 /* Install FIR xmit handler*/
963 dev->hard_start_xmit = ali_ircc_fir_hard_xmit;
965 /* Enable Interuupt */
966 self->ier = IER_EOM; // benjamin 2000/11/20 07:24PM
968 /* Be ready for incomming frames */
969 ali_ircc_dma_receive(self); // benajmin 2000/11/8 07:46PM not complete
971 /* Go to SIR Speed */
974 ali_ircc_sir_change_speed(self, baud);
976 /* Install SIR xmit handler*/
977 dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
981 SetCOMInterrupts(self, TRUE); // 2000/11/24 11:43AM
983 netif_wake_queue(self->netdev);
985 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
988 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 baud)
992 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
993 struct net_device *dev;
995 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
997 ASSERT(self != NULL, return;);
1000 iobase = self->io.fir_base;
1002 IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __FUNCTION__ ,self->io.speed,baud);
1004 /* Come from SIR speed */
1005 if(self->io.speed <=115200)
1010 /* Update accounting for new speed */
1011 self->io.speed = baud;
1013 // Set Dongle Speed mode
1014 ali_ircc_change_dongle_speed(self, baud);
1016 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1020 * Function ali_sir_change_speed (self, speed)
1022 * Set speed of IrDA port to specified baudrate
1025 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed)
1027 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
1028 unsigned long flags;
1030 int fcr; /* FIFO control reg */
1031 int lcr; /* Line control reg */
1034 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1036 IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __FUNCTION__ , speed);
1038 ASSERT(self != NULL, return;);
1040 iobase = self->io.sir_base;
1042 /* Come from MIR or FIR speed */
1043 if(self->io.speed >115200)
1045 // Set Dongle Speed mode first
1046 ali_ircc_change_dongle_speed(self, speed);
1051 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1053 inb(iobase+UART_LSR);
1054 inb(iobase+UART_SCR);
1056 /* Update accounting for new speed */
1057 self->io.speed = speed;
1059 spin_lock_irqsave(&self->lock, flags);
1061 divisor = 115200/speed;
1063 fcr = UART_FCR_ENABLE_FIFO;
1066 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1067 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1068 * about this timeout since it will always be fast enough.
1070 if (self->io.speed < 38400)
1071 fcr |= UART_FCR_TRIGGER_1;
1073 fcr |= UART_FCR_TRIGGER_14;
1075 /* IrDA ports use 8N1 */
1076 lcr = UART_LCR_WLEN8;
1078 outb(UART_LCR_DLAB | lcr, iobase+UART_LCR); /* Set DLAB */
1079 outb(divisor & 0xff, iobase+UART_DLL); /* Set speed */
1080 outb(divisor >> 8, iobase+UART_DLM);
1081 outb(lcr, iobase+UART_LCR); /* Set 8N1 */
1082 outb(fcr, iobase+UART_FCR); /* Enable FIFO's */
1084 /* without this, the conection will be broken after come back from FIR speed,
1085 but with this, the SIR connection is harder to established */
1086 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase+UART_MCR);
1088 spin_unlock_irqrestore(&self->lock, flags);
1090 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1093 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed)
1096 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
1097 int iobase,dongle_id;
1100 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1102 iobase = self->io.fir_base; /* or iobase = self->io.sir_base; */
1103 dongle_id = self->io.dongle_id;
1105 /* We are already locked, no need to do it again */
1107 IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __FUNCTION__ , dongle_types[dongle_id], speed);
1109 switch_bank(iobase, BANK2);
1110 tmp = inb(iobase+FIR_IRDA_CR);
1112 /* IBM type dongle */
1115 if(speed == 4000000)
1118 // SD/MODE __| |__ __
1123 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1124 tmp |= IRDA_CR_CRC; // CRC=1
1126 switch_bank(iobase, BANK2);
1127 outb(tmp, iobase+FIR_IRDA_CR);
1129 // T1 -> SD/MODE:0 IRTX:0
1132 outb(tmp, iobase+FIR_IRDA_CR);
1135 // T2 -> SD/MODE:1 IRTX:0
1138 outb(tmp, iobase+FIR_IRDA_CR);
1141 // T3 -> SD/MODE:1 IRTX:1
1143 outb(tmp, iobase+FIR_IRDA_CR);
1146 // T4 -> SD/MODE:0 IRTX:1
1149 outb(tmp, iobase+FIR_IRDA_CR);
1152 // T5 -> SD/MODE:0 IRTX:0
1155 outb(tmp, iobase+FIR_IRDA_CR);
1158 // reset -> Normal TX output Signal
1159 outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
1161 else /* speed <=1152000 */
1169 /* MIR 115200, 57600 */
1172 tmp |= 0xA0; //HDLC=1, 1.152Mbps=1
1176 tmp &=~0x80; //HDLC 0.576Mbps
1177 tmp |= 0x20; //HDLC=1,
1180 tmp |= IRDA_CR_CRC; // CRC=1
1182 switch_bank(iobase, BANK2);
1183 outb(tmp, iobase+FIR_IRDA_CR);
1185 /* MIR 115200, 57600 */
1187 //switch_bank(iobase, BANK2);
1188 // T1 -> SD/MODE:0 IRTX:0
1191 outb(tmp, iobase+FIR_IRDA_CR);
1194 // T2 -> SD/MODE:1 IRTX:0
1197 outb(tmp, iobase+FIR_IRDA_CR);
1199 // T3 -> SD/MODE:0 IRTX:0
1202 outb(tmp, iobase+FIR_IRDA_CR);
1205 // reset -> Normal TX output Signal
1206 outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
1209 else if (dongle_id == 1) /* HP HDSL-3600 */
1214 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1218 tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
1222 tmp &=~0x80; // HDLC 0.576Mbps
1223 tmp |= 0x20; // HDLC=1,
1227 tmp |= IRDA_CR_CRC; // CRC=1
1229 switch_bank(iobase, BANK2);
1230 outb(tmp, iobase+FIR_IRDA_CR);
1232 else /* HP HDSL-1100 */
1234 if(speed <= 115200) /* SIR */
1237 tmp &= ~IRDA_CR_FIR_SIN; // HP sin select = 0
1239 switch_bank(iobase, BANK2);
1240 outb(tmp, iobase+FIR_IRDA_CR);
1248 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1252 tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
1256 tmp &=~0x80; // HDLC 0.576Mbps
1257 tmp |= 0x20; // HDLC=1,
1261 tmp |= IRDA_CR_CRC; // CRC=1
1262 tmp |= IRDA_CR_FIR_SIN; // HP sin select = 1
1264 switch_bank(iobase, BANK2);
1265 outb(tmp, iobase+FIR_IRDA_CR);
1269 switch_bank(iobase, BANK0);
1271 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1275 * Function ali_ircc_sir_write (driver)
1277 * Fill Tx FIFO with transmit data
1280 static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1284 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1286 /* Tx FIFO should be empty! */
1287 if (!(inb(iobase+UART_LSR) & UART_LSR_THRE)) {
1288 IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __FUNCTION__ );
1292 /* Fill FIFO with current frame */
1293 while ((fifo_size-- > 0) && (actual < len)) {
1294 /* Transmit next byte */
1295 outb(buf[actual], iobase+UART_TX);
1300 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1305 * Function ali_ircc_net_open (dev)
1310 static int ali_ircc_net_open(struct net_device *dev)
1312 struct ali_ircc_cb *self;
1316 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1318 ASSERT(dev != NULL, return -1;);
1320 self = (struct ali_ircc_cb *) dev->priv;
1322 ASSERT(self != NULL, return 0;);
1324 iobase = self->io.fir_base;
1326 /* Request IRQ and install Interrupt Handler */
1327 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev))
1329 WARNING("%s, unable to allocate irq=%d\n", driver_name,
1335 * Always allocate the DMA channel after the IRQ, and clean up on
1338 if (request_dma(self->io.dma, dev->name)) {
1339 WARNING("%s, unable to allocate dma=%d\n", driver_name,
1341 free_irq(self->io.irq, self);
1345 /* Turn on interrups */
1346 outb(UART_IER_RDI , iobase+UART_IER);
1348 /* Ready to play! */
1349 netif_start_queue(dev); //benjamin by irport
1351 /* Give self a hardware name */
1352 sprintf(hwname, "ALI-FIR @ 0x%03x", self->io.fir_base);
1355 * Open new IrLAP layer instance, now that everything should be
1356 * initialized properly
1358 self->irlap = irlap_open(dev, &self->qos, hwname);
1360 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1366 * Function ali_ircc_net_close (dev)
1371 static int ali_ircc_net_close(struct net_device *dev)
1374 struct ali_ircc_cb *self;
1377 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1379 ASSERT(dev != NULL, return -1;);
1381 self = (struct ali_ircc_cb *) dev->priv;
1382 ASSERT(self != NULL, return 0;);
1385 netif_stop_queue(dev);
1387 /* Stop and remove instance of IrLAP */
1389 irlap_close(self->irlap);
1392 disable_dma(self->io.dma);
1394 /* Disable interrupts */
1395 SetCOMInterrupts(self, FALSE);
1397 free_irq(self->io.irq, dev);
1398 free_dma(self->io.dma);
1400 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1406 * Function ali_ircc_fir_hard_xmit (skb, dev)
1408 * Transmit the frame
1411 static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1413 struct ali_ircc_cb *self;
1414 unsigned long flags;
1419 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1421 self = (struct ali_ircc_cb *) dev->priv;
1422 iobase = self->io.fir_base;
1424 netif_stop_queue(dev);
1426 /* Make sure tests *& speed change are atomic */
1427 spin_lock_irqsave(&self->lock, flags);
1429 /* Note : you should make sure that speed changes are not going
1430 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1431 * details - Jean II */
1433 /* Check if we need to change the speed */
1434 speed = irda_get_next_speed(skb);
1435 if ((speed != self->io.speed) && (speed != -1)) {
1436 /* Check for empty frame */
1438 ali_ircc_change_speed(self, speed);
1439 dev->trans_start = jiffies;
1440 spin_unlock_irqrestore(&self->lock, flags);
1444 self->new_speed = speed;
1447 /* Register and copy this frame to DMA memory */
1448 self->tx_fifo.queue[self->tx_fifo.free].start = self->tx_fifo.tail;
1449 self->tx_fifo.queue[self->tx_fifo.free].len = skb->len;
1450 self->tx_fifo.tail += skb->len;
1452 self->stats.tx_bytes += skb->len;
1454 memcpy(self->tx_fifo.queue[self->tx_fifo.free].start, skb->data,
1457 self->tx_fifo.len++;
1458 self->tx_fifo.free++;
1460 /* Start transmit only if there is currently no transmit going on */
1461 if (self->tx_fifo.len == 1)
1463 /* Check if we must wait the min turn time or not */
1464 mtt = irda_get_mtt(skb);
1468 /* Check how much time we have used already */
1469 do_gettimeofday(&self->now);
1471 diff = self->now.tv_usec - self->stamp.tv_usec;
1472 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1474 IRDA_DEBUG(1, "%s(), ******* diff = %d ******* \n", __FUNCTION__ , diff);
1479 /* Check if the mtt is larger than the time we have
1480 * already used by all the protocol processing
1487 * Use timer if delay larger than 1000 us, and
1488 * use udelay for smaller values which should
1493 /* Adjust for timer resolution */
1494 mtt = (mtt+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1496 IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __FUNCTION__ , mtt);
1499 if (mtt == 1) /* 500 us */
1501 switch_bank(iobase, BANK1);
1502 outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR);
1504 else if (mtt == 2) /* 1 ms */
1506 switch_bank(iobase, BANK1);
1507 outb(TIMER_IIR_1ms, iobase+FIR_TIMER_IIR);
1509 else /* > 2ms -> 4ms */
1511 switch_bank(iobase, BANK1);
1512 outb(TIMER_IIR_2ms, iobase+FIR_TIMER_IIR);
1517 outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
1518 self->io.direction = IO_XMIT;
1520 /* Enable timer interrupt */
1521 self->ier = IER_TIMER;
1522 SetCOMInterrupts(self, TRUE);
1524 /* Timer will take care of the rest */
1529 } // if (if (mtt > diff)
1532 /* Enable EOM interrupt */
1533 self->ier = IER_EOM;
1534 SetCOMInterrupts(self, TRUE);
1536 /* Transmit frame */
1537 ali_ircc_dma_xmit(self);
1538 } // if (self->tx_fifo.len == 1)
1542 /* Not busy transmitting anymore if window is not full */
1543 if (self->tx_fifo.free < MAX_TX_WINDOW)
1544 netif_wake_queue(self->netdev);
1546 /* Restore bank register */
1547 switch_bank(iobase, BANK0);
1549 dev->trans_start = jiffies;
1550 spin_unlock_irqrestore(&self->lock, flags);
1553 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1558 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self)
1561 unsigned char FIFO_OPTI, Hi, Lo;
1564 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1566 iobase = self->io.fir_base;
1568 /* FIFO threshold , this method comes from NDIS5 code */
1570 if(self->tx_fifo.queue[self->tx_fifo.ptr].len < TX_FIFO_Threshold)
1571 FIFO_OPTI = self->tx_fifo.queue[self->tx_fifo.ptr].len-1;
1573 FIFO_OPTI = TX_FIFO_Threshold;
1576 switch_bank(iobase, BANK1);
1577 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1579 self->io.direction = IO_XMIT;
1581 irda_setup_dma(self->io.dma,
1582 ((u8 *)self->tx_fifo.queue[self->tx_fifo.ptr].start -
1583 self->tx_buff.head) + self->tx_buff_dma,
1584 self->tx_fifo.queue[self->tx_fifo.ptr].len,
1588 switch_bank(iobase, BANK0);
1589 outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
1591 /* Set Tx FIFO threshold */
1592 if (self->fifo_opti_buf!=FIFO_OPTI)
1594 switch_bank(iobase, BANK1);
1595 outb(FIFO_OPTI, iobase+FIR_FIFO_TR) ;
1596 self->fifo_opti_buf=FIFO_OPTI;
1599 /* Set Tx DMA threshold */
1600 switch_bank(iobase, BANK1);
1601 outb(TX_DMA_Threshold, iobase+FIR_DMA_TR);
1603 /* Set max Tx frame size */
1604 Hi = (self->tx_fifo.queue[self->tx_fifo.ptr].len >> 8) & 0x0f;
1605 Lo = self->tx_fifo.queue[self->tx_fifo.ptr].len & 0xff;
1606 switch_bank(iobase, BANK2);
1607 outb(Hi, iobase+FIR_TX_DSR_HI);
1608 outb(Lo, iobase+FIR_TX_DSR_LO);
1610 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1611 switch_bank(iobase, BANK0);
1612 tmp = inb(iobase+FIR_LCR_B);
1613 tmp &= ~0x20; // Disable SIP
1614 outb(((unsigned char)(tmp & 0x3f) | LCR_B_TX_MODE) & ~LCR_B_BW, iobase+FIR_LCR_B);
1615 IRDA_DEBUG(1, "%s(), ******* Change to TX mode: FIR_LCR_B = 0x%x ******* \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
1617 outb(0, iobase+FIR_LSR);
1619 /* Enable DMA and Burst Mode */
1620 switch_bank(iobase, BANK1);
1621 outb(inb(iobase+FIR_CR) | CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
1623 switch_bank(iobase, BANK0);
1625 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1628 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self)
1633 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1635 iobase = self->io.fir_base;
1638 switch_bank(iobase, BANK1);
1639 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1641 /* Check for underrun! */
1642 switch_bank(iobase, BANK0);
1643 if((inb(iobase+FIR_LSR) & LSR_FRAME_ABORT) == LSR_FRAME_ABORT)
1646 ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __FUNCTION__);
1647 self->stats.tx_errors++;
1648 self->stats.tx_fifo_errors++;
1652 self->stats.tx_packets++;
1655 /* Check if we need to change the speed */
1656 if (self->new_speed)
1658 ali_ircc_change_speed(self, self->new_speed);
1659 self->new_speed = 0;
1662 /* Finished with this frame, so prepare for next */
1663 self->tx_fifo.ptr++;
1664 self->tx_fifo.len--;
1666 /* Any frames to be sent back-to-back? */
1667 if (self->tx_fifo.len)
1669 ali_ircc_dma_xmit(self);
1671 /* Not finished yet! */
1675 { /* Reset Tx FIFO info */
1676 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
1677 self->tx_fifo.tail = self->tx_buff.head;
1680 /* Make sure we have room for more frames */
1681 if (self->tx_fifo.free < MAX_TX_WINDOW) {
1682 /* Not busy transmitting anymore */
1683 /* Tell the network layer, that we can accept more frames */
1684 netif_wake_queue(self->netdev);
1687 switch_bank(iobase, BANK0);
1689 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1694 * Function ali_ircc_dma_receive (self)
1696 * Get ready for receiving a frame. The device will initiate a DMA
1697 * if it starts to receive a frame.
1700 static int ali_ircc_dma_receive(struct ali_ircc_cb *self)
1704 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1706 iobase = self->io.fir_base;
1708 /* Reset Tx FIFO info */
1709 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
1710 self->tx_fifo.tail = self->tx_buff.head;
1713 switch_bank(iobase, BANK1);
1714 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1716 /* Reset Message Count */
1717 switch_bank(iobase, BANK0);
1718 outb(0x07, iobase+FIR_LSR);
1720 self->rcvFramesOverflow = FALSE;
1722 self->LineStatus = inb(iobase+FIR_LSR) ;
1724 /* Reset Rx FIFO info */
1725 self->io.direction = IO_RECV;
1726 self->rx_buff.data = self->rx_buff.head;
1729 // switch_bank(iobase, BANK0);
1730 outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
1732 self->st_fifo.len = self->st_fifo.pending_bytes = 0;
1733 self->st_fifo.tail = self->st_fifo.head = 0;
1735 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1738 /* Set Receive Mode,Brick Wall */
1739 //switch_bank(iobase, BANK0);
1740 tmp = inb(iobase+FIR_LCR_B);
1741 outb((unsigned char)(tmp &0x3f) | LCR_B_RX_MODE | LCR_B_BW , iobase + FIR_LCR_B); // 2000/12/1 05:16PM
1742 IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x *** \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
1744 /* Set Rx Threshold */
1745 switch_bank(iobase, BANK1);
1746 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
1747 outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
1749 /* Enable DMA and Burst Mode */
1750 // switch_bank(iobase, BANK1);
1751 outb(CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
1753 switch_bank(iobase, BANK0);
1754 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1758 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)
1760 struct st_fifo *st_fifo;
1761 struct sk_buff *skb;
1762 __u8 status, MessageCount;
1763 int len, i, iobase, val;
1765 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1767 st_fifo = &self->st_fifo;
1768 iobase = self->io.fir_base;
1770 switch_bank(iobase, BANK0);
1771 MessageCount = inb(iobase+ FIR_LSR)&0x07;
1773 if (MessageCount > 0)
1774 IRDA_DEBUG(0, "%s(), Messsage count = %d,\n", __FUNCTION__ , MessageCount);
1776 for (i=0; i<=MessageCount; i++)
1779 switch_bank(iobase, BANK0);
1780 status = inb(iobase+FIR_LSR);
1782 switch_bank(iobase, BANK2);
1783 len = inb(iobase+FIR_RX_DSR_HI) & 0x0f;
1785 len |= inb(iobase+FIR_RX_DSR_LO);
1787 IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __FUNCTION__ , len);
1788 IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __FUNCTION__ , status);
1790 if (st_fifo->tail >= MAX_RX_WINDOW) {
1791 IRDA_DEBUG(0, "%s(), window is full!\n", __FUNCTION__ );
1795 st_fifo->entries[st_fifo->tail].status = status;
1796 st_fifo->entries[st_fifo->tail].len = len;
1797 st_fifo->pending_bytes += len;
1802 for (i=0; i<=MessageCount; i++)
1804 /* Get first entry */
1805 status = st_fifo->entries[st_fifo->head].status;
1806 len = st_fifo->entries[st_fifo->head].len;
1807 st_fifo->pending_bytes -= len;
1811 /* Check for errors */
1812 if ((status & 0xd8) || self->rcvFramesOverflow || (len==0))
1814 IRDA_DEBUG(0,"%s(), ************* RX Errors ************ \n", __FUNCTION__ );
1817 self->stats.rx_errors++;
1819 self->rx_buff.data += len;
1821 if (status & LSR_FIFO_UR)
1823 self->stats.rx_frame_errors++;
1824 IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************ \n", __FUNCTION__ );
1826 if (status & LSR_FRAME_ERROR)
1828 self->stats.rx_frame_errors++;
1829 IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************ \n", __FUNCTION__ );
1832 if (status & LSR_CRC_ERROR)
1834 self->stats.rx_crc_errors++;
1835 IRDA_DEBUG(0,"%s(), ************* CRC Errors ************ \n", __FUNCTION__ );
1838 if(self->rcvFramesOverflow)
1840 self->stats.rx_frame_errors++;
1841 IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************ \n", __FUNCTION__ );
1845 self->stats.rx_frame_errors++;
1846 IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 ********* \n", __FUNCTION__ );
1852 if (st_fifo->pending_bytes < 32)
1854 switch_bank(iobase, BANK0);
1855 val = inb(iobase+FIR_BSR);
1856 if ((val& BSR_FIFO_NOT_EMPTY)== 0x80)
1858 IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************ \n", __FUNCTION__ );
1860 /* Put this entry back in fifo */
1863 st_fifo->pending_bytes += len;
1864 st_fifo->entries[st_fifo->head].status = status;
1865 st_fifo->entries[st_fifo->head].len = len;
1868 * DMA not finished yet, so try again
1869 * later, set timer value, resolution
1873 switch_bank(iobase, BANK1);
1874 outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR); // 2001/1/2 05:07PM
1877 outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
1879 return FALSE; /* I'll be back! */
1884 * Remember the time we received this frame, so we can
1885 * reduce the min turn time a bit since we will know
1886 * how much time we have used for protocol processing
1888 do_gettimeofday(&self->stamp);
1890 skb = dev_alloc_skb(len+1);
1893 WARNING("%s(), memory squeeze, "
1894 "dropping frame.\n", __FUNCTION__);
1895 self->stats.rx_dropped++;
1900 /* Make sure IP header gets aligned */
1901 skb_reserve(skb, 1);
1903 /* Copy frame without CRC, CRC is removed by hardware*/
1905 memcpy(skb->data, self->rx_buff.data, len);
1907 /* Move to next frame */
1908 self->rx_buff.data += len;
1909 self->stats.rx_bytes += len;
1910 self->stats.rx_packets++;
1912 skb->dev = self->netdev;
1913 skb->mac.raw = skb->data;
1914 skb->protocol = htons(ETH_P_IRDA);
1916 self->netdev->last_rx = jiffies;
1920 switch_bank(iobase, BANK0);
1922 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1929 * Function ali_ircc_sir_hard_xmit (skb, dev)
1931 * Transmit the frame!
1934 static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1936 struct ali_ircc_cb *self;
1937 unsigned long flags;
1941 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1943 ASSERT(dev != NULL, return 0;);
1945 self = (struct ali_ircc_cb *) dev->priv;
1946 ASSERT(self != NULL, return 0;);
1948 iobase = self->io.sir_base;
1950 netif_stop_queue(dev);
1952 /* Make sure tests *& speed change are atomic */
1953 spin_lock_irqsave(&self->lock, flags);
1955 /* Note : you should make sure that speed changes are not going
1956 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1957 * details - Jean II */
1959 /* Check if we need to change the speed */
1960 speed = irda_get_next_speed(skb);
1961 if ((speed != self->io.speed) && (speed != -1)) {
1962 /* Check for empty frame */
1964 ali_ircc_change_speed(self, speed);
1965 dev->trans_start = jiffies;
1966 spin_unlock_irqrestore(&self->lock, flags);
1970 self->new_speed = speed;
1973 /* Init tx buffer */
1974 self->tx_buff.data = self->tx_buff.head;
1976 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
1977 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
1978 self->tx_buff.truesize);
1980 self->stats.tx_bytes += self->tx_buff.len;
1982 /* Turn on transmit finished interrupt. Will fire immediately! */
1983 outb(UART_IER_THRI, iobase+UART_IER);
1985 dev->trans_start = jiffies;
1986 spin_unlock_irqrestore(&self->lock, flags);
1990 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1997 * Function ali_ircc_net_ioctl (dev, rq, cmd)
1999 * Process IOCTL commands for this device
2002 static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2004 struct if_irda_req *irq = (struct if_irda_req *) rq;
2005 struct ali_ircc_cb *self;
2006 unsigned long flags;
2009 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2011 ASSERT(dev != NULL, return -1;);
2015 ASSERT(self != NULL, return -1;);
2017 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__ , dev->name, cmd);
2020 case SIOCSBANDWIDTH: /* Set bandwidth */
2021 IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __FUNCTION__ );
2023 * This function will also be used by IrLAP to change the
2024 * speed, so we still must allow for speed change within
2025 * interrupt context.
2027 if (!in_interrupt() && !capable(CAP_NET_ADMIN))
2030 spin_lock_irqsave(&self->lock, flags);
2031 ali_ircc_change_speed(self, irq->ifr_baudrate);
2032 spin_unlock_irqrestore(&self->lock, flags);
2034 case SIOCSMEDIABUSY: /* Set media busy */
2035 IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __FUNCTION__ );
2036 if (!capable(CAP_NET_ADMIN))
2038 irda_device_set_media_busy(self->netdev, TRUE);
2040 case SIOCGRECEIVING: /* Check if we are receiving right now */
2041 IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __FUNCTION__ );
2042 /* This is protected */
2043 irq->ifr_receiving = ali_ircc_is_receiving(self);
2049 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2055 * Function ali_ircc_is_receiving (self)
2057 * Return TRUE is we are currently receiving a frame
2060 static int ali_ircc_is_receiving(struct ali_ircc_cb *self)
2062 unsigned long flags;
2066 IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
2068 ASSERT(self != NULL, return FALSE;);
2070 spin_lock_irqsave(&self->lock, flags);
2072 if (self->io.speed > 115200)
2074 iobase = self->io.fir_base;
2076 switch_bank(iobase, BANK1);
2077 if((inb(iobase+FIR_FIFO_FR) & 0x3f) != 0)
2079 /* We are receiving something */
2080 IRDA_DEBUG(1, "%s(), We are receiving something\n", __FUNCTION__ );
2083 switch_bank(iobase, BANK0);
2087 status = (self->rx_buff.state != OUTSIDE_FRAME);
2090 spin_unlock_irqrestore(&self->lock, flags);
2092 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2097 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev)
2099 struct ali_ircc_cb *self = (struct ali_ircc_cb *) dev->priv;
2101 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2103 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2105 return &self->stats;
2108 static void ali_ircc_suspend(struct ali_ircc_cb *self)
2110 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2112 MESSAGE("%s, Suspending\n", driver_name);
2114 if (self->io.suspended)
2117 ali_ircc_net_close(self->netdev);
2119 self->io.suspended = 1;
2121 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2124 static void ali_ircc_wakeup(struct ali_ircc_cb *self)
2126 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2128 if (!self->io.suspended)
2131 ali_ircc_net_open(self->netdev);
2133 MESSAGE("%s, Waking up\n", driver_name);
2135 self->io.suspended = 0;
2137 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2140 static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
2142 struct ali_ircc_cb *self = (struct ali_ircc_cb*) dev->data;
2144 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2149 ali_ircc_suspend(self);
2152 ali_ircc_wakeup(self);
2157 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2163 /* ALi Chip Function */
2165 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)
2168 unsigned char newMask;
2170 int iobase = self->io.fir_base; /* or sir_base */
2172 IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __FUNCTION__ , enable);
2174 /* Enable the interrupt which we wish to */
2176 if (self->io.direction == IO_XMIT)
2178 if (self->io.speed > 115200) /* FIR, MIR */
2180 newMask = self->ier;
2184 newMask = UART_IER_THRI | UART_IER_RDI;
2188 if (self->io.speed > 115200) /* FIR, MIR */
2190 newMask = self->ier;
2194 newMask = UART_IER_RDI;
2198 else /* Disable all the interrupts */
2204 //SIR and FIR has different registers
2205 if (self->io.speed > 115200)
2207 switch_bank(iobase, BANK0);
2208 outb(newMask, iobase+FIR_IER);
2211 outb(newMask, iobase+UART_IER);
2213 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2216 static void SIR2FIR(int iobase)
2218 //unsigned char tmp;
2220 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2222 /* Already protected (change_speed() or setup()), no need to lock.
2225 outb(0x28, iobase+UART_MCR);
2226 outb(0x68, iobase+UART_MCR);
2227 outb(0x88, iobase+UART_MCR);
2229 outb(0x60, iobase+FIR_MCR); /* Master Reset */
2230 outb(0x20, iobase+FIR_MCR); /* Master Interrupt Enable */
2232 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2234 //outb(tmp, iobase+FIR_LCR_B);
2236 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2239 static void FIR2SIR(int iobase)
2243 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2245 /* Already protected (change_speed() or setup()), no need to lock.
2248 outb(0x20, iobase+FIR_MCR); /* IRQ to low */
2249 outb(0x00, iobase+UART_IER);
2251 outb(0xA0, iobase+FIR_MCR); /* Don't set master reset */
2252 outb(0x00, iobase+UART_FCR);
2253 outb(0x07, iobase+UART_FCR);
2255 val = inb(iobase+UART_RX);
2256 val = inb(iobase+UART_LSR);
2257 val = inb(iobase+UART_MSR);
2259 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2262 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2263 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2264 MODULE_LICENSE("GPL");
2267 MODULE_PARM(io, "1-4i");
2268 MODULE_PARM_DESC(io, "Base I/O addresses");
2269 MODULE_PARM(irq, "1-4i");
2270 MODULE_PARM_DESC(irq, "IRQ lines");
2271 MODULE_PARM(dma, "1-4i");
2272 MODULE_PARM_DESC(dma, "DMA channels");
2274 module_init(ali_ircc_init);
2275 module_exit(ali_ircc_cleanup);