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>
25 #include <linux/gfp.h>
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/skbuff.h>
30 #include <linux/netdevice.h>
31 #include <linux/ioport.h>
32 #include <linux/delay.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
35 #include <linux/rtnetlink.h>
36 #include <linux/serial_reg.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/platform_device.h>
42 #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 #define ALI_IRCC_DRIVER_NAME "ali-ircc"
55 /* Power Management */
56 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
);
57 static int ali_ircc_resume(struct platform_device
*dev
);
59 static struct platform_driver ali_ircc_driver
= {
60 .suspend
= ali_ircc_suspend
,
61 .resume
= ali_ircc_resume
,
63 .name
= ALI_IRCC_DRIVER_NAME
,
68 /* Module parameters */
69 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
71 /* Use BIOS settions by default, but user may supply module parameters */
72 static unsigned int io
[] = { ~0, ~0, ~0, ~0 };
73 static unsigned int irq
[] = { 0, 0, 0, 0 };
74 static unsigned int dma
[] = { 0, 0, 0, 0 };
76 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
);
77 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
);
78 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
);
80 /* These are the currently known ALi south-bridge chipsets, the only one difference
81 * is that M1543C doesn't support HP HDSL-3600
83 static ali_chip_t chips
[] =
85 { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53
, ali_ircc_init_43
},
86 { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53
, ali_ircc_init_53
},
87 { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53
, ali_ircc_init_53
},
91 /* Max 4 instances for now */
92 static struct ali_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
95 static char *dongle_types
[] = {
99 "No dongle connected",
102 /* Some prototypes */
103 static int ali_ircc_open(int i
, chipio_t
*info
);
105 static int ali_ircc_close(struct ali_ircc_cb
*self
);
107 static int ali_ircc_setup(chipio_t
*info
);
108 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
);
109 static int ali_ircc_net_open(struct net_device
*dev
);
110 static int ali_ircc_net_close(struct net_device
*dev
);
111 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
112 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
);
115 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
116 struct net_device
*dev
);
117 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
);
118 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
);
119 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
);
120 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
121 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
124 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
125 struct net_device
*dev
);
126 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
127 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
);
128 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
);
129 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
);
130 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
);
131 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
);
134 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
);
135 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
);
137 /* ALi chip function */
138 static void SIR2FIR(int iobase
);
139 static void FIR2SIR(int iobase
);
140 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
);
143 * Function ali_ircc_init ()
145 * Initialize chip. Find out whay kinds of chips we are dealing with
146 * and their configuration registers address
148 static int __init
ali_ircc_init(void)
157 ret
= platform_driver_register(&ali_ircc_driver
);
159 net_err_ratelimited("%s, Can't register driver!\n",
160 ALI_IRCC_DRIVER_NAME
);
166 /* Probe for all the ALi chipsets we know about */
167 for (chip
= chips
; chip
->name
; chip
++, i
++)
169 pr_debug("%s(), Probing for %s ...\n", __func__
, chip
->name
);
171 /* Try all config registers for this chip */
172 for (cfg
=0; cfg
<2; cfg
++)
174 cfg_base
= chip
->cfg
[cfg
];
178 memset(&info
, 0, sizeof(chipio_t
));
179 info
.cfg_base
= cfg_base
;
180 info
.fir_base
= io
[i
];
185 /* Enter Configuration */
186 outb(chip
->entr1
, cfg_base
);
187 outb(chip
->entr2
, cfg_base
);
189 /* Select Logical Device 5 Registers (UART2) */
190 outb(0x07, cfg_base
);
191 outb(0x05, cfg_base
+1);
193 /* Read Chip Identification Register */
194 outb(chip
->cid_index
, cfg_base
);
195 reg
= inb(cfg_base
+1);
197 if (reg
== chip
->cid_value
)
199 pr_debug("%s(), Chip found at 0x%03x\n",
202 outb(0x1F, cfg_base
);
203 revision
= inb(cfg_base
+1);
204 pr_debug("%s(), Found %s chip, revision=%d\n",
205 __func__
, chip
->name
, revision
);
208 * If the user supplies the base address, then
209 * we init the chip, if not we probe the values
214 chip
->init(chip
, &info
);
218 chip
->probe(chip
, &info
);
221 if (ali_ircc_open(i
, &info
) == 0)
227 pr_debug("%s(), No %s chip at 0x%03x\n",
228 __func__
, chip
->name
, cfg_base
);
230 /* Exit configuration */
231 outb(0xbb, cfg_base
);
236 platform_driver_unregister(&ali_ircc_driver
);
242 * Function ali_ircc_cleanup ()
244 * Close all configured chips
247 static void __exit
ali_ircc_cleanup(void)
251 for (i
=0; i
< ARRAY_SIZE(dev_self
); i
++) {
253 ali_ircc_close(dev_self
[i
]);
256 platform_driver_unregister(&ali_ircc_driver
);
260 static const struct net_device_ops ali_ircc_sir_ops
= {
261 .ndo_open
= ali_ircc_net_open
,
262 .ndo_stop
= ali_ircc_net_close
,
263 .ndo_start_xmit
= ali_ircc_sir_hard_xmit
,
264 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
267 static const struct net_device_ops ali_ircc_fir_ops
= {
268 .ndo_open
= ali_ircc_net_open
,
269 .ndo_stop
= ali_ircc_net_close
,
270 .ndo_start_xmit
= ali_ircc_fir_hard_xmit
,
271 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
275 * Function ali_ircc_open (int i, chipio_t *inf)
277 * Open driver instance
280 static int ali_ircc_open(int i
, chipio_t
*info
)
282 struct net_device
*dev
;
283 struct ali_ircc_cb
*self
;
287 if (i
>= ARRAY_SIZE(dev_self
)) {
288 net_err_ratelimited("%s(), maximum number of supported chips reached!\n",
293 /* Set FIR FIFO and DMA Threshold */
294 if ((ali_ircc_setup(info
)) == -1)
297 dev
= alloc_irdadev(sizeof(*self
));
299 net_err_ratelimited("%s(), can't allocate memory for control block!\n",
304 self
= netdev_priv(dev
);
306 spin_lock_init(&self
->lock
);
308 /* Need to store self somewhere */
313 self
->io
.cfg_base
= info
->cfg_base
; /* In ali_ircc_probe_53 assign */
314 self
->io
.fir_base
= info
->fir_base
; /* info->sir_base = info->fir_base */
315 self
->io
.sir_base
= info
->sir_base
; /* ALi SIR and FIR use the same address */
316 self
->io
.irq
= info
->irq
;
317 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
318 self
->io
.dma
= info
->dma
;
319 self
->io
.fifo_size
= 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
321 /* Reserve the ioports that we need */
322 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
,
323 ALI_IRCC_DRIVER_NAME
)) {
324 net_warn_ratelimited("%s(), can't get iobase of 0x%03x\n",
325 __func__
, self
->io
.fir_base
);
330 /* Initialize QoS for this device */
331 irda_init_max_qos_capabilies(&self
->qos
);
333 /* The only value we must override it the baudrate */
334 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
335 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8); // benjamin 2000/11/8 05:27PM
337 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
339 irda_qos_bits_to_value(&self
->qos
);
341 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
342 self
->rx_buff
.truesize
= 14384;
343 self
->tx_buff
.truesize
= 14384;
345 /* Allocate memory if needed */
347 dma_zalloc_coherent(NULL
, self
->rx_buff
.truesize
,
348 &self
->rx_buff_dma
, GFP_KERNEL
);
349 if (self
->rx_buff
.head
== NULL
) {
355 dma_zalloc_coherent(NULL
, self
->tx_buff
.truesize
,
356 &self
->tx_buff_dma
, GFP_KERNEL
);
357 if (self
->tx_buff
.head
== NULL
) {
362 self
->rx_buff
.in_frame
= FALSE
;
363 self
->rx_buff
.state
= OUTSIDE_FRAME
;
364 self
->tx_buff
.data
= self
->tx_buff
.head
;
365 self
->rx_buff
.data
= self
->rx_buff
.head
;
367 /* Reset Tx queue info */
368 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
369 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
371 /* Override the network functions we need to use */
372 dev
->netdev_ops
= &ali_ircc_sir_ops
;
374 err
= register_netdev(dev
);
376 net_err_ratelimited("%s(), register_netdev() failed!\n",
380 net_info_ratelimited("IrDA: Registered device %s\n", dev
->name
);
382 /* Check dongle id */
383 dongle_id
= ali_ircc_read_dongle_id(i
, info
);
384 net_info_ratelimited("%s(), %s, Found dongle: %s\n",
385 __func__
, ALI_IRCC_DRIVER_NAME
,
386 dongle_types
[dongle_id
]);
388 self
->io
.dongle_id
= dongle_id
;
394 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
395 self
->tx_buff
.head
, self
->tx_buff_dma
);
397 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
398 self
->rx_buff
.head
, self
->rx_buff_dma
);
400 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
409 * Function ali_ircc_close (self)
411 * Close driver instance
414 static int __exit
ali_ircc_close(struct ali_ircc_cb
*self
)
418 IRDA_ASSERT(self
!= NULL
, return -1;);
420 iobase
= self
->io
.fir_base
;
422 /* Remove netdevice */
423 unregister_netdev(self
->netdev
);
425 /* Release the PORT that this driver is using */
426 pr_debug("%s(), Releasing Region %03x\n", __func__
, self
->io
.fir_base
);
427 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
429 if (self
->tx_buff
.head
)
430 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
431 self
->tx_buff
.head
, self
->tx_buff_dma
);
433 if (self
->rx_buff
.head
)
434 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
435 self
->rx_buff
.head
, self
->rx_buff_dma
);
437 dev_self
[self
->index
] = NULL
;
438 free_netdev(self
->netdev
);
445 * Function ali_ircc_init_43 (chip, info)
447 * Initialize the ALi M1543 chip.
449 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
)
451 /* All controller information like I/O address, DMA channel, IRQ
459 * Function ali_ircc_init_53 (chip, info)
461 * Initialize the ALi M1535 chip.
463 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
)
465 /* All controller information like I/O address, DMA channel, IRQ
473 * Function ali_ircc_probe_53 (chip, info)
475 * Probes for the ALi M1535D or M1535
477 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
)
479 int cfg_base
= info
->cfg_base
;
483 /* Enter Configuration */
484 outb(chip
->entr1
, cfg_base
);
485 outb(chip
->entr2
, cfg_base
);
487 /* Select Logical Device 5 Registers (UART2) */
488 outb(0x07, cfg_base
);
489 outb(0x05, cfg_base
+1);
491 /* Read address control register */
492 outb(0x60, cfg_base
);
493 hi
= inb(cfg_base
+1);
494 outb(0x61, cfg_base
);
495 low
= inb(cfg_base
+1);
496 info
->fir_base
= (hi
<<8) + low
;
498 info
->sir_base
= info
->fir_base
;
500 pr_debug("%s(), probing fir_base=0x%03x\n", __func__
, info
->fir_base
);
502 /* Read IRQ control register */
503 outb(0x70, cfg_base
);
504 reg
= inb(cfg_base
+1);
505 info
->irq
= reg
& 0x0f;
506 pr_debug("%s(), probing irq=%d\n", __func__
, info
->irq
);
508 /* Read DMA channel */
509 outb(0x74, cfg_base
);
510 reg
= inb(cfg_base
+1);
511 info
->dma
= reg
& 0x07;
513 if(info
->dma
== 0x04)
514 net_warn_ratelimited("%s(), No DMA channel assigned !\n",
517 pr_debug("%s(), probing dma=%d\n", __func__
, info
->dma
);
519 /* Read Enabled Status */
520 outb(0x30, cfg_base
);
521 reg
= inb(cfg_base
+1);
522 info
->enabled
= (reg
& 0x80) && (reg
& 0x01);
523 pr_debug("%s(), probing enabled=%d\n", __func__
, info
->enabled
);
525 /* Read Power Status */
526 outb(0x22, cfg_base
);
527 reg
= inb(cfg_base
+1);
528 info
->suspended
= (reg
& 0x20);
529 pr_debug("%s(), probing suspended=%d\n", __func__
, info
->suspended
);
531 /* Exit configuration */
532 outb(0xbb, cfg_base
);
539 * Function ali_ircc_setup (info)
541 * Set FIR FIFO and DMA Threshold
542 * Returns non-negative on success.
545 static int ali_ircc_setup(chipio_t
*info
)
549 int iobase
= info
->fir_base
;
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 */
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 */
570 net_err_ratelimited("%s, Wrong chip version %02x\n",
571 ALI_IRCC_DRIVER_NAME
, version
);
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
);
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
595 outb(tmp
, iobase
+FIR_LCR_B
);
597 /* Disable Interrupt */
598 outb(0x00, iobase
+FIR_IER
);
601 /* Switch to SIR space */
604 net_info_ratelimited("%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
616 * Function ali_ircc_read_dongle_id (int index, info)
618 * Try to read dongle identification. This procedure needs to be executed
619 * once after power-on/reset. It also needs to be used whenever you suspect
620 * that the user may have plugged/unplugged the IrDA Dongle.
622 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
)
625 int cfg_base
= info
->cfg_base
;
628 /* Enter Configuration */
629 outb(chips
[i
].entr1
, cfg_base
);
630 outb(chips
[i
].entr2
, cfg_base
);
632 /* Select Logical Device 5 Registers (UART2) */
633 outb(0x07, cfg_base
);
634 outb(0x05, cfg_base
+1);
637 outb(0xf0, cfg_base
);
638 reg
= inb(cfg_base
+1);
639 dongle_id
= ((reg
>>6)&0x02) | ((reg
>>5)&0x01);
640 pr_debug("%s(), probing dongle_id=%d, dongle_types=%s\n",
641 __func__
, dongle_id
, dongle_types
[dongle_id
]);
643 /* Exit configuration */
644 outb(0xbb, cfg_base
);
651 * Function ali_ircc_interrupt (irq, dev_id, regs)
653 * An interrupt from the chip has arrived. Time to do some work
656 static irqreturn_t
ali_ircc_interrupt(int irq
, void *dev_id
)
658 struct net_device
*dev
= dev_id
;
659 struct ali_ircc_cb
*self
;
663 self
= netdev_priv(dev
);
665 spin_lock(&self
->lock
);
667 /* Dispatch interrupt handler for the current speed */
668 if (self
->io
.speed
> 115200)
669 ret
= ali_ircc_fir_interrupt(self
);
671 ret
= ali_ircc_sir_interrupt(self
);
673 spin_unlock(&self
->lock
);
678 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
680 * Handle MIR/FIR interrupt
683 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
)
685 __u8 eir
, OldMessageCount
;
689 iobase
= self
->io
.fir_base
;
691 switch_bank(iobase
, BANK0
);
692 self
->InterruptID
= inb(iobase
+FIR_IIR
);
693 self
->BusStatus
= inb(iobase
+FIR_BSR
);
695 OldMessageCount
= (self
->LineStatus
+ 1) & 0x07;
696 self
->LineStatus
= inb(iobase
+FIR_LSR
);
697 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
698 eir
= self
->InterruptID
& self
->ier
; /* Mask out the interesting ones */
700 pr_debug("%s(), self->InterruptID = %x\n", __func__
, self
->InterruptID
);
701 pr_debug("%s(), self->LineStatus = %x\n", __func__
, self
->LineStatus
);
702 pr_debug("%s(), self->ier = %x\n", __func__
, self
->ier
);
703 pr_debug("%s(), eir = %x\n", __func__
, eir
);
705 /* Disable interrupts */
706 SetCOMInterrupts(self
, FALSE
);
708 /* Tx or Rx Interrupt */
712 if (self
->io
.direction
== IO_XMIT
) /* TX */
714 pr_debug("%s(), ******* IIR_EOM (Tx) *******\n",
717 if(ali_ircc_dma_xmit_complete(self
))
719 if (irda_device_txqueue_empty(self
->netdev
))
721 /* Prepare for receive */
722 ali_ircc_dma_receive(self
);
734 pr_debug("%s(), ******* IIR_EOM (Rx) *******\n",
737 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
739 self
->rcvFramesOverflow
= TRUE
;
740 pr_debug("%s(), ******* self->rcvFramesOverflow = TRUE ********\n",
744 if (ali_ircc_dma_receive_complete(self
))
746 pr_debug("%s(), ******* receive complete ********\n",
753 pr_debug("%s(), ******* Not receive complete ********\n",
756 self
->ier
= IER_EOM
| IER_TIMER
;
761 /* Timer Interrupt */
762 else if (eir
& IIR_TIMER
)
764 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
766 self
->rcvFramesOverflow
= TRUE
;
767 pr_debug("%s(), ******* self->rcvFramesOverflow = TRUE *******\n",
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 */
786 if(ali_ircc_dma_receive_complete(self
))
792 self
->ier
= IER_EOM
| IER_TIMER
;
797 /* Restore Interrupt */
798 SetCOMInterrupts(self
, TRUE
);
800 return IRQ_RETVAL(eir
);
804 * Function ali_ircc_sir_interrupt (irq, self, eir)
806 * Handle SIR interrupt
809 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
)
815 iobase
= self
->io
.sir_base
;
817 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
819 /* Clear interrupt */
820 lsr
= inb(iobase
+UART_LSR
);
822 pr_debug("%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
823 __func__
, iir
, lsr
, iobase
);
828 pr_debug("%s(), RLSI\n", __func__
);
831 /* Receive interrupt */
832 ali_ircc_sir_receive(self
);
835 if (lsr
& UART_LSR_THRE
)
837 /* Transmitter ready for data */
838 ali_ircc_sir_write_wakeup(self
);
842 pr_debug("%s(), unhandled IIR=%#x\n",
850 return IRQ_RETVAL(iir
);
855 * Function ali_ircc_sir_receive (self)
857 * Receive one frame from the infrared port
860 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
)
865 IRDA_ASSERT(self
!= NULL
, return;);
867 iobase
= self
->io
.sir_base
;
870 * Receive all characters in Rx FIFO, unwrap and unstuff them.
871 * async_unwrap_char will deliver all found frames
874 async_unwrap_char(self
->netdev
, &self
->netdev
->stats
, &self
->rx_buff
,
875 inb(iobase
+UART_RX
));
877 /* Make sure we don't stay here too long */
878 if (boguscount
++ > 32) {
879 pr_debug("%s(), breaking!\n", __func__
);
882 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
887 * Function ali_ircc_sir_write_wakeup (tty)
889 * Called by the driver when there's room for more data. If we have
890 * more packets to send, we send them here.
893 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
)
898 IRDA_ASSERT(self
!= NULL
, return;);
901 iobase
= self
->io
.sir_base
;
903 /* Finished with frame? */
904 if (self
->tx_buff
.len
> 0)
906 /* Write data left in transmit buffer */
907 actual
= ali_ircc_sir_write(iobase
, self
->io
.fifo_size
,
908 self
->tx_buff
.data
, self
->tx_buff
.len
);
909 self
->tx_buff
.data
+= actual
;
910 self
->tx_buff
.len
-= actual
;
916 /* We must wait until all data are gone */
917 while(!(inb(iobase
+UART_LSR
) & UART_LSR_TEMT
))
918 pr_debug("%s(), UART_LSR_THRE\n", __func__
);
920 pr_debug("%s(), Changing speed! self->new_speed = %d\n",
921 __func__
, self
->new_speed
);
922 ali_ircc_change_speed(self
, self
->new_speed
);
925 // benjamin 2000/11/10 06:32PM
926 if (self
->io
.speed
> 115200)
928 pr_debug("%s(), ali_ircc_change_speed from UART_LSR_TEMT\n",
932 // SetCOMInterrupts(self, TRUE);
938 netif_wake_queue(self
->netdev
);
941 self
->netdev
->stats
.tx_packets
++;
943 /* Turn on receive interrupts */
944 outb(UART_IER_RDI
, iobase
+UART_IER
);
949 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
)
951 struct net_device
*dev
= self
->netdev
;
955 pr_debug("%s(), setting speed = %d\n", __func__
, baud
);
957 /* This function *must* be called with irq off and spin-lock.
960 iobase
= self
->io
.fir_base
;
962 SetCOMInterrupts(self
, FALSE
); // 2000/11/24 11:43AM
964 /* Go to MIR, FIR Speed */
969 ali_ircc_fir_change_speed(self
, baud
);
971 /* Install FIR xmit handler*/
972 dev
->netdev_ops
= &ali_ircc_fir_ops
;
974 /* Enable Interuupt */
975 self
->ier
= IER_EOM
; // benjamin 2000/11/20 07:24PM
977 /* Be ready for incoming frames */
978 ali_ircc_dma_receive(self
); // benajmin 2000/11/8 07:46PM not complete
980 /* Go to SIR Speed */
983 ali_ircc_sir_change_speed(self
, baud
);
985 /* Install SIR xmit handler*/
986 dev
->netdev_ops
= &ali_ircc_sir_ops
;
990 SetCOMInterrupts(self
, TRUE
); // 2000/11/24 11:43AM
992 netif_wake_queue(self
->netdev
);
996 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 baud
)
1000 struct ali_ircc_cb
*self
= priv
;
1001 struct net_device
*dev
;
1004 IRDA_ASSERT(self
!= NULL
, return;);
1007 iobase
= self
->io
.fir_base
;
1009 pr_debug("%s(), self->io.speed = %d, change to speed = %d\n",
1010 __func__
, self
->io
.speed
, baud
);
1012 /* Come from SIR speed */
1013 if(self
->io
.speed
<=115200)
1018 /* Update accounting for new speed */
1019 self
->io
.speed
= baud
;
1021 // Set Dongle Speed mode
1022 ali_ircc_change_dongle_speed(self
, baud
);
1027 * Function ali_sir_change_speed (self, speed)
1029 * Set speed of IrDA port to specified baudrate
1032 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
)
1034 struct ali_ircc_cb
*self
= priv
;
1035 unsigned long flags
;
1037 int fcr
; /* FIFO control reg */
1038 int lcr
; /* Line control reg */
1042 pr_debug("%s(), Setting speed to: %d\n", __func__
, speed
);
1044 IRDA_ASSERT(self
!= NULL
, return;);
1046 iobase
= self
->io
.sir_base
;
1048 /* Come from MIR or FIR speed */
1049 if(self
->io
.speed
>115200)
1051 // Set Dongle Speed mode first
1052 ali_ircc_change_dongle_speed(self
, speed
);
1057 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1059 inb(iobase
+UART_LSR
);
1060 inb(iobase
+UART_SCR
);
1062 /* Update accounting for new speed */
1063 self
->io
.speed
= speed
;
1065 spin_lock_irqsave(&self
->lock
, flags
);
1067 divisor
= 115200/speed
;
1069 fcr
= UART_FCR_ENABLE_FIFO
;
1072 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1073 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1074 * about this timeout since it will always be fast enough.
1076 if (self
->io
.speed
< 38400)
1077 fcr
|= UART_FCR_TRIGGER_1
;
1079 fcr
|= UART_FCR_TRIGGER_14
;
1081 /* IrDA ports use 8N1 */
1082 lcr
= UART_LCR_WLEN8
;
1084 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
1085 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
1086 outb(divisor
>> 8, iobase
+UART_DLM
);
1087 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
1088 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
1090 /* without this, the connection will be broken after come back from FIR speed,
1091 but with this, the SIR connection is harder to established */
1092 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), iobase
+UART_MCR
);
1094 spin_unlock_irqrestore(&self
->lock
, flags
);
1098 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
)
1101 struct ali_ircc_cb
*self
= priv
;
1102 int iobase
,dongle_id
;
1106 iobase
= self
->io
.fir_base
; /* or iobase = self->io.sir_base; */
1107 dongle_id
= self
->io
.dongle_id
;
1109 /* We are already locked, no need to do it again */
1111 pr_debug("%s(), Set Speed for %s , Speed = %d\n",
1112 __func__
, dongle_types
[dongle_id
], speed
);
1114 switch_bank(iobase
, BANK2
);
1115 tmp
= inb(iobase
+FIR_IRDA_CR
);
1117 /* IBM type dongle */
1120 if(speed
== 4000000)
1123 // SD/MODE __| |__ __
1128 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1129 tmp
|= IRDA_CR_CRC
; // CRC=1
1131 switch_bank(iobase
, BANK2
);
1132 outb(tmp
, iobase
+FIR_IRDA_CR
);
1134 // T1 -> SD/MODE:0 IRTX:0
1137 outb(tmp
, iobase
+FIR_IRDA_CR
);
1140 // T2 -> SD/MODE:1 IRTX:0
1143 outb(tmp
, iobase
+FIR_IRDA_CR
);
1146 // T3 -> SD/MODE:1 IRTX:1
1148 outb(tmp
, iobase
+FIR_IRDA_CR
);
1151 // T4 -> SD/MODE:0 IRTX:1
1154 outb(tmp
, iobase
+FIR_IRDA_CR
);
1157 // T5 -> SD/MODE:0 IRTX:0
1160 outb(tmp
, iobase
+FIR_IRDA_CR
);
1163 // reset -> Normal TX output Signal
1164 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1166 else /* speed <=1152000 */
1174 /* MIR 115200, 57600 */
1177 tmp
|= 0xA0; //HDLC=1, 1.152Mbps=1
1181 tmp
&=~0x80; //HDLC 0.576Mbps
1182 tmp
|= 0x20; //HDLC=1,
1185 tmp
|= IRDA_CR_CRC
; // CRC=1
1187 switch_bank(iobase
, BANK2
);
1188 outb(tmp
, iobase
+FIR_IRDA_CR
);
1190 /* MIR 115200, 57600 */
1192 //switch_bank(iobase, BANK2);
1193 // T1 -> SD/MODE:0 IRTX:0
1196 outb(tmp
, iobase
+FIR_IRDA_CR
);
1199 // T2 -> SD/MODE:1 IRTX:0
1202 outb(tmp
, iobase
+FIR_IRDA_CR
);
1204 // T3 -> SD/MODE:0 IRTX:0
1207 outb(tmp
, iobase
+FIR_IRDA_CR
);
1210 // reset -> Normal TX output Signal
1211 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1214 else if (dongle_id
== 1) /* HP HDSL-3600 */
1219 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1223 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1227 tmp
&=~0x80; // HDLC 0.576Mbps
1228 tmp
|= 0x20; // HDLC=1,
1232 tmp
|= IRDA_CR_CRC
; // CRC=1
1234 switch_bank(iobase
, BANK2
);
1235 outb(tmp
, iobase
+FIR_IRDA_CR
);
1237 else /* HP HDSL-1100 */
1239 if(speed
<= 115200) /* SIR */
1242 tmp
&= ~IRDA_CR_FIR_SIN
; // HP sin select = 0
1244 switch_bank(iobase
, BANK2
);
1245 outb(tmp
, iobase
+FIR_IRDA_CR
);
1253 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1257 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1261 tmp
&=~0x80; // HDLC 0.576Mbps
1262 tmp
|= 0x20; // HDLC=1,
1266 tmp
|= IRDA_CR_CRC
; // CRC=1
1267 tmp
|= IRDA_CR_FIR_SIN
; // HP sin select = 1
1269 switch_bank(iobase
, BANK2
);
1270 outb(tmp
, iobase
+FIR_IRDA_CR
);
1274 switch_bank(iobase
, BANK0
);
1279 * Function ali_ircc_sir_write (driver)
1281 * Fill Tx FIFO with transmit data
1284 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
1289 /* Tx FIFO should be empty! */
1290 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
1291 pr_debug("%s(), failed, fifo not empty!\n", __func__
);
1295 /* Fill FIFO with current frame */
1296 while ((fifo_size
-- > 0) && (actual
< len
)) {
1297 /* Transmit next byte */
1298 outb(buf
[actual
], iobase
+UART_TX
);
1307 * Function ali_ircc_net_open (dev)
1312 static int ali_ircc_net_open(struct net_device
*dev
)
1314 struct ali_ircc_cb
*self
;
1319 IRDA_ASSERT(dev
!= NULL
, return -1;);
1321 self
= netdev_priv(dev
);
1323 IRDA_ASSERT(self
!= NULL
, return 0;);
1325 iobase
= self
->io
.fir_base
;
1327 /* Request IRQ and install Interrupt Handler */
1328 if (request_irq(self
->io
.irq
, ali_ircc_interrupt
, 0, dev
->name
, dev
))
1330 net_warn_ratelimited("%s, unable to allocate irq=%d\n",
1331 ALI_IRCC_DRIVER_NAME
, self
->io
.irq
);
1336 * Always allocate the DMA channel after the IRQ, and clean up on
1339 if (request_dma(self
->io
.dma
, dev
->name
)) {
1340 net_warn_ratelimited("%s, unable to allocate dma=%d\n",
1341 ALI_IRCC_DRIVER_NAME
, self
->io
.dma
);
1342 free_irq(self
->io
.irq
, dev
);
1346 /* Turn on interrups */
1347 outb(UART_IER_RDI
, iobase
+UART_IER
);
1349 /* Ready to play! */
1350 netif_start_queue(dev
); //benjamin by irport
1352 /* Give self a hardware name */
1353 sprintf(hwname
, "ALI-FIR @ 0x%03x", self
->io
.fir_base
);
1356 * Open new IrLAP layer instance, now that everything should be
1357 * initialized properly
1359 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1366 * Function ali_ircc_net_close (dev)
1371 static int ali_ircc_net_close(struct net_device
*dev
)
1374 struct ali_ircc_cb
*self
;
1378 IRDA_ASSERT(dev
!= NULL
, return -1;);
1380 self
= netdev_priv(dev
);
1381 IRDA_ASSERT(self
!= NULL
, return 0;);
1384 netif_stop_queue(dev
);
1386 /* Stop and remove instance of IrLAP */
1388 irlap_close(self
->irlap
);
1391 disable_dma(self
->io
.dma
);
1393 /* Disable interrupts */
1394 SetCOMInterrupts(self
, FALSE
);
1396 free_irq(self
->io
.irq
, dev
);
1397 free_dma(self
->io
.dma
);
1404 * Function ali_ircc_fir_hard_xmit (skb, dev)
1406 * Transmit the frame
1409 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
1410 struct net_device
*dev
)
1412 struct ali_ircc_cb
*self
;
1413 unsigned long flags
;
1419 self
= netdev_priv(dev
);
1420 iobase
= self
->io
.fir_base
;
1422 netif_stop_queue(dev
);
1424 /* Make sure tests *& speed change are atomic */
1425 spin_lock_irqsave(&self
->lock
, flags
);
1427 /* Note : you should make sure that speed changes are not going
1428 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1429 * details - Jean II */
1431 /* Check if we need to change the speed */
1432 speed
= irda_get_next_speed(skb
);
1433 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1434 /* Check for empty frame */
1436 ali_ircc_change_speed(self
, speed
);
1437 dev
->trans_start
= jiffies
;
1438 spin_unlock_irqrestore(&self
->lock
, flags
);
1440 return NETDEV_TX_OK
;
1442 self
->new_speed
= speed
;
1445 /* Register and copy this frame to DMA memory */
1446 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
1447 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
1448 self
->tx_fifo
.tail
+= skb
->len
;
1450 dev
->stats
.tx_bytes
+= skb
->len
;
1452 skb_copy_from_linear_data(skb
, self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
,
1454 self
->tx_fifo
.len
++;
1455 self
->tx_fifo
.free
++;
1457 /* Start transmit only if there is currently no transmit going on */
1458 if (self
->tx_fifo
.len
== 1)
1460 /* Check if we must wait the min turn time or not */
1461 mtt
= irda_get_mtt(skb
);
1465 /* Check how much time we have used already */
1466 do_gettimeofday(&self
->now
);
1468 diff
= self
->now
.tv_usec
- self
->stamp
.tv_usec
;
1469 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1471 pr_debug("%s(), ******* diff = %d *******\n",
1477 /* Check if the mtt is larger than the time we have
1478 * already used by all the protocol processing
1485 * Use timer if delay larger than 1000 us, and
1486 * use udelay for smaller values which should
1491 /* Adjust for timer resolution */
1492 mtt
= (mtt
+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1494 pr_debug("%s(), ************** mtt = %d ***********\n",
1498 if (mtt
== 1) /* 500 us */
1500 switch_bank(iobase
, BANK1
);
1501 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
);
1503 else if (mtt
== 2) /* 1 ms */
1505 switch_bank(iobase
, BANK1
);
1506 outb(TIMER_IIR_1ms
, iobase
+FIR_TIMER_IIR
);
1508 else /* > 2ms -> 4ms */
1510 switch_bank(iobase
, BANK1
);
1511 outb(TIMER_IIR_2ms
, iobase
+FIR_TIMER_IIR
);
1516 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1517 self
->io
.direction
= IO_XMIT
;
1519 /* Enable timer interrupt */
1520 self
->ier
= IER_TIMER
;
1521 SetCOMInterrupts(self
, TRUE
);
1523 /* Timer will take care of the rest */
1528 } // if (if (mtt > diff)
1531 /* Enable EOM interrupt */
1532 self
->ier
= IER_EOM
;
1533 SetCOMInterrupts(self
, TRUE
);
1535 /* Transmit frame */
1536 ali_ircc_dma_xmit(self
);
1537 } // if (self->tx_fifo.len == 1)
1541 /* Not busy transmitting anymore if window is not full */
1542 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
)
1543 netif_wake_queue(self
->netdev
);
1545 /* Restore bank register */
1546 switch_bank(iobase
, BANK0
);
1548 dev
->trans_start
= jiffies
;
1549 spin_unlock_irqrestore(&self
->lock
, flags
);
1552 return NETDEV_TX_OK
;
1556 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
)
1559 unsigned char FIFO_OPTI
, Hi
, Lo
;
1563 iobase
= self
->io
.fir_base
;
1565 /* FIFO threshold , this method comes from NDIS5 code */
1567 if(self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
< TX_FIFO_Threshold
)
1568 FIFO_OPTI
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
-1;
1570 FIFO_OPTI
= TX_FIFO_Threshold
;
1573 switch_bank(iobase
, BANK1
);
1574 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1576 self
->io
.direction
= IO_XMIT
;
1578 irda_setup_dma(self
->io
.dma
,
1579 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
1580 self
->tx_buff
.head
) + self
->tx_buff_dma
,
1581 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
1585 switch_bank(iobase
, BANK0
);
1586 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1588 /* Set Tx FIFO threshold */
1589 if (self
->fifo_opti_buf
!=FIFO_OPTI
)
1591 switch_bank(iobase
, BANK1
);
1592 outb(FIFO_OPTI
, iobase
+FIR_FIFO_TR
) ;
1593 self
->fifo_opti_buf
=FIFO_OPTI
;
1596 /* Set Tx DMA threshold */
1597 switch_bank(iobase
, BANK1
);
1598 outb(TX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1600 /* Set max Tx frame size */
1601 Hi
= (self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
>> 8) & 0x0f;
1602 Lo
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
& 0xff;
1603 switch_bank(iobase
, BANK2
);
1604 outb(Hi
, iobase
+FIR_TX_DSR_HI
);
1605 outb(Lo
, iobase
+FIR_TX_DSR_LO
);
1607 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1608 switch_bank(iobase
, BANK0
);
1609 tmp
= inb(iobase
+FIR_LCR_B
);
1610 tmp
&= ~0x20; // Disable SIP
1611 outb(((unsigned char)(tmp
& 0x3f) | LCR_B_TX_MODE
) & ~LCR_B_BW
, iobase
+FIR_LCR_B
);
1612 pr_debug("%s(), *** Change to TX mode: FIR_LCR_B = 0x%x ***\n",
1613 __func__
, inb(iobase
+ FIR_LCR_B
));
1615 outb(0, iobase
+FIR_LSR
);
1617 /* Enable DMA and Burst Mode */
1618 switch_bank(iobase
, BANK1
);
1619 outb(inb(iobase
+FIR_CR
) | CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1621 switch_bank(iobase
, BANK0
);
1625 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
)
1631 iobase
= self
->io
.fir_base
;
1634 switch_bank(iobase
, BANK1
);
1635 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1637 /* Check for underrun! */
1638 switch_bank(iobase
, BANK0
);
1639 if((inb(iobase
+FIR_LSR
) & LSR_FRAME_ABORT
) == LSR_FRAME_ABORT
)
1642 net_err_ratelimited("%s(), ********* LSR_FRAME_ABORT *********\n",
1644 self
->netdev
->stats
.tx_errors
++;
1645 self
->netdev
->stats
.tx_fifo_errors
++;
1649 self
->netdev
->stats
.tx_packets
++;
1652 /* Check if we need to change the speed */
1653 if (self
->new_speed
)
1655 ali_ircc_change_speed(self
, self
->new_speed
);
1656 self
->new_speed
= 0;
1659 /* Finished with this frame, so prepare for next */
1660 self
->tx_fifo
.ptr
++;
1661 self
->tx_fifo
.len
--;
1663 /* Any frames to be sent back-to-back? */
1664 if (self
->tx_fifo
.len
)
1666 ali_ircc_dma_xmit(self
);
1668 /* Not finished yet! */
1672 { /* Reset Tx FIFO info */
1673 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1674 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1677 /* Make sure we have room for more frames */
1678 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
) {
1679 /* Not busy transmitting anymore */
1680 /* Tell the network layer, that we can accept more frames */
1681 netif_wake_queue(self
->netdev
);
1684 switch_bank(iobase
, BANK0
);
1690 * Function ali_ircc_dma_receive (self)
1692 * Get ready for receiving a frame. The device will initiate a DMA
1693 * if it starts to receive a frame.
1696 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
)
1701 iobase
= self
->io
.fir_base
;
1703 /* Reset Tx FIFO info */
1704 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1705 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1708 switch_bank(iobase
, BANK1
);
1709 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1711 /* Reset Message Count */
1712 switch_bank(iobase
, BANK0
);
1713 outb(0x07, iobase
+FIR_LSR
);
1715 self
->rcvFramesOverflow
= FALSE
;
1717 self
->LineStatus
= inb(iobase
+FIR_LSR
) ;
1719 /* Reset Rx FIFO info */
1720 self
->io
.direction
= IO_RECV
;
1721 self
->rx_buff
.data
= self
->rx_buff
.head
;
1724 // switch_bank(iobase, BANK0);
1725 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1727 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1728 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1730 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1733 /* Set Receive Mode,Brick Wall */
1734 //switch_bank(iobase, BANK0);
1735 tmp
= inb(iobase
+FIR_LCR_B
);
1736 outb((unsigned char)(tmp
&0x3f) | LCR_B_RX_MODE
| LCR_B_BW
, iobase
+ FIR_LCR_B
); // 2000/12/1 05:16PM
1737 pr_debug("%s(), *** Change To RX mode: FIR_LCR_B = 0x%x ***\n",
1738 __func__
, inb(iobase
+ FIR_LCR_B
));
1740 /* Set Rx Threshold */
1741 switch_bank(iobase
, BANK1
);
1742 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
1743 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1745 /* Enable DMA and Burst Mode */
1746 // switch_bank(iobase, BANK1);
1747 outb(CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1749 switch_bank(iobase
, BANK0
);
1753 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
)
1755 struct st_fifo
*st_fifo
;
1756 struct sk_buff
*skb
;
1757 __u8 status
, MessageCount
;
1758 int len
, i
, iobase
, val
;
1760 st_fifo
= &self
->st_fifo
;
1761 iobase
= self
->io
.fir_base
;
1763 switch_bank(iobase
, BANK0
);
1764 MessageCount
= inb(iobase
+ FIR_LSR
)&0x07;
1766 if (MessageCount
> 0)
1767 pr_debug("%s(), Message count = %d\n", __func__
, MessageCount
);
1769 for (i
=0; i
<=MessageCount
; i
++)
1772 switch_bank(iobase
, BANK0
);
1773 status
= inb(iobase
+FIR_LSR
);
1775 switch_bank(iobase
, BANK2
);
1776 len
= inb(iobase
+FIR_RX_DSR_HI
) & 0x0f;
1778 len
|= inb(iobase
+FIR_RX_DSR_LO
);
1780 pr_debug("%s(), RX Length = 0x%.2x,\n", __func__
, len
);
1781 pr_debug("%s(), RX Status = 0x%.2x,\n", __func__
, status
);
1783 if (st_fifo
->tail
>= MAX_RX_WINDOW
) {
1784 pr_debug("%s(), window is full!\n", __func__
);
1788 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1789 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1790 st_fifo
->pending_bytes
+= len
;
1795 for (i
=0; i
<=MessageCount
; i
++)
1797 /* Get first entry */
1798 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1799 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1800 st_fifo
->pending_bytes
-= len
;
1804 /* Check for errors */
1805 if ((status
& 0xd8) || self
->rcvFramesOverflow
|| (len
==0))
1807 pr_debug("%s(), ************* RX Errors ************\n",
1811 self
->netdev
->stats
.rx_errors
++;
1813 self
->rx_buff
.data
+= len
;
1815 if (status
& LSR_FIFO_UR
)
1817 self
->netdev
->stats
.rx_frame_errors
++;
1818 pr_debug("%s(), ************* FIFO Errors ************\n",
1821 if (status
& LSR_FRAME_ERROR
)
1823 self
->netdev
->stats
.rx_frame_errors
++;
1824 pr_debug("%s(), ************* FRAME Errors ************\n",
1828 if (status
& LSR_CRC_ERROR
)
1830 self
->netdev
->stats
.rx_crc_errors
++;
1831 pr_debug("%s(), ************* CRC Errors ************\n",
1835 if(self
->rcvFramesOverflow
)
1837 self
->netdev
->stats
.rx_frame_errors
++;
1838 pr_debug("%s(), ************* Overran DMA buffer ************\n",
1843 self
->netdev
->stats
.rx_frame_errors
++;
1844 pr_debug("%s(), ********** Receive Frame Size = 0 *********\n",
1851 if (st_fifo
->pending_bytes
< 32)
1853 switch_bank(iobase
, BANK0
);
1854 val
= inb(iobase
+FIR_BSR
);
1855 if ((val
& BSR_FIFO_NOT_EMPTY
)== 0x80)
1857 pr_debug("%s(), ************* BSR_FIFO_NOT_EMPTY ************\n",
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 self
->netdev
->stats
.rx_dropped
++;
1898 /* Make sure IP header gets aligned */
1899 skb_reserve(skb
, 1);
1901 /* Copy frame without CRC, CRC is removed by hardware*/
1903 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
);
1905 /* Move to next frame */
1906 self
->rx_buff
.data
+= len
;
1907 self
->netdev
->stats
.rx_bytes
+= len
;
1908 self
->netdev
->stats
.rx_packets
++;
1910 skb
->dev
= self
->netdev
;
1911 skb_reset_mac_header(skb
);
1912 skb
->protocol
= htons(ETH_P_IRDA
);
1917 switch_bank(iobase
, BANK0
);
1925 * Function ali_ircc_sir_hard_xmit (skb, dev)
1927 * Transmit the frame!
1930 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
1931 struct net_device
*dev
)
1933 struct ali_ircc_cb
*self
;
1934 unsigned long flags
;
1939 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
1941 self
= netdev_priv(dev
);
1942 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
1944 iobase
= self
->io
.sir_base
;
1946 netif_stop_queue(dev
);
1948 /* Make sure tests *& speed change are atomic */
1949 spin_lock_irqsave(&self
->lock
, flags
);
1951 /* Note : you should make sure that speed changes are not going
1952 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1953 * details - Jean II */
1955 /* Check if we need to change the speed */
1956 speed
= irda_get_next_speed(skb
);
1957 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1958 /* Check for empty frame */
1960 ali_ircc_change_speed(self
, speed
);
1961 dev
->trans_start
= jiffies
;
1962 spin_unlock_irqrestore(&self
->lock
, flags
);
1964 return NETDEV_TX_OK
;
1966 self
->new_speed
= speed
;
1969 /* Init tx buffer */
1970 self
->tx_buff
.data
= self
->tx_buff
.head
;
1972 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
1973 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
1974 self
->tx_buff
.truesize
);
1976 self
->netdev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
1978 /* Turn on transmit finished interrupt. Will fire immediately! */
1979 outb(UART_IER_THRI
, iobase
+UART_IER
);
1981 dev
->trans_start
= jiffies
;
1982 spin_unlock_irqrestore(&self
->lock
, flags
);
1987 return NETDEV_TX_OK
;
1992 * Function ali_ircc_net_ioctl (dev, rq, cmd)
1994 * Process IOCTL commands for this device
1997 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1999 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
2000 struct ali_ircc_cb
*self
;
2001 unsigned long flags
;
2005 IRDA_ASSERT(dev
!= NULL
, return -1;);
2007 self
= netdev_priv(dev
);
2009 IRDA_ASSERT(self
!= NULL
, return -1;);
2011 pr_debug("%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
2014 case SIOCSBANDWIDTH
: /* Set bandwidth */
2015 pr_debug("%s(), SIOCSBANDWIDTH\n", __func__
);
2017 * This function will also be used by IrLAP to change the
2018 * speed, so we still must allow for speed change within
2019 * interrupt context.
2021 if (!in_interrupt() && !capable(CAP_NET_ADMIN
))
2024 spin_lock_irqsave(&self
->lock
, flags
);
2025 ali_ircc_change_speed(self
, irq
->ifr_baudrate
);
2026 spin_unlock_irqrestore(&self
->lock
, flags
);
2028 case SIOCSMEDIABUSY
: /* Set media busy */
2029 pr_debug("%s(), SIOCSMEDIABUSY\n", __func__
);
2030 if (!capable(CAP_NET_ADMIN
))
2032 irda_device_set_media_busy(self
->netdev
, TRUE
);
2034 case SIOCGRECEIVING
: /* Check if we are receiving right now */
2035 pr_debug("%s(), SIOCGRECEIVING\n", __func__
);
2036 /* This is protected */
2037 irq
->ifr_receiving
= ali_ircc_is_receiving(self
);
2048 * Function ali_ircc_is_receiving (self)
2050 * Return TRUE is we are currently receiving a frame
2053 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
)
2055 unsigned long flags
;
2060 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
2062 spin_lock_irqsave(&self
->lock
, flags
);
2064 if (self
->io
.speed
> 115200)
2066 iobase
= self
->io
.fir_base
;
2068 switch_bank(iobase
, BANK1
);
2069 if((inb(iobase
+FIR_FIFO_FR
) & 0x3f) != 0)
2071 /* We are receiving something */
2072 pr_debug("%s(), We are receiving something\n",
2076 switch_bank(iobase
, BANK0
);
2080 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
2083 spin_unlock_irqrestore(&self
->lock
, flags
);
2089 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
2091 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2093 net_info_ratelimited("%s, Suspending\n", ALI_IRCC_DRIVER_NAME
);
2095 if (self
->io
.suspended
)
2098 ali_ircc_net_close(self
->netdev
);
2100 self
->io
.suspended
= 1;
2105 static int ali_ircc_resume(struct platform_device
*dev
)
2107 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2109 if (!self
->io
.suspended
)
2112 ali_ircc_net_open(self
->netdev
);
2114 net_info_ratelimited("%s, Waking up\n", ALI_IRCC_DRIVER_NAME
);
2116 self
->io
.suspended
= 0;
2121 /* ALi Chip Function */
2123 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
)
2126 unsigned char newMask
;
2128 int iobase
= self
->io
.fir_base
; /* or sir_base */
2130 pr_debug("%s(), -------- Start -------- ( Enable = %d )\n",
2133 /* Enable the interrupt which we wish to */
2135 if (self
->io
.direction
== IO_XMIT
)
2137 if (self
->io
.speed
> 115200) /* FIR, MIR */
2139 newMask
= self
->ier
;
2143 newMask
= UART_IER_THRI
| UART_IER_RDI
;
2147 if (self
->io
.speed
> 115200) /* FIR, MIR */
2149 newMask
= self
->ier
;
2153 newMask
= UART_IER_RDI
;
2157 else /* Disable all the interrupts */
2163 //SIR and FIR has different registers
2164 if (self
->io
.speed
> 115200)
2166 switch_bank(iobase
, BANK0
);
2167 outb(newMask
, iobase
+FIR_IER
);
2170 outb(newMask
, iobase
+UART_IER
);
2174 static void SIR2FIR(int iobase
)
2176 //unsigned char tmp;
2179 /* Already protected (change_speed() or setup()), no need to lock.
2182 outb(0x28, iobase
+UART_MCR
);
2183 outb(0x68, iobase
+UART_MCR
);
2184 outb(0x88, iobase
+UART_MCR
);
2186 outb(0x60, iobase
+FIR_MCR
); /* Master Reset */
2187 outb(0x20, iobase
+FIR_MCR
); /* Master Interrupt Enable */
2189 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2191 //outb(tmp, iobase+FIR_LCR_B);
2195 static void FIR2SIR(int iobase
)
2200 /* Already protected (change_speed() or setup()), no need to lock.
2203 outb(0x20, iobase
+FIR_MCR
); /* IRQ to low */
2204 outb(0x00, iobase
+UART_IER
);
2206 outb(0xA0, iobase
+FIR_MCR
); /* Don't set master reset */
2207 outb(0x00, iobase
+UART_FCR
);
2208 outb(0x07, iobase
+UART_FCR
);
2210 val
= inb(iobase
+UART_RX
);
2211 val
= inb(iobase
+UART_LSR
);
2212 val
= inb(iobase
+UART_MSR
);
2216 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2217 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2218 MODULE_LICENSE("GPL");
2219 MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME
);
2222 module_param_array(io
, int, NULL
, 0);
2223 MODULE_PARM_DESC(io
, "Base I/O addresses");
2224 module_param_array(irq
, int, NULL
, 0);
2225 MODULE_PARM_DESC(irq
, "IRQ lines");
2226 module_param_array(dma
, int, NULL
, 0);
2227 MODULE_PARM_DESC(dma
, "DMA channels");
2229 module_init(ali_ircc_init
);
2230 module_exit(ali_ircc_cleanup
);