1 /*********************************************************************
5 * Description: Driver for the ALI M1535D and M1543C FIR Controller
6 * Status: Experimental.
7 * Author: Benjamin Kong <benjamin_kong@ali.com.tw>
8 * Created at: 2000/10/16 03:46PM
9 * Modified at: 2001/1/3 02:55PM
10 * Modified by: Benjamin Kong <benjamin_kong@ali.com.tw>
11 * Modified at: 2003/11/6 and support for ALi south-bridge chipsets M1563
12 * Modified by: Clear Zhang <clear_zhang@ali.com.tw>
14 * Copyright (c) 2000 Benjamin Kong <benjamin_kong@ali.com.tw>
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 ********************************************************************/
24 #include <linux/module.h>
25 #include <linux/gfp.h>
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/skbuff.h>
30 #include <linux/netdevice.h>
31 #include <linux/ioport.h>
32 #include <linux/delay.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
35 #include <linux/rtnetlink.h>
36 #include <linux/serial_reg.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/platform_device.h>
42 #include <asm/byteorder.h>
44 #include <net/irda/wrapper.h>
45 #include <net/irda/irda.h>
46 #include <net/irda/irda_device.h>
50 #define CHIP_IO_EXTENT 8
51 #define BROKEN_DONGLE_ID
53 #define ALI_IRCC_DRIVER_NAME "ali-ircc"
55 /* Power Management */
56 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
);
57 static int ali_ircc_resume(struct platform_device
*dev
);
59 static struct platform_driver ali_ircc_driver
= {
60 .suspend
= ali_ircc_suspend
,
61 .resume
= ali_ircc_resume
,
63 .name
= ALI_IRCC_DRIVER_NAME
,
68 /* Module parameters */
69 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
71 /* Use BIOS settions by default, but user may supply module parameters */
72 static unsigned int io
[] = { ~0, ~0, ~0, ~0 };
73 static unsigned int irq
[] = { 0, 0, 0, 0 };
74 static unsigned int dma
[] = { 0, 0, 0, 0 };
76 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
);
77 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
);
78 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
);
80 /* These are the currently known ALi south-bridge chipsets, the only one difference
81 * is that M1543C doesn't support HP HDSL-3600
83 static ali_chip_t chips
[] =
85 { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53
, ali_ircc_init_43
},
86 { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53
, ali_ircc_init_53
},
87 { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53
, ali_ircc_init_53
},
91 /* Max 4 instances for now */
92 static struct ali_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
95 static char *dongle_types
[] = {
99 "No dongle connected",
102 /* Some prototypes */
103 static int ali_ircc_open(int i
, chipio_t
*info
);
105 static int ali_ircc_close(struct ali_ircc_cb
*self
);
107 static int ali_ircc_setup(chipio_t
*info
);
108 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
);
109 static int ali_ircc_net_open(struct net_device
*dev
);
110 static int ali_ircc_net_close(struct net_device
*dev
);
111 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
112 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
);
115 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
116 struct net_device
*dev
);
117 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
);
118 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
);
119 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
);
120 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
121 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
124 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
125 struct net_device
*dev
);
126 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
);
127 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
);
128 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
);
129 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
);
130 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
);
131 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
);
134 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
);
135 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
);
137 /* ALi chip function */
138 static void SIR2FIR(int iobase
);
139 static void FIR2SIR(int iobase
);
140 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
);
143 * Function ali_ircc_init ()
145 * Initialize chip. Find out whay kinds of chips we are dealing with
146 * and their configuration registers address
148 static int __init
ali_ircc_init(void)
157 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
159 ret
= platform_driver_register(&ali_ircc_driver
);
161 IRDA_ERROR("%s, Can't register driver!\n",
162 ALI_IRCC_DRIVER_NAME
);
168 /* Probe for all the ALi chipsets we know about */
169 for (chip
= chips
; chip
->name
; chip
++, i
++)
171 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __func__
, chip
->name
);
173 /* Try all config registers for this chip */
174 for (cfg
=0; cfg
<2; cfg
++)
176 cfg_base
= chip
->cfg
[cfg
];
180 memset(&info
, 0, sizeof(chipio_t
));
181 info
.cfg_base
= cfg_base
;
182 info
.fir_base
= io
[i
];
187 /* Enter Configuration */
188 outb(chip
->entr1
, cfg_base
);
189 outb(chip
->entr2
, cfg_base
);
191 /* Select Logical Device 5 Registers (UART2) */
192 outb(0x07, cfg_base
);
193 outb(0x05, cfg_base
+1);
195 /* Read Chip Identification Register */
196 outb(chip
->cid_index
, cfg_base
);
197 reg
= inb(cfg_base
+1);
199 if (reg
== chip
->cid_value
)
201 IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __func__
, cfg_base
);
203 outb(0x1F, cfg_base
);
204 revision
= inb(cfg_base
+1);
205 IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __func__
,
206 chip
->name
, revision
);
209 * If the user supplies the base address, then
210 * we init the chip, if not we probe the values
215 chip
->init(chip
, &info
);
219 chip
->probe(chip
, &info
);
222 if (ali_ircc_open(i
, &info
) == 0)
228 IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __func__
, chip
->name
, cfg_base
);
230 /* Exit configuration */
231 outb(0xbb, cfg_base
);
235 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
238 platform_driver_unregister(&ali_ircc_driver
);
244 * Function ali_ircc_cleanup ()
246 * Close all configured chips
249 static void __exit
ali_ircc_cleanup(void)
253 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
255 for (i
=0; i
< ARRAY_SIZE(dev_self
); i
++) {
257 ali_ircc_close(dev_self
[i
]);
260 platform_driver_unregister(&ali_ircc_driver
);
262 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
265 static const struct net_device_ops ali_ircc_sir_ops
= {
266 .ndo_open
= ali_ircc_net_open
,
267 .ndo_stop
= ali_ircc_net_close
,
268 .ndo_start_xmit
= ali_ircc_sir_hard_xmit
,
269 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
272 static const struct net_device_ops ali_ircc_fir_ops
= {
273 .ndo_open
= ali_ircc_net_open
,
274 .ndo_stop
= ali_ircc_net_close
,
275 .ndo_start_xmit
= ali_ircc_fir_hard_xmit
,
276 .ndo_do_ioctl
= ali_ircc_net_ioctl
,
280 * Function ali_ircc_open (int i, chipio_t *inf)
282 * Open driver instance
285 static int ali_ircc_open(int i
, chipio_t
*info
)
287 struct net_device
*dev
;
288 struct ali_ircc_cb
*self
;
292 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
294 if (i
>= ARRAY_SIZE(dev_self
)) {
295 IRDA_ERROR("%s(), maximum number of supported chips reached!\n",
300 /* Set FIR FIFO and DMA Threshold */
301 if ((ali_ircc_setup(info
)) == -1)
304 dev
= alloc_irdadev(sizeof(*self
));
306 IRDA_ERROR("%s(), can't allocate memory for control block!\n",
311 self
= netdev_priv(dev
);
313 spin_lock_init(&self
->lock
);
315 /* Need to store self somewhere */
320 self
->io
.cfg_base
= info
->cfg_base
; /* In ali_ircc_probe_53 assign */
321 self
->io
.fir_base
= info
->fir_base
; /* info->sir_base = info->fir_base */
322 self
->io
.sir_base
= info
->sir_base
; /* ALi SIR and FIR use the same address */
323 self
->io
.irq
= info
->irq
;
324 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
325 self
->io
.dma
= info
->dma
;
326 self
->io
.fifo_size
= 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
328 /* Reserve the ioports that we need */
329 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
,
330 ALI_IRCC_DRIVER_NAME
)) {
331 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __func__
,
337 /* Initialize QoS for this device */
338 irda_init_max_qos_capabilies(&self
->qos
);
340 /* The only value we must override it the baudrate */
341 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
342 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8); // benjamin 2000/11/8 05:27PM
344 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
346 irda_qos_bits_to_value(&self
->qos
);
348 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
349 self
->rx_buff
.truesize
= 14384;
350 self
->tx_buff
.truesize
= 14384;
352 /* Allocate memory if needed */
354 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
355 &self
->rx_buff_dma
, GFP_KERNEL
| __GFP_ZERO
);
356 if (self
->rx_buff
.head
== NULL
) {
362 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
363 &self
->tx_buff_dma
, GFP_KERNEL
| __GFP_ZERO
);
364 if (self
->tx_buff
.head
== NULL
) {
369 self
->rx_buff
.in_frame
= FALSE
;
370 self
->rx_buff
.state
= OUTSIDE_FRAME
;
371 self
->tx_buff
.data
= self
->tx_buff
.head
;
372 self
->rx_buff
.data
= self
->rx_buff
.head
;
374 /* Reset Tx queue info */
375 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
376 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
378 /* Override the network functions we need to use */
379 dev
->netdev_ops
= &ali_ircc_sir_ops
;
381 err
= register_netdev(dev
);
383 IRDA_ERROR("%s(), register_netdev() failed!\n", __func__
);
386 IRDA_MESSAGE("IrDA: Registered device %s\n", dev
->name
);
388 /* Check dongle id */
389 dongle_id
= ali_ircc_read_dongle_id(i
, info
);
390 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __func__
,
391 ALI_IRCC_DRIVER_NAME
, dongle_types
[dongle_id
]);
393 self
->io
.dongle_id
= dongle_id
;
395 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
400 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
401 self
->tx_buff
.head
, self
->tx_buff_dma
);
403 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
404 self
->rx_buff
.head
, self
->rx_buff_dma
);
406 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
415 * Function ali_ircc_close (self)
417 * Close driver instance
420 static int __exit
ali_ircc_close(struct ali_ircc_cb
*self
)
424 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__
);
426 IRDA_ASSERT(self
!= NULL
, return -1;);
428 iobase
= self
->io
.fir_base
;
430 /* Remove netdevice */
431 unregister_netdev(self
->netdev
);
433 /* Release the PORT that this driver is using */
434 IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __func__
, self
->io
.fir_base
);
435 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
437 if (self
->tx_buff
.head
)
438 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
439 self
->tx_buff
.head
, self
->tx_buff_dma
);
441 if (self
->rx_buff
.head
)
442 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
443 self
->rx_buff
.head
, self
->rx_buff_dma
);
445 dev_self
[self
->index
] = NULL
;
446 free_netdev(self
->netdev
);
448 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
454 * Function ali_ircc_init_43 (chip, info)
456 * Initialize the ALi M1543 chip.
458 static int ali_ircc_init_43(ali_chip_t
*chip
, chipio_t
*info
)
460 /* All controller information like I/O address, DMA channel, IRQ
468 * Function ali_ircc_init_53 (chip, info)
470 * Initialize the ALi M1535 chip.
472 static int ali_ircc_init_53(ali_chip_t
*chip
, chipio_t
*info
)
474 /* All controller information like I/O address, DMA channel, IRQ
482 * Function ali_ircc_probe_53 (chip, info)
484 * Probes for the ALi M1535D or M1535
486 static int ali_ircc_probe_53(ali_chip_t
*chip
, chipio_t
*info
)
488 int cfg_base
= info
->cfg_base
;
491 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
493 /* Enter Configuration */
494 outb(chip
->entr1
, cfg_base
);
495 outb(chip
->entr2
, cfg_base
);
497 /* Select Logical Device 5 Registers (UART2) */
498 outb(0x07, cfg_base
);
499 outb(0x05, cfg_base
+1);
501 /* Read address control register */
502 outb(0x60, cfg_base
);
503 hi
= inb(cfg_base
+1);
504 outb(0x61, cfg_base
);
505 low
= inb(cfg_base
+1);
506 info
->fir_base
= (hi
<<8) + low
;
508 info
->sir_base
= info
->fir_base
;
510 IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __func__
, info
->fir_base
);
512 /* Read IRQ control register */
513 outb(0x70, cfg_base
);
514 reg
= inb(cfg_base
+1);
515 info
->irq
= reg
& 0x0f;
516 IRDA_DEBUG(2, "%s(), probing irq=%d\n", __func__
, info
->irq
);
518 /* Read DMA channel */
519 outb(0x74, cfg_base
);
520 reg
= inb(cfg_base
+1);
521 info
->dma
= reg
& 0x07;
523 if(info
->dma
== 0x04)
524 IRDA_WARNING("%s(), No DMA channel assigned !\n", __func__
);
526 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __func__
, info
->dma
);
528 /* Read Enabled Status */
529 outb(0x30, cfg_base
);
530 reg
= inb(cfg_base
+1);
531 info
->enabled
= (reg
& 0x80) && (reg
& 0x01);
532 IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __func__
, info
->enabled
);
534 /* Read Power Status */
535 outb(0x22, cfg_base
);
536 reg
= inb(cfg_base
+1);
537 info
->suspended
= (reg
& 0x20);
538 IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __func__
, info
->suspended
);
540 /* Exit configuration */
541 outb(0xbb, cfg_base
);
543 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__
);
549 * Function ali_ircc_setup (info)
551 * Set FIR FIFO and DMA Threshold
552 * Returns non-negative on success.
555 static int ali_ircc_setup(chipio_t
*info
)
559 int iobase
= info
->fir_base
;
561 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
563 /* Locking comments :
564 * Most operations here need to be protected. We are called before
565 * the device instance is created in ali_ircc_open(), therefore
566 * nobody can bother us - Jean II */
568 /* Switch to FIR space */
572 outb(0x40, iobase
+FIR_MCR
); // benjamin 2000/11/30 11:45AM
574 /* Read FIR ID Version Register */
575 switch_bank(iobase
, BANK3
);
576 version
= inb(iobase
+FIR_ID_VR
);
578 /* Should be 0x00 in the M1535/M1535D */
581 IRDA_ERROR("%s, Wrong chip version %02x\n",
582 ALI_IRCC_DRIVER_NAME
, version
);
586 /* Set FIR FIFO Threshold Register */
587 switch_bank(iobase
, BANK1
);
588 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
590 /* Set FIR DMA Threshold Register */
591 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
594 switch_bank(iobase
, BANK2
);
595 outb(inb(iobase
+FIR_IRDA_CR
) | IRDA_CR_CRC
, iobase
+FIR_IRDA_CR
);
597 /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
599 /* Switch to Bank 0 */
600 switch_bank(iobase
, BANK0
);
602 tmp
= inb(iobase
+FIR_LCR_B
);
603 tmp
&=~0x20; // disable SIP
604 tmp
|= 0x80; // these two steps make RX mode
606 outb(tmp
, iobase
+FIR_LCR_B
);
608 /* Disable Interrupt */
609 outb(0x00, iobase
+FIR_IER
);
612 /* Switch to SIR space */
615 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
616 ALI_IRCC_DRIVER_NAME
);
618 /* Enable receive interrupts */
619 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
620 // Turn on the interrupts in ali_ircc_net_open
622 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
628 * Function ali_ircc_read_dongle_id (int index, info)
630 * Try to read dongle indentification. This procedure needs to be executed
631 * once after power-on/reset. It also needs to be used whenever you suspect
632 * that the user may have plugged/unplugged the IrDA Dongle.
634 static int ali_ircc_read_dongle_id (int i
, chipio_t
*info
)
637 int cfg_base
= info
->cfg_base
;
639 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
641 /* Enter Configuration */
642 outb(chips
[i
].entr1
, cfg_base
);
643 outb(chips
[i
].entr2
, cfg_base
);
645 /* Select Logical Device 5 Registers (UART2) */
646 outb(0x07, cfg_base
);
647 outb(0x05, cfg_base
+1);
650 outb(0xf0, cfg_base
);
651 reg
= inb(cfg_base
+1);
652 dongle_id
= ((reg
>>6)&0x02) | ((reg
>>5)&0x01);
653 IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __func__
,
654 dongle_id
, dongle_types
[dongle_id
]);
656 /* Exit configuration */
657 outb(0xbb, cfg_base
);
659 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
665 * Function ali_ircc_interrupt (irq, dev_id, regs)
667 * An interrupt from the chip has arrived. Time to do some work
670 static irqreturn_t
ali_ircc_interrupt(int irq
, void *dev_id
)
672 struct net_device
*dev
= dev_id
;
673 struct ali_ircc_cb
*self
;
676 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
678 self
= netdev_priv(dev
);
680 spin_lock(&self
->lock
);
682 /* Dispatch interrupt handler for the current speed */
683 if (self
->io
.speed
> 115200)
684 ret
= ali_ircc_fir_interrupt(self
);
686 ret
= ali_ircc_sir_interrupt(self
);
688 spin_unlock(&self
->lock
);
690 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
694 * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
696 * Handle MIR/FIR interrupt
699 static irqreturn_t
ali_ircc_fir_interrupt(struct ali_ircc_cb
*self
)
701 __u8 eir
, OldMessageCount
;
704 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
706 iobase
= self
->io
.fir_base
;
708 switch_bank(iobase
, BANK0
);
709 self
->InterruptID
= inb(iobase
+FIR_IIR
);
710 self
->BusStatus
= inb(iobase
+FIR_BSR
);
712 OldMessageCount
= (self
->LineStatus
+ 1) & 0x07;
713 self
->LineStatus
= inb(iobase
+FIR_LSR
);
714 //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
715 eir
= self
->InterruptID
& self
->ier
; /* Mask out the interesting ones */
717 IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __func__
,self
->InterruptID
);
718 IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __func__
,self
->LineStatus
);
719 IRDA_DEBUG(1, "%s(), self->ier = %x\n", __func__
,self
->ier
);
720 IRDA_DEBUG(1, "%s(), eir = %x\n", __func__
,eir
);
722 /* Disable interrupts */
723 SetCOMInterrupts(self
, FALSE
);
725 /* Tx or Rx Interrupt */
729 if (self
->io
.direction
== IO_XMIT
) /* TX */
731 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __func__
);
733 if(ali_ircc_dma_xmit_complete(self
))
735 if (irda_device_txqueue_empty(self
->netdev
))
737 /* Prepare for receive */
738 ali_ircc_dma_receive(self
);
750 IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __func__
);
752 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
754 self
->rcvFramesOverflow
= TRUE
;
755 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ********\n", __func__
);
758 if (ali_ircc_dma_receive_complete(self
))
760 IRDA_DEBUG(1, "%s(), ******* receive complete ********\n", __func__
);
766 IRDA_DEBUG(1, "%s(), ******* Not receive complete ********\n", __func__
);
768 self
->ier
= IER_EOM
| IER_TIMER
;
773 /* Timer Interrupt */
774 else if (eir
& IIR_TIMER
)
776 if(OldMessageCount
> ((self
->LineStatus
+1) & 0x07))
778 self
->rcvFramesOverflow
= TRUE
;
779 IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE *******\n", __func__
);
782 switch_bank(iobase
, BANK1
);
783 tmp
= inb(iobase
+FIR_CR
);
784 outb( tmp
& ~CR_TIMER_EN
, iobase
+FIR_CR
);
786 /* Check if this is a Tx timer interrupt */
787 if (self
->io
.direction
== IO_XMIT
)
789 ali_ircc_dma_xmit(self
);
791 /* Interrupt on EOM */
797 if(ali_ircc_dma_receive_complete(self
))
803 self
->ier
= IER_EOM
| IER_TIMER
;
808 /* Restore Interrupt */
809 SetCOMInterrupts(self
, TRUE
);
811 IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __func__
);
812 return IRQ_RETVAL(eir
);
816 * Function ali_ircc_sir_interrupt (irq, self, eir)
818 * Handle SIR interrupt
821 static irqreturn_t
ali_ircc_sir_interrupt(struct ali_ircc_cb
*self
)
826 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
828 iobase
= self
->io
.sir_base
;
830 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
832 /* Clear interrupt */
833 lsr
= inb(iobase
+UART_LSR
);
835 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __func__
,
841 IRDA_DEBUG(2, "%s(), RLSI\n", __func__
);
844 /* Receive interrupt */
845 ali_ircc_sir_receive(self
);
848 if (lsr
& UART_LSR_THRE
)
850 /* Transmitter ready for data */
851 ali_ircc_sir_write_wakeup(self
);
855 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __func__
, iir
);
862 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
864 return IRQ_RETVAL(iir
);
869 * Function ali_ircc_sir_receive (self)
871 * Receive one frame from the infrared port
874 static void ali_ircc_sir_receive(struct ali_ircc_cb
*self
)
879 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
880 IRDA_ASSERT(self
!= NULL
, return;);
882 iobase
= self
->io
.sir_base
;
885 * Receive all characters in Rx FIFO, unwrap and unstuff them.
886 * async_unwrap_char will deliver all found frames
889 async_unwrap_char(self
->netdev
, &self
->netdev
->stats
, &self
->rx_buff
,
890 inb(iobase
+UART_RX
));
892 /* Make sure we don't stay here too long */
893 if (boguscount
++ > 32) {
894 IRDA_DEBUG(2,"%s(), breaking!\n", __func__
);
897 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
899 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
903 * Function ali_ircc_sir_write_wakeup (tty)
905 * Called by the driver when there's room for more data. If we have
906 * more packets to send, we send them here.
909 static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb
*self
)
914 IRDA_ASSERT(self
!= NULL
, return;);
916 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
918 iobase
= self
->io
.sir_base
;
920 /* Finished with frame? */
921 if (self
->tx_buff
.len
> 0)
923 /* Write data left in transmit buffer */
924 actual
= ali_ircc_sir_write(iobase
, self
->io
.fifo_size
,
925 self
->tx_buff
.data
, self
->tx_buff
.len
);
926 self
->tx_buff
.data
+= actual
;
927 self
->tx_buff
.len
-= actual
;
933 /* We must wait until all data are gone */
934 while(!(inb(iobase
+UART_LSR
) & UART_LSR_TEMT
))
935 IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __func__
);
937 IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __func__
, self
->new_speed
);
938 ali_ircc_change_speed(self
, self
->new_speed
);
941 // benjamin 2000/11/10 06:32PM
942 if (self
->io
.speed
> 115200)
944 IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT\n", __func__
);
947 // SetCOMInterrupts(self, TRUE);
953 netif_wake_queue(self
->netdev
);
956 self
->netdev
->stats
.tx_packets
++;
958 /* Turn on receive interrupts */
959 outb(UART_IER_RDI
, iobase
+UART_IER
);
962 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
965 static void ali_ircc_change_speed(struct ali_ircc_cb
*self
, __u32 baud
)
967 struct net_device
*dev
= self
->netdev
;
970 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
972 IRDA_DEBUG(2, "%s(), setting speed = %d\n", __func__
, baud
);
974 /* This function *must* be called with irq off and spin-lock.
977 iobase
= self
->io
.fir_base
;
979 SetCOMInterrupts(self
, FALSE
); // 2000/11/24 11:43AM
981 /* Go to MIR, FIR Speed */
986 ali_ircc_fir_change_speed(self
, baud
);
988 /* Install FIR xmit handler*/
989 dev
->netdev_ops
= &ali_ircc_fir_ops
;
991 /* Enable Interuupt */
992 self
->ier
= IER_EOM
; // benjamin 2000/11/20 07:24PM
994 /* Be ready for incoming frames */
995 ali_ircc_dma_receive(self
); // benajmin 2000/11/8 07:46PM not complete
997 /* Go to SIR Speed */
1000 ali_ircc_sir_change_speed(self
, baud
);
1002 /* Install SIR xmit handler*/
1003 dev
->netdev_ops
= &ali_ircc_sir_ops
;
1007 SetCOMInterrupts(self
, TRUE
); // 2000/11/24 11:43AM
1009 netif_wake_queue(self
->netdev
);
1011 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1014 static void ali_ircc_fir_change_speed(struct ali_ircc_cb
*priv
, __u32 baud
)
1018 struct ali_ircc_cb
*self
= priv
;
1019 struct net_device
*dev
;
1021 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1023 IRDA_ASSERT(self
!= NULL
, return;);
1026 iobase
= self
->io
.fir_base
;
1028 IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __func__
,self
->io
.speed
,baud
);
1030 /* Come from SIR speed */
1031 if(self
->io
.speed
<=115200)
1036 /* Update accounting for new speed */
1037 self
->io
.speed
= baud
;
1039 // Set Dongle Speed mode
1040 ali_ircc_change_dongle_speed(self
, baud
);
1042 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1046 * Function ali_sir_change_speed (self, speed)
1048 * Set speed of IrDA port to specified baudrate
1051 static void ali_ircc_sir_change_speed(struct ali_ircc_cb
*priv
, __u32 speed
)
1053 struct ali_ircc_cb
*self
= priv
;
1054 unsigned long flags
;
1056 int fcr
; /* FIFO control reg */
1057 int lcr
; /* Line control reg */
1060 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1062 IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __func__
, speed
);
1064 IRDA_ASSERT(self
!= NULL
, return;);
1066 iobase
= self
->io
.sir_base
;
1068 /* Come from MIR or FIR speed */
1069 if(self
->io
.speed
>115200)
1071 // Set Dongle Speed mode first
1072 ali_ircc_change_dongle_speed(self
, speed
);
1077 // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
1079 inb(iobase
+UART_LSR
);
1080 inb(iobase
+UART_SCR
);
1082 /* Update accounting for new speed */
1083 self
->io
.speed
= speed
;
1085 spin_lock_irqsave(&self
->lock
, flags
);
1087 divisor
= 115200/speed
;
1089 fcr
= UART_FCR_ENABLE_FIFO
;
1092 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1093 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1094 * about this timeout since it will always be fast enough.
1096 if (self
->io
.speed
< 38400)
1097 fcr
|= UART_FCR_TRIGGER_1
;
1099 fcr
|= UART_FCR_TRIGGER_14
;
1101 /* IrDA ports use 8N1 */
1102 lcr
= UART_LCR_WLEN8
;
1104 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
1105 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
1106 outb(divisor
>> 8, iobase
+UART_DLM
);
1107 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
1108 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
1110 /* without this, the connection will be broken after come back from FIR speed,
1111 but with this, the SIR connection is harder to established */
1112 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), iobase
+UART_MCR
);
1114 spin_unlock_irqrestore(&self
->lock
, flags
);
1116 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1119 static void ali_ircc_change_dongle_speed(struct ali_ircc_cb
*priv
, int speed
)
1122 struct ali_ircc_cb
*self
= priv
;
1123 int iobase
,dongle_id
;
1126 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
1128 iobase
= self
->io
.fir_base
; /* or iobase = self->io.sir_base; */
1129 dongle_id
= self
->io
.dongle_id
;
1131 /* We are already locked, no need to do it again */
1133 IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __func__
, dongle_types
[dongle_id
], speed
);
1135 switch_bank(iobase
, BANK2
);
1136 tmp
= inb(iobase
+FIR_IRDA_CR
);
1138 /* IBM type dongle */
1141 if(speed
== 4000000)
1144 // SD/MODE __| |__ __
1149 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1150 tmp
|= IRDA_CR_CRC
; // CRC=1
1152 switch_bank(iobase
, BANK2
);
1153 outb(tmp
, iobase
+FIR_IRDA_CR
);
1155 // T1 -> SD/MODE:0 IRTX:0
1158 outb(tmp
, iobase
+FIR_IRDA_CR
);
1161 // T2 -> SD/MODE:1 IRTX:0
1164 outb(tmp
, iobase
+FIR_IRDA_CR
);
1167 // T3 -> SD/MODE:1 IRTX:1
1169 outb(tmp
, iobase
+FIR_IRDA_CR
);
1172 // T4 -> SD/MODE:0 IRTX:1
1175 outb(tmp
, iobase
+FIR_IRDA_CR
);
1178 // T5 -> SD/MODE:0 IRTX:0
1181 outb(tmp
, iobase
+FIR_IRDA_CR
);
1184 // reset -> Normal TX output Signal
1185 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1187 else /* speed <=1152000 */
1195 /* MIR 115200, 57600 */
1198 tmp
|= 0xA0; //HDLC=1, 1.152Mbps=1
1202 tmp
&=~0x80; //HDLC 0.576Mbps
1203 tmp
|= 0x20; //HDLC=1,
1206 tmp
|= IRDA_CR_CRC
; // CRC=1
1208 switch_bank(iobase
, BANK2
);
1209 outb(tmp
, iobase
+FIR_IRDA_CR
);
1211 /* MIR 115200, 57600 */
1213 //switch_bank(iobase, BANK2);
1214 // T1 -> SD/MODE:0 IRTX:0
1217 outb(tmp
, iobase
+FIR_IRDA_CR
);
1220 // T2 -> SD/MODE:1 IRTX:0
1223 outb(tmp
, iobase
+FIR_IRDA_CR
);
1225 // T3 -> SD/MODE:0 IRTX:0
1228 outb(tmp
, iobase
+FIR_IRDA_CR
);
1231 // reset -> Normal TX output Signal
1232 outb(tmp
& ~0x02, iobase
+FIR_IRDA_CR
);
1235 else if (dongle_id
== 1) /* HP HDSL-3600 */
1240 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1244 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1248 tmp
&=~0x80; // HDLC 0.576Mbps
1249 tmp
|= 0x20; // HDLC=1,
1253 tmp
|= IRDA_CR_CRC
; // CRC=1
1255 switch_bank(iobase
, BANK2
);
1256 outb(tmp
, iobase
+FIR_IRDA_CR
);
1258 else /* HP HDSL-1100 */
1260 if(speed
<= 115200) /* SIR */
1263 tmp
&= ~IRDA_CR_FIR_SIN
; // HP sin select = 0
1265 switch_bank(iobase
, BANK2
);
1266 outb(tmp
, iobase
+FIR_IRDA_CR
);
1274 tmp
&= ~IRDA_CR_HDLC
; // HDLC=0
1278 tmp
|= 0xA0; // HDLC=1, 1.152Mbps=1
1282 tmp
&=~0x80; // HDLC 0.576Mbps
1283 tmp
|= 0x20; // HDLC=1,
1287 tmp
|= IRDA_CR_CRC
; // CRC=1
1288 tmp
|= IRDA_CR_FIR_SIN
; // HP sin select = 1
1290 switch_bank(iobase
, BANK2
);
1291 outb(tmp
, iobase
+FIR_IRDA_CR
);
1295 switch_bank(iobase
, BANK0
);
1297 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1301 * Function ali_ircc_sir_write (driver)
1303 * Fill Tx FIFO with transmit data
1306 static int ali_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
1310 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1312 /* Tx FIFO should be empty! */
1313 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
1314 IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __func__
);
1318 /* Fill FIFO with current frame */
1319 while ((fifo_size
-- > 0) && (actual
< len
)) {
1320 /* Transmit next byte */
1321 outb(buf
[actual
], iobase
+UART_TX
);
1326 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1331 * Function ali_ircc_net_open (dev)
1336 static int ali_ircc_net_open(struct net_device
*dev
)
1338 struct ali_ircc_cb
*self
;
1342 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1344 IRDA_ASSERT(dev
!= NULL
, return -1;);
1346 self
= netdev_priv(dev
);
1348 IRDA_ASSERT(self
!= NULL
, return 0;);
1350 iobase
= self
->io
.fir_base
;
1352 /* Request IRQ and install Interrupt Handler */
1353 if (request_irq(self
->io
.irq
, ali_ircc_interrupt
, 0, dev
->name
, dev
))
1355 IRDA_WARNING("%s, unable to allocate irq=%d\n",
1356 ALI_IRCC_DRIVER_NAME
,
1362 * Always allocate the DMA channel after the IRQ, and clean up on
1365 if (request_dma(self
->io
.dma
, dev
->name
)) {
1366 IRDA_WARNING("%s, unable to allocate dma=%d\n",
1367 ALI_IRCC_DRIVER_NAME
,
1369 free_irq(self
->io
.irq
, dev
);
1373 /* Turn on interrups */
1374 outb(UART_IER_RDI
, iobase
+UART_IER
);
1376 /* Ready to play! */
1377 netif_start_queue(dev
); //benjamin by irport
1379 /* Give self a hardware name */
1380 sprintf(hwname
, "ALI-FIR @ 0x%03x", self
->io
.fir_base
);
1383 * Open new IrLAP layer instance, now that everything should be
1384 * initialized properly
1386 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1388 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1394 * Function ali_ircc_net_close (dev)
1399 static int ali_ircc_net_close(struct net_device
*dev
)
1402 struct ali_ircc_cb
*self
;
1405 IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__
);
1407 IRDA_ASSERT(dev
!= NULL
, return -1;);
1409 self
= netdev_priv(dev
);
1410 IRDA_ASSERT(self
!= NULL
, return 0;);
1413 netif_stop_queue(dev
);
1415 /* Stop and remove instance of IrLAP */
1417 irlap_close(self
->irlap
);
1420 disable_dma(self
->io
.dma
);
1422 /* Disable interrupts */
1423 SetCOMInterrupts(self
, FALSE
);
1425 free_irq(self
->io
.irq
, dev
);
1426 free_dma(self
->io
.dma
);
1428 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
1434 * Function ali_ircc_fir_hard_xmit (skb, dev)
1436 * Transmit the frame
1439 static netdev_tx_t
ali_ircc_fir_hard_xmit(struct sk_buff
*skb
,
1440 struct net_device
*dev
)
1442 struct ali_ircc_cb
*self
;
1443 unsigned long flags
;
1448 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1450 self
= netdev_priv(dev
);
1451 iobase
= self
->io
.fir_base
;
1453 netif_stop_queue(dev
);
1455 /* Make sure tests *& speed change are atomic */
1456 spin_lock_irqsave(&self
->lock
, flags
);
1458 /* Note : you should make sure that speed changes are not going
1459 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1460 * details - Jean II */
1462 /* Check if we need to change the speed */
1463 speed
= irda_get_next_speed(skb
);
1464 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1465 /* Check for empty frame */
1467 ali_ircc_change_speed(self
, speed
);
1468 dev
->trans_start
= jiffies
;
1469 spin_unlock_irqrestore(&self
->lock
, flags
);
1471 return NETDEV_TX_OK
;
1473 self
->new_speed
= speed
;
1476 /* Register and copy this frame to DMA memory */
1477 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
1478 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
1479 self
->tx_fifo
.tail
+= skb
->len
;
1481 dev
->stats
.tx_bytes
+= skb
->len
;
1483 skb_copy_from_linear_data(skb
, self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
,
1485 self
->tx_fifo
.len
++;
1486 self
->tx_fifo
.free
++;
1488 /* Start transmit only if there is currently no transmit going on */
1489 if (self
->tx_fifo
.len
== 1)
1491 /* Check if we must wait the min turn time or not */
1492 mtt
= irda_get_mtt(skb
);
1496 /* Check how much time we have used already */
1497 do_gettimeofday(&self
->now
);
1499 diff
= self
->now
.tv_usec
- self
->stamp
.tv_usec
;
1500 /* self->stamp is set from ali_ircc_dma_receive_complete() */
1502 IRDA_DEBUG(1, "%s(), ******* diff = %d *******\n", __func__
, diff
);
1507 /* Check if the mtt is larger than the time we have
1508 * already used by all the protocol processing
1515 * Use timer if delay larger than 1000 us, and
1516 * use udelay for smaller values which should
1521 /* Adjust for timer resolution */
1522 mtt
= (mtt
+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
1524 IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __func__
, mtt
);
1527 if (mtt
== 1) /* 500 us */
1529 switch_bank(iobase
, BANK1
);
1530 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
);
1532 else if (mtt
== 2) /* 1 ms */
1534 switch_bank(iobase
, BANK1
);
1535 outb(TIMER_IIR_1ms
, iobase
+FIR_TIMER_IIR
);
1537 else /* > 2ms -> 4ms */
1539 switch_bank(iobase
, BANK1
);
1540 outb(TIMER_IIR_2ms
, iobase
+FIR_TIMER_IIR
);
1545 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1546 self
->io
.direction
= IO_XMIT
;
1548 /* Enable timer interrupt */
1549 self
->ier
= IER_TIMER
;
1550 SetCOMInterrupts(self
, TRUE
);
1552 /* Timer will take care of the rest */
1557 } // if (if (mtt > diff)
1560 /* Enable EOM interrupt */
1561 self
->ier
= IER_EOM
;
1562 SetCOMInterrupts(self
, TRUE
);
1564 /* Transmit frame */
1565 ali_ircc_dma_xmit(self
);
1566 } // if (self->tx_fifo.len == 1)
1570 /* Not busy transmitting anymore if window is not full */
1571 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
)
1572 netif_wake_queue(self
->netdev
);
1574 /* Restore bank register */
1575 switch_bank(iobase
, BANK0
);
1577 dev
->trans_start
= jiffies
;
1578 spin_unlock_irqrestore(&self
->lock
, flags
);
1581 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1582 return NETDEV_TX_OK
;
1586 static void ali_ircc_dma_xmit(struct ali_ircc_cb
*self
)
1589 unsigned char FIFO_OPTI
, Hi
, Lo
;
1592 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1594 iobase
= self
->io
.fir_base
;
1596 /* FIFO threshold , this method comes from NDIS5 code */
1598 if(self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
< TX_FIFO_Threshold
)
1599 FIFO_OPTI
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
-1;
1601 FIFO_OPTI
= TX_FIFO_Threshold
;
1604 switch_bank(iobase
, BANK1
);
1605 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1607 self
->io
.direction
= IO_XMIT
;
1609 irda_setup_dma(self
->io
.dma
,
1610 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
1611 self
->tx_buff
.head
) + self
->tx_buff_dma
,
1612 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
1616 switch_bank(iobase
, BANK0
);
1617 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1619 /* Set Tx FIFO threshold */
1620 if (self
->fifo_opti_buf
!=FIFO_OPTI
)
1622 switch_bank(iobase
, BANK1
);
1623 outb(FIFO_OPTI
, iobase
+FIR_FIFO_TR
) ;
1624 self
->fifo_opti_buf
=FIFO_OPTI
;
1627 /* Set Tx DMA threshold */
1628 switch_bank(iobase
, BANK1
);
1629 outb(TX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1631 /* Set max Tx frame size */
1632 Hi
= (self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
>> 8) & 0x0f;
1633 Lo
= self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
& 0xff;
1634 switch_bank(iobase
, BANK2
);
1635 outb(Hi
, iobase
+FIR_TX_DSR_HI
);
1636 outb(Lo
, iobase
+FIR_TX_DSR_LO
);
1638 /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
1639 switch_bank(iobase
, BANK0
);
1640 tmp
= inb(iobase
+FIR_LCR_B
);
1641 tmp
&= ~0x20; // Disable SIP
1642 outb(((unsigned char)(tmp
& 0x3f) | LCR_B_TX_MODE
) & ~LCR_B_BW
, iobase
+FIR_LCR_B
);
1643 IRDA_DEBUG(1, "%s(), *** Change to TX mode: FIR_LCR_B = 0x%x ***\n", __func__
, inb(iobase
+FIR_LCR_B
));
1645 outb(0, iobase
+FIR_LSR
);
1647 /* Enable DMA and Burst Mode */
1648 switch_bank(iobase
, BANK1
);
1649 outb(inb(iobase
+FIR_CR
) | CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1651 switch_bank(iobase
, BANK0
);
1653 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1656 static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb
*self
)
1661 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1663 iobase
= self
->io
.fir_base
;
1666 switch_bank(iobase
, BANK1
);
1667 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1669 /* Check for underrun! */
1670 switch_bank(iobase
, BANK0
);
1671 if((inb(iobase
+FIR_LSR
) & LSR_FRAME_ABORT
) == LSR_FRAME_ABORT
)
1674 IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __func__
);
1675 self
->netdev
->stats
.tx_errors
++;
1676 self
->netdev
->stats
.tx_fifo_errors
++;
1680 self
->netdev
->stats
.tx_packets
++;
1683 /* Check if we need to change the speed */
1684 if (self
->new_speed
)
1686 ali_ircc_change_speed(self
, self
->new_speed
);
1687 self
->new_speed
= 0;
1690 /* Finished with this frame, so prepare for next */
1691 self
->tx_fifo
.ptr
++;
1692 self
->tx_fifo
.len
--;
1694 /* Any frames to be sent back-to-back? */
1695 if (self
->tx_fifo
.len
)
1697 ali_ircc_dma_xmit(self
);
1699 /* Not finished yet! */
1703 { /* Reset Tx FIFO info */
1704 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1705 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1708 /* Make sure we have room for more frames */
1709 if (self
->tx_fifo
.free
< MAX_TX_WINDOW
) {
1710 /* Not busy transmitting anymore */
1711 /* Tell the network layer, that we can accept more frames */
1712 netif_wake_queue(self
->netdev
);
1715 switch_bank(iobase
, BANK0
);
1717 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1722 * Function ali_ircc_dma_receive (self)
1724 * Get ready for receiving a frame. The device will initiate a DMA
1725 * if it starts to receive a frame.
1728 static int ali_ircc_dma_receive(struct ali_ircc_cb
*self
)
1732 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1734 iobase
= self
->io
.fir_base
;
1736 /* Reset Tx FIFO info */
1737 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1738 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1741 switch_bank(iobase
, BANK1
);
1742 outb(inb(iobase
+FIR_CR
) & ~CR_DMA_EN
, iobase
+FIR_CR
);
1744 /* Reset Message Count */
1745 switch_bank(iobase
, BANK0
);
1746 outb(0x07, iobase
+FIR_LSR
);
1748 self
->rcvFramesOverflow
= FALSE
;
1750 self
->LineStatus
= inb(iobase
+FIR_LSR
) ;
1752 /* Reset Rx FIFO info */
1753 self
->io
.direction
= IO_RECV
;
1754 self
->rx_buff
.data
= self
->rx_buff
.head
;
1757 // switch_bank(iobase, BANK0);
1758 outb(LCR_A_FIFO_RESET
, iobase
+FIR_LCR_A
);
1760 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1761 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1763 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1766 /* Set Receive Mode,Brick Wall */
1767 //switch_bank(iobase, BANK0);
1768 tmp
= inb(iobase
+FIR_LCR_B
);
1769 outb((unsigned char)(tmp
&0x3f) | LCR_B_RX_MODE
| LCR_B_BW
, iobase
+ FIR_LCR_B
); // 2000/12/1 05:16PM
1770 IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x ***\n", __func__
, inb(iobase
+FIR_LCR_B
));
1772 /* Set Rx Threshold */
1773 switch_bank(iobase
, BANK1
);
1774 outb(RX_FIFO_Threshold
, iobase
+FIR_FIFO_TR
);
1775 outb(RX_DMA_Threshold
, iobase
+FIR_DMA_TR
);
1777 /* Enable DMA and Burst Mode */
1778 // switch_bank(iobase, BANK1);
1779 outb(CR_DMA_EN
| CR_DMA_BURST
, iobase
+FIR_CR
);
1781 switch_bank(iobase
, BANK0
);
1782 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1786 static int ali_ircc_dma_receive_complete(struct ali_ircc_cb
*self
)
1788 struct st_fifo
*st_fifo
;
1789 struct sk_buff
*skb
;
1790 __u8 status
, MessageCount
;
1791 int len
, i
, iobase
, val
;
1793 IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__
);
1795 st_fifo
= &self
->st_fifo
;
1796 iobase
= self
->io
.fir_base
;
1798 switch_bank(iobase
, BANK0
);
1799 MessageCount
= inb(iobase
+ FIR_LSR
)&0x07;
1801 if (MessageCount
> 0)
1802 IRDA_DEBUG(0, "%s(), Message count = %d,\n", __func__
, MessageCount
);
1804 for (i
=0; i
<=MessageCount
; i
++)
1807 switch_bank(iobase
, BANK0
);
1808 status
= inb(iobase
+FIR_LSR
);
1810 switch_bank(iobase
, BANK2
);
1811 len
= inb(iobase
+FIR_RX_DSR_HI
) & 0x0f;
1813 len
|= inb(iobase
+FIR_RX_DSR_LO
);
1815 IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __func__
, len
);
1816 IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __func__
, status
);
1818 if (st_fifo
->tail
>= MAX_RX_WINDOW
) {
1819 IRDA_DEBUG(0, "%s(), window is full!\n", __func__
);
1823 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1824 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1825 st_fifo
->pending_bytes
+= len
;
1830 for (i
=0; i
<=MessageCount
; i
++)
1832 /* Get first entry */
1833 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1834 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1835 st_fifo
->pending_bytes
-= len
;
1839 /* Check for errors */
1840 if ((status
& 0xd8) || self
->rcvFramesOverflow
|| (len
==0))
1842 IRDA_DEBUG(0,"%s(), ************* RX Errors ************\n", __func__
);
1845 self
->netdev
->stats
.rx_errors
++;
1847 self
->rx_buff
.data
+= len
;
1849 if (status
& LSR_FIFO_UR
)
1851 self
->netdev
->stats
.rx_frame_errors
++;
1852 IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************\n", __func__
);
1854 if (status
& LSR_FRAME_ERROR
)
1856 self
->netdev
->stats
.rx_frame_errors
++;
1857 IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************\n", __func__
);
1860 if (status
& LSR_CRC_ERROR
)
1862 self
->netdev
->stats
.rx_crc_errors
++;
1863 IRDA_DEBUG(0,"%s(), ************* CRC Errors ************\n", __func__
);
1866 if(self
->rcvFramesOverflow
)
1868 self
->netdev
->stats
.rx_frame_errors
++;
1869 IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************\n", __func__
);
1873 self
->netdev
->stats
.rx_frame_errors
++;
1874 IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 *********\n", __func__
);
1880 if (st_fifo
->pending_bytes
< 32)
1882 switch_bank(iobase
, BANK0
);
1883 val
= inb(iobase
+FIR_BSR
);
1884 if ((val
& BSR_FIFO_NOT_EMPTY
)== 0x80)
1886 IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************\n", __func__
);
1888 /* Put this entry back in fifo */
1891 st_fifo
->pending_bytes
+= len
;
1892 st_fifo
->entries
[st_fifo
->head
].status
= status
;
1893 st_fifo
->entries
[st_fifo
->head
].len
= len
;
1896 * DMA not finished yet, so try again
1897 * later, set timer value, resolution
1901 switch_bank(iobase
, BANK1
);
1902 outb(TIMER_IIR_500
, iobase
+FIR_TIMER_IIR
); // 2001/1/2 05:07PM
1905 outb(inb(iobase
+FIR_CR
) | CR_TIMER_EN
, iobase
+FIR_CR
);
1907 return FALSE
; /* I'll be back! */
1912 * Remember the time we received this frame, so we can
1913 * reduce the min turn time a bit since we will know
1914 * how much time we have used for protocol processing
1916 do_gettimeofday(&self
->stamp
);
1918 skb
= dev_alloc_skb(len
+1);
1921 IRDA_WARNING("%s(), memory squeeze, "
1922 "dropping frame.\n",
1924 self
->netdev
->stats
.rx_dropped
++;
1929 /* Make sure IP header gets aligned */
1930 skb_reserve(skb
, 1);
1932 /* Copy frame without CRC, CRC is removed by hardware*/
1934 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
);
1936 /* Move to next frame */
1937 self
->rx_buff
.data
+= len
;
1938 self
->netdev
->stats
.rx_bytes
+= len
;
1939 self
->netdev
->stats
.rx_packets
++;
1941 skb
->dev
= self
->netdev
;
1942 skb_reset_mac_header(skb
);
1943 skb
->protocol
= htons(ETH_P_IRDA
);
1948 switch_bank(iobase
, BANK0
);
1950 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
1957 * Function ali_ircc_sir_hard_xmit (skb, dev)
1959 * Transmit the frame!
1962 static netdev_tx_t
ali_ircc_sir_hard_xmit(struct sk_buff
*skb
,
1963 struct net_device
*dev
)
1965 struct ali_ircc_cb
*self
;
1966 unsigned long flags
;
1970 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
1972 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
1974 self
= netdev_priv(dev
);
1975 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
1977 iobase
= self
->io
.sir_base
;
1979 netif_stop_queue(dev
);
1981 /* Make sure tests *& speed change are atomic */
1982 spin_lock_irqsave(&self
->lock
, flags
);
1984 /* Note : you should make sure that speed changes are not going
1985 * to corrupt any outgoing frame. Look at nsc-ircc for the gory
1986 * details - Jean II */
1988 /* Check if we need to change the speed */
1989 speed
= irda_get_next_speed(skb
);
1990 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1991 /* Check for empty frame */
1993 ali_ircc_change_speed(self
, speed
);
1994 dev
->trans_start
= jiffies
;
1995 spin_unlock_irqrestore(&self
->lock
, flags
);
1997 return NETDEV_TX_OK
;
1999 self
->new_speed
= speed
;
2002 /* Init tx buffer */
2003 self
->tx_buff
.data
= self
->tx_buff
.head
;
2005 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
2006 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
2007 self
->tx_buff
.truesize
);
2009 self
->netdev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
2011 /* Turn on transmit finished interrupt. Will fire immediately! */
2012 outb(UART_IER_THRI
, iobase
+UART_IER
);
2014 dev
->trans_start
= jiffies
;
2015 spin_unlock_irqrestore(&self
->lock
, flags
);
2019 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2021 return NETDEV_TX_OK
;
2026 * Function ali_ircc_net_ioctl (dev, rq, cmd)
2028 * Process IOCTL commands for this device
2031 static int ali_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2033 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
2034 struct ali_ircc_cb
*self
;
2035 unsigned long flags
;
2038 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__
);
2040 IRDA_ASSERT(dev
!= NULL
, return -1;);
2042 self
= netdev_priv(dev
);
2044 IRDA_ASSERT(self
!= NULL
, return -1;);
2046 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
2049 case SIOCSBANDWIDTH
: /* Set bandwidth */
2050 IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __func__
);
2052 * This function will also be used by IrLAP to change the
2053 * speed, so we still must allow for speed change within
2054 * interrupt context.
2056 if (!in_interrupt() && !capable(CAP_NET_ADMIN
))
2059 spin_lock_irqsave(&self
->lock
, flags
);
2060 ali_ircc_change_speed(self
, irq
->ifr_baudrate
);
2061 spin_unlock_irqrestore(&self
->lock
, flags
);
2063 case SIOCSMEDIABUSY
: /* Set media busy */
2064 IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __func__
);
2065 if (!capable(CAP_NET_ADMIN
))
2067 irda_device_set_media_busy(self
->netdev
, TRUE
);
2069 case SIOCGRECEIVING
: /* Check if we are receiving right now */
2070 IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __func__
);
2071 /* This is protected */
2072 irq
->ifr_receiving
= ali_ircc_is_receiving(self
);
2078 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2084 * Function ali_ircc_is_receiving (self)
2086 * Return TRUE is we are currently receiving a frame
2089 static int ali_ircc_is_receiving(struct ali_ircc_cb
*self
)
2091 unsigned long flags
;
2095 IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __func__
);
2097 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
2099 spin_lock_irqsave(&self
->lock
, flags
);
2101 if (self
->io
.speed
> 115200)
2103 iobase
= self
->io
.fir_base
;
2105 switch_bank(iobase
, BANK1
);
2106 if((inb(iobase
+FIR_FIFO_FR
) & 0x3f) != 0)
2108 /* We are receiving something */
2109 IRDA_DEBUG(1, "%s(), We are receiving something\n", __func__
);
2112 switch_bank(iobase
, BANK0
);
2116 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
2119 spin_unlock_irqrestore(&self
->lock
, flags
);
2121 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2126 static int ali_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
2128 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2130 IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME
);
2132 if (self
->io
.suspended
)
2135 ali_ircc_net_close(self
->netdev
);
2137 self
->io
.suspended
= 1;
2142 static int ali_ircc_resume(struct platform_device
*dev
)
2144 struct ali_ircc_cb
*self
= platform_get_drvdata(dev
);
2146 if (!self
->io
.suspended
)
2149 ali_ircc_net_open(self
->netdev
);
2151 IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME
);
2153 self
->io
.suspended
= 0;
2158 /* ALi Chip Function */
2160 static void SetCOMInterrupts(struct ali_ircc_cb
*self
, unsigned char enable
)
2163 unsigned char newMask
;
2165 int iobase
= self
->io
.fir_base
; /* or sir_base */
2167 IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __func__
, enable
);
2169 /* Enable the interrupt which we wish to */
2171 if (self
->io
.direction
== IO_XMIT
)
2173 if (self
->io
.speed
> 115200) /* FIR, MIR */
2175 newMask
= self
->ier
;
2179 newMask
= UART_IER_THRI
| UART_IER_RDI
;
2183 if (self
->io
.speed
> 115200) /* FIR, MIR */
2185 newMask
= self
->ier
;
2189 newMask
= UART_IER_RDI
;
2193 else /* Disable all the interrupts */
2199 //SIR and FIR has different registers
2200 if (self
->io
.speed
> 115200)
2202 switch_bank(iobase
, BANK0
);
2203 outb(newMask
, iobase
+FIR_IER
);
2206 outb(newMask
, iobase
+UART_IER
);
2208 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__
);
2211 static void SIR2FIR(int iobase
)
2213 //unsigned char tmp;
2215 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
2217 /* Already protected (change_speed() or setup()), no need to lock.
2220 outb(0x28, iobase
+UART_MCR
);
2221 outb(0x68, iobase
+UART_MCR
);
2222 outb(0x88, iobase
+UART_MCR
);
2224 outb(0x60, iobase
+FIR_MCR
); /* Master Reset */
2225 outb(0x20, iobase
+FIR_MCR
); /* Master Interrupt Enable */
2227 //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
2229 //outb(tmp, iobase+FIR_LCR_B);
2231 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
2234 static void FIR2SIR(int iobase
)
2238 IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__
);
2240 /* Already protected (change_speed() or setup()), no need to lock.
2243 outb(0x20, iobase
+FIR_MCR
); /* IRQ to low */
2244 outb(0x00, iobase
+UART_IER
);
2246 outb(0xA0, iobase
+FIR_MCR
); /* Don't set master reset */
2247 outb(0x00, iobase
+UART_FCR
);
2248 outb(0x07, iobase
+UART_FCR
);
2250 val
= inb(iobase
+UART_RX
);
2251 val
= inb(iobase
+UART_LSR
);
2252 val
= inb(iobase
+UART_MSR
);
2254 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__
);
2257 MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2258 MODULE_DESCRIPTION("ALi FIR Controller Driver");
2259 MODULE_LICENSE("GPL");
2260 MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME
);
2263 module_param_array(io
, int, NULL
, 0);
2264 MODULE_PARM_DESC(io
, "Base I/O addresses");
2265 module_param_array(irq
, int, NULL
, 0);
2266 MODULE_PARM_DESC(irq
, "IRQ lines");
2267 module_param_array(dma
, int, NULL
, 0);
2268 MODULE_PARM_DESC(dma
, "DMA channels");
2270 module_init(ali_ircc_init
);
2271 module_exit(ali_ircc_cleanup
);