Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / drivers / net / irda / ali-ircc.c
blob9f584521304a8a84ce5e8230f43df2fa72def8b3
1 /*********************************************************************
2 *
3 * Filename: ali-ircc.h
4 * Version: 0.5
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>
15 * All Rights Reserved
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>
37 #include <linux/platform_device.h>
39 #include <asm/io.h>
40 #include <asm/dma.h>
41 #include <asm/byteorder.h>
43 #include <net/irda/wrapper.h>
44 #include <net/irda/irda.h>
45 #include <net/irda/irda_device.h>
47 #include "ali-ircc.h"
49 #define CHIP_IO_EXTENT 8
50 #define BROKEN_DONGLE_ID
52 #define ALI_IRCC_DRIVER_NAME "ali-ircc"
54 /* Power Management */
55 static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state);
56 static int ali_ircc_resume(struct platform_device *dev);
58 static struct platform_driver ali_ircc_driver = {
59 .suspend = ali_ircc_suspend,
60 .resume = ali_ircc_resume,
61 .driver = {
62 .name = ALI_IRCC_DRIVER_NAME,
66 /* Module parameters */
67 static int qos_mtt_bits = 0x07; /* 1 ms or more */
69 /* Use BIOS settions by default, but user may supply module parameters */
70 static unsigned int io[] = { ~0, ~0, ~0, ~0 };
71 static unsigned int irq[] = { 0, 0, 0, 0 };
72 static unsigned int dma[] = { 0, 0, 0, 0 };
74 static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info);
75 static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info);
76 static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info);
78 /* These are the currently known ALi sourth-bridge chipsets, the only one difference
79 * is that M1543C doesn't support HP HDSL-3600
81 static ali_chip_t chips[] =
83 { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53, ali_ircc_init_43 },
84 { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53, ali_ircc_init_53 },
85 { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53, ali_ircc_init_53 },
86 { NULL }
89 /* Max 4 instances for now */
90 static struct ali_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
92 /* Dongle Types */
93 static char *dongle_types[] = {
94 "TFDS6000",
95 "HP HSDL-3600",
96 "HP HSDL-1100",
97 "No dongle connected",
100 /* Some prototypes */
101 static int ali_ircc_open(int i, chipio_t *info);
103 static int ali_ircc_close(struct ali_ircc_cb *self);
105 static int ali_ircc_setup(chipio_t *info);
106 static int ali_ircc_is_receiving(struct ali_ircc_cb *self);
107 static int ali_ircc_net_open(struct net_device *dev);
108 static int ali_ircc_net_close(struct net_device *dev);
109 static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
110 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
111 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev);
113 /* SIR function */
114 static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
115 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self);
116 static void ali_ircc_sir_receive(struct ali_ircc_cb *self);
117 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self);
118 static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
119 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
121 /* FIR function */
122 static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev);
123 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
124 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self);
125 static int ali_ircc_dma_receive(struct ali_ircc_cb *self);
126 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self);
127 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self);
128 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self);
130 /* My Function */
131 static int ali_ircc_read_dongle_id (int i, chipio_t *info);
132 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed);
134 /* ALi chip function */
135 static void SIR2FIR(int iobase);
136 static void FIR2SIR(int iobase);
137 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable);
140 * Function ali_ircc_init ()
142 * Initialize chip. Find out whay kinds of chips we are dealing with
143 * and their configuation registers address
145 static int __init ali_ircc_init(void)
147 ali_chip_t *chip;
148 chipio_t info;
149 int ret;
150 int cfg, cfg_base;
151 int reg, revision;
152 int i = 0;
154 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
156 ret = platform_driver_register(&ali_ircc_driver);
157 if (ret) {
158 IRDA_ERROR("%s, Can't register driver!\n",
159 ALI_IRCC_DRIVER_NAME);
160 return ret;
163 ret = -ENODEV;
165 /* Probe for all the ALi chipsets we know about */
166 for (chip= chips; chip->name; chip++, i++)
168 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__, chip->name);
170 /* Try all config registers for this chip */
171 for (cfg=0; cfg<2; cfg++)
173 cfg_base = chip->cfg[cfg];
174 if (!cfg_base)
175 continue;
177 memset(&info, 0, sizeof(chipio_t));
178 info.cfg_base = cfg_base;
179 info.fir_base = io[i];
180 info.dma = dma[i];
181 info.irq = irq[i];
184 /* Enter Configuration */
185 outb(chip->entr1, cfg_base);
186 outb(chip->entr2, cfg_base);
188 /* Select Logical Device 5 Registers (UART2) */
189 outb(0x07, cfg_base);
190 outb(0x05, cfg_base+1);
192 /* Read Chip Identification Register */
193 outb(chip->cid_index, cfg_base);
194 reg = inb(cfg_base+1);
196 if (reg == chip->cid_value)
198 IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __FUNCTION__, cfg_base);
200 outb(0x1F, cfg_base);
201 revision = inb(cfg_base+1);
202 IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __FUNCTION__,
203 chip->name, revision);
206 * If the user supplies the base address, then
207 * we init the chip, if not we probe the values
208 * set by the BIOS
210 if (io[i] < 2000)
212 chip->init(chip, &info);
214 else
216 chip->probe(chip, &info);
219 if (ali_ircc_open(i, &info) == 0)
220 ret = 0;
221 i++;
223 else
225 IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __FUNCTION__, chip->name, cfg_base);
227 /* Exit configuration */
228 outb(0xbb, cfg_base);
232 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
234 if (ret)
235 platform_driver_unregister(&ali_ircc_driver);
237 return ret;
241 * Function ali_ircc_cleanup ()
243 * Close all configured chips
246 static void __exit ali_ircc_cleanup(void)
248 int i;
250 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
252 for (i=0; i < ARRAY_SIZE(dev_self); i++) {
253 if (dev_self[i])
254 ali_ircc_close(dev_self[i]);
257 platform_driver_unregister(&ali_ircc_driver);
259 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
263 * Function ali_ircc_open (int i, chipio_t *inf)
265 * Open driver instance
268 static int ali_ircc_open(int i, chipio_t *info)
270 struct net_device *dev;
271 struct ali_ircc_cb *self;
272 int dongle_id;
273 int err;
275 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
277 if (i >= ARRAY_SIZE(dev_self)) {
278 IRDA_ERROR("%s(), maximum number of supported chips reached!\n",
279 __FUNCTION__);
280 return -ENOMEM;
283 /* Set FIR FIFO and DMA Threshold */
284 if ((ali_ircc_setup(info)) == -1)
285 return -1;
287 dev = alloc_irdadev(sizeof(*self));
288 if (dev == NULL) {
289 IRDA_ERROR("%s(), can't allocate memory for control block!\n",
290 __FUNCTION__);
291 return -ENOMEM;
294 self = dev->priv;
295 self->netdev = dev;
296 spin_lock_init(&self->lock);
298 /* Need to store self somewhere */
299 dev_self[i] = self;
300 self->index = i;
302 /* Initialize IO */
303 self->io.cfg_base = info->cfg_base; /* In ali_ircc_probe_53 assign */
304 self->io.fir_base = info->fir_base; /* info->sir_base = info->fir_base */
305 self->io.sir_base = info->sir_base; /* ALi SIR and FIR use the same address */
306 self->io.irq = info->irq;
307 self->io.fir_ext = CHIP_IO_EXTENT;
308 self->io.dma = info->dma;
309 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
311 /* Reserve the ioports that we need */
312 if (!request_region(self->io.fir_base, self->io.fir_ext,
313 ALI_IRCC_DRIVER_NAME)) {
314 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
315 self->io.fir_base);
316 err = -ENODEV;
317 goto err_out1;
320 /* Initialize QoS for this device */
321 irda_init_max_qos_capabilies(&self->qos);
323 /* The only value we must override it the baudrate */
324 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
325 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); // benjamin 2000/11/8 05:27PM
327 self->qos.min_turn_time.bits = qos_mtt_bits;
329 irda_qos_bits_to_value(&self->qos);
331 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
332 self->rx_buff.truesize = 14384;
333 self->tx_buff.truesize = 14384;
335 /* Allocate memory if needed */
336 self->rx_buff.head =
337 dma_alloc_coherent(NULL, self->rx_buff.truesize,
338 &self->rx_buff_dma, GFP_KERNEL);
339 if (self->rx_buff.head == NULL) {
340 err = -ENOMEM;
341 goto err_out2;
343 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
345 self->tx_buff.head =
346 dma_alloc_coherent(NULL, self->tx_buff.truesize,
347 &self->tx_buff_dma, GFP_KERNEL);
348 if (self->tx_buff.head == NULL) {
349 err = -ENOMEM;
350 goto err_out3;
352 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
354 self->rx_buff.in_frame = FALSE;
355 self->rx_buff.state = OUTSIDE_FRAME;
356 self->tx_buff.data = self->tx_buff.head;
357 self->rx_buff.data = self->rx_buff.head;
359 /* Reset Tx queue info */
360 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
361 self->tx_fifo.tail = self->tx_buff.head;
363 /* Override the network functions we need to use */
364 dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
365 dev->open = ali_ircc_net_open;
366 dev->stop = ali_ircc_net_close;
367 dev->do_ioctl = ali_ircc_net_ioctl;
368 dev->get_stats = ali_ircc_net_get_stats;
370 err = register_netdev(dev);
371 if (err) {
372 IRDA_ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
373 goto err_out4;
375 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
377 /* Check dongle id */
378 dongle_id = ali_ircc_read_dongle_id(i, info);
379 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__,
380 ALI_IRCC_DRIVER_NAME, dongle_types[dongle_id]);
382 self->io.dongle_id = dongle_id;
384 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
386 return 0;
388 err_out4:
389 dma_free_coherent(NULL, self->tx_buff.truesize,
390 self->tx_buff.head, self->tx_buff_dma);
391 err_out3:
392 dma_free_coherent(NULL, self->rx_buff.truesize,
393 self->rx_buff.head, self->rx_buff_dma);
394 err_out2:
395 release_region(self->io.fir_base, self->io.fir_ext);
396 err_out1:
397 dev_self[i] = NULL;
398 free_netdev(dev);
399 return err;
404 * Function ali_ircc_close (self)
406 * Close driver instance
409 static int __exit ali_ircc_close(struct ali_ircc_cb *self)
411 int iobase;
413 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
415 IRDA_ASSERT(self != NULL, return -1;);
417 iobase = self->io.fir_base;
419 /* Remove netdevice */
420 unregister_netdev(self->netdev);
422 /* Release the PORT that this driver is using */
423 IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __FUNCTION__, self->io.fir_base);
424 release_region(self->io.fir_base, self->io.fir_ext);
426 if (self->tx_buff.head)
427 dma_free_coherent(NULL, self->tx_buff.truesize,
428 self->tx_buff.head, self->tx_buff_dma);
430 if (self->rx_buff.head)
431 dma_free_coherent(NULL, self->rx_buff.truesize,
432 self->rx_buff.head, self->rx_buff_dma);
434 dev_self[self->index] = NULL;
435 free_netdev(self->netdev);
437 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
439 return 0;
443 * Function ali_ircc_init_43 (chip, info)
445 * Initialize the ALi M1543 chip.
447 static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info)
449 /* All controller information like I/O address, DMA channel, IRQ
450 * are set by BIOS
453 return 0;
457 * Function ali_ircc_init_53 (chip, info)
459 * Initialize the ALi M1535 chip.
461 static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info)
463 /* All controller information like I/O address, DMA channel, IRQ
464 * are set by BIOS
467 return 0;
471 * Function ali_ircc_probe_53 (chip, info)
473 * Probes for the ALi M1535D or M1535
475 static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info)
477 int cfg_base = info->cfg_base;
478 int hi, low, reg;
480 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
482 /* Enter Configuration */
483 outb(chip->entr1, cfg_base);
484 outb(chip->entr2, cfg_base);
486 /* Select Logical Device 5 Registers (UART2) */
487 outb(0x07, cfg_base);
488 outb(0x05, cfg_base+1);
490 /* Read address control register */
491 outb(0x60, cfg_base);
492 hi = inb(cfg_base+1);
493 outb(0x61, cfg_base);
494 low = inb(cfg_base+1);
495 info->fir_base = (hi<<8) + low;
497 info->sir_base = info->fir_base;
499 IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __FUNCTION__, info->fir_base);
501 /* Read IRQ control register */
502 outb(0x70, cfg_base);
503 reg = inb(cfg_base+1);
504 info->irq = reg & 0x0f;
505 IRDA_DEBUG(2, "%s(), probing irq=%d\n", __FUNCTION__, info->irq);
507 /* Read DMA channel */
508 outb(0x74, cfg_base);
509 reg = inb(cfg_base+1);
510 info->dma = reg & 0x07;
512 if(info->dma == 0x04)
513 IRDA_WARNING("%s(), No DMA channel assigned !\n", __FUNCTION__);
514 else
515 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __FUNCTION__, info->dma);
517 /* Read Enabled Status */
518 outb(0x30, cfg_base);
519 reg = inb(cfg_base+1);
520 info->enabled = (reg & 0x80) && (reg & 0x01);
521 IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __FUNCTION__, info->enabled);
523 /* Read Power Status */
524 outb(0x22, cfg_base);
525 reg = inb(cfg_base+1);
526 info->suspended = (reg & 0x20);
527 IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __FUNCTION__, info->suspended);
529 /* Exit configuration */
530 outb(0xbb, cfg_base);
532 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
534 return 0;
538 * Function ali_ircc_setup (info)
540 * Set FIR FIFO and DMA Threshold
541 * Returns non-negative on success.
544 static int ali_ircc_setup(chipio_t *info)
546 unsigned char tmp;
547 int version;
548 int iobase = info->fir_base;
550 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
552 /* Locking comments :
553 * Most operations here need to be protected. We are called before
554 * the device instance is created in ali_ircc_open(), therefore
555 * nobody can bother us - Jean II */
557 /* Switch to FIR space */
558 SIR2FIR(iobase);
560 /* Master Reset */
561 outb(0x40, iobase+FIR_MCR); // benjamin 2000/11/30 11:45AM
563 /* Read FIR ID Version Register */
564 switch_bank(iobase, BANK3);
565 version = inb(iobase+FIR_ID_VR);
567 /* Should be 0x00 in the M1535/M1535D */
568 if(version != 0x00)
570 IRDA_ERROR("%s, Wrong chip version %02x\n",
571 ALI_IRCC_DRIVER_NAME, version);
572 return -1;
575 /* Set FIR FIFO Threshold Register */
576 switch_bank(iobase, BANK1);
577 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
579 /* Set FIR DMA Threshold Register */
580 outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
582 /* CRC enable */
583 switch_bank(iobase, BANK2);
584 outb(inb(iobase+FIR_IRDA_CR) | IRDA_CR_CRC, iobase+FIR_IRDA_CR);
586 /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
588 /* Switch to Bank 0 */
589 switch_bank(iobase, BANK0);
591 tmp = inb(iobase+FIR_LCR_B);
592 tmp &=~0x20; // disable SIP
593 tmp |= 0x80; // these two steps make RX mode
594 tmp &= 0xbf;
595 outb(tmp, iobase+FIR_LCR_B);
597 /* Disable Interrupt */
598 outb(0x00, iobase+FIR_IER);
601 /* Switch to SIR space */
602 FIR2SIR(iobase);
604 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
605 ALI_IRCC_DRIVER_NAME);
607 /* Enable receive interrupts */
608 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
609 // Turn on the interrupts in ali_ircc_net_open
611 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
613 return 0;
617 * Function ali_ircc_read_dongle_id (int index, info)
619 * Try to read dongle indentification. This procedure needs to be executed
620 * once after power-on/reset. It also needs to be used whenever you suspect
621 * that the user may have plugged/unplugged the IrDA Dongle.
623 static int ali_ircc_read_dongle_id (int i, chipio_t *info)
625 int dongle_id, reg;
626 int cfg_base = info->cfg_base;
628 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
630 /* Enter Configuration */
631 outb(chips[i].entr1, cfg_base);
632 outb(chips[i].entr2, cfg_base);
634 /* Select Logical Device 5 Registers (UART2) */
635 outb(0x07, cfg_base);
636 outb(0x05, cfg_base+1);
638 /* Read Dongle ID */
639 outb(0xf0, cfg_base);
640 reg = inb(cfg_base+1);
641 dongle_id = ((reg>>6)&0x02) | ((reg>>5)&0x01);
642 IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __FUNCTION__,
643 dongle_id, dongle_types[dongle_id]);
645 /* Exit configuration */
646 outb(0xbb, cfg_base);
648 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
650 return dongle_id;
654 * Function ali_ircc_interrupt (irq, dev_id, regs)
656 * An interrupt from the chip has arrived. Time to do some work
659 static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id)
661 struct net_device *dev = dev_id;
662 struct ali_ircc_cb *self;
663 int ret;
665 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
667 self = dev->priv;
669 spin_lock(&self->lock);
671 /* Dispatch interrupt handler for the current speed */
672 if (self->io.speed > 115200)
673 ret = ali_ircc_fir_interrupt(self);
674 else
675 ret = ali_ircc_sir_interrupt(self);
677 spin_unlock(&self->lock);
679 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
680 return ret;
683 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
685 * Handle MIR/FIR interrupt
688 static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self)
690 __u8 eir, OldMessageCount;
691 int iobase, tmp;
693 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
695 iobase = self->io.fir_base;
697 switch_bank(iobase, BANK0);
698 self->InterruptID = inb(iobase+FIR_IIR);
699 self->BusStatus = inb(iobase+FIR_BSR);
701 OldMessageCount = (self->LineStatus + 1) & 0x07;
702 self->LineStatus = inb(iobase+FIR_LSR);
703 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
704 eir = self->InterruptID & self->ier; /* Mask out the interesting ones */
706 IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __FUNCTION__,self->InterruptID);
707 IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __FUNCTION__,self->LineStatus);
708 IRDA_DEBUG(1, "%s(), self->ier = %x\n", __FUNCTION__,self->ier);
709 IRDA_DEBUG(1, "%s(), eir = %x\n", __FUNCTION__,eir);
711 /* Disable interrupts */
712 SetCOMInterrupts(self, FALSE);
714 /* Tx or Rx Interrupt */
716 if (eir & IIR_EOM)
718 if (self->io.direction == IO_XMIT) /* TX */
720 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __FUNCTION__);
722 if(ali_ircc_dma_xmit_complete(self))
724 if (irda_device_txqueue_empty(self->netdev))
726 /* Prepare for receive */
727 ali_ircc_dma_receive(self);
728 self->ier = IER_EOM;
731 else
733 self->ier = IER_EOM;
737 else /* RX */
739 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __FUNCTION__);
741 if(OldMessageCount > ((self->LineStatus+1) & 0x07))
743 self->rcvFramesOverflow = TRUE;
744 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******** \n", __FUNCTION__);
747 if (ali_ircc_dma_receive_complete(self))
749 IRDA_DEBUG(1, "%s(), ******* receive complete ******** \n", __FUNCTION__);
751 self->ier = IER_EOM;
753 else
755 IRDA_DEBUG(1, "%s(), ******* Not receive complete ******** \n", __FUNCTION__);
757 self->ier = IER_EOM | IER_TIMER;
762 /* Timer Interrupt */
763 else if (eir & IIR_TIMER)
765 if(OldMessageCount > ((self->LineStatus+1) & 0x07))
767 self->rcvFramesOverflow = TRUE;
768 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******* \n", __FUNCTION__);
770 /* Disable Timer */
771 switch_bank(iobase, BANK1);
772 tmp = inb(iobase+FIR_CR);
773 outb( tmp& ~CR_TIMER_EN, iobase+FIR_CR);
775 /* Check if this is a Tx timer interrupt */
776 if (self->io.direction == IO_XMIT)
778 ali_ircc_dma_xmit(self);
780 /* Interrupt on EOM */
781 self->ier = IER_EOM;
784 else /* Rx */
786 if(ali_ircc_dma_receive_complete(self))
788 self->ier = IER_EOM;
790 else
792 self->ier = IER_EOM | IER_TIMER;
797 /* Restore Interrupt */
798 SetCOMInterrupts(self, TRUE);
800 IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __FUNCTION__);
801 return IRQ_RETVAL(eir);
805 * Function ali_ircc_sir_interrupt (irq, self, eir)
807 * Handle SIR interrupt
810 static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self)
812 int iobase;
813 int iir, lsr;
815 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
817 iobase = self->io.sir_base;
819 iir = inb(iobase+UART_IIR) & UART_IIR_ID;
820 if (iir) {
821 /* Clear interrupt */
822 lsr = inb(iobase+UART_LSR);
824 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __FUNCTION__,
825 iir, lsr, iobase);
827 switch (iir)
829 case UART_IIR_RLSI:
830 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
831 break;
832 case UART_IIR_RDI:
833 /* Receive interrupt */
834 ali_ircc_sir_receive(self);
835 break;
836 case UART_IIR_THRI:
837 if (lsr & UART_LSR_THRE)
839 /* Transmitter ready for data */
840 ali_ircc_sir_write_wakeup(self);
842 break;
843 default:
844 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __FUNCTION__, iir);
845 break;
851 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__);
853 return IRQ_RETVAL(iir);
858 * Function ali_ircc_sir_receive (self)
860 * Receive one frame from the infrared port
863 static void ali_ircc_sir_receive(struct ali_ircc_cb *self)
865 int boguscount = 0;
866 int iobase;
868 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
869 IRDA_ASSERT(self != NULL, return;);
871 iobase = self->io.sir_base;
874 * Receive all characters in Rx FIFO, unwrap and unstuff them.
875 * async_unwrap_char will deliver all found frames
877 do {
878 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
879 inb(iobase+UART_RX));
881 /* Make sure we don't stay here too long */
882 if (boguscount++ > 32) {
883 IRDA_DEBUG(2,"%s(), breaking!\n", __FUNCTION__);
884 break;
886 } while (inb(iobase+UART_LSR) & UART_LSR_DR);
888 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
892 * Function ali_ircc_sir_write_wakeup (tty)
894 * Called by the driver when there's room for more data. If we have
895 * more packets to send, we send them here.
898 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self)
900 int actual = 0;
901 int iobase;
903 IRDA_ASSERT(self != NULL, return;);
905 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
907 iobase = self->io.sir_base;
909 /* Finished with frame? */
910 if (self->tx_buff.len > 0)
912 /* Write data left in transmit buffer */
913 actual = ali_ircc_sir_write(iobase, self->io.fifo_size,
914 self->tx_buff.data, self->tx_buff.len);
915 self->tx_buff.data += actual;
916 self->tx_buff.len -= actual;
918 else
920 if (self->new_speed)
922 /* We must wait until all data are gone */
923 while(!(inb(iobase+UART_LSR) & UART_LSR_TEMT))
924 IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __FUNCTION__ );
926 IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __FUNCTION__ , self->new_speed);
927 ali_ircc_change_speed(self, self->new_speed);
928 self->new_speed = 0;
930 // benjamin 2000/11/10 06:32PM
931 if (self->io.speed > 115200)
933 IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT \n", __FUNCTION__ );
935 self->ier = IER_EOM;
936 // SetCOMInterrupts(self, TRUE);
937 return;
940 else
942 netif_wake_queue(self->netdev);
945 self->stats.tx_packets++;
947 /* Turn on receive interrupts */
948 outb(UART_IER_RDI, iobase+UART_IER);
951 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
954 static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud)
956 struct net_device *dev = self->netdev;
957 int iobase;
959 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
961 IRDA_DEBUG(2, "%s(), setting speed = %d \n", __FUNCTION__ , baud);
963 /* This function *must* be called with irq off and spin-lock.
964 * - Jean II */
966 iobase = self->io.fir_base;
968 SetCOMInterrupts(self, FALSE); // 2000/11/24 11:43AM
970 /* Go to MIR, FIR Speed */
971 if (baud > 115200)
975 ali_ircc_fir_change_speed(self, baud);
977 /* Install FIR xmit handler*/
978 dev->hard_start_xmit = ali_ircc_fir_hard_xmit;
980 /* Enable Interuupt */
981 self->ier = IER_EOM; // benjamin 2000/11/20 07:24PM
983 /* Be ready for incomming frames */
984 ali_ircc_dma_receive(self); // benajmin 2000/11/8 07:46PM not complete
986 /* Go to SIR Speed */
987 else
989 ali_ircc_sir_change_speed(self, baud);
991 /* Install SIR xmit handler*/
992 dev->hard_start_xmit = ali_ircc_sir_hard_xmit;
996 SetCOMInterrupts(self, TRUE); // 2000/11/24 11:43AM
998 netif_wake_queue(self->netdev);
1000 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1003 static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 baud)
1006 int iobase;
1007 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
1008 struct net_device *dev;
1010 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1012 IRDA_ASSERT(self != NULL, return;);
1014 dev = self->netdev;
1015 iobase = self->io.fir_base;
1017 IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __FUNCTION__ ,self->io.speed,baud);
1019 /* Come from SIR speed */
1020 if(self->io.speed <=115200)
1022 SIR2FIR(iobase);
1025 /* Update accounting for new speed */
1026 self->io.speed = baud;
1028 // Set Dongle Speed mode
1029 ali_ircc_change_dongle_speed(self, baud);
1031 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1035 * Function ali_sir_change_speed (self, speed)
1037 * Set speed of IrDA port to specified baudrate
1040 static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed)
1042 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
1043 unsigned long flags;
1044 int iobase;
1045 int fcr; /* FIFO control reg */
1046 int lcr; /* Line control reg */
1047 int divisor;
1049 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1051 IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __FUNCTION__ , speed);
1053 IRDA_ASSERT(self != NULL, return;);
1055 iobase = self->io.sir_base;
1057 /* Come from MIR or FIR speed */
1058 if(self->io.speed >115200)
1060 // Set Dongle Speed mode first
1061 ali_ircc_change_dongle_speed(self, speed);
1063 FIR2SIR(iobase);
1066 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1068 inb(iobase+UART_LSR);
1069 inb(iobase+UART_SCR);
1071 /* Update accounting for new speed */
1072 self->io.speed = speed;
1074 spin_lock_irqsave(&self->lock, flags);
1076 divisor = 115200/speed;
1078 fcr = UART_FCR_ENABLE_FIFO;
1081 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1082 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1083 * about this timeout since it will always be fast enough.
1085 if (self->io.speed < 38400)
1086 fcr |= UART_FCR_TRIGGER_1;
1087 else
1088 fcr |= UART_FCR_TRIGGER_14;
1090 /* IrDA ports use 8N1 */
1091 lcr = UART_LCR_WLEN8;
1093 outb(UART_LCR_DLAB | lcr, iobase+UART_LCR); /* Set DLAB */
1094 outb(divisor & 0xff, iobase+UART_DLL); /* Set speed */
1095 outb(divisor >> 8, iobase+UART_DLM);
1096 outb(lcr, iobase+UART_LCR); /* Set 8N1 */
1097 outb(fcr, iobase+UART_FCR); /* Enable FIFO's */
1099 /* without this, the conection will be broken after come back from FIR speed,
1100 but with this, the SIR connection is harder to established */
1101 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase+UART_MCR);
1103 spin_unlock_irqrestore(&self->lock, flags);
1105 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1108 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed)
1111 struct ali_ircc_cb *self = (struct ali_ircc_cb *) priv;
1112 int iobase,dongle_id;
1113 int tmp = 0;
1115 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1117 iobase = self->io.fir_base; /* or iobase = self->io.sir_base; */
1118 dongle_id = self->io.dongle_id;
1120 /* We are already locked, no need to do it again */
1122 IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __FUNCTION__ , dongle_types[dongle_id], speed);
1124 switch_bank(iobase, BANK2);
1125 tmp = inb(iobase+FIR_IRDA_CR);
1127 /* IBM type dongle */
1128 if(dongle_id == 0)
1130 if(speed == 4000000)
1132 // __ __
1133 // SD/MODE __| |__ __
1134 // __ __
1135 // IRTX __ __| |__
1136 // T1 T2 T3 T4 T5
1138 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1139 tmp |= IRDA_CR_CRC; // CRC=1
1141 switch_bank(iobase, BANK2);
1142 outb(tmp, iobase+FIR_IRDA_CR);
1144 // T1 -> SD/MODE:0 IRTX:0
1145 tmp &= ~0x09;
1146 tmp |= 0x02;
1147 outb(tmp, iobase+FIR_IRDA_CR);
1148 udelay(2);
1150 // T2 -> SD/MODE:1 IRTX:0
1151 tmp &= ~0x01;
1152 tmp |= 0x0a;
1153 outb(tmp, iobase+FIR_IRDA_CR);
1154 udelay(2);
1156 // T3 -> SD/MODE:1 IRTX:1
1157 tmp |= 0x0b;
1158 outb(tmp, iobase+FIR_IRDA_CR);
1159 udelay(2);
1161 // T4 -> SD/MODE:0 IRTX:1
1162 tmp &= ~0x08;
1163 tmp |= 0x03;
1164 outb(tmp, iobase+FIR_IRDA_CR);
1165 udelay(2);
1167 // T5 -> SD/MODE:0 IRTX:0
1168 tmp &= ~0x09;
1169 tmp |= 0x02;
1170 outb(tmp, iobase+FIR_IRDA_CR);
1171 udelay(2);
1173 // reset -> Normal TX output Signal
1174 outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
1176 else /* speed <=1152000 */
1178 // __
1179 // SD/MODE __| |__
1181 // IRTX ________
1182 // T1 T2 T3
1184 /* MIR 115200, 57600 */
1185 if (speed==1152000)
1187 tmp |= 0xA0; //HDLC=1, 1.152Mbps=1
1189 else
1191 tmp &=~0x80; //HDLC 0.576Mbps
1192 tmp |= 0x20; //HDLC=1,
1195 tmp |= IRDA_CR_CRC; // CRC=1
1197 switch_bank(iobase, BANK2);
1198 outb(tmp, iobase+FIR_IRDA_CR);
1200 /* MIR 115200, 57600 */
1202 //switch_bank(iobase, BANK2);
1203 // T1 -> SD/MODE:0 IRTX:0
1204 tmp &= ~0x09;
1205 tmp |= 0x02;
1206 outb(tmp, iobase+FIR_IRDA_CR);
1207 udelay(2);
1209 // T2 -> SD/MODE:1 IRTX:0
1210 tmp &= ~0x01;
1211 tmp |= 0x0a;
1212 outb(tmp, iobase+FIR_IRDA_CR);
1214 // T3 -> SD/MODE:0 IRTX:0
1215 tmp &= ~0x09;
1216 tmp |= 0x02;
1217 outb(tmp, iobase+FIR_IRDA_CR);
1218 udelay(2);
1220 // reset -> Normal TX output Signal
1221 outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
1224 else if (dongle_id == 1) /* HP HDSL-3600 */
1226 switch(speed)
1228 case 4000000:
1229 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1230 break;
1232 case 1152000:
1233 tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
1234 break;
1236 case 576000:
1237 tmp &=~0x80; // HDLC 0.576Mbps
1238 tmp |= 0x20; // HDLC=1,
1239 break;
1242 tmp |= IRDA_CR_CRC; // CRC=1
1244 switch_bank(iobase, BANK2);
1245 outb(tmp, iobase+FIR_IRDA_CR);
1247 else /* HP HDSL-1100 */
1249 if(speed <= 115200) /* SIR */
1252 tmp &= ~IRDA_CR_FIR_SIN; // HP sin select = 0
1254 switch_bank(iobase, BANK2);
1255 outb(tmp, iobase+FIR_IRDA_CR);
1257 else /* MIR FIR */
1260 switch(speed)
1262 case 4000000:
1263 tmp &= ~IRDA_CR_HDLC; // HDLC=0
1264 break;
1266 case 1152000:
1267 tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
1268 break;
1270 case 576000:
1271 tmp &=~0x80; // HDLC 0.576Mbps
1272 tmp |= 0x20; // HDLC=1,
1273 break;
1276 tmp |= IRDA_CR_CRC; // CRC=1
1277 tmp |= IRDA_CR_FIR_SIN; // HP sin select = 1
1279 switch_bank(iobase, BANK2);
1280 outb(tmp, iobase+FIR_IRDA_CR);
1284 switch_bank(iobase, BANK0);
1286 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1290 * Function ali_ircc_sir_write (driver)
1292 * Fill Tx FIFO with transmit data
1295 static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1297 int actual = 0;
1299 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1301 /* Tx FIFO should be empty! */
1302 if (!(inb(iobase+UART_LSR) & UART_LSR_THRE)) {
1303 IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __FUNCTION__ );
1304 return 0;
1307 /* Fill FIFO with current frame */
1308 while ((fifo_size-- > 0) && (actual < len)) {
1309 /* Transmit next byte */
1310 outb(buf[actual], iobase+UART_TX);
1312 actual++;
1315 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1316 return actual;
1320 * Function ali_ircc_net_open (dev)
1322 * Start the device
1325 static int ali_ircc_net_open(struct net_device *dev)
1327 struct ali_ircc_cb *self;
1328 int iobase;
1329 char hwname[32];
1331 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1333 IRDA_ASSERT(dev != NULL, return -1;);
1335 self = (struct ali_ircc_cb *) dev->priv;
1337 IRDA_ASSERT(self != NULL, return 0;);
1339 iobase = self->io.fir_base;
1341 /* Request IRQ and install Interrupt Handler */
1342 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev))
1344 IRDA_WARNING("%s, unable to allocate irq=%d\n",
1345 ALI_IRCC_DRIVER_NAME,
1346 self->io.irq);
1347 return -EAGAIN;
1351 * Always allocate the DMA channel after the IRQ, and clean up on
1352 * failure.
1354 if (request_dma(self->io.dma, dev->name)) {
1355 IRDA_WARNING("%s, unable to allocate dma=%d\n",
1356 ALI_IRCC_DRIVER_NAME,
1357 self->io.dma);
1358 free_irq(self->io.irq, self);
1359 return -EAGAIN;
1362 /* Turn on interrups */
1363 outb(UART_IER_RDI , iobase+UART_IER);
1365 /* Ready to play! */
1366 netif_start_queue(dev); //benjamin by irport
1368 /* Give self a hardware name */
1369 sprintf(hwname, "ALI-FIR @ 0x%03x", self->io.fir_base);
1372 * Open new IrLAP layer instance, now that everything should be
1373 * initialized properly
1375 self->irlap = irlap_open(dev, &self->qos, hwname);
1377 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1379 return 0;
1383 * Function ali_ircc_net_close (dev)
1385 * Stop the device
1388 static int ali_ircc_net_close(struct net_device *dev)
1391 struct ali_ircc_cb *self;
1392 //int iobase;
1394 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1396 IRDA_ASSERT(dev != NULL, return -1;);
1398 self = (struct ali_ircc_cb *) dev->priv;
1399 IRDA_ASSERT(self != NULL, return 0;);
1401 /* Stop device */
1402 netif_stop_queue(dev);
1404 /* Stop and remove instance of IrLAP */
1405 if (self->irlap)
1406 irlap_close(self->irlap);
1407 self->irlap = NULL;
1409 disable_dma(self->io.dma);
1411 /* Disable interrupts */
1412 SetCOMInterrupts(self, FALSE);
1414 free_irq(self->io.irq, dev);
1415 free_dma(self->io.dma);
1417 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1419 return 0;
1423 * Function ali_ircc_fir_hard_xmit (skb, dev)
1425 * Transmit the frame
1428 static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1430 struct ali_ircc_cb *self;
1431 unsigned long flags;
1432 int iobase;
1433 __u32 speed;
1434 int mtt, diff;
1436 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1438 self = (struct ali_ircc_cb *) dev->priv;
1439 iobase = self->io.fir_base;
1441 netif_stop_queue(dev);
1443 /* Make sure tests *& speed change are atomic */
1444 spin_lock_irqsave(&self->lock, flags);
1446 /* Note : you should make sure that speed changes are not going
1447 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1448 * details - Jean II */
1450 /* Check if we need to change the speed */
1451 speed = irda_get_next_speed(skb);
1452 if ((speed != self->io.speed) && (speed != -1)) {
1453 /* Check for empty frame */
1454 if (!skb->len) {
1455 ali_ircc_change_speed(self, speed);
1456 dev->trans_start = jiffies;
1457 spin_unlock_irqrestore(&self->lock, flags);
1458 dev_kfree_skb(skb);
1459 return 0;
1460 } else
1461 self->new_speed = speed;
1464 /* Register and copy this frame to DMA memory */
1465 self->tx_fifo.queue[self->tx_fifo.free].start = self->tx_fifo.tail;
1466 self->tx_fifo.queue[self->tx_fifo.free].len = skb->len;
1467 self->tx_fifo.tail += skb->len;
1469 self->stats.tx_bytes += skb->len;
1471 skb_copy_from_linear_data(skb, self->tx_fifo.queue[self->tx_fifo.free].start,
1472 skb->len);
1473 self->tx_fifo.len++;
1474 self->tx_fifo.free++;
1476 /* Start transmit only if there is currently no transmit going on */
1477 if (self->tx_fifo.len == 1)
1479 /* Check if we must wait the min turn time or not */
1480 mtt = irda_get_mtt(skb);
1482 if (mtt)
1484 /* Check how much time we have used already */
1485 do_gettimeofday(&self->now);
1487 diff = self->now.tv_usec - self->stamp.tv_usec;
1488 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1490 IRDA_DEBUG(1, "%s(), ******* diff = %d ******* \n", __FUNCTION__ , diff);
1492 if (diff < 0)
1493 diff += 1000000;
1495 /* Check if the mtt is larger than the time we have
1496 * already used by all the protocol processing
1498 if (mtt > diff)
1500 mtt -= diff;
1503 * Use timer if delay larger than 1000 us, and
1504 * use udelay for smaller values which should
1505 * be acceptable
1507 if (mtt > 500)
1509 /* Adjust for timer resolution */
1510 mtt = (mtt+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1512 IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __FUNCTION__ , mtt);
1514 /* Setup timer */
1515 if (mtt == 1) /* 500 us */
1517 switch_bank(iobase, BANK1);
1518 outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR);
1520 else if (mtt == 2) /* 1 ms */
1522 switch_bank(iobase, BANK1);
1523 outb(TIMER_IIR_1ms, iobase+FIR_TIMER_IIR);
1525 else /* > 2ms -> 4ms */
1527 switch_bank(iobase, BANK1);
1528 outb(TIMER_IIR_2ms, iobase+FIR_TIMER_IIR);
1532 /* Start timer */
1533 outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
1534 self->io.direction = IO_XMIT;
1536 /* Enable timer interrupt */
1537 self->ier = IER_TIMER;
1538 SetCOMInterrupts(self, TRUE);
1540 /* Timer will take care of the rest */
1541 goto out;
1543 else
1544 udelay(mtt);
1545 } // if (if (mtt > diff)
1546 }// if (mtt)
1548 /* Enable EOM interrupt */
1549 self->ier = IER_EOM;
1550 SetCOMInterrupts(self, TRUE);
1552 /* Transmit frame */
1553 ali_ircc_dma_xmit(self);
1554 } // if (self->tx_fifo.len == 1)
1556 out:
1558 /* Not busy transmitting anymore if window is not full */
1559 if (self->tx_fifo.free < MAX_TX_WINDOW)
1560 netif_wake_queue(self->netdev);
1562 /* Restore bank register */
1563 switch_bank(iobase, BANK0);
1565 dev->trans_start = jiffies;
1566 spin_unlock_irqrestore(&self->lock, flags);
1567 dev_kfree_skb(skb);
1569 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1570 return 0;
1574 static void ali_ircc_dma_xmit(struct ali_ircc_cb *self)
1576 int iobase, tmp;
1577 unsigned char FIFO_OPTI, Hi, Lo;
1580 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1582 iobase = self->io.fir_base;
1584 /* FIFO threshold , this method comes from NDIS5 code */
1586 if(self->tx_fifo.queue[self->tx_fifo.ptr].len < TX_FIFO_Threshold)
1587 FIFO_OPTI = self->tx_fifo.queue[self->tx_fifo.ptr].len-1;
1588 else
1589 FIFO_OPTI = TX_FIFO_Threshold;
1591 /* Disable DMA */
1592 switch_bank(iobase, BANK1);
1593 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1595 self->io.direction = IO_XMIT;
1597 irda_setup_dma(self->io.dma,
1598 ((u8 *)self->tx_fifo.queue[self->tx_fifo.ptr].start -
1599 self->tx_buff.head) + self->tx_buff_dma,
1600 self->tx_fifo.queue[self->tx_fifo.ptr].len,
1601 DMA_TX_MODE);
1603 /* Reset Tx FIFO */
1604 switch_bank(iobase, BANK0);
1605 outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
1607 /* Set Tx FIFO threshold */
1608 if (self->fifo_opti_buf!=FIFO_OPTI)
1610 switch_bank(iobase, BANK1);
1611 outb(FIFO_OPTI, iobase+FIR_FIFO_TR) ;
1612 self->fifo_opti_buf=FIFO_OPTI;
1615 /* Set Tx DMA threshold */
1616 switch_bank(iobase, BANK1);
1617 outb(TX_DMA_Threshold, iobase+FIR_DMA_TR);
1619 /* Set max Tx frame size */
1620 Hi = (self->tx_fifo.queue[self->tx_fifo.ptr].len >> 8) & 0x0f;
1621 Lo = self->tx_fifo.queue[self->tx_fifo.ptr].len & 0xff;
1622 switch_bank(iobase, BANK2);
1623 outb(Hi, iobase+FIR_TX_DSR_HI);
1624 outb(Lo, iobase+FIR_TX_DSR_LO);
1626 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1627 switch_bank(iobase, BANK0);
1628 tmp = inb(iobase+FIR_LCR_B);
1629 tmp &= ~0x20; // Disable SIP
1630 outb(((unsigned char)(tmp & 0x3f) | LCR_B_TX_MODE) & ~LCR_B_BW, iobase+FIR_LCR_B);
1631 IRDA_DEBUG(1, "%s(), ******* Change to TX mode: FIR_LCR_B = 0x%x ******* \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
1633 outb(0, iobase+FIR_LSR);
1635 /* Enable DMA and Burst Mode */
1636 switch_bank(iobase, BANK1);
1637 outb(inb(iobase+FIR_CR) | CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
1639 switch_bank(iobase, BANK0);
1641 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1644 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self)
1646 int iobase;
1647 int ret = TRUE;
1649 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1651 iobase = self->io.fir_base;
1653 /* Disable DMA */
1654 switch_bank(iobase, BANK1);
1655 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1657 /* Check for underrun! */
1658 switch_bank(iobase, BANK0);
1659 if((inb(iobase+FIR_LSR) & LSR_FRAME_ABORT) == LSR_FRAME_ABORT)
1662 IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __FUNCTION__);
1663 self->stats.tx_errors++;
1664 self->stats.tx_fifo_errors++;
1666 else
1668 self->stats.tx_packets++;
1671 /* Check if we need to change the speed */
1672 if (self->new_speed)
1674 ali_ircc_change_speed(self, self->new_speed);
1675 self->new_speed = 0;
1678 /* Finished with this frame, so prepare for next */
1679 self->tx_fifo.ptr++;
1680 self->tx_fifo.len--;
1682 /* Any frames to be sent back-to-back? */
1683 if (self->tx_fifo.len)
1685 ali_ircc_dma_xmit(self);
1687 /* Not finished yet! */
1688 ret = FALSE;
1690 else
1691 { /* Reset Tx FIFO info */
1692 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
1693 self->tx_fifo.tail = self->tx_buff.head;
1696 /* Make sure we have room for more frames */
1697 if (self->tx_fifo.free < MAX_TX_WINDOW) {
1698 /* Not busy transmitting anymore */
1699 /* Tell the network layer, that we can accept more frames */
1700 netif_wake_queue(self->netdev);
1703 switch_bank(iobase, BANK0);
1705 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1706 return ret;
1710 * Function ali_ircc_dma_receive (self)
1712 * Get ready for receiving a frame. The device will initiate a DMA
1713 * if it starts to receive a frame.
1716 static int ali_ircc_dma_receive(struct ali_ircc_cb *self)
1718 int iobase, tmp;
1720 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1722 iobase = self->io.fir_base;
1724 /* Reset Tx FIFO info */
1725 self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
1726 self->tx_fifo.tail = self->tx_buff.head;
1728 /* Disable DMA */
1729 switch_bank(iobase, BANK1);
1730 outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
1732 /* Reset Message Count */
1733 switch_bank(iobase, BANK0);
1734 outb(0x07, iobase+FIR_LSR);
1736 self->rcvFramesOverflow = FALSE;
1738 self->LineStatus = inb(iobase+FIR_LSR) ;
1740 /* Reset Rx FIFO info */
1741 self->io.direction = IO_RECV;
1742 self->rx_buff.data = self->rx_buff.head;
1744 /* Reset Rx FIFO */
1745 // switch_bank(iobase, BANK0);
1746 outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
1748 self->st_fifo.len = self->st_fifo.pending_bytes = 0;
1749 self->st_fifo.tail = self->st_fifo.head = 0;
1751 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1752 DMA_RX_MODE);
1754 /* Set Receive Mode,Brick Wall */
1755 //switch_bank(iobase, BANK0);
1756 tmp = inb(iobase+FIR_LCR_B);
1757 outb((unsigned char)(tmp &0x3f) | LCR_B_RX_MODE | LCR_B_BW , iobase + FIR_LCR_B); // 2000/12/1 05:16PM
1758 IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x *** \n", __FUNCTION__ , inb(iobase+FIR_LCR_B));
1760 /* Set Rx Threshold */
1761 switch_bank(iobase, BANK1);
1762 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
1763 outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
1765 /* Enable DMA and Burst Mode */
1766 // switch_bank(iobase, BANK1);
1767 outb(CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
1769 switch_bank(iobase, BANK0);
1770 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1771 return 0;
1774 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)
1776 struct st_fifo *st_fifo;
1777 struct sk_buff *skb;
1778 __u8 status, MessageCount;
1779 int len, i, iobase, val;
1781 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
1783 st_fifo = &self->st_fifo;
1784 iobase = self->io.fir_base;
1786 switch_bank(iobase, BANK0);
1787 MessageCount = inb(iobase+ FIR_LSR)&0x07;
1789 if (MessageCount > 0)
1790 IRDA_DEBUG(0, "%s(), Messsage count = %d,\n", __FUNCTION__ , MessageCount);
1792 for (i=0; i<=MessageCount; i++)
1794 /* Bank 0 */
1795 switch_bank(iobase, BANK0);
1796 status = inb(iobase+FIR_LSR);
1798 switch_bank(iobase, BANK2);
1799 len = inb(iobase+FIR_RX_DSR_HI) & 0x0f;
1800 len = len << 8;
1801 len |= inb(iobase+FIR_RX_DSR_LO);
1803 IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __FUNCTION__ , len);
1804 IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __FUNCTION__ , status);
1806 if (st_fifo->tail >= MAX_RX_WINDOW) {
1807 IRDA_DEBUG(0, "%s(), window is full!\n", __FUNCTION__ );
1808 continue;
1811 st_fifo->entries[st_fifo->tail].status = status;
1812 st_fifo->entries[st_fifo->tail].len = len;
1813 st_fifo->pending_bytes += len;
1814 st_fifo->tail++;
1815 st_fifo->len++;
1818 for (i=0; i<=MessageCount; i++)
1820 /* Get first entry */
1821 status = st_fifo->entries[st_fifo->head].status;
1822 len = st_fifo->entries[st_fifo->head].len;
1823 st_fifo->pending_bytes -= len;
1824 st_fifo->head++;
1825 st_fifo->len--;
1827 /* Check for errors */
1828 if ((status & 0xd8) || self->rcvFramesOverflow || (len==0))
1830 IRDA_DEBUG(0,"%s(), ************* RX Errors ************ \n", __FUNCTION__ );
1832 /* Skip frame */
1833 self->stats.rx_errors++;
1835 self->rx_buff.data += len;
1837 if (status & LSR_FIFO_UR)
1839 self->stats.rx_frame_errors++;
1840 IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************ \n", __FUNCTION__ );
1842 if (status & LSR_FRAME_ERROR)
1844 self->stats.rx_frame_errors++;
1845 IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************ \n", __FUNCTION__ );
1848 if (status & LSR_CRC_ERROR)
1850 self->stats.rx_crc_errors++;
1851 IRDA_DEBUG(0,"%s(), ************* CRC Errors ************ \n", __FUNCTION__ );
1854 if(self->rcvFramesOverflow)
1856 self->stats.rx_frame_errors++;
1857 IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************ \n", __FUNCTION__ );
1859 if(len == 0)
1861 self->stats.rx_frame_errors++;
1862 IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 ********* \n", __FUNCTION__ );
1865 else
1868 if (st_fifo->pending_bytes < 32)
1870 switch_bank(iobase, BANK0);
1871 val = inb(iobase+FIR_BSR);
1872 if ((val& BSR_FIFO_NOT_EMPTY)== 0x80)
1874 IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************ \n", __FUNCTION__ );
1876 /* Put this entry back in fifo */
1877 st_fifo->head--;
1878 st_fifo->len++;
1879 st_fifo->pending_bytes += len;
1880 st_fifo->entries[st_fifo->head].status = status;
1881 st_fifo->entries[st_fifo->head].len = len;
1884 * DMA not finished yet, so try again
1885 * later, set timer value, resolution
1886 * 500 us
1889 switch_bank(iobase, BANK1);
1890 outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR); // 2001/1/2 05:07PM
1892 /* Enable Timer */
1893 outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
1895 return FALSE; /* I'll be back! */
1900 * Remember the time we received this frame, so we can
1901 * reduce the min turn time a bit since we will know
1902 * how much time we have used for protocol processing
1904 do_gettimeofday(&self->stamp);
1906 skb = dev_alloc_skb(len+1);
1907 if (skb == NULL)
1909 IRDA_WARNING("%s(), memory squeeze, "
1910 "dropping frame.\n",
1911 __FUNCTION__);
1912 self->stats.rx_dropped++;
1914 return FALSE;
1917 /* Make sure IP header gets aligned */
1918 skb_reserve(skb, 1);
1920 /* Copy frame without CRC, CRC is removed by hardware*/
1921 skb_put(skb, len);
1922 skb_copy_to_linear_data(skb, self->rx_buff.data, len);
1924 /* Move to next frame */
1925 self->rx_buff.data += len;
1926 self->stats.rx_bytes += len;
1927 self->stats.rx_packets++;
1929 skb->dev = self->netdev;
1930 skb_reset_mac_header(skb);
1931 skb->protocol = htons(ETH_P_IRDA);
1932 netif_rx(skb);
1933 self->netdev->last_rx = jiffies;
1937 switch_bank(iobase, BANK0);
1939 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
1940 return TRUE;
1946 * Function ali_ircc_sir_hard_xmit (skb, dev)
1948 * Transmit the frame!
1951 static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1953 struct ali_ircc_cb *self;
1954 unsigned long flags;
1955 int iobase;
1956 __u32 speed;
1958 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
1960 IRDA_ASSERT(dev != NULL, return 0;);
1962 self = (struct ali_ircc_cb *) dev->priv;
1963 IRDA_ASSERT(self != NULL, return 0;);
1965 iobase = self->io.sir_base;
1967 netif_stop_queue(dev);
1969 /* Make sure tests *& speed change are atomic */
1970 spin_lock_irqsave(&self->lock, flags);
1972 /* Note : you should make sure that speed changes are not going
1973 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1974 * details - Jean II */
1976 /* Check if we need to change the speed */
1977 speed = irda_get_next_speed(skb);
1978 if ((speed != self->io.speed) && (speed != -1)) {
1979 /* Check for empty frame */
1980 if (!skb->len) {
1981 ali_ircc_change_speed(self, speed);
1982 dev->trans_start = jiffies;
1983 spin_unlock_irqrestore(&self->lock, flags);
1984 dev_kfree_skb(skb);
1985 return 0;
1986 } else
1987 self->new_speed = speed;
1990 /* Init tx buffer */
1991 self->tx_buff.data = self->tx_buff.head;
1993 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
1994 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
1995 self->tx_buff.truesize);
1997 self->stats.tx_bytes += self->tx_buff.len;
1999 /* Turn on transmit finished interrupt. Will fire immediately! */
2000 outb(UART_IER_THRI, iobase+UART_IER);
2002 dev->trans_start = jiffies;
2003 spin_unlock_irqrestore(&self->lock, flags);
2005 dev_kfree_skb(skb);
2007 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2009 return 0;
2014 * Function ali_ircc_net_ioctl (dev, rq, cmd)
2016 * Process IOCTL commands for this device
2019 static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2021 struct if_irda_req *irq = (struct if_irda_req *) rq;
2022 struct ali_ircc_cb *self;
2023 unsigned long flags;
2024 int ret = 0;
2026 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2028 IRDA_ASSERT(dev != NULL, return -1;);
2030 self = dev->priv;
2032 IRDA_ASSERT(self != NULL, return -1;);
2034 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__ , dev->name, cmd);
2036 switch (cmd) {
2037 case SIOCSBANDWIDTH: /* Set bandwidth */
2038 IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __FUNCTION__ );
2040 * This function will also be used by IrLAP to change the
2041 * speed, so we still must allow for speed change within
2042 * interrupt context.
2044 if (!in_interrupt() && !capable(CAP_NET_ADMIN))
2045 return -EPERM;
2047 spin_lock_irqsave(&self->lock, flags);
2048 ali_ircc_change_speed(self, irq->ifr_baudrate);
2049 spin_unlock_irqrestore(&self->lock, flags);
2050 break;
2051 case SIOCSMEDIABUSY: /* Set media busy */
2052 IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __FUNCTION__ );
2053 if (!capable(CAP_NET_ADMIN))
2054 return -EPERM;
2055 irda_device_set_media_busy(self->netdev, TRUE);
2056 break;
2057 case SIOCGRECEIVING: /* Check if we are receiving right now */
2058 IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __FUNCTION__ );
2059 /* This is protected */
2060 irq->ifr_receiving = ali_ircc_is_receiving(self);
2061 break;
2062 default:
2063 ret = -EOPNOTSUPP;
2066 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2068 return ret;
2072 * Function ali_ircc_is_receiving (self)
2074 * Return TRUE is we are currently receiving a frame
2077 static int ali_ircc_is_receiving(struct ali_ircc_cb *self)
2079 unsigned long flags;
2080 int status = FALSE;
2081 int iobase;
2083 IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
2085 IRDA_ASSERT(self != NULL, return FALSE;);
2087 spin_lock_irqsave(&self->lock, flags);
2089 if (self->io.speed > 115200)
2091 iobase = self->io.fir_base;
2093 switch_bank(iobase, BANK1);
2094 if((inb(iobase+FIR_FIFO_FR) & 0x3f) != 0)
2096 /* We are receiving something */
2097 IRDA_DEBUG(1, "%s(), We are receiving something\n", __FUNCTION__ );
2098 status = TRUE;
2100 switch_bank(iobase, BANK0);
2102 else
2104 status = (self->rx_buff.state != OUTSIDE_FRAME);
2107 spin_unlock_irqrestore(&self->lock, flags);
2109 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2111 return status;
2114 static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev)
2116 struct ali_ircc_cb *self = (struct ali_ircc_cb *) dev->priv;
2118 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2120 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2122 return &self->stats;
2125 static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state)
2127 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2129 IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME);
2131 if (self->io.suspended)
2132 return 0;
2134 ali_ircc_net_close(self->netdev);
2136 self->io.suspended = 1;
2138 return 0;
2141 static int ali_ircc_resume(struct platform_device *dev)
2143 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2145 if (!self->io.suspended)
2146 return 0;
2148 ali_ircc_net_open(self->netdev);
2150 IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME);
2152 self->io.suspended = 0;
2154 return 0;
2157 /* ALi Chip Function */
2159 static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)
2162 unsigned char newMask;
2164 int iobase = self->io.fir_base; /* or sir_base */
2166 IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __FUNCTION__ , enable);
2168 /* Enable the interrupt which we wish to */
2169 if (enable){
2170 if (self->io.direction == IO_XMIT)
2172 if (self->io.speed > 115200) /* FIR, MIR */
2174 newMask = self->ier;
2176 else /* SIR */
2178 newMask = UART_IER_THRI | UART_IER_RDI;
2181 else {
2182 if (self->io.speed > 115200) /* FIR, MIR */
2184 newMask = self->ier;
2186 else /* SIR */
2188 newMask = UART_IER_RDI;
2192 else /* Disable all the interrupts */
2194 newMask = 0x00;
2198 //SIR and FIR has different registers
2199 if (self->io.speed > 115200)
2201 switch_bank(iobase, BANK0);
2202 outb(newMask, iobase+FIR_IER);
2204 else
2205 outb(newMask, iobase+UART_IER);
2207 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2210 static void SIR2FIR(int iobase)
2212 //unsigned char tmp;
2214 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2216 /* Already protected (change_speed() or setup()), no need to lock.
2217 * Jean II */
2219 outb(0x28, iobase+UART_MCR);
2220 outb(0x68, iobase+UART_MCR);
2221 outb(0x88, iobase+UART_MCR);
2223 outb(0x60, iobase+FIR_MCR); /* Master Reset */
2224 outb(0x20, iobase+FIR_MCR); /* Master Interrupt Enable */
2226 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2227 //tmp |= 0x20;
2228 //outb(tmp, iobase+FIR_LCR_B);
2230 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2233 static void FIR2SIR(int iobase)
2235 unsigned char val;
2237 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2239 /* Already protected (change_speed() or setup()), no need to lock.
2240 * Jean II */
2242 outb(0x20, iobase+FIR_MCR); /* IRQ to low */
2243 outb(0x00, iobase+UART_IER);
2245 outb(0xA0, iobase+FIR_MCR); /* Don't set master reset */
2246 outb(0x00, iobase+UART_FCR);
2247 outb(0x07, iobase+UART_FCR);
2249 val = inb(iobase+UART_RX);
2250 val = inb(iobase+UART_LSR);
2251 val = inb(iobase+UART_MSR);
2253 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2256 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2257 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2258 MODULE_LICENSE("GPL");
2261 module_param_array(io, int, NULL, 0);
2262 MODULE_PARM_DESC(io, "Base I/O addresses");
2263 module_param_array(irq, int, NULL, 0);
2264 MODULE_PARM_DESC(irq, "IRQ lines");
2265 module_param_array(dma, int, NULL, 0);
2266 MODULE_PARM_DESC(dma, "DMA channels");
2268 module_init(ali_ircc_init);
2269 module_exit(ali_ircc_cleanup);