1 /*********************************************************************
5 * Description: Driver for the ALI M1535D and M1543C FIR Controller
6 * Status: Experimental.
7 * Author: Benjamin Kong <benjamin_kong@ali.com.tw>
8 * Created at: 2000/10/16 03:46PM
9 * Modified at: 2001/1/3 02:55PM
10 * Modified by: Benjamin Kong <benjamin_kong@ali.com.tw>
11 * Modified at: 2003/11/6 and support for ALi south-bridge chipsets M1563
12 * Modified by: Clear Zhang <clear_zhang@ali.com.tw>
14 * Copyright (c) 2000 Benjamin Kong <benjamin_kong@ali.com.tw>
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 ********************************************************************/
24 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/skbuff.h>
29 #include <linux/netdevice.h>
30 #include <linux/ioport.h>
31 #include <linux/delay.h>
32 #include <linux/slab.h>
33 #include <linux/init.h>
34 #include <linux/rtnetlink.h>
35 #include <linux/serial_reg.h>
36 #include <linux/dma-mapping.h>
37 #include <linux/platform_device.h>
41 #include <asm/byteorder.h>
43 #include <net/irda/wrapper.h>
44 #include <net/irda/irda.h>
45 #include <net/irda/irda_device.h>
49 #define CHIP_IO_EXTENT 8
50 #define BROKEN_DONGLE_ID
52 #define ALI_IRCC_DRIVER_NAME "ali-ircc"
54 /* Power Management */
55 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
);
56 static int ali_ircc_resume(struct platform_device
*dev
);
58 static struct platform_driver ali_ircc_driver
= {
59 .suspend
= ali_ircc_suspend
,
60 .resume
= ali_ircc_resume
,
62 .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 sourth-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 configuation registers address
147 static int __init
ali_ircc_init(void)
156 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
158 ret
= platform_driver_register(&ali_ircc_driver
);
160 IRDA_ERROR("%s, Can't register driver!\n",
161 ALI_IRCC_DRIVER_NAME
);
167 /* Probe for all the ALi chipsets we know about */
168 for (chip
= chips
; chip
->name
; chip
++, i
++)
170 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __func__
, chip
->name
);
172 /* Try all config registers for this chip */
173 for (cfg
=0; cfg
<2; cfg
++)
175 cfg_base
= chip
->cfg
[cfg
];
179 memset(&info
, 0, sizeof(chipio_t
));
180 info
.cfg_base
= cfg_base
;
181 info
.fir_base
= io
[i
];
186 /* Enter Configuration */
187 outb(chip
->entr1
, cfg_base
);
188 outb(chip
->entr2
, cfg_base
);
190 /* Select Logical Device 5 Registers (UART2) */
191 outb(0x07, cfg_base
);
192 outb(0x05, cfg_base
+1);
194 /* Read Chip Identification Register */
195 outb(chip
->cid_index
, cfg_base
);
196 reg
= inb(cfg_base
+1);
198 if (reg
== chip
->cid_value
)
200 IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __func__
, cfg_base
);
202 outb(0x1F, cfg_base
);
203 revision
= inb(cfg_base
+1);
204 IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __func__
,
205 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 IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __func__
, chip
->name
, cfg_base
);
229 /* Exit configuration */
230 outb(0xbb, cfg_base
);
234 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
237 platform_driver_unregister(&ali_ircc_driver
);
243 * Function ali_ircc_cleanup ()
245 * Close all configured chips
248 static void __exit
ali_ircc_cleanup(void)
252 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
254 for (i
=0; i
< ARRAY_SIZE(dev_self
); i
++) {
256 ali_ircc_close(dev_self
[i
]);
259 platform_driver_unregister(&ali_ircc_driver
);
261 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
264 static const struct net_device_ops ali_ircc_sir_ops
= {
265 .ndo_open
= ali_ircc_net_open
,
266 .ndo_stop
= ali_ircc_net_close
,
267 .ndo_start_xmit
= ali_ircc_sir_hard_xmit
,
268 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
271 static const struct net_device_ops ali_ircc_fir_ops
= {
272 .ndo_open
= ali_ircc_net_open
,
273 .ndo_stop
= ali_ircc_net_close
,
274 .ndo_start_xmit
= ali_ircc_fir_hard_xmit
,
275 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
279 * Function ali_ircc_open (int i, chipio_t *inf)
281 * Open driver instance
284 static int ali_ircc_open(int i
, chipio_t
*info
)
286 struct net_device
*dev
;
287 struct ali_ircc_cb
*self
;
291 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
293 if (i
>= ARRAY_SIZE(dev_self
)) {
294 IRDA_ERROR("%s(), maximum number of supported chips reached!\n",
299 /* Set FIR FIFO and DMA Threshold */
300 if ((ali_ircc_setup(info
)) == -1)
303 dev
= alloc_irdadev(sizeof(*self
));
305 IRDA_ERROR("%s(), can't allocate memory for control block!\n",
310 self
= netdev_priv(dev
);
312 spin_lock_init(&self
->lock
);
314 /* Need to store self somewhere */
319 self
->io
.cfg_base
= info
->cfg_base
; /* In ali_ircc_probe_53 assign */
320 self
->io
.fir_base
= info
->fir_base
; /* info->sir_base = info->fir_base */
321 self
->io
.sir_base
= info
->sir_base
; /* ALi SIR and FIR use the same address */
322 self
->io
.irq
= info
->irq
;
323 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
324 self
->io
.dma
= info
->dma
;
325 self
->io
.fifo_size
= 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
327 /* Reserve the ioports that we need */
328 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
,
329 ALI_IRCC_DRIVER_NAME
)) {
330 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __func__
,
336 /* Initialize QoS for this device */
337 irda_init_max_qos_capabilies(&self
->qos
);
339 /* The only value we must override it the baudrate */
340 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
341 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8); // benjamin 2000/11/8 05:27PM
343 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
345 irda_qos_bits_to_value(&self
->qos
);
347 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
348 self
->rx_buff
.truesize
= 14384;
349 self
->tx_buff
.truesize
= 14384;
351 /* Allocate memory if needed */
353 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
354 &self
->rx_buff_dma
, GFP_KERNEL
);
355 if (self
->rx_buff
.head
== NULL
) {
359 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
362 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
363 &self
->tx_buff_dma
, GFP_KERNEL
);
364 if (self
->tx_buff
.head
== NULL
) {
368 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
370 self
->rx_buff
.in_frame
= FALSE
;
371 self
->rx_buff
.state
= OUTSIDE_FRAME
;
372 self
->tx_buff
.data
= self
->tx_buff
.head
;
373 self
->rx_buff
.data
= self
->rx_buff
.head
;
375 /* Reset Tx queue info */
376 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
377 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
379 /* Override the network functions we need to use */
380 dev
->netdev_ops
= &ali_ircc_sir_ops
;
382 err
= register_netdev(dev
);
384 IRDA_ERROR("%s(), register_netdev() failed!\n", __func__
);
387 IRDA_MESSAGE("IrDA: Registered device %s\n", dev
->name
);
389 /* Check dongle id */
390 dongle_id
= ali_ircc_read_dongle_id(i
, info
);
391 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __func__
,
392 ALI_IRCC_DRIVER_NAME
, dongle_types
[dongle_id
]);
394 self
->io
.dongle_id
= dongle_id
;
396 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
401 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
402 self
->tx_buff
.head
, self
->tx_buff_dma
);
404 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
405 self
->rx_buff
.head
, self
->rx_buff_dma
);
407 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
416 * Function ali_ircc_close (self)
418 * Close driver instance
421 static int __exit
ali_ircc_close(struct ali_ircc_cb
*self
)
425 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__
);
427 IRDA_ASSERT(self
!= NULL
, return -1;);
429 iobase
= self
->io
.fir_base
;
431 /* Remove netdevice */
432 unregister_netdev(self
->netdev
);
434 /* Release the PORT that this driver is using */
435 IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __func__
, self
->io
.fir_base
);
436 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
438 if (self
->tx_buff
.head
)
439 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
440 self
->tx_buff
.head
, self
->tx_buff_dma
);
442 if (self
->rx_buff
.head
)
443 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
444 self
->rx_buff
.head
, self
->rx_buff_dma
);
446 dev_self
[self
->index
] = NULL
;
447 free_netdev(self
->netdev
);
449 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
455 * Function ali_ircc_init_43 (chip, info)
457 * Initialize the ALi M1543 chip.
459 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
)
461 /* All controller information like I/O address, DMA channel, IRQ
469 * Function ali_ircc_init_53 (chip, info)
471 * Initialize the ALi M1535 chip.
473 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
)
475 /* All controller information like I/O address, DMA channel, IRQ
483 * Function ali_ircc_probe_53 (chip, info)
485 * Probes for the ALi M1535D or M1535
487 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
)
489 int cfg_base
= info
->cfg_base
;
492 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
494 /* Enter Configuration */
495 outb(chip
->entr1
, cfg_base
);
496 outb(chip
->entr2
, cfg_base
);
498 /* Select Logical Device 5 Registers (UART2) */
499 outb(0x07, cfg_base
);
500 outb(0x05, cfg_base
+1);
502 /* Read address control register */
503 outb(0x60, cfg_base
);
504 hi
= inb(cfg_base
+1);
505 outb(0x61, cfg_base
);
506 low
= inb(cfg_base
+1);
507 info
->fir_base
= (hi
<<8) + low
;
509 info
->sir_base
= info
->fir_base
;
511 IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __func__
, info
->fir_base
);
513 /* Read IRQ control register */
514 outb(0x70, cfg_base
);
515 reg
= inb(cfg_base
+1);
516 info
->irq
= reg
& 0x0f;
517 IRDA_DEBUG(2, "%s(), probing irq=%d\n", __func__
, info
->irq
);
519 /* Read DMA channel */
520 outb(0x74, cfg_base
);
521 reg
= inb(cfg_base
+1);
522 info
->dma
= reg
& 0x07;
524 if(info
->dma
== 0x04)
525 IRDA_WARNING("%s(), No DMA channel assigned !\n", __func__
);
527 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __func__
, info
->dma
);
529 /* Read Enabled Status */
530 outb(0x30, cfg_base
);
531 reg
= inb(cfg_base
+1);
532 info
->enabled
= (reg
& 0x80) && (reg
& 0x01);
533 IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __func__
, info
->enabled
);
535 /* Read Power Status */
536 outb(0x22, cfg_base
);
537 reg
= inb(cfg_base
+1);
538 info
->suspended
= (reg
& 0x20);
539 IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __func__
, info
->suspended
);
541 /* Exit configuration */
542 outb(0xbb, cfg_base
);
544 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
550 * Function ali_ircc_setup (info)
552 * Set FIR FIFO and DMA Threshold
553 * Returns non-negative on success.
556 static int ali_ircc_setup(chipio_t
*info
)
560 int iobase
= info
->fir_base
;
562 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
564 /* Locking comments :
565 * Most operations here need to be protected. We are called before
566 * the device instance is created in ali_ircc_open(), therefore
567 * nobody can bother us - Jean II */
569 /* Switch to FIR space */
573 outb(0x40, iobase
+FIR_MCR
); // benjamin 2000/11/30 11:45AM
575 /* Read FIR ID Version Register */
576 switch_bank(iobase
, BANK3
);
577 version
= inb(iobase
+FIR_ID_VR
);
579 /* Should be 0x00 in the M1535/M1535D */
582 IRDA_ERROR("%s, Wrong chip version %02x\n",
583 ALI_IRCC_DRIVER_NAME
, version
);
587 /* Set FIR FIFO Threshold Register */
588 switch_bank(iobase
, BANK1
);
589 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
591 /* Set FIR DMA Threshold Register */
592 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
595 switch_bank(iobase
, BANK2
);
596 outb(inb(iobase
+FIR_IRDA_CR
) | IRDA_CR_CRC
, iobase
+FIR_IRDA_CR
);
598 /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
600 /* Switch to Bank 0 */
601 switch_bank(iobase
, BANK0
);
603 tmp
= inb(iobase
+FIR_LCR_B
);
604 tmp
&=~0x20; // disable SIP
605 tmp
|= 0x80; // these two steps make RX mode
607 outb(tmp
, iobase
+FIR_LCR_B
);
609 /* Disable Interrupt */
610 outb(0x00, iobase
+FIR_IER
);
613 /* Switch to SIR space */
616 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
617 ALI_IRCC_DRIVER_NAME
);
619 /* Enable receive interrupts */
620 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
621 // Turn on the interrupts in ali_ircc_net_open
623 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
629 * Function ali_ircc_read_dongle_id (int index, info)
631 * Try to read dongle indentification. This procedure needs to be executed
632 * once after power-on/reset. It also needs to be used whenever you suspect
633 * that the user may have plugged/unplugged the IrDA Dongle.
635 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
)
638 int cfg_base
= info
->cfg_base
;
640 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
642 /* Enter Configuration */
643 outb(chips
[i
].entr1
, cfg_base
);
644 outb(chips
[i
].entr2
, cfg_base
);
646 /* Select Logical Device 5 Registers (UART2) */
647 outb(0x07, cfg_base
);
648 outb(0x05, cfg_base
+1);
651 outb(0xf0, cfg_base
);
652 reg
= inb(cfg_base
+1);
653 dongle_id
= ((reg
>>6)&0x02) | ((reg
>>5)&0x01);
654 IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __func__
,
655 dongle_id
, dongle_types
[dongle_id
]);
657 /* Exit configuration */
658 outb(0xbb, cfg_base
);
660 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
666 * Function ali_ircc_interrupt (irq, dev_id, regs)
668 * An interrupt from the chip has arrived. Time to do some work
671 static irqreturn_t
ali_ircc_interrupt(int irq
, void *dev_id
)
673 struct net_device
*dev
= dev_id
;
674 struct ali_ircc_cb
*self
;
677 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
679 self
= netdev_priv(dev
);
681 spin_lock(&self
->lock
);
683 /* Dispatch interrupt handler for the current speed */
684 if (self
->io
.speed
> 115200)
685 ret
= ali_ircc_fir_interrupt(self
);
687 ret
= ali_ircc_sir_interrupt(self
);
689 spin_unlock(&self
->lock
);
691 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
695 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
697 * Handle MIR/FIR interrupt
700 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
)
702 __u8 eir
, OldMessageCount
;
705 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
707 iobase
= self
->io
.fir_base
;
709 switch_bank(iobase
, BANK0
);
710 self
->InterruptID
= inb(iobase
+FIR_IIR
);
711 self
->BusStatus
= inb(iobase
+FIR_BSR
);
713 OldMessageCount
= (self
->LineStatus
+ 1) & 0x07;
714 self
->LineStatus
= inb(iobase
+FIR_LSR
);
715 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
716 eir
= self
->InterruptID
& self
->ier
; /* Mask out the interesting ones */
718 IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __func__
,self
->InterruptID
);
719 IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __func__
,self
->LineStatus
);
720 IRDA_DEBUG(1, "%s(), self->ier = %x\n", __func__
,self
->ier
);
721 IRDA_DEBUG(1, "%s(), eir = %x\n", __func__
,eir
);
723 /* Disable interrupts */
724 SetCOMInterrupts(self
, FALSE
);
726 /* Tx or Rx Interrupt */
730 if (self
->io
.direction
== IO_XMIT
) /* TX */
732 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __func__
);
734 if(ali_ircc_dma_xmit_complete(self
))
736 if (irda_device_txqueue_empty(self
->netdev
))
738 /* Prepare for receive */
739 ali_ircc_dma_receive(self
);
751 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __func__
);
753 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
755 self
->rcvFramesOverflow
= TRUE
;
756 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******** \n", __func__
);
759 if (ali_ircc_dma_receive_complete(self
))
761 IRDA_DEBUG(1, "%s(), ******* receive complete ******** \n", __func__
);
767 IRDA_DEBUG(1, "%s(), ******* Not receive complete ******** \n", __func__
);
769 self
->ier
= IER_EOM
| IER_TIMER
;
774 /* Timer Interrupt */
775 else if (eir
& IIR_TIMER
)
777 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
779 self
->rcvFramesOverflow
= TRUE
;
780 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ******* \n", __func__
);
783 switch_bank(iobase
, BANK1
);
784 tmp
= inb(iobase
+FIR_CR
);
785 outb( tmp
& ~CR_TIMER_EN
, iobase
+FIR_CR
);
787 /* Check if this is a Tx timer interrupt */
788 if (self
->io
.direction
== IO_XMIT
)
790 ali_ircc_dma_xmit(self
);
792 /* Interrupt on EOM */
798 if(ali_ircc_dma_receive_complete(self
))
804 self
->ier
= IER_EOM
| IER_TIMER
;
809 /* Restore Interrupt */
810 SetCOMInterrupts(self
, TRUE
);
812 IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __func__
);
813 return IRQ_RETVAL(eir
);
817 * Function ali_ircc_sir_interrupt (irq, self, eir)
819 * Handle SIR interrupt
822 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
)
827 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
829 iobase
= self
->io
.sir_base
;
831 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
833 /* Clear interrupt */
834 lsr
= inb(iobase
+UART_LSR
);
836 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __func__
,
842 IRDA_DEBUG(2, "%s(), RLSI\n", __func__
);
845 /* Receive interrupt */
846 ali_ircc_sir_receive(self
);
849 if (lsr
& UART_LSR_THRE
)
851 /* Transmitter ready for data */
852 ali_ircc_sir_write_wakeup(self
);
856 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __func__
, iir
);
863 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
865 return IRQ_RETVAL(iir
);
870 * Function ali_ircc_sir_receive (self)
872 * Receive one frame from the infrared port
875 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
)
880 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
881 IRDA_ASSERT(self
!= NULL
, return;);
883 iobase
= self
->io
.sir_base
;
886 * Receive all characters in Rx FIFO, unwrap and unstuff them.
887 * async_unwrap_char will deliver all found frames
890 async_unwrap_char(self
->netdev
, &self
->netdev
->stats
, &self
->rx_buff
,
891 inb(iobase
+UART_RX
));
893 /* Make sure we don't stay here too long */
894 if (boguscount
++ > 32) {
895 IRDA_DEBUG(2,"%s(), breaking!\n", __func__
);
898 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
900 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
904 * Function ali_ircc_sir_write_wakeup (tty)
906 * Called by the driver when there's room for more data. If we have
907 * more packets to send, we send them here.
910 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
)
915 IRDA_ASSERT(self
!= NULL
, return;);
917 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
919 iobase
= self
->io
.sir_base
;
921 /* Finished with frame? */
922 if (self
->tx_buff
.len
> 0)
924 /* Write data left in transmit buffer */
925 actual
= ali_ircc_sir_write(iobase
, self
->io
.fifo_size
,
926 self
->tx_buff
.data
, self
->tx_buff
.len
);
927 self
->tx_buff
.data
+= actual
;
928 self
->tx_buff
.len
-= actual
;
934 /* We must wait until all data are gone */
935 while(!(inb(iobase
+UART_LSR
) & UART_LSR_TEMT
))
936 IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __func__
);
938 IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __func__
, self
->new_speed
);
939 ali_ircc_change_speed(self
, self
->new_speed
);
942 // benjamin 2000/11/10 06:32PM
943 if (self
->io
.speed
> 115200)
945 IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT \n", __func__
);
948 // SetCOMInterrupts(self, TRUE);
954 netif_wake_queue(self
->netdev
);
957 self
->netdev
->stats
.tx_packets
++;
959 /* Turn on receive interrupts */
960 outb(UART_IER_RDI
, iobase
+UART_IER
);
963 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
966 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
)
968 struct net_device
*dev
= self
->netdev
;
971 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
973 IRDA_DEBUG(2, "%s(), setting speed = %d \n", __func__
, baud
);
975 /* This function *must* be called with irq off and spin-lock.
978 iobase
= self
->io
.fir_base
;
980 SetCOMInterrupts(self
, FALSE
); // 2000/11/24 11:43AM
982 /* Go to MIR, FIR Speed */
987 ali_ircc_fir_change_speed(self
, baud
);
989 /* Install FIR xmit handler*/
990 dev
->netdev_ops
= &ali_ircc_fir_ops
;
992 /* Enable Interuupt */
993 self
->ier
= IER_EOM
; // benjamin 2000/11/20 07:24PM
995 /* Be ready for incomming frames */
996 ali_ircc_dma_receive(self
); // benajmin 2000/11/8 07:46PM not complete
998 /* Go to SIR Speed */
1001 ali_ircc_sir_change_speed(self
, baud
);
1003 /* Install SIR xmit handler*/
1004 dev
->netdev_ops
= &ali_ircc_sir_ops
;
1008 SetCOMInterrupts(self
, TRUE
); // 2000/11/24 11:43AM
1010 netif_wake_queue(self
->netdev
);
1012 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1015 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 baud
)
1019 struct ali_ircc_cb
*self
= (struct ali_ircc_cb
*) priv
;
1020 struct net_device
*dev
;
1022 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1024 IRDA_ASSERT(self
!= NULL
, return;);
1027 iobase
= self
->io
.fir_base
;
1029 IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __func__
,self
->io
.speed
,baud
);
1031 /* Come from SIR speed */
1032 if(self
->io
.speed
<=115200)
1037 /* Update accounting for new speed */
1038 self
->io
.speed
= baud
;
1040 // Set Dongle Speed mode
1041 ali_ircc_change_dongle_speed(self
, baud
);
1043 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1047 * Function ali_sir_change_speed (self, speed)
1049 * Set speed of IrDA port to specified baudrate
1052 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
)
1054 struct ali_ircc_cb
*self
= (struct ali_ircc_cb
*) priv
;
1055 unsigned long flags
;
1057 int fcr
; /* FIFO control reg */
1058 int lcr
; /* Line control reg */
1061 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1063 IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __func__
, speed
);
1065 IRDA_ASSERT(self
!= NULL
, return;);
1067 iobase
= self
->io
.sir_base
;
1069 /* Come from MIR or FIR speed */
1070 if(self
->io
.speed
>115200)
1072 // Set Dongle Speed mode first
1073 ali_ircc_change_dongle_speed(self
, speed
);
1078 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1080 inb(iobase
+UART_LSR
);
1081 inb(iobase
+UART_SCR
);
1083 /* Update accounting for new speed */
1084 self
->io
.speed
= speed
;
1086 spin_lock_irqsave(&self
->lock
, flags
);
1088 divisor
= 115200/speed
;
1090 fcr
= UART_FCR_ENABLE_FIFO
;
1093 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1094 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1095 * about this timeout since it will always be fast enough.
1097 if (self
->io
.speed
< 38400)
1098 fcr
|= UART_FCR_TRIGGER_1
;
1100 fcr
|= UART_FCR_TRIGGER_14
;
1102 /* IrDA ports use 8N1 */
1103 lcr
= UART_LCR_WLEN8
;
1105 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
1106 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
1107 outb(divisor
>> 8, iobase
+UART_DLM
);
1108 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
1109 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
1111 /* without this, the conection will be broken after come back from FIR speed,
1112 but with this, the SIR connection is harder to established */
1113 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), iobase
+UART_MCR
);
1115 spin_unlock_irqrestore(&self
->lock
, flags
);
1117 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1120 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
)
1123 struct ali_ircc_cb
*self
= (struct ali_ircc_cb
*) priv
;
1124 int iobase
,dongle_id
;
1127 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1129 iobase
= self
->io
.fir_base
; /* or iobase = self->io.sir_base; */
1130 dongle_id
= self
->io
.dongle_id
;
1132 /* We are already locked, no need to do it again */
1134 IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __func__
, dongle_types
[dongle_id
], speed
);
1136 switch_bank(iobase
, BANK2
);
1137 tmp
= inb(iobase
+FIR_IRDA_CR
);
1139 /* IBM type dongle */
1142 if(speed
== 4000000)
1145 // SD/MODE __| |__ __
1150 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1151 tmp
|= IRDA_CR_CRC
; // CRC=1
1153 switch_bank(iobase
, BANK2
);
1154 outb(tmp
, iobase
+FIR_IRDA_CR
);
1156 // T1 -> SD/MODE:0 IRTX:0
1159 outb(tmp
, iobase
+FIR_IRDA_CR
);
1162 // T2 -> SD/MODE:1 IRTX:0
1165 outb(tmp
, iobase
+FIR_IRDA_CR
);
1168 // T3 -> SD/MODE:1 IRTX:1
1170 outb(tmp
, iobase
+FIR_IRDA_CR
);
1173 // T4 -> SD/MODE:0 IRTX:1
1176 outb(tmp
, iobase
+FIR_IRDA_CR
);
1179 // T5 -> SD/MODE:0 IRTX:0
1182 outb(tmp
, iobase
+FIR_IRDA_CR
);
1185 // reset -> Normal TX output Signal
1186 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1188 else /* speed <=1152000 */
1196 /* MIR 115200, 57600 */
1199 tmp
|= 0xA0; //HDLC=1, 1.152Mbps=1
1203 tmp
&=~0x80; //HDLC 0.576Mbps
1204 tmp
|= 0x20; //HDLC=1,
1207 tmp
|= IRDA_CR_CRC
; // CRC=1
1209 switch_bank(iobase
, BANK2
);
1210 outb(tmp
, iobase
+FIR_IRDA_CR
);
1212 /* MIR 115200, 57600 */
1214 //switch_bank(iobase, BANK2);
1215 // T1 -> SD/MODE:0 IRTX:0
1218 outb(tmp
, iobase
+FIR_IRDA_CR
);
1221 // T2 -> SD/MODE:1 IRTX:0
1224 outb(tmp
, iobase
+FIR_IRDA_CR
);
1226 // T3 -> SD/MODE:0 IRTX:0
1229 outb(tmp
, iobase
+FIR_IRDA_CR
);
1232 // reset -> Normal TX output Signal
1233 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1236 else if (dongle_id
== 1) /* HP HDSL-3600 */
1241 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1245 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1249 tmp
&=~0x80; // HDLC 0.576Mbps
1250 tmp
|= 0x20; // HDLC=1,
1254 tmp
|= IRDA_CR_CRC
; // CRC=1
1256 switch_bank(iobase
, BANK2
);
1257 outb(tmp
, iobase
+FIR_IRDA_CR
);
1259 else /* HP HDSL-1100 */
1261 if(speed
<= 115200) /* SIR */
1264 tmp
&= ~IRDA_CR_FIR_SIN
; // HP sin select = 0
1266 switch_bank(iobase
, BANK2
);
1267 outb(tmp
, iobase
+FIR_IRDA_CR
);
1275 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1279 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1283 tmp
&=~0x80; // HDLC 0.576Mbps
1284 tmp
|= 0x20; // HDLC=1,
1288 tmp
|= IRDA_CR_CRC
; // CRC=1
1289 tmp
|= IRDA_CR_FIR_SIN
; // HP sin select = 1
1291 switch_bank(iobase
, BANK2
);
1292 outb(tmp
, iobase
+FIR_IRDA_CR
);
1296 switch_bank(iobase
, BANK0
);
1298 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1302 * Function ali_ircc_sir_write (driver)
1304 * Fill Tx FIFO with transmit data
1307 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
1311 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1313 /* Tx FIFO should be empty! */
1314 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
1315 IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __func__
);
1319 /* Fill FIFO with current frame */
1320 while ((fifo_size
-- > 0) && (actual
< len
)) {
1321 /* Transmit next byte */
1322 outb(buf
[actual
], iobase
+UART_TX
);
1327 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1332 * Function ali_ircc_net_open (dev)
1337 static int ali_ircc_net_open(struct net_device
*dev
)
1339 struct ali_ircc_cb
*self
;
1343 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1345 IRDA_ASSERT(dev
!= NULL
, return -1;);
1347 self
= netdev_priv(dev
);
1349 IRDA_ASSERT(self
!= NULL
, return 0;);
1351 iobase
= self
->io
.fir_base
;
1353 /* Request IRQ and install Interrupt Handler */
1354 if (request_irq(self
->io
.irq
, ali_ircc_interrupt
, 0, dev
->name
, dev
))
1356 IRDA_WARNING("%s, unable to allocate irq=%d\n",
1357 ALI_IRCC_DRIVER_NAME
,
1363 * Always allocate the DMA channel after the IRQ, and clean up on
1366 if (request_dma(self
->io
.dma
, dev
->name
)) {
1367 IRDA_WARNING("%s, unable to allocate dma=%d\n",
1368 ALI_IRCC_DRIVER_NAME
,
1370 free_irq(self
->io
.irq
, self
);
1374 /* Turn on interrups */
1375 outb(UART_IER_RDI
, iobase
+UART_IER
);
1377 /* Ready to play! */
1378 netif_start_queue(dev
); //benjamin by irport
1380 /* Give self a hardware name */
1381 sprintf(hwname
, "ALI-FIR @ 0x%03x", self
->io
.fir_base
);
1384 * Open new IrLAP layer instance, now that everything should be
1385 * initialized properly
1387 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1389 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1395 * Function ali_ircc_net_close (dev)
1400 static int ali_ircc_net_close(struct net_device
*dev
)
1403 struct ali_ircc_cb
*self
;
1406 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__
);
1408 IRDA_ASSERT(dev
!= NULL
, return -1;);
1410 self
= netdev_priv(dev
);
1411 IRDA_ASSERT(self
!= NULL
, return 0;);
1414 netif_stop_queue(dev
);
1416 /* Stop and remove instance of IrLAP */
1418 irlap_close(self
->irlap
);
1421 disable_dma(self
->io
.dma
);
1423 /* Disable interrupts */
1424 SetCOMInterrupts(self
, FALSE
);
1426 free_irq(self
->io
.irq
, dev
);
1427 free_dma(self
->io
.dma
);
1429 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1435 * Function ali_ircc_fir_hard_xmit (skb, dev)
1437 * Transmit the frame
1440 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
1441 struct net_device
*dev
)
1443 struct ali_ircc_cb
*self
;
1444 unsigned long flags
;
1449 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1451 self
= netdev_priv(dev
);
1452 iobase
= self
->io
.fir_base
;
1454 netif_stop_queue(dev
);
1456 /* Make sure tests *& speed change are atomic */
1457 spin_lock_irqsave(&self
->lock
, flags
);
1459 /* Note : you should make sure that speed changes are not going
1460 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1461 * details - Jean II */
1463 /* Check if we need to change the speed */
1464 speed
= irda_get_next_speed(skb
);
1465 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1466 /* Check for empty frame */
1468 ali_ircc_change_speed(self
, speed
);
1469 dev
->trans_start
= jiffies
;
1470 spin_unlock_irqrestore(&self
->lock
, flags
);
1472 return NETDEV_TX_OK
;
1474 self
->new_speed
= speed
;
1477 /* Register and copy this frame to DMA memory */
1478 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
1479 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
1480 self
->tx_fifo
.tail
+= skb
->len
;
1482 dev
->stats
.tx_bytes
+= skb
->len
;
1484 skb_copy_from_linear_data(skb
, self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
,
1486 self
->tx_fifo
.len
++;
1487 self
->tx_fifo
.free
++;
1489 /* Start transmit only if there is currently no transmit going on */
1490 if (self
->tx_fifo
.len
== 1)
1492 /* Check if we must wait the min turn time or not */
1493 mtt
= irda_get_mtt(skb
);
1497 /* Check how much time we have used already */
1498 do_gettimeofday(&self
->now
);
1500 diff
= self
->now
.tv_usec
- self
->stamp
.tv_usec
;
1501 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1503 IRDA_DEBUG(1, "%s(), ******* diff = %d ******* \n", __func__
, diff
);
1508 /* Check if the mtt is larger than the time we have
1509 * already used by all the protocol processing
1516 * Use timer if delay larger than 1000 us, and
1517 * use udelay for smaller values which should
1522 /* Adjust for timer resolution */
1523 mtt
= (mtt
+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1525 IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __func__
, mtt
);
1528 if (mtt
== 1) /* 500 us */
1530 switch_bank(iobase
, BANK1
);
1531 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
);
1533 else if (mtt
== 2) /* 1 ms */
1535 switch_bank(iobase
, BANK1
);
1536 outb(TIMER_IIR_1ms
, iobase
+FIR_TIMER_IIR
);
1538 else /* > 2ms -> 4ms */
1540 switch_bank(iobase
, BANK1
);
1541 outb(TIMER_IIR_2ms
, iobase
+FIR_TIMER_IIR
);
1546 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1547 self
->io
.direction
= IO_XMIT
;
1549 /* Enable timer interrupt */
1550 self
->ier
= IER_TIMER
;
1551 SetCOMInterrupts(self
, TRUE
);
1553 /* Timer will take care of the rest */
1558 } // if (if (mtt > diff)
1561 /* Enable EOM interrupt */
1562 self
->ier
= IER_EOM
;
1563 SetCOMInterrupts(self
, TRUE
);
1565 /* Transmit frame */
1566 ali_ircc_dma_xmit(self
);
1567 } // if (self->tx_fifo.len == 1)
1571 /* Not busy transmitting anymore if window is not full */
1572 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
)
1573 netif_wake_queue(self
->netdev
);
1575 /* Restore bank register */
1576 switch_bank(iobase
, BANK0
);
1578 dev
->trans_start
= jiffies
;
1579 spin_unlock_irqrestore(&self
->lock
, flags
);
1582 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1583 return NETDEV_TX_OK
;
1587 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
)
1590 unsigned char FIFO_OPTI
, Hi
, Lo
;
1593 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1595 iobase
= self
->io
.fir_base
;
1597 /* FIFO threshold , this method comes from NDIS5 code */
1599 if(self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
< TX_FIFO_Threshold
)
1600 FIFO_OPTI
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
-1;
1602 FIFO_OPTI
= TX_FIFO_Threshold
;
1605 switch_bank(iobase
, BANK1
);
1606 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1608 self
->io
.direction
= IO_XMIT
;
1610 irda_setup_dma(self
->io
.dma
,
1611 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
1612 self
->tx_buff
.head
) + self
->tx_buff_dma
,
1613 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
1617 switch_bank(iobase
, BANK0
);
1618 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1620 /* Set Tx FIFO threshold */
1621 if (self
->fifo_opti_buf
!=FIFO_OPTI
)
1623 switch_bank(iobase
, BANK1
);
1624 outb(FIFO_OPTI
, iobase
+FIR_FIFO_TR
) ;
1625 self
->fifo_opti_buf
=FIFO_OPTI
;
1628 /* Set Tx DMA threshold */
1629 switch_bank(iobase
, BANK1
);
1630 outb(TX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1632 /* Set max Tx frame size */
1633 Hi
= (self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
>> 8) & 0x0f;
1634 Lo
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
& 0xff;
1635 switch_bank(iobase
, BANK2
);
1636 outb(Hi
, iobase
+FIR_TX_DSR_HI
);
1637 outb(Lo
, iobase
+FIR_TX_DSR_LO
);
1639 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1640 switch_bank(iobase
, BANK0
);
1641 tmp
= inb(iobase
+FIR_LCR_B
);
1642 tmp
&= ~0x20; // Disable SIP
1643 outb(((unsigned char)(tmp
& 0x3f) | LCR_B_TX_MODE
) & ~LCR_B_BW
, iobase
+FIR_LCR_B
);
1644 IRDA_DEBUG(1, "%s(), ******* Change to TX mode: FIR_LCR_B = 0x%x ******* \n", __func__
, inb(iobase
+FIR_LCR_B
));
1646 outb(0, iobase
+FIR_LSR
);
1648 /* Enable DMA and Burst Mode */
1649 switch_bank(iobase
, BANK1
);
1650 outb(inb(iobase
+FIR_CR
) | CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1652 switch_bank(iobase
, BANK0
);
1654 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1657 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
)
1662 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1664 iobase
= self
->io
.fir_base
;
1667 switch_bank(iobase
, BANK1
);
1668 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1670 /* Check for underrun! */
1671 switch_bank(iobase
, BANK0
);
1672 if((inb(iobase
+FIR_LSR
) & LSR_FRAME_ABORT
) == LSR_FRAME_ABORT
)
1675 IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __func__
);
1676 self
->netdev
->stats
.tx_errors
++;
1677 self
->netdev
->stats
.tx_fifo_errors
++;
1681 self
->netdev
->stats
.tx_packets
++;
1684 /* Check if we need to change the speed */
1685 if (self
->new_speed
)
1687 ali_ircc_change_speed(self
, self
->new_speed
);
1688 self
->new_speed
= 0;
1691 /* Finished with this frame, so prepare for next */
1692 self
->tx_fifo
.ptr
++;
1693 self
->tx_fifo
.len
--;
1695 /* Any frames to be sent back-to-back? */
1696 if (self
->tx_fifo
.len
)
1698 ali_ircc_dma_xmit(self
);
1700 /* Not finished yet! */
1704 { /* Reset Tx FIFO info */
1705 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1706 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1709 /* Make sure we have room for more frames */
1710 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
) {
1711 /* Not busy transmitting anymore */
1712 /* Tell the network layer, that we can accept more frames */
1713 netif_wake_queue(self
->netdev
);
1716 switch_bank(iobase
, BANK0
);
1718 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1723 * Function ali_ircc_dma_receive (self)
1725 * Get ready for receiving a frame. The device will initiate a DMA
1726 * if it starts to receive a frame.
1729 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
)
1733 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1735 iobase
= self
->io
.fir_base
;
1737 /* Reset Tx FIFO info */
1738 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1739 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1742 switch_bank(iobase
, BANK1
);
1743 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1745 /* Reset Message Count */
1746 switch_bank(iobase
, BANK0
);
1747 outb(0x07, iobase
+FIR_LSR
);
1749 self
->rcvFramesOverflow
= FALSE
;
1751 self
->LineStatus
= inb(iobase
+FIR_LSR
) ;
1753 /* Reset Rx FIFO info */
1754 self
->io
.direction
= IO_RECV
;
1755 self
->rx_buff
.data
= self
->rx_buff
.head
;
1758 // switch_bank(iobase, BANK0);
1759 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1761 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1762 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1764 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1767 /* Set Receive Mode,Brick Wall */
1768 //switch_bank(iobase, BANK0);
1769 tmp
= inb(iobase
+FIR_LCR_B
);
1770 outb((unsigned char)(tmp
&0x3f) | LCR_B_RX_MODE
| LCR_B_BW
, iobase
+ FIR_LCR_B
); // 2000/12/1 05:16PM
1771 IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x *** \n", __func__
, inb(iobase
+FIR_LCR_B
));
1773 /* Set Rx Threshold */
1774 switch_bank(iobase
, BANK1
);
1775 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
1776 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1778 /* Enable DMA and Burst Mode */
1779 // switch_bank(iobase, BANK1);
1780 outb(CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1782 switch_bank(iobase
, BANK0
);
1783 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1787 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
)
1789 struct st_fifo
*st_fifo
;
1790 struct sk_buff
*skb
;
1791 __u8 status
, MessageCount
;
1792 int len
, i
, iobase
, val
;
1794 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1796 st_fifo
= &self
->st_fifo
;
1797 iobase
= self
->io
.fir_base
;
1799 switch_bank(iobase
, BANK0
);
1800 MessageCount
= inb(iobase
+ FIR_LSR
)&0x07;
1802 if (MessageCount
> 0)
1803 IRDA_DEBUG(0, "%s(), Messsage count = %d,\n", __func__
, MessageCount
);
1805 for (i
=0; i
<=MessageCount
; i
++)
1808 switch_bank(iobase
, BANK0
);
1809 status
= inb(iobase
+FIR_LSR
);
1811 switch_bank(iobase
, BANK2
);
1812 len
= inb(iobase
+FIR_RX_DSR_HI
) & 0x0f;
1814 len
|= inb(iobase
+FIR_RX_DSR_LO
);
1816 IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __func__
, len
);
1817 IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __func__
, status
);
1819 if (st_fifo
->tail
>= MAX_RX_WINDOW
) {
1820 IRDA_DEBUG(0, "%s(), window is full!\n", __func__
);
1824 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1825 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1826 st_fifo
->pending_bytes
+= len
;
1831 for (i
=0; i
<=MessageCount
; i
++)
1833 /* Get first entry */
1834 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1835 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1836 st_fifo
->pending_bytes
-= len
;
1840 /* Check for errors */
1841 if ((status
& 0xd8) || self
->rcvFramesOverflow
|| (len
==0))
1843 IRDA_DEBUG(0,"%s(), ************* RX Errors ************ \n", __func__
);
1846 self
->netdev
->stats
.rx_errors
++;
1848 self
->rx_buff
.data
+= len
;
1850 if (status
& LSR_FIFO_UR
)
1852 self
->netdev
->stats
.rx_frame_errors
++;
1853 IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************ \n", __func__
);
1855 if (status
& LSR_FRAME_ERROR
)
1857 self
->netdev
->stats
.rx_frame_errors
++;
1858 IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************ \n", __func__
);
1861 if (status
& LSR_CRC_ERROR
)
1863 self
->netdev
->stats
.rx_crc_errors
++;
1864 IRDA_DEBUG(0,"%s(), ************* CRC Errors ************ \n", __func__
);
1867 if(self
->rcvFramesOverflow
)
1869 self
->netdev
->stats
.rx_frame_errors
++;
1870 IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************ \n", __func__
);
1874 self
->netdev
->stats
.rx_frame_errors
++;
1875 IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 ********* \n", __func__
);
1881 if (st_fifo
->pending_bytes
< 32)
1883 switch_bank(iobase
, BANK0
);
1884 val
= inb(iobase
+FIR_BSR
);
1885 if ((val
& BSR_FIFO_NOT_EMPTY
)== 0x80)
1887 IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************ \n", __func__
);
1889 /* Put this entry back in fifo */
1892 st_fifo
->pending_bytes
+= len
;
1893 st_fifo
->entries
[st_fifo
->head
].status
= status
;
1894 st_fifo
->entries
[st_fifo
->head
].len
= len
;
1897 * DMA not finished yet, so try again
1898 * later, set timer value, resolution
1902 switch_bank(iobase
, BANK1
);
1903 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
); // 2001/1/2 05:07PM
1906 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1908 return FALSE
; /* I'll be back! */
1913 * Remember the time we received this frame, so we can
1914 * reduce the min turn time a bit since we will know
1915 * how much time we have used for protocol processing
1917 do_gettimeofday(&self
->stamp
);
1919 skb
= dev_alloc_skb(len
+1);
1922 IRDA_WARNING("%s(), memory squeeze, "
1923 "dropping frame.\n",
1925 self
->netdev
->stats
.rx_dropped
++;
1930 /* Make sure IP header gets aligned */
1931 skb_reserve(skb
, 1);
1933 /* Copy frame without CRC, CRC is removed by hardware*/
1935 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
);
1937 /* Move to next frame */
1938 self
->rx_buff
.data
+= len
;
1939 self
->netdev
->stats
.rx_bytes
+= len
;
1940 self
->netdev
->stats
.rx_packets
++;
1942 skb
->dev
= self
->netdev
;
1943 skb_reset_mac_header(skb
);
1944 skb
->protocol
= htons(ETH_P_IRDA
);
1949 switch_bank(iobase
, BANK0
);
1951 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1958 * Function ali_ircc_sir_hard_xmit (skb, dev)
1960 * Transmit the frame!
1963 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
1964 struct net_device
*dev
)
1966 struct ali_ircc_cb
*self
;
1967 unsigned long flags
;
1971 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1973 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
1975 self
= netdev_priv(dev
);
1976 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
1978 iobase
= self
->io
.sir_base
;
1980 netif_stop_queue(dev
);
1982 /* Make sure tests *& speed change are atomic */
1983 spin_lock_irqsave(&self
->lock
, flags
);
1985 /* Note : you should make sure that speed changes are not going
1986 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1987 * details - Jean II */
1989 /* Check if we need to change the speed */
1990 speed
= irda_get_next_speed(skb
);
1991 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1992 /* Check for empty frame */
1994 ali_ircc_change_speed(self
, speed
);
1995 dev
->trans_start
= jiffies
;
1996 spin_unlock_irqrestore(&self
->lock
, flags
);
1998 return NETDEV_TX_OK
;
2000 self
->new_speed
= speed
;
2003 /* Init tx buffer */
2004 self
->tx_buff
.data
= self
->tx_buff
.head
;
2006 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
2007 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
2008 self
->tx_buff
.truesize
);
2010 self
->netdev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
2012 /* Turn on transmit finished interrupt. Will fire immediately! */
2013 outb(UART_IER_THRI
, iobase
+UART_IER
);
2015 dev
->trans_start
= jiffies
;
2016 spin_unlock_irqrestore(&self
->lock
, flags
);
2020 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2022 return NETDEV_TX_OK
;
2027 * Function ali_ircc_net_ioctl (dev, rq, cmd)
2029 * Process IOCTL commands for this device
2032 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2034 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
2035 struct ali_ircc_cb
*self
;
2036 unsigned long flags
;
2039 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
2041 IRDA_ASSERT(dev
!= NULL
, return -1;);
2043 self
= netdev_priv(dev
);
2045 IRDA_ASSERT(self
!= NULL
, return -1;);
2047 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
2050 case SIOCSBANDWIDTH
: /* Set bandwidth */
2051 IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __func__
);
2053 * This function will also be used by IrLAP to change the
2054 * speed, so we still must allow for speed change within
2055 * interrupt context.
2057 if (!in_interrupt() && !capable(CAP_NET_ADMIN
))
2060 spin_lock_irqsave(&self
->lock
, flags
);
2061 ali_ircc_change_speed(self
, irq
->ifr_baudrate
);
2062 spin_unlock_irqrestore(&self
->lock
, flags
);
2064 case SIOCSMEDIABUSY
: /* Set media busy */
2065 IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __func__
);
2066 if (!capable(CAP_NET_ADMIN
))
2068 irda_device_set_media_busy(self
->netdev
, TRUE
);
2070 case SIOCGRECEIVING
: /* Check if we are receiving right now */
2071 IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __func__
);
2072 /* This is protected */
2073 irq
->ifr_receiving
= ali_ircc_is_receiving(self
);
2079 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2085 * Function ali_ircc_is_receiving (self)
2087 * Return TRUE is we are currently receiving a frame
2090 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
)
2092 unsigned long flags
;
2096 IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __func__
);
2098 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
2100 spin_lock_irqsave(&self
->lock
, flags
);
2102 if (self
->io
.speed
> 115200)
2104 iobase
= self
->io
.fir_base
;
2106 switch_bank(iobase
, BANK1
);
2107 if((inb(iobase
+FIR_FIFO_FR
) & 0x3f) != 0)
2109 /* We are receiving something */
2110 IRDA_DEBUG(1, "%s(), We are receiving something\n", __func__
);
2113 switch_bank(iobase
, BANK0
);
2117 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
2120 spin_unlock_irqrestore(&self
->lock
, flags
);
2122 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2127 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
2129 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2131 IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME
);
2133 if (self
->io
.suspended
)
2136 ali_ircc_net_close(self
->netdev
);
2138 self
->io
.suspended
= 1;
2143 static int ali_ircc_resume(struct platform_device
*dev
)
2145 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2147 if (!self
->io
.suspended
)
2150 ali_ircc_net_open(self
->netdev
);
2152 IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME
);
2154 self
->io
.suspended
= 0;
2159 /* ALi Chip Function */
2161 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
)
2164 unsigned char newMask
;
2166 int iobase
= self
->io
.fir_base
; /* or sir_base */
2168 IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __func__
, enable
);
2170 /* Enable the interrupt which we wish to */
2172 if (self
->io
.direction
== IO_XMIT
)
2174 if (self
->io
.speed
> 115200) /* FIR, MIR */
2176 newMask
= self
->ier
;
2180 newMask
= UART_IER_THRI
| UART_IER_RDI
;
2184 if (self
->io
.speed
> 115200) /* FIR, MIR */
2186 newMask
= self
->ier
;
2190 newMask
= UART_IER_RDI
;
2194 else /* Disable all the interrupts */
2200 //SIR and FIR has different registers
2201 if (self
->io
.speed
> 115200)
2203 switch_bank(iobase
, BANK0
);
2204 outb(newMask
, iobase
+FIR_IER
);
2207 outb(newMask
, iobase
+UART_IER
);
2209 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2212 static void SIR2FIR(int iobase
)
2214 //unsigned char tmp;
2216 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
2218 /* Already protected (change_speed() or setup()), no need to lock.
2221 outb(0x28, iobase
+UART_MCR
);
2222 outb(0x68, iobase
+UART_MCR
);
2223 outb(0x88, iobase
+UART_MCR
);
2225 outb(0x60, iobase
+FIR_MCR
); /* Master Reset */
2226 outb(0x20, iobase
+FIR_MCR
); /* Master Interrupt Enable */
2228 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2230 //outb(tmp, iobase+FIR_LCR_B);
2232 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
2235 static void FIR2SIR(int iobase
)
2239 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
2241 /* Already protected (change_speed() or setup()), no need to lock.
2244 outb(0x20, iobase
+FIR_MCR
); /* IRQ to low */
2245 outb(0x00, iobase
+UART_IER
);
2247 outb(0xA0, iobase
+FIR_MCR
); /* Don't set master reset */
2248 outb(0x00, iobase
+UART_FCR
);
2249 outb(0x07, iobase
+UART_FCR
);
2251 val
= inb(iobase
+UART_RX
);
2252 val
= inb(iobase
+UART_LSR
);
2253 val
= inb(iobase
+UART_MSR
);
2255 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
2258 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2259 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2260 MODULE_LICENSE("GPL");
2261 MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME
);
2264 module_param_array(io
, int, NULL
, 0);
2265 MODULE_PARM_DESC(io
, "Base I/O addresses");
2266 module_param_array(irq
, int, NULL
, 0);
2267 MODULE_PARM_DESC(irq
, "IRQ lines");
2268 module_param_array(dma
, int, NULL
, 0);
2269 MODULE_PARM_DESC(dma
, "DMA channels");
2271 module_init(ali_ircc_init
);
2272 module_exit(ali_ircc_cleanup
);