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
,
67 /* Module parameters */
68 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
70 /* Use BIOS settions by default, but user may supply module parameters */
71 static unsigned int io
[] = { ~0, ~0, ~0, ~0 };
72 static unsigned int irq
[] = { 0, 0, 0, 0 };
73 static unsigned int dma
[] = { 0, 0, 0, 0 };
75 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
);
76 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
);
77 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
);
79 /* These are the currently known ALi south-bridge chipsets, the only one difference
80 * is that M1543C doesn't support HP HDSL-3600
82 static ali_chip_t chips
[] =
84 { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53
, ali_ircc_init_43
},
85 { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53
, ali_ircc_init_53
},
86 { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53
, ali_ircc_init_53
},
90 /* Max 4 instances for now */
91 static struct ali_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
94 static char *dongle_types
[] = {
98 "No dongle connected",
101 /* Some prototypes */
102 static int ali_ircc_open(int i
, chipio_t
*info
);
104 static int ali_ircc_close(struct ali_ircc_cb
*self
);
106 static int ali_ircc_setup(chipio_t
*info
);
107 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
);
108 static int ali_ircc_net_open(struct net_device
*dev
);
109 static int ali_ircc_net_close(struct net_device
*dev
);
110 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
111 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
);
114 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
115 struct net_device
*dev
);
116 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
);
117 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
);
118 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
);
119 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
120 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
123 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
124 struct net_device
*dev
);
125 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
126 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
);
127 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
);
128 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
);
129 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
);
130 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
);
133 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
);
134 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
);
136 /* ALi chip function */
137 static void SIR2FIR(int iobase
);
138 static void FIR2SIR(int iobase
);
139 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
);
142 * Function ali_ircc_init ()
144 * Initialize chip. Find out whay kinds of chips we are dealing with
145 * and their configuration registers address
147 static int __init
ali_ircc_init(void)
156 ret
= platform_driver_register(&ali_ircc_driver
);
158 net_err_ratelimited("%s, Can't register driver!\n",
159 ALI_IRCC_DRIVER_NAME
);
165 /* Probe for all the ALi chipsets we know about */
166 for (chip
= chips
; chip
->name
; chip
++, i
++)
168 pr_debug("%s(), Probing for %s ...\n", __func__
, chip
->name
);
170 /* Try all config registers for this chip */
171 for (cfg
=0; cfg
<2; cfg
++)
173 cfg_base
= chip
->cfg
[cfg
];
177 memset(&info
, 0, sizeof(chipio_t
));
178 info
.cfg_base
= cfg_base
;
179 info
.fir_base
= io
[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 pr_debug("%s(), Chip found at 0x%03x\n",
201 outb(0x1F, cfg_base
);
202 revision
= inb(cfg_base
+1);
203 pr_debug("%s(), Found %s chip, revision=%d\n",
204 __func__
, chip
->name
, revision
);
207 * If the user supplies the base address, then
208 * we init the chip, if not we probe the values
213 chip
->init(chip
, &info
);
217 chip
->probe(chip
, &info
);
220 if (ali_ircc_open(i
, &info
) == 0)
226 pr_debug("%s(), No %s chip at 0x%03x\n",
227 __func__
, chip
->name
, cfg_base
);
229 /* Exit configuration */
230 outb(0xbb, cfg_base
);
235 platform_driver_unregister(&ali_ircc_driver
);
241 * Function ali_ircc_cleanup ()
243 * Close all configured chips
246 static void __exit
ali_ircc_cleanup(void)
250 for (i
=0; i
< ARRAY_SIZE(dev_self
); i
++) {
252 ali_ircc_close(dev_self
[i
]);
255 platform_driver_unregister(&ali_ircc_driver
);
259 static const struct net_device_ops ali_ircc_sir_ops
= {
260 .ndo_open
= ali_ircc_net_open
,
261 .ndo_stop
= ali_ircc_net_close
,
262 .ndo_start_xmit
= ali_ircc_sir_hard_xmit
,
263 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
266 static const struct net_device_ops ali_ircc_fir_ops
= {
267 .ndo_open
= ali_ircc_net_open
,
268 .ndo_stop
= ali_ircc_net_close
,
269 .ndo_start_xmit
= ali_ircc_fir_hard_xmit
,
270 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
274 * Function ali_ircc_open (int i, chipio_t *inf)
276 * Open driver instance
279 static int ali_ircc_open(int i
, chipio_t
*info
)
281 struct net_device
*dev
;
282 struct ali_ircc_cb
*self
;
286 if (i
>= ARRAY_SIZE(dev_self
)) {
287 net_err_ratelimited("%s(), maximum number of supported chips reached!\n",
292 /* Set FIR FIFO and DMA Threshold */
293 if ((ali_ircc_setup(info
)) == -1)
296 dev
= alloc_irdadev(sizeof(*self
));
298 net_err_ratelimited("%s(), can't allocate memory for control block!\n",
303 self
= netdev_priv(dev
);
305 spin_lock_init(&self
->lock
);
307 /* Need to store self somewhere */
312 self
->io
.cfg_base
= info
->cfg_base
; /* In ali_ircc_probe_53 assign */
313 self
->io
.fir_base
= info
->fir_base
; /* info->sir_base = info->fir_base */
314 self
->io
.sir_base
= info
->sir_base
; /* ALi SIR and FIR use the same address */
315 self
->io
.irq
= info
->irq
;
316 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
317 self
->io
.dma
= info
->dma
;
318 self
->io
.fifo_size
= 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
320 /* Reserve the ioports that we need */
321 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
,
322 ALI_IRCC_DRIVER_NAME
)) {
323 net_warn_ratelimited("%s(), can't get iobase of 0x%03x\n",
324 __func__
, self
->io
.fir_base
);
329 /* Initialize QoS for this device */
330 irda_init_max_qos_capabilies(&self
->qos
);
332 /* The only value we must override it the baudrate */
333 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
334 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8); // benjamin 2000/11/8 05:27PM
336 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
338 irda_qos_bits_to_value(&self
->qos
);
340 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
341 self
->rx_buff
.truesize
= 14384;
342 self
->tx_buff
.truesize
= 14384;
344 /* Allocate memory if needed */
346 dma_zalloc_coherent(NULL
, self
->rx_buff
.truesize
,
347 &self
->rx_buff_dma
, GFP_KERNEL
);
348 if (self
->rx_buff
.head
== NULL
) {
354 dma_zalloc_coherent(NULL
, self
->tx_buff
.truesize
,
355 &self
->tx_buff_dma
, GFP_KERNEL
);
356 if (self
->tx_buff
.head
== NULL
) {
361 self
->rx_buff
.in_frame
= FALSE
;
362 self
->rx_buff
.state
= OUTSIDE_FRAME
;
363 self
->tx_buff
.data
= self
->tx_buff
.head
;
364 self
->rx_buff
.data
= self
->rx_buff
.head
;
366 /* Reset Tx queue info */
367 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
368 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
370 /* Override the network functions we need to use */
371 dev
->netdev_ops
= &ali_ircc_sir_ops
;
373 err
= register_netdev(dev
);
375 net_err_ratelimited("%s(), register_netdev() failed!\n",
379 net_info_ratelimited("IrDA: Registered device %s\n", dev
->name
);
381 /* Check dongle id */
382 dongle_id
= ali_ircc_read_dongle_id(i
, info
);
383 net_info_ratelimited("%s(), %s, Found dongle: %s\n",
384 __func__
, ALI_IRCC_DRIVER_NAME
,
385 dongle_types
[dongle_id
]);
387 self
->io
.dongle_id
= dongle_id
;
393 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
394 self
->tx_buff
.head
, self
->tx_buff_dma
);
396 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
397 self
->rx_buff
.head
, self
->rx_buff_dma
);
399 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
408 * Function ali_ircc_close (self)
410 * Close driver instance
413 static int __exit
ali_ircc_close(struct ali_ircc_cb
*self
)
417 IRDA_ASSERT(self
!= NULL
, return -1;);
419 iobase
= self
->io
.fir_base
;
421 /* Remove netdevice */
422 unregister_netdev(self
->netdev
);
424 /* Release the PORT that this driver is using */
425 pr_debug("%s(), Releasing Region %03x\n", __func__
, self
->io
.fir_base
);
426 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
428 if (self
->tx_buff
.head
)
429 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
430 self
->tx_buff
.head
, self
->tx_buff_dma
);
432 if (self
->rx_buff
.head
)
433 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
434 self
->rx_buff
.head
, self
->rx_buff_dma
);
436 dev_self
[self
->index
] = NULL
;
437 free_netdev(self
->netdev
);
444 * Function ali_ircc_init_43 (chip, info)
446 * Initialize the ALi M1543 chip.
448 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
)
450 /* All controller information like I/O address, DMA channel, IRQ
458 * Function ali_ircc_init_53 (chip, info)
460 * Initialize the ALi M1535 chip.
462 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
)
464 /* All controller information like I/O address, DMA channel, IRQ
472 * Function ali_ircc_probe_53 (chip, info)
474 * Probes for the ALi M1535D or M1535
476 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
)
478 int cfg_base
= info
->cfg_base
;
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 pr_debug("%s(), probing fir_base=0x%03x\n", __func__
, 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 pr_debug("%s(), probing irq=%d\n", __func__
, 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 net_warn_ratelimited("%s(), No DMA channel assigned !\n",
516 pr_debug("%s(), probing dma=%d\n", __func__
, info
->dma
);
518 /* Read Enabled Status */
519 outb(0x30, cfg_base
);
520 reg
= inb(cfg_base
+1);
521 info
->enabled
= (reg
& 0x80) && (reg
& 0x01);
522 pr_debug("%s(), probing enabled=%d\n", __func__
, info
->enabled
);
524 /* Read Power Status */
525 outb(0x22, cfg_base
);
526 reg
= inb(cfg_base
+1);
527 info
->suspended
= (reg
& 0x20);
528 pr_debug("%s(), probing suspended=%d\n", __func__
, info
->suspended
);
530 /* Exit configuration */
531 outb(0xbb, cfg_base
);
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
)
548 int iobase
= info
->fir_base
;
551 /* Locking comments :
552 * Most operations here need to be protected. We are called before
553 * the device instance is created in ali_ircc_open(), therefore
554 * nobody can bother us - Jean II */
556 /* Switch to FIR space */
560 outb(0x40, iobase
+FIR_MCR
); // benjamin 2000/11/30 11:45AM
562 /* Read FIR ID Version Register */
563 switch_bank(iobase
, BANK3
);
564 version
= inb(iobase
+FIR_ID_VR
);
566 /* Should be 0x00 in the M1535/M1535D */
569 net_err_ratelimited("%s, Wrong chip version %02x\n",
570 ALI_IRCC_DRIVER_NAME
, version
);
574 /* Set FIR FIFO Threshold Register */
575 switch_bank(iobase
, BANK1
);
576 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
578 /* Set FIR DMA Threshold Register */
579 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
582 switch_bank(iobase
, BANK2
);
583 outb(inb(iobase
+FIR_IRDA_CR
) | IRDA_CR_CRC
, iobase
+FIR_IRDA_CR
);
585 /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
587 /* Switch to Bank 0 */
588 switch_bank(iobase
, BANK0
);
590 tmp
= inb(iobase
+FIR_LCR_B
);
591 tmp
&=~0x20; // disable SIP
592 tmp
|= 0x80; // these two steps make RX mode
594 outb(tmp
, iobase
+FIR_LCR_B
);
596 /* Disable Interrupt */
597 outb(0x00, iobase
+FIR_IER
);
600 /* Switch to SIR space */
603 net_info_ratelimited("%s, driver loaded (Benjamin Kong)\n",
604 ALI_IRCC_DRIVER_NAME
);
606 /* Enable receive interrupts */
607 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
608 // Turn on the interrupts in ali_ircc_net_open
615 * Function ali_ircc_read_dongle_id (int index, info)
617 * Try to read dongle identification. This procedure needs to be executed
618 * once after power-on/reset. It also needs to be used whenever you suspect
619 * that the user may have plugged/unplugged the IrDA Dongle.
621 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
)
624 int cfg_base
= info
->cfg_base
;
627 /* Enter Configuration */
628 outb(chips
[i
].entr1
, cfg_base
);
629 outb(chips
[i
].entr2
, cfg_base
);
631 /* Select Logical Device 5 Registers (UART2) */
632 outb(0x07, cfg_base
);
633 outb(0x05, cfg_base
+1);
636 outb(0xf0, cfg_base
);
637 reg
= inb(cfg_base
+1);
638 dongle_id
= ((reg
>>6)&0x02) | ((reg
>>5)&0x01);
639 pr_debug("%s(), probing dongle_id=%d, dongle_types=%s\n",
640 __func__
, dongle_id
, dongle_types
[dongle_id
]);
642 /* Exit configuration */
643 outb(0xbb, cfg_base
);
650 * Function ali_ircc_interrupt (irq, dev_id, regs)
652 * An interrupt from the chip has arrived. Time to do some work
655 static irqreturn_t
ali_ircc_interrupt(int irq
, void *dev_id
)
657 struct net_device
*dev
= dev_id
;
658 struct ali_ircc_cb
*self
;
662 self
= netdev_priv(dev
);
664 spin_lock(&self
->lock
);
666 /* Dispatch interrupt handler for the current speed */
667 if (self
->io
.speed
> 115200)
668 ret
= ali_ircc_fir_interrupt(self
);
670 ret
= ali_ircc_sir_interrupt(self
);
672 spin_unlock(&self
->lock
);
677 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
679 * Handle MIR/FIR interrupt
682 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
)
684 __u8 eir
, OldMessageCount
;
688 iobase
= self
->io
.fir_base
;
690 switch_bank(iobase
, BANK0
);
691 self
->InterruptID
= inb(iobase
+FIR_IIR
);
692 self
->BusStatus
= inb(iobase
+FIR_BSR
);
694 OldMessageCount
= (self
->LineStatus
+ 1) & 0x07;
695 self
->LineStatus
= inb(iobase
+FIR_LSR
);
696 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
697 eir
= self
->InterruptID
& self
->ier
; /* Mask out the interesting ones */
699 pr_debug("%s(), self->InterruptID = %x\n", __func__
, self
->InterruptID
);
700 pr_debug("%s(), self->LineStatus = %x\n", __func__
, self
->LineStatus
);
701 pr_debug("%s(), self->ier = %x\n", __func__
, self
->ier
);
702 pr_debug("%s(), eir = %x\n", __func__
, eir
);
704 /* Disable interrupts */
705 SetCOMInterrupts(self
, FALSE
);
707 /* Tx or Rx Interrupt */
711 if (self
->io
.direction
== IO_XMIT
) /* TX */
713 pr_debug("%s(), ******* IIR_EOM (Tx) *******\n",
716 if(ali_ircc_dma_xmit_complete(self
))
718 if (irda_device_txqueue_empty(self
->netdev
))
720 /* Prepare for receive */
721 ali_ircc_dma_receive(self
);
733 pr_debug("%s(), ******* IIR_EOM (Rx) *******\n",
736 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
738 self
->rcvFramesOverflow
= TRUE
;
739 pr_debug("%s(), ******* self->rcvFramesOverflow = TRUE ********\n",
743 if (ali_ircc_dma_receive_complete(self
))
745 pr_debug("%s(), ******* receive complete ********\n",
752 pr_debug("%s(), ******* Not receive complete ********\n",
755 self
->ier
= IER_EOM
| IER_TIMER
;
760 /* Timer Interrupt */
761 else if (eir
& IIR_TIMER
)
763 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
765 self
->rcvFramesOverflow
= TRUE
;
766 pr_debug("%s(), ******* self->rcvFramesOverflow = TRUE *******\n",
770 switch_bank(iobase
, BANK1
);
771 tmp
= inb(iobase
+FIR_CR
);
772 outb( tmp
& ~CR_TIMER_EN
, iobase
+FIR_CR
);
774 /* Check if this is a Tx timer interrupt */
775 if (self
->io
.direction
== IO_XMIT
)
777 ali_ircc_dma_xmit(self
);
779 /* Interrupt on EOM */
785 if(ali_ircc_dma_receive_complete(self
))
791 self
->ier
= IER_EOM
| IER_TIMER
;
796 /* Restore Interrupt */
797 SetCOMInterrupts(self
, TRUE
);
799 return IRQ_RETVAL(eir
);
803 * Function ali_ircc_sir_interrupt (irq, self, eir)
805 * Handle SIR interrupt
808 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
)
814 iobase
= self
->io
.sir_base
;
816 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
818 /* Clear interrupt */
819 lsr
= inb(iobase
+UART_LSR
);
821 pr_debug("%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
822 __func__
, iir
, lsr
, iobase
);
827 pr_debug("%s(), RLSI\n", __func__
);
830 /* Receive interrupt */
831 ali_ircc_sir_receive(self
);
834 if (lsr
& UART_LSR_THRE
)
836 /* Transmitter ready for data */
837 ali_ircc_sir_write_wakeup(self
);
841 pr_debug("%s(), unhandled IIR=%#x\n",
849 return IRQ_RETVAL(iir
);
854 * Function ali_ircc_sir_receive (self)
856 * Receive one frame from the infrared port
859 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
)
864 IRDA_ASSERT(self
!= NULL
, return;);
866 iobase
= self
->io
.sir_base
;
869 * Receive all characters in Rx FIFO, unwrap and unstuff them.
870 * async_unwrap_char will deliver all found frames
873 async_unwrap_char(self
->netdev
, &self
->netdev
->stats
, &self
->rx_buff
,
874 inb(iobase
+UART_RX
));
876 /* Make sure we don't stay here too long */
877 if (boguscount
++ > 32) {
878 pr_debug("%s(), breaking!\n", __func__
);
881 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
886 * Function ali_ircc_sir_write_wakeup (tty)
888 * Called by the driver when there's room for more data. If we have
889 * more packets to send, we send them here.
892 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
)
897 IRDA_ASSERT(self
!= NULL
, return;);
900 iobase
= self
->io
.sir_base
;
902 /* Finished with frame? */
903 if (self
->tx_buff
.len
> 0)
905 /* Write data left in transmit buffer */
906 actual
= ali_ircc_sir_write(iobase
, self
->io
.fifo_size
,
907 self
->tx_buff
.data
, self
->tx_buff
.len
);
908 self
->tx_buff
.data
+= actual
;
909 self
->tx_buff
.len
-= actual
;
915 /* We must wait until all data are gone */
916 while(!(inb(iobase
+UART_LSR
) & UART_LSR_TEMT
))
917 pr_debug("%s(), UART_LSR_THRE\n", __func__
);
919 pr_debug("%s(), Changing speed! self->new_speed = %d\n",
920 __func__
, self
->new_speed
);
921 ali_ircc_change_speed(self
, self
->new_speed
);
924 // benjamin 2000/11/10 06:32PM
925 if (self
->io
.speed
> 115200)
927 pr_debug("%s(), ali_ircc_change_speed from UART_LSR_TEMT\n",
931 // SetCOMInterrupts(self, TRUE);
937 netif_wake_queue(self
->netdev
);
940 self
->netdev
->stats
.tx_packets
++;
942 /* Turn on receive interrupts */
943 outb(UART_IER_RDI
, iobase
+UART_IER
);
948 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
)
950 struct net_device
*dev
= self
->netdev
;
954 pr_debug("%s(), setting speed = %d\n", __func__
, baud
);
956 /* This function *must* be called with irq off and spin-lock.
959 iobase
= self
->io
.fir_base
;
961 SetCOMInterrupts(self
, FALSE
); // 2000/11/24 11:43AM
963 /* Go to MIR, FIR Speed */
968 ali_ircc_fir_change_speed(self
, baud
);
970 /* Install FIR xmit handler*/
971 dev
->netdev_ops
= &ali_ircc_fir_ops
;
973 /* Enable Interuupt */
974 self
->ier
= IER_EOM
; // benjamin 2000/11/20 07:24PM
976 /* Be ready for incoming frames */
977 ali_ircc_dma_receive(self
); // benajmin 2000/11/8 07:46PM not complete
979 /* Go to SIR Speed */
982 ali_ircc_sir_change_speed(self
, baud
);
984 /* Install SIR xmit handler*/
985 dev
->netdev_ops
= &ali_ircc_sir_ops
;
989 SetCOMInterrupts(self
, TRUE
); // 2000/11/24 11:43AM
991 netif_wake_queue(self
->netdev
);
995 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 baud
)
999 struct ali_ircc_cb
*self
= priv
;
1000 struct net_device
*dev
;
1003 IRDA_ASSERT(self
!= NULL
, return;);
1006 iobase
= self
->io
.fir_base
;
1008 pr_debug("%s(), self->io.speed = %d, change to speed = %d\n",
1009 __func__
, self
->io
.speed
, baud
);
1011 /* Come from SIR speed */
1012 if(self
->io
.speed
<=115200)
1017 /* Update accounting for new speed */
1018 self
->io
.speed
= baud
;
1020 // Set Dongle Speed mode
1021 ali_ircc_change_dongle_speed(self
, baud
);
1026 * Function ali_sir_change_speed (self, speed)
1028 * Set speed of IrDA port to specified baudrate
1031 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
)
1033 struct ali_ircc_cb
*self
= priv
;
1034 unsigned long flags
;
1036 int fcr
; /* FIFO control reg */
1037 int lcr
; /* Line control reg */
1041 pr_debug("%s(), Setting speed to: %d\n", __func__
, speed
);
1043 IRDA_ASSERT(self
!= NULL
, return;);
1045 iobase
= self
->io
.sir_base
;
1047 /* Come from MIR or FIR speed */
1048 if(self
->io
.speed
>115200)
1050 // Set Dongle Speed mode first
1051 ali_ircc_change_dongle_speed(self
, speed
);
1056 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1058 inb(iobase
+UART_LSR
);
1059 inb(iobase
+UART_SCR
);
1061 /* Update accounting for new speed */
1062 self
->io
.speed
= speed
;
1064 spin_lock_irqsave(&self
->lock
, flags
);
1066 divisor
= 115200/speed
;
1068 fcr
= UART_FCR_ENABLE_FIFO
;
1071 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1072 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1073 * about this timeout since it will always be fast enough.
1075 if (self
->io
.speed
< 38400)
1076 fcr
|= UART_FCR_TRIGGER_1
;
1078 fcr
|= UART_FCR_TRIGGER_14
;
1080 /* IrDA ports use 8N1 */
1081 lcr
= UART_LCR_WLEN8
;
1083 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
1084 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
1085 outb(divisor
>> 8, iobase
+UART_DLM
);
1086 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
1087 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
1089 /* without this, the connection will be broken after come back from FIR speed,
1090 but with this, the SIR connection is harder to established */
1091 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), iobase
+UART_MCR
);
1093 spin_unlock_irqrestore(&self
->lock
, flags
);
1097 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
)
1100 struct ali_ircc_cb
*self
= priv
;
1101 int iobase
,dongle_id
;
1105 iobase
= self
->io
.fir_base
; /* or iobase = self->io.sir_base; */
1106 dongle_id
= self
->io
.dongle_id
;
1108 /* We are already locked, no need to do it again */
1110 pr_debug("%s(), Set Speed for %s , Speed = %d\n",
1111 __func__
, dongle_types
[dongle_id
], speed
);
1113 switch_bank(iobase
, BANK2
);
1114 tmp
= inb(iobase
+FIR_IRDA_CR
);
1116 /* IBM type dongle */
1119 if(speed
== 4000000)
1122 // SD/MODE __| |__ __
1127 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1128 tmp
|= IRDA_CR_CRC
; // CRC=1
1130 switch_bank(iobase
, BANK2
);
1131 outb(tmp
, iobase
+FIR_IRDA_CR
);
1133 // T1 -> SD/MODE:0 IRTX:0
1136 outb(tmp
, iobase
+FIR_IRDA_CR
);
1139 // T2 -> SD/MODE:1 IRTX:0
1142 outb(tmp
, iobase
+FIR_IRDA_CR
);
1145 // T3 -> SD/MODE:1 IRTX:1
1147 outb(tmp
, iobase
+FIR_IRDA_CR
);
1150 // T4 -> SD/MODE:0 IRTX:1
1153 outb(tmp
, iobase
+FIR_IRDA_CR
);
1156 // T5 -> SD/MODE:0 IRTX:0
1159 outb(tmp
, iobase
+FIR_IRDA_CR
);
1162 // reset -> Normal TX output Signal
1163 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1165 else /* speed <=1152000 */
1173 /* MIR 115200, 57600 */
1176 tmp
|= 0xA0; //HDLC=1, 1.152Mbps=1
1180 tmp
&=~0x80; //HDLC 0.576Mbps
1181 tmp
|= 0x20; //HDLC=1,
1184 tmp
|= IRDA_CR_CRC
; // CRC=1
1186 switch_bank(iobase
, BANK2
);
1187 outb(tmp
, iobase
+FIR_IRDA_CR
);
1189 /* MIR 115200, 57600 */
1191 //switch_bank(iobase, BANK2);
1192 // T1 -> SD/MODE:0 IRTX:0
1195 outb(tmp
, iobase
+FIR_IRDA_CR
);
1198 // T2 -> SD/MODE:1 IRTX:0
1201 outb(tmp
, iobase
+FIR_IRDA_CR
);
1203 // T3 -> SD/MODE:0 IRTX:0
1206 outb(tmp
, iobase
+FIR_IRDA_CR
);
1209 // reset -> Normal TX output Signal
1210 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1213 else if (dongle_id
== 1) /* HP HDSL-3600 */
1218 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1222 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1226 tmp
&=~0x80; // HDLC 0.576Mbps
1227 tmp
|= 0x20; // HDLC=1,
1231 tmp
|= IRDA_CR_CRC
; // CRC=1
1233 switch_bank(iobase
, BANK2
);
1234 outb(tmp
, iobase
+FIR_IRDA_CR
);
1236 else /* HP HDSL-1100 */
1238 if(speed
<= 115200) /* SIR */
1241 tmp
&= ~IRDA_CR_FIR_SIN
; // HP sin select = 0
1243 switch_bank(iobase
, BANK2
);
1244 outb(tmp
, iobase
+FIR_IRDA_CR
);
1252 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1256 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1260 tmp
&=~0x80; // HDLC 0.576Mbps
1261 tmp
|= 0x20; // HDLC=1,
1265 tmp
|= IRDA_CR_CRC
; // CRC=1
1266 tmp
|= IRDA_CR_FIR_SIN
; // HP sin select = 1
1268 switch_bank(iobase
, BANK2
);
1269 outb(tmp
, iobase
+FIR_IRDA_CR
);
1273 switch_bank(iobase
, BANK0
);
1278 * Function ali_ircc_sir_write (driver)
1280 * Fill Tx FIFO with transmit data
1283 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
1288 /* Tx FIFO should be empty! */
1289 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
1290 pr_debug("%s(), failed, fifo not empty!\n", __func__
);
1294 /* Fill FIFO with current frame */
1295 while ((fifo_size
-- > 0) && (actual
< len
)) {
1296 /* Transmit next byte */
1297 outb(buf
[actual
], iobase
+UART_TX
);
1306 * Function ali_ircc_net_open (dev)
1311 static int ali_ircc_net_open(struct net_device
*dev
)
1313 struct ali_ircc_cb
*self
;
1318 IRDA_ASSERT(dev
!= NULL
, return -1;);
1320 self
= netdev_priv(dev
);
1322 IRDA_ASSERT(self
!= NULL
, return 0;);
1324 iobase
= self
->io
.fir_base
;
1326 /* Request IRQ and install Interrupt Handler */
1327 if (request_irq(self
->io
.irq
, ali_ircc_interrupt
, 0, dev
->name
, dev
))
1329 net_warn_ratelimited("%s, unable to allocate irq=%d\n",
1330 ALI_IRCC_DRIVER_NAME
, self
->io
.irq
);
1335 * Always allocate the DMA channel after the IRQ, and clean up on
1338 if (request_dma(self
->io
.dma
, dev
->name
)) {
1339 net_warn_ratelimited("%s, unable to allocate dma=%d\n",
1340 ALI_IRCC_DRIVER_NAME
, self
->io
.dma
);
1341 free_irq(self
->io
.irq
, dev
);
1345 /* Turn on interrups */
1346 outb(UART_IER_RDI
, iobase
+UART_IER
);
1348 /* Ready to play! */
1349 netif_start_queue(dev
); //benjamin by irport
1351 /* Give self a hardware name */
1352 sprintf(hwname
, "ALI-FIR @ 0x%03x", self
->io
.fir_base
);
1355 * Open new IrLAP layer instance, now that everything should be
1356 * initialized properly
1358 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1365 * Function ali_ircc_net_close (dev)
1370 static int ali_ircc_net_close(struct net_device
*dev
)
1373 struct ali_ircc_cb
*self
;
1377 IRDA_ASSERT(dev
!= NULL
, return -1;);
1379 self
= netdev_priv(dev
);
1380 IRDA_ASSERT(self
!= NULL
, return 0;);
1383 netif_stop_queue(dev
);
1385 /* Stop and remove instance of IrLAP */
1387 irlap_close(self
->irlap
);
1390 disable_dma(self
->io
.dma
);
1392 /* Disable interrupts */
1393 SetCOMInterrupts(self
, FALSE
);
1395 free_irq(self
->io
.irq
, dev
);
1396 free_dma(self
->io
.dma
);
1403 * Function ali_ircc_fir_hard_xmit (skb, dev)
1405 * Transmit the frame
1408 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
1409 struct net_device
*dev
)
1411 struct ali_ircc_cb
*self
;
1412 unsigned long flags
;
1418 self
= netdev_priv(dev
);
1419 iobase
= self
->io
.fir_base
;
1421 netif_stop_queue(dev
);
1423 /* Make sure tests *& speed change are atomic */
1424 spin_lock_irqsave(&self
->lock
, flags
);
1426 /* Note : you should make sure that speed changes are not going
1427 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1428 * details - Jean II */
1430 /* Check if we need to change the speed */
1431 speed
= irda_get_next_speed(skb
);
1432 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1433 /* Check for empty frame */
1435 ali_ircc_change_speed(self
, speed
);
1436 dev
->trans_start
= jiffies
;
1437 spin_unlock_irqrestore(&self
->lock
, flags
);
1439 return NETDEV_TX_OK
;
1441 self
->new_speed
= speed
;
1444 /* Register and copy this frame to DMA memory */
1445 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
1446 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
1447 self
->tx_fifo
.tail
+= skb
->len
;
1449 dev
->stats
.tx_bytes
+= skb
->len
;
1451 skb_copy_from_linear_data(skb
, self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
,
1453 self
->tx_fifo
.len
++;
1454 self
->tx_fifo
.free
++;
1456 /* Start transmit only if there is currently no transmit going on */
1457 if (self
->tx_fifo
.len
== 1)
1459 /* Check if we must wait the min turn time or not */
1460 mtt
= irda_get_mtt(skb
);
1464 /* Check how much time we have used already */
1465 diff
= ktime_us_delta(ktime_get(), self
->stamp
);
1466 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1468 pr_debug("%s(), ******* diff = %d *******\n",
1471 /* Check if the mtt is larger than the time we have
1472 * already used by all the protocol processing
1479 * Use timer if delay larger than 1000 us, and
1480 * use udelay for smaller values which should
1485 /* Adjust for timer resolution */
1486 mtt
= (mtt
+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1488 pr_debug("%s(), ************** mtt = %d ***********\n",
1492 if (mtt
== 1) /* 500 us */
1494 switch_bank(iobase
, BANK1
);
1495 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
);
1497 else if (mtt
== 2) /* 1 ms */
1499 switch_bank(iobase
, BANK1
);
1500 outb(TIMER_IIR_1ms
, iobase
+FIR_TIMER_IIR
);
1502 else /* > 2ms -> 4ms */
1504 switch_bank(iobase
, BANK1
);
1505 outb(TIMER_IIR_2ms
, iobase
+FIR_TIMER_IIR
);
1510 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1511 self
->io
.direction
= IO_XMIT
;
1513 /* Enable timer interrupt */
1514 self
->ier
= IER_TIMER
;
1515 SetCOMInterrupts(self
, TRUE
);
1517 /* Timer will take care of the rest */
1522 } // if (if (mtt > diff)
1525 /* Enable EOM interrupt */
1526 self
->ier
= IER_EOM
;
1527 SetCOMInterrupts(self
, TRUE
);
1529 /* Transmit frame */
1530 ali_ircc_dma_xmit(self
);
1531 } // if (self->tx_fifo.len == 1)
1535 /* Not busy transmitting anymore if window is not full */
1536 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
)
1537 netif_wake_queue(self
->netdev
);
1539 /* Restore bank register */
1540 switch_bank(iobase
, BANK0
);
1542 dev
->trans_start
= jiffies
;
1543 spin_unlock_irqrestore(&self
->lock
, flags
);
1546 return NETDEV_TX_OK
;
1550 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
)
1553 unsigned char FIFO_OPTI
, Hi
, Lo
;
1557 iobase
= self
->io
.fir_base
;
1559 /* FIFO threshold , this method comes from NDIS5 code */
1561 if(self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
< TX_FIFO_Threshold
)
1562 FIFO_OPTI
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
-1;
1564 FIFO_OPTI
= TX_FIFO_Threshold
;
1567 switch_bank(iobase
, BANK1
);
1568 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1570 self
->io
.direction
= IO_XMIT
;
1572 irda_setup_dma(self
->io
.dma
,
1573 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
1574 self
->tx_buff
.head
) + self
->tx_buff_dma
,
1575 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
1579 switch_bank(iobase
, BANK0
);
1580 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1582 /* Set Tx FIFO threshold */
1583 if (self
->fifo_opti_buf
!=FIFO_OPTI
)
1585 switch_bank(iobase
, BANK1
);
1586 outb(FIFO_OPTI
, iobase
+FIR_FIFO_TR
) ;
1587 self
->fifo_opti_buf
=FIFO_OPTI
;
1590 /* Set Tx DMA threshold */
1591 switch_bank(iobase
, BANK1
);
1592 outb(TX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1594 /* Set max Tx frame size */
1595 Hi
= (self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
>> 8) & 0x0f;
1596 Lo
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
& 0xff;
1597 switch_bank(iobase
, BANK2
);
1598 outb(Hi
, iobase
+FIR_TX_DSR_HI
);
1599 outb(Lo
, iobase
+FIR_TX_DSR_LO
);
1601 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1602 switch_bank(iobase
, BANK0
);
1603 tmp
= inb(iobase
+FIR_LCR_B
);
1604 tmp
&= ~0x20; // Disable SIP
1605 outb(((unsigned char)(tmp
& 0x3f) | LCR_B_TX_MODE
) & ~LCR_B_BW
, iobase
+FIR_LCR_B
);
1606 pr_debug("%s(), *** Change to TX mode: FIR_LCR_B = 0x%x ***\n",
1607 __func__
, inb(iobase
+ FIR_LCR_B
));
1609 outb(0, iobase
+FIR_LSR
);
1611 /* Enable DMA and Burst Mode */
1612 switch_bank(iobase
, BANK1
);
1613 outb(inb(iobase
+FIR_CR
) | CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1615 switch_bank(iobase
, BANK0
);
1619 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
)
1625 iobase
= self
->io
.fir_base
;
1628 switch_bank(iobase
, BANK1
);
1629 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1631 /* Check for underrun! */
1632 switch_bank(iobase
, BANK0
);
1633 if((inb(iobase
+FIR_LSR
) & LSR_FRAME_ABORT
) == LSR_FRAME_ABORT
)
1636 net_err_ratelimited("%s(), ********* LSR_FRAME_ABORT *********\n",
1638 self
->netdev
->stats
.tx_errors
++;
1639 self
->netdev
->stats
.tx_fifo_errors
++;
1643 self
->netdev
->stats
.tx_packets
++;
1646 /* Check if we need to change the speed */
1647 if (self
->new_speed
)
1649 ali_ircc_change_speed(self
, self
->new_speed
);
1650 self
->new_speed
= 0;
1653 /* Finished with this frame, so prepare for next */
1654 self
->tx_fifo
.ptr
++;
1655 self
->tx_fifo
.len
--;
1657 /* Any frames to be sent back-to-back? */
1658 if (self
->tx_fifo
.len
)
1660 ali_ircc_dma_xmit(self
);
1662 /* Not finished yet! */
1666 { /* Reset Tx FIFO info */
1667 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1668 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1671 /* Make sure we have room for more frames */
1672 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
) {
1673 /* Not busy transmitting anymore */
1674 /* Tell the network layer, that we can accept more frames */
1675 netif_wake_queue(self
->netdev
);
1678 switch_bank(iobase
, BANK0
);
1684 * Function ali_ircc_dma_receive (self)
1686 * Get ready for receiving a frame. The device will initiate a DMA
1687 * if it starts to receive a frame.
1690 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
)
1695 iobase
= self
->io
.fir_base
;
1697 /* Reset Tx FIFO info */
1698 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1699 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1702 switch_bank(iobase
, BANK1
);
1703 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1705 /* Reset Message Count */
1706 switch_bank(iobase
, BANK0
);
1707 outb(0x07, iobase
+FIR_LSR
);
1709 self
->rcvFramesOverflow
= FALSE
;
1711 self
->LineStatus
= inb(iobase
+FIR_LSR
) ;
1713 /* Reset Rx FIFO info */
1714 self
->io
.direction
= IO_RECV
;
1715 self
->rx_buff
.data
= self
->rx_buff
.head
;
1718 // switch_bank(iobase, BANK0);
1719 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1721 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1722 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1724 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1727 /* Set Receive Mode,Brick Wall */
1728 //switch_bank(iobase, BANK0);
1729 tmp
= inb(iobase
+FIR_LCR_B
);
1730 outb((unsigned char)(tmp
&0x3f) | LCR_B_RX_MODE
| LCR_B_BW
, iobase
+ FIR_LCR_B
); // 2000/12/1 05:16PM
1731 pr_debug("%s(), *** Change To RX mode: FIR_LCR_B = 0x%x ***\n",
1732 __func__
, inb(iobase
+ FIR_LCR_B
));
1734 /* Set Rx Threshold */
1735 switch_bank(iobase
, BANK1
);
1736 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
1737 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1739 /* Enable DMA and Burst Mode */
1740 // switch_bank(iobase, BANK1);
1741 outb(CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1743 switch_bank(iobase
, BANK0
);
1747 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
)
1749 struct st_fifo
*st_fifo
;
1750 struct sk_buff
*skb
;
1751 __u8 status
, MessageCount
;
1752 int len
, i
, iobase
, val
;
1754 st_fifo
= &self
->st_fifo
;
1755 iobase
= self
->io
.fir_base
;
1757 switch_bank(iobase
, BANK0
);
1758 MessageCount
= inb(iobase
+ FIR_LSR
)&0x07;
1760 if (MessageCount
> 0)
1761 pr_debug("%s(), Message count = %d\n", __func__
, MessageCount
);
1763 for (i
=0; i
<=MessageCount
; i
++)
1766 switch_bank(iobase
, BANK0
);
1767 status
= inb(iobase
+FIR_LSR
);
1769 switch_bank(iobase
, BANK2
);
1770 len
= inb(iobase
+FIR_RX_DSR_HI
) & 0x0f;
1772 len
|= inb(iobase
+FIR_RX_DSR_LO
);
1774 pr_debug("%s(), RX Length = 0x%.2x,\n", __func__
, len
);
1775 pr_debug("%s(), RX Status = 0x%.2x,\n", __func__
, status
);
1777 if (st_fifo
->tail
>= MAX_RX_WINDOW
) {
1778 pr_debug("%s(), window is full!\n", __func__
);
1782 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1783 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1784 st_fifo
->pending_bytes
+= len
;
1789 for (i
=0; i
<=MessageCount
; i
++)
1791 /* Get first entry */
1792 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1793 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1794 st_fifo
->pending_bytes
-= len
;
1798 /* Check for errors */
1799 if ((status
& 0xd8) || self
->rcvFramesOverflow
|| (len
==0))
1801 pr_debug("%s(), ************* RX Errors ************\n",
1805 self
->netdev
->stats
.rx_errors
++;
1807 self
->rx_buff
.data
+= len
;
1809 if (status
& LSR_FIFO_UR
)
1811 self
->netdev
->stats
.rx_frame_errors
++;
1812 pr_debug("%s(), ************* FIFO Errors ************\n",
1815 if (status
& LSR_FRAME_ERROR
)
1817 self
->netdev
->stats
.rx_frame_errors
++;
1818 pr_debug("%s(), ************* FRAME Errors ************\n",
1822 if (status
& LSR_CRC_ERROR
)
1824 self
->netdev
->stats
.rx_crc_errors
++;
1825 pr_debug("%s(), ************* CRC Errors ************\n",
1829 if(self
->rcvFramesOverflow
)
1831 self
->netdev
->stats
.rx_frame_errors
++;
1832 pr_debug("%s(), ************* Overran DMA buffer ************\n",
1837 self
->netdev
->stats
.rx_frame_errors
++;
1838 pr_debug("%s(), ********** Receive Frame Size = 0 *********\n",
1845 if (st_fifo
->pending_bytes
< 32)
1847 switch_bank(iobase
, BANK0
);
1848 val
= inb(iobase
+FIR_BSR
);
1849 if ((val
& BSR_FIFO_NOT_EMPTY
)== 0x80)
1851 pr_debug("%s(), ************* BSR_FIFO_NOT_EMPTY ************\n",
1854 /* Put this entry back in fifo */
1857 st_fifo
->pending_bytes
+= len
;
1858 st_fifo
->entries
[st_fifo
->head
].status
= status
;
1859 st_fifo
->entries
[st_fifo
->head
].len
= len
;
1862 * DMA not finished yet, so try again
1863 * later, set timer value, resolution
1867 switch_bank(iobase
, BANK1
);
1868 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
); // 2001/1/2 05:07PM
1871 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1873 return FALSE
; /* I'll be back! */
1878 * Remember the time we received this frame, so we can
1879 * reduce the min turn time a bit since we will know
1880 * how much time we have used for protocol processing
1882 self
->stamp
= ktime_get();
1884 skb
= dev_alloc_skb(len
+1);
1887 self
->netdev
->stats
.rx_dropped
++;
1892 /* Make sure IP header gets aligned */
1893 skb_reserve(skb
, 1);
1895 /* Copy frame without CRC, CRC is removed by hardware*/
1897 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
);
1899 /* Move to next frame */
1900 self
->rx_buff
.data
+= len
;
1901 self
->netdev
->stats
.rx_bytes
+= len
;
1902 self
->netdev
->stats
.rx_packets
++;
1904 skb
->dev
= self
->netdev
;
1905 skb_reset_mac_header(skb
);
1906 skb
->protocol
= htons(ETH_P_IRDA
);
1911 switch_bank(iobase
, BANK0
);
1919 * Function ali_ircc_sir_hard_xmit (skb, dev)
1921 * Transmit the frame!
1924 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
1925 struct net_device
*dev
)
1927 struct ali_ircc_cb
*self
;
1928 unsigned long flags
;
1933 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
1935 self
= netdev_priv(dev
);
1936 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
1938 iobase
= self
->io
.sir_base
;
1940 netif_stop_queue(dev
);
1942 /* Make sure tests *& speed change are atomic */
1943 spin_lock_irqsave(&self
->lock
, flags
);
1945 /* Note : you should make sure that speed changes are not going
1946 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1947 * details - Jean II */
1949 /* Check if we need to change the speed */
1950 speed
= irda_get_next_speed(skb
);
1951 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1952 /* Check for empty frame */
1954 ali_ircc_change_speed(self
, speed
);
1955 dev
->trans_start
= jiffies
;
1956 spin_unlock_irqrestore(&self
->lock
, flags
);
1958 return NETDEV_TX_OK
;
1960 self
->new_speed
= speed
;
1963 /* Init tx buffer */
1964 self
->tx_buff
.data
= self
->tx_buff
.head
;
1966 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
1967 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
1968 self
->tx_buff
.truesize
);
1970 self
->netdev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
1972 /* Turn on transmit finished interrupt. Will fire immediately! */
1973 outb(UART_IER_THRI
, iobase
+UART_IER
);
1975 dev
->trans_start
= jiffies
;
1976 spin_unlock_irqrestore(&self
->lock
, flags
);
1981 return NETDEV_TX_OK
;
1986 * Function ali_ircc_net_ioctl (dev, rq, cmd)
1988 * Process IOCTL commands for this device
1991 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1993 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
1994 struct ali_ircc_cb
*self
;
1995 unsigned long flags
;
1999 IRDA_ASSERT(dev
!= NULL
, return -1;);
2001 self
= netdev_priv(dev
);
2003 IRDA_ASSERT(self
!= NULL
, return -1;);
2005 pr_debug("%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
2008 case SIOCSBANDWIDTH
: /* Set bandwidth */
2009 pr_debug("%s(), SIOCSBANDWIDTH\n", __func__
);
2011 * This function will also be used by IrLAP to change the
2012 * speed, so we still must allow for speed change within
2013 * interrupt context.
2015 if (!in_interrupt() && !capable(CAP_NET_ADMIN
))
2018 spin_lock_irqsave(&self
->lock
, flags
);
2019 ali_ircc_change_speed(self
, irq
->ifr_baudrate
);
2020 spin_unlock_irqrestore(&self
->lock
, flags
);
2022 case SIOCSMEDIABUSY
: /* Set media busy */
2023 pr_debug("%s(), SIOCSMEDIABUSY\n", __func__
);
2024 if (!capable(CAP_NET_ADMIN
))
2026 irda_device_set_media_busy(self
->netdev
, TRUE
);
2028 case SIOCGRECEIVING
: /* Check if we are receiving right now */
2029 pr_debug("%s(), SIOCGRECEIVING\n", __func__
);
2030 /* This is protected */
2031 irq
->ifr_receiving
= ali_ircc_is_receiving(self
);
2042 * Function ali_ircc_is_receiving (self)
2044 * Return TRUE is we are currently receiving a frame
2047 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
)
2049 unsigned long flags
;
2054 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
2056 spin_lock_irqsave(&self
->lock
, flags
);
2058 if (self
->io
.speed
> 115200)
2060 iobase
= self
->io
.fir_base
;
2062 switch_bank(iobase
, BANK1
);
2063 if((inb(iobase
+FIR_FIFO_FR
) & 0x3f) != 0)
2065 /* We are receiving something */
2066 pr_debug("%s(), We are receiving something\n",
2070 switch_bank(iobase
, BANK0
);
2074 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
2077 spin_unlock_irqrestore(&self
->lock
, flags
);
2083 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
2085 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2087 net_info_ratelimited("%s, Suspending\n", ALI_IRCC_DRIVER_NAME
);
2089 if (self
->io
.suspended
)
2092 ali_ircc_net_close(self
->netdev
);
2094 self
->io
.suspended
= 1;
2099 static int ali_ircc_resume(struct platform_device
*dev
)
2101 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2103 if (!self
->io
.suspended
)
2106 ali_ircc_net_open(self
->netdev
);
2108 net_info_ratelimited("%s, Waking up\n", ALI_IRCC_DRIVER_NAME
);
2110 self
->io
.suspended
= 0;
2115 /* ALi Chip Function */
2117 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
)
2120 unsigned char newMask
;
2122 int iobase
= self
->io
.fir_base
; /* or sir_base */
2124 pr_debug("%s(), -------- Start -------- ( Enable = %d )\n",
2127 /* Enable the interrupt which we wish to */
2129 if (self
->io
.direction
== IO_XMIT
)
2131 if (self
->io
.speed
> 115200) /* FIR, MIR */
2133 newMask
= self
->ier
;
2137 newMask
= UART_IER_THRI
| UART_IER_RDI
;
2141 if (self
->io
.speed
> 115200) /* FIR, MIR */
2143 newMask
= self
->ier
;
2147 newMask
= UART_IER_RDI
;
2151 else /* Disable all the interrupts */
2157 //SIR and FIR has different registers
2158 if (self
->io
.speed
> 115200)
2160 switch_bank(iobase
, BANK0
);
2161 outb(newMask
, iobase
+FIR_IER
);
2164 outb(newMask
, iobase
+UART_IER
);
2168 static void SIR2FIR(int iobase
)
2170 //unsigned char tmp;
2173 /* Already protected (change_speed() or setup()), no need to lock.
2176 outb(0x28, iobase
+UART_MCR
);
2177 outb(0x68, iobase
+UART_MCR
);
2178 outb(0x88, iobase
+UART_MCR
);
2180 outb(0x60, iobase
+FIR_MCR
); /* Master Reset */
2181 outb(0x20, iobase
+FIR_MCR
); /* Master Interrupt Enable */
2183 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2185 //outb(tmp, iobase+FIR_LCR_B);
2189 static void FIR2SIR(int iobase
)
2194 /* Already protected (change_speed() or setup()), no need to lock.
2197 outb(0x20, iobase
+FIR_MCR
); /* IRQ to low */
2198 outb(0x00, iobase
+UART_IER
);
2200 outb(0xA0, iobase
+FIR_MCR
); /* Don't set master reset */
2201 outb(0x00, iobase
+UART_FCR
);
2202 outb(0x07, iobase
+UART_FCR
);
2204 val
= inb(iobase
+UART_RX
);
2205 val
= inb(iobase
+UART_LSR
);
2206 val
= inb(iobase
+UART_MSR
);
2210 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2211 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2212 MODULE_LICENSE("GPL");
2213 MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME
);
2216 module_param_array(io
, int, NULL
, 0);
2217 MODULE_PARM_DESC(io
, "Base I/O addresses");
2218 module_param_array(irq
, int, NULL
, 0);
2219 MODULE_PARM_DESC(irq
, "IRQ lines");
2220 module_param_array(dma
, int, NULL
, 0);
2221 MODULE_PARM_DESC(dma
, "DMA channels");
2223 module_init(ali_ircc_init
);
2224 module_exit(ali_ircc_cleanup
);