1 /********************************************************************
4 Description: Driver for the VIA VT8231/VT8233 IrDA chipsets
5 Author: VIA Technologies,inc
8 Copyright (c) 1998-2003 VIA Technologies, Inc.
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTIES OR REPRESENTATIONS; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 F01 Oct/02/02: Modify code for V0.11(move out back to back transfer)
24 F02 Oct/28/02: Add SB device ID for 3147 and 3177.
26 jul/09/2002 : only implement two kind of dongle currently.
27 Oct/02/2002 : work on VT8231 and VT8233 .
28 Aug/06/2003 : change driver format to pci driver .
30 2004-02-16: <sda@bdit.de>
31 - Removed unneeded 'legacy' pci stuff.
32 - Make sure SIR mode is set (hw_init()) before calling mode-dependant stuff.
33 - On speed change from core, don't send SIR frame with new speed.
34 Use current speed and change speeds later.
35 - Make module-param dongle_id actually work.
36 - New dongle_id 17 (0x11): TDFS4500. Single-ended SIR only.
37 Tested with home-grown PCB on EPIA boards.
40 ********************************************************************/
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/types.h>
44 #include <linux/skbuff.h>
45 #include <linux/netdevice.h>
46 #include <linux/ioport.h>
47 #include <linux/delay.h>
48 #include <linux/init.h>
49 #include <linux/rtnetlink.h>
50 #include <linux/pci.h>
51 #include <linux/dma-mapping.h>
52 #include <linux/gfp.h>
56 #include <asm/byteorder.h>
60 #include <net/irda/wrapper.h>
61 #include <net/irda/irda.h>
62 #include <net/irda/irda_device.h>
66 #define VIA_MODULE_NAME "via-ircc"
67 #define CHIP_IO_EXTENT 0x40
69 static char *driver_name
= VIA_MODULE_NAME
;
71 /* Module parameters */
72 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
73 static int dongle_id
= 0; /* default: probe */
75 /* We can't guess the type of connected dongle, user *must* supply it. */
76 module_param(dongle_id
, int, 0);
78 /* Max 4 instances for now */
79 static struct via_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
82 static int via_ircc_open(int i
, chipio_t
* info
, unsigned int id
);
83 static int via_ircc_close(struct via_ircc_cb
*self
);
84 static int via_ircc_dma_receive(struct via_ircc_cb
*self
);
85 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
87 static netdev_tx_t
via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
88 struct net_device
*dev
);
89 static netdev_tx_t
via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
90 struct net_device
*dev
);
91 static void via_hw_init(struct via_ircc_cb
*self
);
92 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 baud
);
93 static irqreturn_t
via_ircc_interrupt(int irq
, void *dev_id
);
94 static int via_ircc_is_receiving(struct via_ircc_cb
*self
);
95 static int via_ircc_read_dongle_id(int iobase
);
97 static int via_ircc_net_open(struct net_device
*dev
);
98 static int via_ircc_net_close(struct net_device
*dev
);
99 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
101 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
103 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
);
104 static void hwreset(struct via_ircc_cb
*self
);
105 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
);
106 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
);
107 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
);
108 static void __devexit
via_remove_one (struct pci_dev
*pdev
);
110 static void iodelay(int udelay
)
115 for (i
= 0; i
< udelay
; i
++) {
120 static DEFINE_PCI_DEVICE_TABLE(via_pci_tbl
) = {
121 { PCI_VENDOR_ID_VIA
, 0x8231, PCI_ANY_ID
, PCI_ANY_ID
,0,0,0 },
122 { PCI_VENDOR_ID_VIA
, 0x3109, PCI_ANY_ID
, PCI_ANY_ID
,0,0,1 },
123 { PCI_VENDOR_ID_VIA
, 0x3074, PCI_ANY_ID
, PCI_ANY_ID
,0,0,2 },
124 { PCI_VENDOR_ID_VIA
, 0x3147, PCI_ANY_ID
, PCI_ANY_ID
,0,0,3 },
125 { PCI_VENDOR_ID_VIA
, 0x3177, PCI_ANY_ID
, PCI_ANY_ID
,0,0,4 },
129 MODULE_DEVICE_TABLE(pci
,via_pci_tbl
);
132 static struct pci_driver via_driver
= {
133 .name
= VIA_MODULE_NAME
,
134 .id_table
= via_pci_tbl
,
135 .probe
= via_init_one
,
136 .remove
= __devexit_p(via_remove_one
),
141 * Function via_ircc_init ()
143 * Initialize chip. Just find out chip type and resource.
145 static int __init
via_ircc_init(void)
149 IRDA_DEBUG(3, "%s()\n", __func__
);
151 rc
= pci_register_driver(&via_driver
);
153 IRDA_DEBUG(0, "%s(): error rc = %d, returning -ENODEV...\n",
160 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
)
163 u8 temp
,oldPCI_40
,oldPCI_44
,bTmp
,bTmp1
;
164 u16 Chipset
,FirDRQ1
,FirDRQ0
,FirIRQ
,FirIOBase
;
167 IRDA_DEBUG(2, "%s(): Device ID=(0X%X)\n", __func__
, id
->device
);
169 rc
= pci_enable_device (pcidev
);
171 IRDA_DEBUG(0, "%s(): error rc = %d\n", __func__
, rc
);
175 // South Bridge exist
176 if ( ReadLPCReg(0x20) != 0x3C )
181 if (Chipset
==0x3076) {
182 IRDA_DEBUG(2, "%s(): Chipset = 3076\n", __func__
);
184 WriteLPCReg(7,0x0c );
185 temp
=ReadLPCReg(0x30);//check if BIOS Enable Fir
186 if((temp
&0x01)==1) { // BIOS close or no FIR
187 WriteLPCReg(0x1d, 0x82 );
188 WriteLPCReg(0x23,0x18);
189 temp
=ReadLPCReg(0xF0);
191 temp
=(ReadLPCReg(0x74)&0x03); //DMA
193 temp
=(ReadLPCReg(0x74)&0x0C) >> 2;
196 temp
=(ReadLPCReg(0x74)&0x0C) >> 2; //DMA
200 FirIRQ
=(ReadLPCReg(0x70)&0x0f); //IRQ
201 FirIOBase
=ReadLPCReg(0x60 ) << 8; //IO Space :high byte
202 FirIOBase
=FirIOBase
| ReadLPCReg(0x61) ; //low byte
203 FirIOBase
=FirIOBase
;
204 info
.fir_base
=FirIOBase
;
208 pci_read_config_byte(pcidev
,0x40,&bTmp
);
209 pci_write_config_byte(pcidev
,0x40,((bTmp
| 0x08) & 0xfe));
210 pci_read_config_byte(pcidev
,0x42,&bTmp
);
211 pci_write_config_byte(pcidev
,0x42,(bTmp
| 0xf0));
212 pci_write_config_byte(pcidev
,0x5a,0xc0);
213 WriteLPCReg(0x28, 0x70 );
214 if (via_ircc_open(0, &info
,0x3076) == 0)
217 rc
= -ENODEV
; //IR not turn on
218 } else { //Not VT1211
219 IRDA_DEBUG(2, "%s(): Chipset = 3096\n", __func__
);
221 pci_read_config_byte(pcidev
,0x67,&bTmp
);//check if BIOS Enable Fir
222 if((bTmp
&0x01)==1) { // BIOS enable FIR
223 //Enable Double DMA clock
224 pci_read_config_byte(pcidev
,0x42,&oldPCI_40
);
225 pci_write_config_byte(pcidev
,0x42,oldPCI_40
| 0x80);
226 pci_read_config_byte(pcidev
,0x40,&oldPCI_40
);
227 pci_write_config_byte(pcidev
,0x40,oldPCI_40
& 0xf7);
228 pci_read_config_byte(pcidev
,0x44,&oldPCI_44
);
229 pci_write_config_byte(pcidev
,0x44,0x4e);
230 //---------- read configuration from Function0 of south bridge
232 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
233 FirDRQ0
= (bTmp1
& 0x30) >> 4;
234 pci_read_config_byte(pcidev
,0x44,&bTmp1
);
235 FirDRQ1
= (bTmp1
& 0xc0) >> 6;
237 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
238 FirDRQ0
= (bTmp1
& 0x30) >> 4 ;
241 pci_read_config_byte(pcidev
,0x47,&bTmp1
); //IRQ
242 FirIRQ
= bTmp1
& 0x0f;
244 pci_read_config_byte(pcidev
,0x69,&bTmp
);
245 FirIOBase
= bTmp
<< 8;//hight byte
246 pci_read_config_byte(pcidev
,0x68,&bTmp
);
247 FirIOBase
= (FirIOBase
| bTmp
) & 0xfff0;
248 //-------------------------
249 info
.fir_base
=FirIOBase
;
253 if (via_ircc_open(0, &info
,0x3096) == 0)
256 rc
= -ENODEV
; //IR not turn on !!!!!
259 IRDA_DEBUG(2, "%s(): End - rc = %d\n", __func__
, rc
);
264 * Function via_ircc_clean ()
266 * Close all configured chips
269 static void via_ircc_clean(void)
273 IRDA_DEBUG(3, "%s()\n", __func__
);
275 for (i
=0; i
< ARRAY_SIZE(dev_self
); i
++) {
277 via_ircc_close(dev_self
[i
]);
281 static void __devexit
via_remove_one (struct pci_dev
*pdev
)
283 IRDA_DEBUG(3, "%s()\n", __func__
);
287 pci_disable_device(pdev
);
290 static void __exit
via_ircc_cleanup(void)
292 IRDA_DEBUG(3, "%s()\n", __func__
);
296 /* Cleanup all instances of the driver */
297 pci_unregister_driver (&via_driver
);
300 static const struct net_device_ops via_ircc_sir_ops
= {
301 .ndo_start_xmit
= via_ircc_hard_xmit_sir
,
302 .ndo_open
= via_ircc_net_open
,
303 .ndo_stop
= via_ircc_net_close
,
304 .ndo_do_ioctl
= via_ircc_net_ioctl
,
306 static const struct net_device_ops via_ircc_fir_ops
= {
307 .ndo_start_xmit
= via_ircc_hard_xmit_fir
,
308 .ndo_open
= via_ircc_net_open
,
309 .ndo_stop
= via_ircc_net_close
,
310 .ndo_do_ioctl
= via_ircc_net_ioctl
,
314 * Function via_ircc_open (iobase, irq)
316 * Open driver instance
319 static __devinit
int via_ircc_open(int i
, chipio_t
* info
, unsigned int id
)
321 struct net_device
*dev
;
322 struct via_ircc_cb
*self
;
325 IRDA_DEBUG(3, "%s()\n", __func__
);
327 if (i
>= ARRAY_SIZE(dev_self
))
330 /* Allocate new instance of the driver */
331 dev
= alloc_irdadev(sizeof(struct via_ircc_cb
));
335 self
= netdev_priv(dev
);
337 spin_lock_init(&self
->lock
);
339 /* Need to store self somewhere */
342 /* Initialize Resource */
343 self
->io
.cfg_base
= info
->cfg_base
;
344 self
->io
.fir_base
= info
->fir_base
;
345 self
->io
.irq
= info
->irq
;
346 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
347 self
->io
.dma
= info
->dma
;
348 self
->io
.dma2
= info
->dma2
;
349 self
->io
.fifo_size
= 32;
351 self
->st_fifo
.len
= 0;
352 self
->RxDataReady
= 0;
354 /* Reserve the ioports that we need */
355 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
)) {
356 IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n",
357 __func__
, self
->io
.fir_base
);
362 /* Initialize QoS for this device */
363 irda_init_max_qos_capabilies(&self
->qos
);
365 /* Check if user has supplied the dongle id or not */
367 dongle_id
= via_ircc_read_dongle_id(self
->io
.fir_base
);
368 self
->io
.dongle_id
= dongle_id
;
370 /* The only value we must override it the baudrate */
371 /* Maximum speeds and capabilities are dongle-dependant. */
372 switch( self
->io
.dongle_id
){
374 self
->qos
.baud_rate
.bits
=
375 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
|
376 IR_576000
| IR_1152000
| (IR_4000000
<< 8);
379 self
->qos
.baud_rate
.bits
=
380 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
;
384 /* Following was used for testing:
386 * self->qos.baud_rate.bits = IR_9600;
388 * Is is no good, as it prohibits (error-prone) speed-changes.
391 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
392 irda_qos_bits_to_value(&self
->qos
);
394 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
395 self
->rx_buff
.truesize
= 14384 + 2048;
396 self
->tx_buff
.truesize
= 14384 + 2048;
398 /* Allocate memory if needed */
400 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
401 &self
->rx_buff_dma
, GFP_KERNEL
);
402 if (self
->rx_buff
.head
== NULL
) {
406 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
409 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
410 &self
->tx_buff_dma
, GFP_KERNEL
);
411 if (self
->tx_buff
.head
== NULL
) {
415 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
417 self
->rx_buff
.in_frame
= FALSE
;
418 self
->rx_buff
.state
= OUTSIDE_FRAME
;
419 self
->tx_buff
.data
= self
->tx_buff
.head
;
420 self
->rx_buff
.data
= self
->rx_buff
.head
;
422 /* Reset Tx queue info */
423 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
424 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
426 /* Override the network functions we need to use */
427 dev
->netdev_ops
= &via_ircc_sir_ops
;
429 err
= register_netdev(dev
);
433 IRDA_MESSAGE("IrDA: Registered device %s (via-ircc)\n", dev
->name
);
435 /* Initialise the hardware..
437 self
->io
.speed
= 9600;
441 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
442 self
->tx_buff
.head
, self
->tx_buff_dma
);
444 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
445 self
->rx_buff
.head
, self
->rx_buff_dma
);
447 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
455 * Function via_ircc_close (self)
457 * Close driver instance
460 static int via_ircc_close(struct via_ircc_cb
*self
)
464 IRDA_DEBUG(3, "%s()\n", __func__
);
466 IRDA_ASSERT(self
!= NULL
, return -1;);
468 iobase
= self
->io
.fir_base
;
470 ResetChip(iobase
, 5); //hardware reset.
471 /* Remove netdevice */
472 unregister_netdev(self
->netdev
);
474 /* Release the PORT that this driver is using */
475 IRDA_DEBUG(2, "%s(), Releasing Region %03x\n",
476 __func__
, self
->io
.fir_base
);
477 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
478 if (self
->tx_buff
.head
)
479 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
480 self
->tx_buff
.head
, self
->tx_buff_dma
);
481 if (self
->rx_buff
.head
)
482 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
483 self
->rx_buff
.head
, self
->rx_buff_dma
);
484 dev_self
[self
->index
] = NULL
;
486 free_netdev(self
->netdev
);
492 * Function via_hw_init(self)
494 * Returns non-negative on success.
496 * Formerly via_ircc_setup
498 static void via_hw_init(struct via_ircc_cb
*self
)
500 int iobase
= self
->io
.fir_base
;
502 IRDA_DEBUG(3, "%s()\n", __func__
);
504 SetMaxRxPacketSize(iobase
, 0x0fff); //set to max:4095
506 EnRXFIFOReadyInt(iobase
, OFF
);
507 EnRXFIFOHalfLevelInt(iobase
, OFF
);
508 EnTXFIFOHalfLevelInt(iobase
, OFF
);
509 EnTXFIFOUnderrunEOMInt(iobase
, ON
);
510 EnTXFIFOReadyInt(iobase
, OFF
);
511 InvertTX(iobase
, OFF
);
512 InvertRX(iobase
, OFF
);
514 if (ReadLPCReg(0x20) == 0x3c)
515 WriteLPCReg(0xF0, 0); // for VT1211
517 EnRXSpecInt(iobase
, ON
);
519 /* The following is basically hwreset */
520 /* If this is the case, why not just call hwreset() ? Jean II */
521 ResetChip(iobase
, 5);
522 EnableDMA(iobase
, OFF
);
523 EnableTX(iobase
, OFF
);
524 EnableRX(iobase
, OFF
);
525 EnRXDMA(iobase
, OFF
);
526 EnTXDMA(iobase
, OFF
);
527 RXStart(iobase
, OFF
);
528 TXStart(iobase
, OFF
);
531 SIRFilter(iobase
, ON
);
535 WriteReg(iobase
, I_ST_CT_0
, 0x00);
536 SetBaudRate(iobase
, 9600);
537 SetPulseWidth(iobase
, 12);
538 SetSendPreambleCount(iobase
, 0);
540 self
->io
.speed
= 9600;
541 self
->st_fifo
.len
= 0;
543 via_ircc_change_dongle_speed(iobase
, self
->io
.speed
,
546 WriteReg(iobase
, I_ST_CT_0
, 0x80);
550 * Function via_ircc_read_dongle_id (void)
553 static int via_ircc_read_dongle_id(int iobase
)
555 int dongle_id
= 9; /* Default to IBM */
557 IRDA_ERROR("via-ircc: dongle probing not supported, please specify dongle_id module parameter.\n");
562 * Function via_ircc_change_dongle_speed (iobase, speed, dongle_id)
563 * Change speed of the attach dongle
564 * only implement two type of dongle currently.
566 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
571 /* speed is unused, as we use IsSIROn()/IsMIROn() */
574 IRDA_DEBUG(1, "%s(): change_dongle_speed to %d for 0x%x, %d\n",
575 __func__
, speed
, iobase
, dongle_id
);
579 /* Note: The dongle_id's listed here are derived from
582 case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
583 UseOneRX(iobase
, ON
); // use one RX pin RX1,RX2
584 InvertTX(iobase
, OFF
);
585 InvertRX(iobase
, OFF
);
587 EnRX2(iobase
, ON
); //sir to rx2
588 EnGPIOtoRX2(iobase
, OFF
);
590 if (IsSIROn(iobase
)) { //sir
592 SlowIRRXLowActive(iobase
, ON
);
594 SlowIRRXLowActive(iobase
, OFF
);
596 if (IsMIROn(iobase
)) { //mir
598 SlowIRRXLowActive(iobase
, OFF
);
601 if (IsFIROn(iobase
)) { //fir
603 SlowIRRXLowActive(iobase
, OFF
);
610 case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
611 UseOneRX(iobase
, ON
); //use ONE RX....RX1
612 InvertTX(iobase
, OFF
);
613 InvertRX(iobase
, OFF
); // invert RX pin
616 EnGPIOtoRX2(iobase
, OFF
);
617 if (IsSIROn(iobase
)) { //sir
619 SlowIRRXLowActive(iobase
, ON
);
622 SlowIRRXLowActive(iobase
, OFF
);
624 if (IsMIROn(iobase
)) { //mir
626 SlowIRRXLowActive(iobase
, OFF
);
629 SlowIRRXLowActive(iobase
, ON
);
631 if (IsFIROn(iobase
)) { //fir
633 SlowIRRXLowActive(iobase
, OFF
);
638 SlowIRRXLowActive(iobase
, ON
);
641 WriteTX(iobase
, OFF
);
647 UseOneRX(iobase
, OFF
); // use two RX pin RX1,RX2
648 InvertTX(iobase
, OFF
);
649 InvertRX(iobase
, OFF
);
650 SlowIRRXLowActive(iobase
, OFF
);
651 if (IsSIROn(iobase
)) { //sir
652 EnGPIOtoRX2(iobase
, OFF
);
653 WriteGIO(iobase
, OFF
);
654 EnRX2(iobase
, OFF
); //sir to rx2
656 EnGPIOtoRX2(iobase
, OFF
);
657 WriteGIO(iobase
, OFF
);
658 EnRX2(iobase
, OFF
); //fir to rx
662 case 0x11: /* Temic TFDS4500 */
664 IRDA_DEBUG(2, "%s: Temic TFDS4500: One RX pin, TX normal, RX inverted.\n", __func__
);
666 UseOneRX(iobase
, ON
); //use ONE RX....RX1
667 InvertTX(iobase
, OFF
);
668 InvertRX(iobase
, ON
); // invert RX pin
670 EnRX2(iobase
, ON
); //sir to rx2
671 EnGPIOtoRX2(iobase
, OFF
);
673 if( IsSIROn(iobase
) ){ //sir
676 SlowIRRXLowActive(iobase
, ON
);
679 SlowIRRXLowActive(iobase
, OFF
);
682 IRDA_DEBUG(0, "%s: Warning: TFDS4500 not running in SIR mode !\n", __func__
);
686 case 0x0ff: /* Vishay */
689 else if (IsMIROn(iobase
))
691 else if (IsFIROn(iobase
))
693 else if (IsVFIROn(iobase
))
695 SI_SetMode(iobase
, mode
);
699 IRDA_ERROR("%s: Error: dongle_id %d unsupported !\n",
700 __func__
, dongle_id
);
705 * Function via_ircc_change_speed (self, baud)
707 * Change the speed of the device
710 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 speed
)
712 struct net_device
*dev
= self
->netdev
;
716 iobase
= self
->io
.fir_base
;
717 /* Update accounting for new speed */
718 self
->io
.speed
= speed
;
719 IRDA_DEBUG(1, "%s: change_speed to %d bps.\n", __func__
, speed
);
721 WriteReg(iobase
, I_ST_CT_0
, 0x0);
723 /* Controller mode sellection */
731 value
= (115200/speed
)-1;
747 SetPulseWidth(iobase
, 0);
748 SetSendPreambleCount(iobase
, 14);
761 /* Set baudrate to 0x19[2..7] */
762 bTmp
= (ReadReg(iobase
, I_CF_H_1
) & 0x03);
764 WriteReg(iobase
, I_CF_H_1
, bTmp
);
766 /* Some dongles may need to be informed about speed changes. */
767 via_ircc_change_dongle_speed(iobase
, speed
, self
->io
.dongle_id
);
769 /* Set FIFO size to 64 */
773 WriteReg(iobase
, I_ST_CT_0
, 0x80);
775 // EnTXFIFOHalfLevelInt(iobase,ON);
777 /* Enable some interrupts so we can receive frames */
778 //EnAllInt(iobase,ON);
780 if (IsSIROn(iobase
)) {
781 SIRFilter(iobase
, ON
);
782 SIRRecvAny(iobase
, ON
);
784 SIRFilter(iobase
, OFF
);
785 SIRRecvAny(iobase
, OFF
);
788 if (speed
> 115200) {
789 /* Install FIR xmit handler */
790 dev
->netdev_ops
= &via_ircc_fir_ops
;
791 via_ircc_dma_receive(self
);
793 /* Install SIR xmit handler */
794 dev
->netdev_ops
= &via_ircc_sir_ops
;
796 netif_wake_queue(dev
);
800 * Function via_ircc_hard_xmit (skb, dev)
802 * Transmit the frame!
805 static netdev_tx_t
via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
806 struct net_device
*dev
)
808 struct via_ircc_cb
*self
;
813 self
= netdev_priv(dev
);
814 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
815 iobase
= self
->io
.fir_base
;
817 netif_stop_queue(dev
);
818 /* Check if we need to change the speed */
819 speed
= irda_get_next_speed(skb
);
820 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
821 /* Check for empty frame */
823 via_ircc_change_speed(self
, speed
);
824 dev
->trans_start
= jiffies
;
828 self
->new_speed
= speed
;
832 SIRFilter(iobase
, ON
);
836 WriteReg(iobase
, I_ST_CT_0
, 0x00);
838 spin_lock_irqsave(&self
->lock
, flags
);
839 self
->tx_buff
.data
= self
->tx_buff
.head
;
841 async_wrap_skb(skb
, self
->tx_buff
.data
,
842 self
->tx_buff
.truesize
);
844 dev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
845 /* Send this frame with old speed */
846 SetBaudRate(iobase
, self
->io
.speed
);
847 SetPulseWidth(iobase
, 12);
848 SetSendPreambleCount(iobase
, 0);
849 WriteReg(iobase
, I_ST_CT_0
, 0x80);
851 EnableTX(iobase
, ON
);
852 EnableRX(iobase
, OFF
);
854 ResetChip(iobase
, 0);
855 ResetChip(iobase
, 1);
856 ResetChip(iobase
, 2);
857 ResetChip(iobase
, 3);
858 ResetChip(iobase
, 4);
860 EnAllInt(iobase
, ON
);
862 EnRXDMA(iobase
, OFF
);
864 irda_setup_dma(self
->io
.dma
, self
->tx_buff_dma
, self
->tx_buff
.len
,
867 SetSendByte(iobase
, self
->tx_buff
.len
);
868 RXStart(iobase
, OFF
);
871 dev
->trans_start
= jiffies
;
872 spin_unlock_irqrestore(&self
->lock
, flags
);
877 static netdev_tx_t
via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
878 struct net_device
*dev
)
880 struct via_ircc_cb
*self
;
885 self
= netdev_priv(dev
);
886 iobase
= self
->io
.fir_base
;
888 if (self
->st_fifo
.len
)
890 if (self
->chip_id
== 0x3076)
894 netif_stop_queue(dev
);
895 speed
= irda_get_next_speed(skb
);
896 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
898 via_ircc_change_speed(self
, speed
);
899 dev
->trans_start
= jiffies
;
903 self
->new_speed
= speed
;
905 spin_lock_irqsave(&self
->lock
, flags
);
906 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
907 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
909 self
->tx_fifo
.tail
+= skb
->len
;
910 dev
->stats
.tx_bytes
+= skb
->len
;
911 skb_copy_from_linear_data(skb
,
912 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
, skb
->len
);
914 self
->tx_fifo
.free
++;
915 //F01 if (self->tx_fifo.len == 1) {
916 via_ircc_dma_xmit(self
, iobase
);
918 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) netif_wake_queue(self->netdev);
919 dev
->trans_start
= jiffies
;
921 spin_unlock_irqrestore(&self
->lock
, flags
);
926 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
)
928 EnTXDMA(iobase
, OFF
);
929 self
->io
.direction
= IO_XMIT
;
931 EnableTX(iobase
, ON
);
932 EnableRX(iobase
, OFF
);
933 ResetChip(iobase
, 0);
934 ResetChip(iobase
, 1);
935 ResetChip(iobase
, 2);
936 ResetChip(iobase
, 3);
937 ResetChip(iobase
, 4);
938 EnAllInt(iobase
, ON
);
940 EnRXDMA(iobase
, OFF
);
941 irda_setup_dma(self
->io
.dma
,
942 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
943 self
->tx_buff
.head
) + self
->tx_buff_dma
,
944 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
, DMA_TX_MODE
);
945 IRDA_DEBUG(1, "%s: tx_fifo.ptr=%x,len=%x,tx_fifo.len=%x..\n",
946 __func__
, self
->tx_fifo
.ptr
,
947 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
950 SetSendByte(iobase
, self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
);
951 RXStart(iobase
, OFF
);
958 * Function via_ircc_dma_xmit_complete (self)
960 * The transfer of a frame in finished. This function will only be called
961 * by the interrupt handler
964 static int via_ircc_dma_xmit_complete(struct via_ircc_cb
*self
)
970 IRDA_DEBUG(3, "%s()\n", __func__
);
972 iobase
= self
->io
.fir_base
;
974 // DisableDmaChannel(self->io.dma);
975 /* Check for underrrun! */
976 /* Clear bit, by writing 1 into it */
977 Tx_status
= GetTXStatus(iobase
);
978 if (Tx_status
& 0x08) {
979 self
->netdev
->stats
.tx_errors
++;
980 self
->netdev
->stats
.tx_fifo_errors
++;
982 // how to clear underrrun ?
984 self
->netdev
->stats
.tx_packets
++;
985 ResetChip(iobase
, 3);
986 ResetChip(iobase
, 4);
988 /* Check if we need to change the speed */
989 if (self
->new_speed
) {
990 via_ircc_change_speed(self
, self
->new_speed
);
994 /* Finished with this frame, so prepare for next */
995 if (IsFIROn(iobase
)) {
996 if (self
->tx_fifo
.len
) {
1002 "%s: tx_fifo.len=%x ,tx_fifo.ptr=%x,tx_fifo.free=%x...\n",
1004 self
->tx_fifo
.len
, self
->tx_fifo
.ptr
, self
->tx_fifo
.free
);
1006 // Any frames to be sent back-to-back?
1007 if (self->tx_fifo.len) {
1008 // Not finished yet!
1009 via_ircc_dma_xmit(self, iobase);
1013 // Reset Tx FIFO info
1014 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1015 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1018 // Make sure we have room for more frames
1019 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) {
1020 // Not busy transmitting anymore
1021 // Tell the network layer, that we can accept more frames
1022 netif_wake_queue(self
->netdev
);
1028 * Function via_ircc_dma_receive (self)
1030 * Set configuration for receive a frame.
1033 static int via_ircc_dma_receive(struct via_ircc_cb
*self
)
1037 iobase
= self
->io
.fir_base
;
1039 IRDA_DEBUG(3, "%s()\n", __func__
);
1041 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1042 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1043 self
->RxDataReady
= 0;
1044 self
->io
.direction
= IO_RECV
;
1045 self
->rx_buff
.data
= self
->rx_buff
.head
;
1046 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1047 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1050 EnableTX(iobase
, OFF
);
1051 EnableRX(iobase
, ON
);
1053 ResetChip(iobase
, 0);
1054 ResetChip(iobase
, 1);
1055 ResetChip(iobase
, 2);
1056 ResetChip(iobase
, 3);
1057 ResetChip(iobase
, 4);
1059 EnAllInt(iobase
, ON
);
1060 EnTXDMA(iobase
, OFF
);
1061 EnRXDMA(iobase
, ON
);
1062 irda_setup_dma(self
->io
.dma2
, self
->rx_buff_dma
,
1063 self
->rx_buff
.truesize
, DMA_RX_MODE
);
1064 TXStart(iobase
, OFF
);
1065 RXStart(iobase
, ON
);
1071 * Function via_ircc_dma_receive_complete (self)
1073 * Controller Finished with receiving frames,
1074 * and this routine is call by ISR
1077 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
1080 struct st_fifo
*st_fifo
;
1081 struct sk_buff
*skb
;
1085 iobase
= self
->io
.fir_base
;
1086 st_fifo
= &self
->st_fifo
;
1088 if (self
->io
.speed
< 4000000) { //Speed below FIR
1089 len
= GetRecvByte(iobase
, self
);
1090 skb
= dev_alloc_skb(len
+ 1);
1093 // Make sure IP header gets aligned
1094 skb_reserve(skb
, 1);
1095 skb_put(skb
, len
- 2);
1096 if (self
->chip_id
== 0x3076) {
1097 for (i
= 0; i
< len
- 2; i
++)
1098 skb
->data
[i
] = self
->rx_buff
.data
[i
* 2];
1100 if (self
->chip_id
== 0x3096) {
1101 for (i
= 0; i
< len
- 2; i
++)
1103 self
->rx_buff
.data
[i
];
1106 // Move to next frame
1107 self
->rx_buff
.data
+= len
;
1108 self
->netdev
->stats
.rx_bytes
+= len
;
1109 self
->netdev
->stats
.rx_packets
++;
1110 skb
->dev
= self
->netdev
;
1111 skb_reset_mac_header(skb
);
1112 skb
->protocol
= htons(ETH_P_IRDA
);
1118 len
= GetRecvByte(iobase
, self
);
1120 return TRUE
; //interrupt only, data maybe move by RxT
1121 if (((len
- 4) < 2) || ((len
- 4) > 2048)) {
1122 IRDA_DEBUG(1, "%s(): Trouble:len=%x,CurCount=%x,LastCount=%x..\n",
1123 __func__
, len
, RxCurCount(iobase
, self
),
1128 IRDA_DEBUG(2, "%s(): fifo.len=%x,len=%x,CurCount=%x..\n",
1130 st_fifo
->len
, len
- 4, RxCurCount(iobase
, self
));
1132 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1133 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1134 st_fifo
->pending_bytes
+= len
;
1137 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1139 self
->RxDataReady
= 0;
1141 // It maybe have MAX_RX_WINDOW package receive by
1142 // receive_complete before Timer IRQ
1144 if (st_fifo->len < (MAX_RX_WINDOW+2 )) {
1150 EnableRX(iobase
, OFF
);
1151 EnRXDMA(iobase
, OFF
);
1152 RXStart(iobase
, OFF
);
1154 // Put this entry back in fifo
1155 if (st_fifo
->head
> MAX_RX_WINDOW
)
1157 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1158 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1162 skb
= dev_alloc_skb(len
+ 1 - 4);
1164 * if frame size,data ptr,or skb ptr are wrong ,the get next
1167 if ((skb
== NULL
) || (skb
->data
== NULL
) ||
1168 (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1169 self
->netdev
->stats
.rx_dropped
++;
1172 skb_reserve(skb
, 1);
1173 skb_put(skb
, len
- 4);
1175 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4);
1176 IRDA_DEBUG(2, "%s(): len=%x.rx_buff=%p\n", __func__
,
1177 len
- 4, self
->rx_buff
.data
);
1179 // Move to next frame
1180 self
->rx_buff
.data
+= len
;
1181 self
->netdev
->stats
.rx_bytes
+= len
;
1182 self
->netdev
->stats
.rx_packets
++;
1183 skb
->dev
= self
->netdev
;
1184 skb_reset_mac_header(skb
);
1185 skb
->protocol
= htons(ETH_P_IRDA
);
1195 * if frame is received , but no INT ,then use this routine to upload frame.
1197 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
)
1199 struct sk_buff
*skb
;
1201 struct st_fifo
*st_fifo
;
1202 st_fifo
= &self
->st_fifo
;
1204 len
= GetRecvByte(iobase
, self
);
1206 IRDA_DEBUG(2, "%s(): len=%x\n", __func__
, len
);
1208 if ((len
- 4) < 2) {
1209 self
->netdev
->stats
.rx_dropped
++;
1213 skb
= dev_alloc_skb(len
+ 1);
1215 self
->netdev
->stats
.rx_dropped
++;
1218 skb_reserve(skb
, 1);
1219 skb_put(skb
, len
- 4 + 1);
1220 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4 + 1);
1223 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1225 // Move to next frame
1226 self
->rx_buff
.data
+= len
;
1227 self
->netdev
->stats
.rx_bytes
+= len
;
1228 self
->netdev
->stats
.rx_packets
++;
1229 skb
->dev
= self
->netdev
;
1230 skb_reset_mac_header(skb
);
1231 skb
->protocol
= htons(ETH_P_IRDA
);
1233 if (st_fifo
->len
< (MAX_RX_WINDOW
+ 2)) {
1234 RXStart(iobase
, ON
);
1236 EnableRX(iobase
, OFF
);
1237 EnRXDMA(iobase
, OFF
);
1238 RXStart(iobase
, OFF
);
1244 * Implement back to back receive , use this routine to upload data.
1247 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
)
1249 struct st_fifo
*st_fifo
;
1250 struct sk_buff
*skb
;
1254 st_fifo
= &self
->st_fifo
;
1256 if (CkRxRecv(iobase
, self
)) {
1257 // if still receiving ,then return ,don't upload frame
1258 self
->RetryCount
= 0;
1259 SetTimer(iobase
, 20);
1260 self
->RxDataReady
++;
1265 if ((self
->RetryCount
>= 1) ||
1266 ((st_fifo
->pending_bytes
+ 2048) > self
->rx_buff
.truesize
) ||
1267 (st_fifo
->len
>= (MAX_RX_WINDOW
))) {
1268 while (st_fifo
->len
> 0) { //upload frame
1269 // Put this entry back in fifo
1270 if (st_fifo
->head
> MAX_RX_WINDOW
)
1272 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1273 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1277 skb
= dev_alloc_skb(len
+ 1 - 4);
1279 * if frame size, data ptr, or skb ptr are wrong,
1280 * then get next entry.
1282 if ((skb
== NULL
) || (skb
->data
== NULL
) ||
1283 (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1284 self
->netdev
->stats
.rx_dropped
++;
1287 skb_reserve(skb
, 1);
1288 skb_put(skb
, len
- 4);
1289 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4);
1291 IRDA_DEBUG(2, "%s(): len=%x.head=%x\n", __func__
,
1292 len
- 4, st_fifo
->head
);
1294 // Move to next frame
1295 self
->rx_buff
.data
+= len
;
1296 self
->netdev
->stats
.rx_bytes
+= len
;
1297 self
->netdev
->stats
.rx_packets
++;
1298 skb
->dev
= self
->netdev
;
1299 skb_reset_mac_header(skb
);
1300 skb
->protocol
= htons(ETH_P_IRDA
);
1303 self
->RetryCount
= 0;
1306 "%s(): End of upload HostStatus=%x,RxStatus=%x\n",
1308 GetHostStatus(iobase
), GetRXStatus(iobase
));
1311 * if frame is receive complete at this routine ,then upload
1314 if ((GetRXStatus(iobase
) & 0x10) &&
1315 (RxCurCount(iobase
, self
) != self
->RxLastCount
)) {
1316 upload_rxdata(self
, iobase
);
1317 if (irda_device_txqueue_empty(self
->netdev
))
1318 via_ircc_dma_receive(self
);
1320 } // timer detect complete
1322 SetTimer(iobase
, 4);
1330 * Function via_ircc_interrupt (irq, dev_id)
1332 * An interrupt from the chip has arrived. Time to do some work
1335 static irqreturn_t
via_ircc_interrupt(int dummy
, void *dev_id
)
1337 struct net_device
*dev
= dev_id
;
1338 struct via_ircc_cb
*self
= netdev_priv(dev
);
1340 u8 iHostIntType
, iRxIntType
, iTxIntType
;
1342 iobase
= self
->io
.fir_base
;
1343 spin_lock(&self
->lock
);
1344 iHostIntType
= GetHostStatus(iobase
);
1346 IRDA_DEBUG(4, "%s(): iHostIntType %02x: %s %s %s %02x\n",
1347 __func__
, iHostIntType
,
1348 (iHostIntType
& 0x40) ? "Timer" : "",
1349 (iHostIntType
& 0x20) ? "Tx" : "",
1350 (iHostIntType
& 0x10) ? "Rx" : "",
1351 (iHostIntType
& 0x0e) >> 1);
1353 if ((iHostIntType
& 0x40) != 0) { //Timer Event
1354 self
->EventFlag
.TimeOut
++;
1355 ClearTimerInt(iobase
, 1);
1356 if (self
->io
.direction
== IO_XMIT
) {
1357 via_ircc_dma_xmit(self
, iobase
);
1359 if (self
->io
.direction
== IO_RECV
) {
1361 * frame ready hold too long, must reset.
1363 if (self
->RxDataReady
> 30) {
1365 if (irda_device_txqueue_empty(self
->netdev
)) {
1366 via_ircc_dma_receive(self
);
1368 } else { // call this to upload frame.
1369 RxTimerHandler(self
, iobase
);
1373 if ((iHostIntType
& 0x20) != 0) { //Tx Event
1374 iTxIntType
= GetTXStatus(iobase
);
1376 IRDA_DEBUG(4, "%s(): iTxIntType %02x: %s %s %s %s\n",
1377 __func__
, iTxIntType
,
1378 (iTxIntType
& 0x08) ? "FIFO underr." : "",
1379 (iTxIntType
& 0x04) ? "EOM" : "",
1380 (iTxIntType
& 0x02) ? "FIFO ready" : "",
1381 (iTxIntType
& 0x01) ? "Early EOM" : "");
1383 if (iTxIntType
& 0x4) {
1384 self
->EventFlag
.EOMessage
++; // read and will auto clean
1385 if (via_ircc_dma_xmit_complete(self
)) {
1386 if (irda_device_txqueue_empty
1388 via_ircc_dma_receive(self
);
1391 self
->EventFlag
.Unknown
++;
1395 //----------------------------------------
1396 if ((iHostIntType
& 0x10) != 0) { //Rx Event
1397 /* Check if DMA has finished */
1398 iRxIntType
= GetRXStatus(iobase
);
1400 IRDA_DEBUG(4, "%s(): iRxIntType %02x: %s %s %s %s %s %s %s\n",
1401 __func__
, iRxIntType
,
1402 (iRxIntType
& 0x80) ? "PHY err." : "",
1403 (iRxIntType
& 0x40) ? "CRC err" : "",
1404 (iRxIntType
& 0x20) ? "FIFO overr." : "",
1405 (iRxIntType
& 0x10) ? "EOF" : "",
1406 (iRxIntType
& 0x08) ? "RxData" : "",
1407 (iRxIntType
& 0x02) ? "RxMaxLen" : "",
1408 (iRxIntType
& 0x01) ? "SIR bad" : "");
1410 IRDA_DEBUG(3, "%s(): RxIRQ =0\n", __func__
);
1412 if (iRxIntType
& 0x10) {
1413 if (via_ircc_dma_receive_complete(self
, iobase
)) {
1414 //F01 if(!(IsFIROn(iobase))) via_ircc_dma_receive(self);
1415 via_ircc_dma_receive(self
);
1419 IRDA_DEBUG(4, "%s(): RxIRQ ERR:iRxIntType=%x,HostIntType=%x,CurCount=%x,RxLastCount=%x_____\n",
1420 __func__
, iRxIntType
, iHostIntType
,
1421 RxCurCount(iobase
, self
),
1424 if (iRxIntType
& 0x20) { //FIFO OverRun ERR
1425 ResetChip(iobase
, 0);
1426 ResetChip(iobase
, 1);
1427 } else { //PHY,CRC ERR
1429 if (iRxIntType
!= 0x08)
1430 hwreset(self
); //F01
1432 via_ircc_dma_receive(self
);
1436 spin_unlock(&self
->lock
);
1437 return IRQ_RETVAL(iHostIntType
);
1440 static void hwreset(struct via_ircc_cb
*self
)
1443 iobase
= self
->io
.fir_base
;
1445 IRDA_DEBUG(3, "%s()\n", __func__
);
1447 ResetChip(iobase
, 5);
1448 EnableDMA(iobase
, OFF
);
1449 EnableTX(iobase
, OFF
);
1450 EnableRX(iobase
, OFF
);
1451 EnRXDMA(iobase
, OFF
);
1452 EnTXDMA(iobase
, OFF
);
1453 RXStart(iobase
, OFF
);
1454 TXStart(iobase
, OFF
);
1457 SIRFilter(iobase
, ON
);
1461 WriteReg(iobase
, I_ST_CT_0
, 0x00);
1462 SetBaudRate(iobase
, 9600);
1463 SetPulseWidth(iobase
, 12);
1464 SetSendPreambleCount(iobase
, 0);
1465 WriteReg(iobase
, I_ST_CT_0
, 0x80);
1467 /* Restore speed. */
1468 via_ircc_change_speed(self
, self
->io
.speed
);
1470 self
->st_fifo
.len
= 0;
1474 * Function via_ircc_is_receiving (self)
1476 * Return TRUE is we are currently receiving a frame
1479 static int via_ircc_is_receiving(struct via_ircc_cb
*self
)
1484 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
1486 iobase
= self
->io
.fir_base
;
1487 if (CkRxRecv(iobase
, self
))
1490 IRDA_DEBUG(2, "%s(): status=%x....\n", __func__
, status
);
1497 * Function via_ircc_net_open (dev)
1502 static int via_ircc_net_open(struct net_device
*dev
)
1504 struct via_ircc_cb
*self
;
1508 IRDA_DEBUG(3, "%s()\n", __func__
);
1510 IRDA_ASSERT(dev
!= NULL
, return -1;);
1511 self
= netdev_priv(dev
);
1512 dev
->stats
.rx_packets
= 0;
1513 IRDA_ASSERT(self
!= NULL
, return 0;);
1514 iobase
= self
->io
.fir_base
;
1515 if (request_irq(self
->io
.irq
, via_ircc_interrupt
, 0, dev
->name
, dev
)) {
1516 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name
,
1521 * Always allocate the DMA channel after the IRQ, and clean up on
1524 if (request_dma(self
->io
.dma
, dev
->name
)) {
1525 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name
,
1527 free_irq(self
->io
.irq
, self
);
1530 if (self
->io
.dma2
!= self
->io
.dma
) {
1531 if (request_dma(self
->io
.dma2
, dev
->name
)) {
1532 IRDA_WARNING("%s, unable to allocate dma2=%d\n",
1533 driver_name
, self
->io
.dma2
);
1534 free_irq(self
->io
.irq
, self
);
1535 free_dma(self
->io
.dma
);
1541 /* turn on interrupts */
1542 EnAllInt(iobase
, ON
);
1543 EnInternalLoop(iobase
, OFF
);
1544 EnExternalLoop(iobase
, OFF
);
1547 via_ircc_dma_receive(self
);
1549 /* Ready to play! */
1550 netif_start_queue(dev
);
1553 * Open new IrLAP layer instance, now that everything should be
1554 * initialized properly
1556 sprintf(hwname
, "VIA @ 0x%x", iobase
);
1557 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1559 self
->RxLastCount
= 0;
1565 * Function via_ircc_net_close (dev)
1570 static int via_ircc_net_close(struct net_device
*dev
)
1572 struct via_ircc_cb
*self
;
1575 IRDA_DEBUG(3, "%s()\n", __func__
);
1577 IRDA_ASSERT(dev
!= NULL
, return -1;);
1578 self
= netdev_priv(dev
);
1579 IRDA_ASSERT(self
!= NULL
, return 0;);
1582 netif_stop_queue(dev
);
1583 /* Stop and remove instance of IrLAP */
1585 irlap_close(self
->irlap
);
1587 iobase
= self
->io
.fir_base
;
1588 EnTXDMA(iobase
, OFF
);
1589 EnRXDMA(iobase
, OFF
);
1590 DisableDmaChannel(self
->io
.dma
);
1592 /* Disable interrupts */
1593 EnAllInt(iobase
, OFF
);
1594 free_irq(self
->io
.irq
, dev
);
1595 free_dma(self
->io
.dma
);
1596 if (self
->io
.dma2
!= self
->io
.dma
)
1597 free_dma(self
->io
.dma2
);
1603 * Function via_ircc_net_ioctl (dev, rq, cmd)
1605 * Process IOCTL commands for this device
1608 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
1611 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
1612 struct via_ircc_cb
*self
;
1613 unsigned long flags
;
1616 IRDA_ASSERT(dev
!= NULL
, return -1;);
1617 self
= netdev_priv(dev
);
1618 IRDA_ASSERT(self
!= NULL
, return -1;);
1619 IRDA_DEBUG(1, "%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
,
1621 /* Disable interrupts & save flags */
1622 spin_lock_irqsave(&self
->lock
, flags
);
1624 case SIOCSBANDWIDTH
: /* Set bandwidth */
1625 if (!capable(CAP_NET_ADMIN
)) {
1629 via_ircc_change_speed(self
, irq
->ifr_baudrate
);
1631 case SIOCSMEDIABUSY
: /* Set media busy */
1632 if (!capable(CAP_NET_ADMIN
)) {
1636 irda_device_set_media_busy(self
->netdev
, TRUE
);
1638 case SIOCGRECEIVING
: /* Check if we are receiving right now */
1639 irq
->ifr_receiving
= via_ircc_is_receiving(self
);
1645 spin_unlock_irqrestore(&self
->lock
, flags
);
1649 MODULE_AUTHOR("VIA Technologies,inc");
1650 MODULE_DESCRIPTION("VIA IrDA Device Driver");
1651 MODULE_LICENSE("GPL");
1653 module_init(via_ircc_init
);
1654 module_exit(via_ircc_cleanup
);