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-dependent 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);
79 static int via_ircc_open(struct pci_dev
*pdev
, chipio_t
* info
,
81 static int via_ircc_dma_receive(struct via_ircc_cb
*self
);
82 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
84 static netdev_tx_t
via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
85 struct net_device
*dev
);
86 static netdev_tx_t
via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
87 struct net_device
*dev
);
88 static void via_hw_init(struct via_ircc_cb
*self
);
89 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 baud
);
90 static irqreturn_t
via_ircc_interrupt(int irq
, void *dev_id
);
91 static int via_ircc_is_receiving(struct via_ircc_cb
*self
);
92 static int via_ircc_read_dongle_id(int iobase
);
94 static int via_ircc_net_open(struct net_device
*dev
);
95 static int via_ircc_net_close(struct net_device
*dev
);
96 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
98 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
100 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
);
101 static void hwreset(struct via_ircc_cb
*self
);
102 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
);
103 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
);
104 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
);
105 static void __devexit
via_remove_one (struct pci_dev
*pdev
);
107 /* FIXME : Should use udelay() instead, even if we are x86 only - Jean II */
108 static void iodelay(int udelay
)
113 for (i
= 0; i
< udelay
; i
++) {
118 static DEFINE_PCI_DEVICE_TABLE(via_pci_tbl
) = {
119 { PCI_VENDOR_ID_VIA
, 0x8231, PCI_ANY_ID
, PCI_ANY_ID
,0,0,0 },
120 { PCI_VENDOR_ID_VIA
, 0x3109, PCI_ANY_ID
, PCI_ANY_ID
,0,0,1 },
121 { PCI_VENDOR_ID_VIA
, 0x3074, PCI_ANY_ID
, PCI_ANY_ID
,0,0,2 },
122 { PCI_VENDOR_ID_VIA
, 0x3147, PCI_ANY_ID
, PCI_ANY_ID
,0,0,3 },
123 { PCI_VENDOR_ID_VIA
, 0x3177, PCI_ANY_ID
, PCI_ANY_ID
,0,0,4 },
127 MODULE_DEVICE_TABLE(pci
,via_pci_tbl
);
130 static struct pci_driver via_driver
= {
131 .name
= VIA_MODULE_NAME
,
132 .id_table
= via_pci_tbl
,
133 .probe
= via_init_one
,
134 .remove
= __devexit_p(via_remove_one
),
139 * Function via_ircc_init ()
141 * Initialize chip. Just find out chip type and resource.
143 static int __init
via_ircc_init(void)
147 IRDA_DEBUG(3, "%s()\n", __func__
);
149 rc
= pci_register_driver(&via_driver
);
151 IRDA_DEBUG(0, "%s(): error rc = %d, returning -ENODEV...\n",
158 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
)
161 u8 temp
,oldPCI_40
,oldPCI_44
,bTmp
,bTmp1
;
162 u16 Chipset
,FirDRQ1
,FirDRQ0
,FirIRQ
,FirIOBase
;
165 IRDA_DEBUG(2, "%s(): Device ID=(0X%X)\n", __func__
, id
->device
);
167 rc
= pci_enable_device (pcidev
);
169 IRDA_DEBUG(0, "%s(): error rc = %d\n", __func__
, rc
);
173 // South Bridge exist
174 if ( ReadLPCReg(0x20) != 0x3C )
179 if (Chipset
==0x3076) {
180 IRDA_DEBUG(2, "%s(): Chipset = 3076\n", __func__
);
182 WriteLPCReg(7,0x0c );
183 temp
=ReadLPCReg(0x30);//check if BIOS Enable Fir
184 if((temp
&0x01)==1) { // BIOS close or no FIR
185 WriteLPCReg(0x1d, 0x82 );
186 WriteLPCReg(0x23,0x18);
187 temp
=ReadLPCReg(0xF0);
189 temp
=(ReadLPCReg(0x74)&0x03); //DMA
191 temp
=(ReadLPCReg(0x74)&0x0C) >> 2;
194 temp
=(ReadLPCReg(0x74)&0x0C) >> 2; //DMA
198 FirIRQ
=(ReadLPCReg(0x70)&0x0f); //IRQ
199 FirIOBase
=ReadLPCReg(0x60 ) << 8; //IO Space :high byte
200 FirIOBase
=FirIOBase
| ReadLPCReg(0x61) ; //low byte
201 FirIOBase
=FirIOBase
;
202 info
.fir_base
=FirIOBase
;
206 pci_read_config_byte(pcidev
,0x40,&bTmp
);
207 pci_write_config_byte(pcidev
,0x40,((bTmp
| 0x08) & 0xfe));
208 pci_read_config_byte(pcidev
,0x42,&bTmp
);
209 pci_write_config_byte(pcidev
,0x42,(bTmp
| 0xf0));
210 pci_write_config_byte(pcidev
,0x5a,0xc0);
211 WriteLPCReg(0x28, 0x70 );
212 if (via_ircc_open(pcidev
, &info
, 0x3076) == 0)
215 rc
= -ENODEV
; //IR not turn on
216 } else { //Not VT1211
217 IRDA_DEBUG(2, "%s(): Chipset = 3096\n", __func__
);
219 pci_read_config_byte(pcidev
,0x67,&bTmp
);//check if BIOS Enable Fir
220 if((bTmp
&0x01)==1) { // BIOS enable FIR
221 //Enable Double DMA clock
222 pci_read_config_byte(pcidev
,0x42,&oldPCI_40
);
223 pci_write_config_byte(pcidev
,0x42,oldPCI_40
| 0x80);
224 pci_read_config_byte(pcidev
,0x40,&oldPCI_40
);
225 pci_write_config_byte(pcidev
,0x40,oldPCI_40
& 0xf7);
226 pci_read_config_byte(pcidev
,0x44,&oldPCI_44
);
227 pci_write_config_byte(pcidev
,0x44,0x4e);
228 //---------- read configuration from Function0 of south bridge
230 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
231 FirDRQ0
= (bTmp1
& 0x30) >> 4;
232 pci_read_config_byte(pcidev
,0x44,&bTmp1
);
233 FirDRQ1
= (bTmp1
& 0xc0) >> 6;
235 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
236 FirDRQ0
= (bTmp1
& 0x30) >> 4 ;
239 pci_read_config_byte(pcidev
,0x47,&bTmp1
); //IRQ
240 FirIRQ
= bTmp1
& 0x0f;
242 pci_read_config_byte(pcidev
,0x69,&bTmp
);
243 FirIOBase
= bTmp
<< 8;//hight byte
244 pci_read_config_byte(pcidev
,0x68,&bTmp
);
245 FirIOBase
= (FirIOBase
| bTmp
) & 0xfff0;
246 //-------------------------
247 info
.fir_base
=FirIOBase
;
251 if (via_ircc_open(pcidev
, &info
, 0x3096) == 0)
254 rc
= -ENODEV
; //IR not turn on !!!!!
257 IRDA_DEBUG(2, "%s(): End - rc = %d\n", __func__
, rc
);
261 static void __exit
via_ircc_cleanup(void)
263 IRDA_DEBUG(3, "%s()\n", __func__
);
265 /* Cleanup all instances of the driver */
266 pci_unregister_driver (&via_driver
);
269 static const struct net_device_ops via_ircc_sir_ops
= {
270 .ndo_start_xmit
= via_ircc_hard_xmit_sir
,
271 .ndo_open
= via_ircc_net_open
,
272 .ndo_stop
= via_ircc_net_close
,
273 .ndo_do_ioctl
= via_ircc_net_ioctl
,
275 static const struct net_device_ops via_ircc_fir_ops
= {
276 .ndo_start_xmit
= via_ircc_hard_xmit_fir
,
277 .ndo_open
= via_ircc_net_open
,
278 .ndo_stop
= via_ircc_net_close
,
279 .ndo_do_ioctl
= via_ircc_net_ioctl
,
283 * Function via_ircc_open(pdev, iobase, irq)
285 * Open driver instance
288 static __devinit
int via_ircc_open(struct pci_dev
*pdev
, chipio_t
* info
,
291 struct net_device
*dev
;
292 struct via_ircc_cb
*self
;
295 IRDA_DEBUG(3, "%s()\n", __func__
);
297 /* Allocate new instance of the driver */
298 dev
= alloc_irdadev(sizeof(struct via_ircc_cb
));
302 self
= netdev_priv(dev
);
304 spin_lock_init(&self
->lock
);
306 pci_set_drvdata(pdev
, self
);
308 /* Initialize Resource */
309 self
->io
.cfg_base
= info
->cfg_base
;
310 self
->io
.fir_base
= info
->fir_base
;
311 self
->io
.irq
= info
->irq
;
312 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
313 self
->io
.dma
= info
->dma
;
314 self
->io
.dma2
= info
->dma2
;
315 self
->io
.fifo_size
= 32;
317 self
->st_fifo
.len
= 0;
318 self
->RxDataReady
= 0;
320 /* Reserve the ioports that we need */
321 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
)) {
322 IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n",
323 __func__
, self
->io
.fir_base
);
328 /* Initialize QoS for this device */
329 irda_init_max_qos_capabilies(&self
->qos
);
331 /* Check if user has supplied the dongle id or not */
333 dongle_id
= via_ircc_read_dongle_id(self
->io
.fir_base
);
334 self
->io
.dongle_id
= dongle_id
;
336 /* The only value we must override it the baudrate */
337 /* Maximum speeds and capabilities are dongle-dependent. */
338 switch( self
->io
.dongle_id
){
340 self
->qos
.baud_rate
.bits
=
341 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
|
342 IR_576000
| IR_1152000
| (IR_4000000
<< 8);
345 self
->qos
.baud_rate
.bits
=
346 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
;
350 /* Following was used for testing:
352 * self->qos.baud_rate.bits = IR_9600;
354 * Is is no good, as it prohibits (error-prone) speed-changes.
357 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
358 irda_qos_bits_to_value(&self
->qos
);
360 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
361 self
->rx_buff
.truesize
= 14384 + 2048;
362 self
->tx_buff
.truesize
= 14384 + 2048;
364 /* Allocate memory if needed */
366 dma_alloc_coherent(&pdev
->dev
, self
->rx_buff
.truesize
,
367 &self
->rx_buff_dma
, GFP_KERNEL
);
368 if (self
->rx_buff
.head
== NULL
) {
372 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
375 dma_alloc_coherent(&pdev
->dev
, self
->tx_buff
.truesize
,
376 &self
->tx_buff_dma
, GFP_KERNEL
);
377 if (self
->tx_buff
.head
== NULL
) {
381 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
383 self
->rx_buff
.in_frame
= FALSE
;
384 self
->rx_buff
.state
= OUTSIDE_FRAME
;
385 self
->tx_buff
.data
= self
->tx_buff
.head
;
386 self
->rx_buff
.data
= self
->rx_buff
.head
;
388 /* Reset Tx queue info */
389 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
390 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
392 /* Override the network functions we need to use */
393 dev
->netdev_ops
= &via_ircc_sir_ops
;
395 err
= register_netdev(dev
);
399 IRDA_MESSAGE("IrDA: Registered device %s (via-ircc)\n", dev
->name
);
401 /* Initialise the hardware..
403 self
->io
.speed
= 9600;
407 dma_free_coherent(&pdev
->dev
, self
->tx_buff
.truesize
,
408 self
->tx_buff
.head
, self
->tx_buff_dma
);
410 dma_free_coherent(&pdev
->dev
, self
->rx_buff
.truesize
,
411 self
->rx_buff
.head
, self
->rx_buff_dma
);
413 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
415 pci_set_drvdata(pdev
, NULL
);
421 * Function via_remove_one(pdev)
423 * Close driver instance
426 static void __devexit
via_remove_one(struct pci_dev
*pdev
)
428 struct via_ircc_cb
*self
= pci_get_drvdata(pdev
);
431 IRDA_DEBUG(3, "%s()\n", __func__
);
433 iobase
= self
->io
.fir_base
;
435 ResetChip(iobase
, 5); //hardware reset.
436 /* Remove netdevice */
437 unregister_netdev(self
->netdev
);
439 /* Release the PORT that this driver is using */
440 IRDA_DEBUG(2, "%s(), Releasing Region %03x\n",
441 __func__
, self
->io
.fir_base
);
442 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
443 if (self
->tx_buff
.head
)
444 dma_free_coherent(&pdev
->dev
, self
->tx_buff
.truesize
,
445 self
->tx_buff
.head
, self
->tx_buff_dma
);
446 if (self
->rx_buff
.head
)
447 dma_free_coherent(&pdev
->dev
, self
->rx_buff
.truesize
,
448 self
->rx_buff
.head
, self
->rx_buff_dma
);
449 pci_set_drvdata(pdev
, NULL
);
451 free_netdev(self
->netdev
);
453 pci_disable_device(pdev
);
457 * Function via_hw_init(self)
459 * Returns non-negative on success.
461 * Formerly via_ircc_setup
463 static void via_hw_init(struct via_ircc_cb
*self
)
465 int iobase
= self
->io
.fir_base
;
467 IRDA_DEBUG(3, "%s()\n", __func__
);
469 SetMaxRxPacketSize(iobase
, 0x0fff); //set to max:4095
471 EnRXFIFOReadyInt(iobase
, OFF
);
472 EnRXFIFOHalfLevelInt(iobase
, OFF
);
473 EnTXFIFOHalfLevelInt(iobase
, OFF
);
474 EnTXFIFOUnderrunEOMInt(iobase
, ON
);
475 EnTXFIFOReadyInt(iobase
, OFF
);
476 InvertTX(iobase
, OFF
);
477 InvertRX(iobase
, OFF
);
479 if (ReadLPCReg(0x20) == 0x3c)
480 WriteLPCReg(0xF0, 0); // for VT1211
482 EnRXSpecInt(iobase
, ON
);
484 /* The following is basically hwreset */
485 /* If this is the case, why not just call hwreset() ? Jean II */
486 ResetChip(iobase
, 5);
487 EnableDMA(iobase
, OFF
);
488 EnableTX(iobase
, OFF
);
489 EnableRX(iobase
, OFF
);
490 EnRXDMA(iobase
, OFF
);
491 EnTXDMA(iobase
, OFF
);
492 RXStart(iobase
, OFF
);
493 TXStart(iobase
, OFF
);
496 SIRFilter(iobase
, ON
);
500 WriteReg(iobase
, I_ST_CT_0
, 0x00);
501 SetBaudRate(iobase
, 9600);
502 SetPulseWidth(iobase
, 12);
503 SetSendPreambleCount(iobase
, 0);
505 self
->io
.speed
= 9600;
506 self
->st_fifo
.len
= 0;
508 via_ircc_change_dongle_speed(iobase
, self
->io
.speed
,
511 WriteReg(iobase
, I_ST_CT_0
, 0x80);
515 * Function via_ircc_read_dongle_id (void)
518 static int via_ircc_read_dongle_id(int iobase
)
520 int dongle_id
= 9; /* Default to IBM */
522 IRDA_ERROR("via-ircc: dongle probing not supported, please specify dongle_id module parameter.\n");
527 * Function via_ircc_change_dongle_speed (iobase, speed, dongle_id)
528 * Change speed of the attach dongle
529 * only implement two type of dongle currently.
531 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
536 /* speed is unused, as we use IsSIROn()/IsMIROn() */
539 IRDA_DEBUG(1, "%s(): change_dongle_speed to %d for 0x%x, %d\n",
540 __func__
, speed
, iobase
, dongle_id
);
544 /* Note: The dongle_id's listed here are derived from
547 case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
548 UseOneRX(iobase
, ON
); // use one RX pin RX1,RX2
549 InvertTX(iobase
, OFF
);
550 InvertRX(iobase
, OFF
);
552 EnRX2(iobase
, ON
); //sir to rx2
553 EnGPIOtoRX2(iobase
, OFF
);
555 if (IsSIROn(iobase
)) { //sir
557 SlowIRRXLowActive(iobase
, ON
);
559 SlowIRRXLowActive(iobase
, OFF
);
561 if (IsMIROn(iobase
)) { //mir
563 SlowIRRXLowActive(iobase
, OFF
);
566 if (IsFIROn(iobase
)) { //fir
568 SlowIRRXLowActive(iobase
, OFF
);
575 case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
576 UseOneRX(iobase
, ON
); //use ONE RX....RX1
577 InvertTX(iobase
, OFF
);
578 InvertRX(iobase
, OFF
); // invert RX pin
581 EnGPIOtoRX2(iobase
, OFF
);
582 if (IsSIROn(iobase
)) { //sir
584 SlowIRRXLowActive(iobase
, ON
);
587 SlowIRRXLowActive(iobase
, OFF
);
589 if (IsMIROn(iobase
)) { //mir
591 SlowIRRXLowActive(iobase
, OFF
);
594 SlowIRRXLowActive(iobase
, ON
);
596 if (IsFIROn(iobase
)) { //fir
598 SlowIRRXLowActive(iobase
, OFF
);
603 SlowIRRXLowActive(iobase
, ON
);
606 WriteTX(iobase
, OFF
);
612 UseOneRX(iobase
, OFF
); // use two RX pin RX1,RX2
613 InvertTX(iobase
, OFF
);
614 InvertRX(iobase
, OFF
);
615 SlowIRRXLowActive(iobase
, OFF
);
616 if (IsSIROn(iobase
)) { //sir
617 EnGPIOtoRX2(iobase
, OFF
);
618 WriteGIO(iobase
, OFF
);
619 EnRX2(iobase
, OFF
); //sir to rx2
621 EnGPIOtoRX2(iobase
, OFF
);
622 WriteGIO(iobase
, OFF
);
623 EnRX2(iobase
, OFF
); //fir to rx
627 case 0x11: /* Temic TFDS4500 */
629 IRDA_DEBUG(2, "%s: Temic TFDS4500: One RX pin, TX normal, RX inverted.\n", __func__
);
631 UseOneRX(iobase
, ON
); //use ONE RX....RX1
632 InvertTX(iobase
, OFF
);
633 InvertRX(iobase
, ON
); // invert RX pin
635 EnRX2(iobase
, ON
); //sir to rx2
636 EnGPIOtoRX2(iobase
, OFF
);
638 if( IsSIROn(iobase
) ){ //sir
641 SlowIRRXLowActive(iobase
, ON
);
644 SlowIRRXLowActive(iobase
, OFF
);
647 IRDA_DEBUG(0, "%s: Warning: TFDS4500 not running in SIR mode !\n", __func__
);
651 case 0x0ff: /* Vishay */
654 else if (IsMIROn(iobase
))
656 else if (IsFIROn(iobase
))
658 else if (IsVFIROn(iobase
))
660 SI_SetMode(iobase
, mode
);
664 IRDA_ERROR("%s: Error: dongle_id %d unsupported !\n",
665 __func__
, dongle_id
);
670 * Function via_ircc_change_speed (self, baud)
672 * Change the speed of the device
675 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 speed
)
677 struct net_device
*dev
= self
->netdev
;
681 iobase
= self
->io
.fir_base
;
682 /* Update accounting for new speed */
683 self
->io
.speed
= speed
;
684 IRDA_DEBUG(1, "%s: change_speed to %d bps.\n", __func__
, speed
);
686 WriteReg(iobase
, I_ST_CT_0
, 0x0);
688 /* Controller mode sellection */
696 value
= (115200/speed
)-1;
701 /* FIXME: this can't be right, as it's the same as 115200,
702 * and 576000 is MIR, not SIR. */
715 SetPulseWidth(iobase
, 0);
716 SetSendPreambleCount(iobase
, 14);
730 /* Set baudrate to 0x19[2..7] */
731 bTmp
= (ReadReg(iobase
, I_CF_H_1
) & 0x03);
733 WriteReg(iobase
, I_CF_H_1
, bTmp
);
735 /* Some dongles may need to be informed about speed changes. */
736 via_ircc_change_dongle_speed(iobase
, speed
, self
->io
.dongle_id
);
738 /* Set FIFO size to 64 */
742 WriteReg(iobase
, I_ST_CT_0
, 0x80);
744 // EnTXFIFOHalfLevelInt(iobase,ON);
746 /* Enable some interrupts so we can receive frames */
747 //EnAllInt(iobase,ON);
749 if (IsSIROn(iobase
)) {
750 SIRFilter(iobase
, ON
);
751 SIRRecvAny(iobase
, ON
);
753 SIRFilter(iobase
, OFF
);
754 SIRRecvAny(iobase
, OFF
);
757 if (speed
> 115200) {
758 /* Install FIR xmit handler */
759 dev
->netdev_ops
= &via_ircc_fir_ops
;
760 via_ircc_dma_receive(self
);
762 /* Install SIR xmit handler */
763 dev
->netdev_ops
= &via_ircc_sir_ops
;
765 netif_wake_queue(dev
);
769 * Function via_ircc_hard_xmit (skb, dev)
771 * Transmit the frame!
774 static netdev_tx_t
via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
775 struct net_device
*dev
)
777 struct via_ircc_cb
*self
;
782 self
= netdev_priv(dev
);
783 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
784 iobase
= self
->io
.fir_base
;
786 netif_stop_queue(dev
);
787 /* Check if we need to change the speed */
788 speed
= irda_get_next_speed(skb
);
789 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
790 /* Check for empty frame */
792 via_ircc_change_speed(self
, speed
);
793 dev
->trans_start
= jiffies
;
797 self
->new_speed
= speed
;
801 SIRFilter(iobase
, ON
);
805 WriteReg(iobase
, I_ST_CT_0
, 0x00);
807 spin_lock_irqsave(&self
->lock
, flags
);
808 self
->tx_buff
.data
= self
->tx_buff
.head
;
810 async_wrap_skb(skb
, self
->tx_buff
.data
,
811 self
->tx_buff
.truesize
);
813 dev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
814 /* Send this frame with old speed */
815 SetBaudRate(iobase
, self
->io
.speed
);
816 SetPulseWidth(iobase
, 12);
817 SetSendPreambleCount(iobase
, 0);
818 WriteReg(iobase
, I_ST_CT_0
, 0x80);
820 EnableTX(iobase
, ON
);
821 EnableRX(iobase
, OFF
);
823 ResetChip(iobase
, 0);
824 ResetChip(iobase
, 1);
825 ResetChip(iobase
, 2);
826 ResetChip(iobase
, 3);
827 ResetChip(iobase
, 4);
829 EnAllInt(iobase
, ON
);
831 EnRXDMA(iobase
, OFF
);
833 irda_setup_dma(self
->io
.dma
, self
->tx_buff_dma
, self
->tx_buff
.len
,
836 SetSendByte(iobase
, self
->tx_buff
.len
);
837 RXStart(iobase
, OFF
);
840 dev
->trans_start
= jiffies
;
841 spin_unlock_irqrestore(&self
->lock
, flags
);
846 static netdev_tx_t
via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
847 struct net_device
*dev
)
849 struct via_ircc_cb
*self
;
854 self
= netdev_priv(dev
);
855 iobase
= self
->io
.fir_base
;
857 if (self
->st_fifo
.len
)
859 if (self
->chip_id
== 0x3076)
863 netif_stop_queue(dev
);
864 speed
= irda_get_next_speed(skb
);
865 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
867 via_ircc_change_speed(self
, speed
);
868 dev
->trans_start
= jiffies
;
872 self
->new_speed
= speed
;
874 spin_lock_irqsave(&self
->lock
, flags
);
875 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
876 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
878 self
->tx_fifo
.tail
+= skb
->len
;
879 dev
->stats
.tx_bytes
+= skb
->len
;
880 skb_copy_from_linear_data(skb
,
881 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
, skb
->len
);
883 self
->tx_fifo
.free
++;
884 //F01 if (self->tx_fifo.len == 1) {
885 via_ircc_dma_xmit(self
, iobase
);
887 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) netif_wake_queue(self->netdev);
888 dev
->trans_start
= jiffies
;
890 spin_unlock_irqrestore(&self
->lock
, flags
);
895 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
)
897 EnTXDMA(iobase
, OFF
);
898 self
->io
.direction
= IO_XMIT
;
900 EnableTX(iobase
, ON
);
901 EnableRX(iobase
, OFF
);
902 ResetChip(iobase
, 0);
903 ResetChip(iobase
, 1);
904 ResetChip(iobase
, 2);
905 ResetChip(iobase
, 3);
906 ResetChip(iobase
, 4);
907 EnAllInt(iobase
, ON
);
909 EnRXDMA(iobase
, OFF
);
910 irda_setup_dma(self
->io
.dma
,
911 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
912 self
->tx_buff
.head
) + self
->tx_buff_dma
,
913 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
, DMA_TX_MODE
);
914 IRDA_DEBUG(1, "%s: tx_fifo.ptr=%x,len=%x,tx_fifo.len=%x..\n",
915 __func__
, self
->tx_fifo
.ptr
,
916 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
919 SetSendByte(iobase
, self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
);
920 RXStart(iobase
, OFF
);
927 * Function via_ircc_dma_xmit_complete (self)
929 * The transfer of a frame in finished. This function will only be called
930 * by the interrupt handler
933 static int via_ircc_dma_xmit_complete(struct via_ircc_cb
*self
)
939 IRDA_DEBUG(3, "%s()\n", __func__
);
941 iobase
= self
->io
.fir_base
;
943 // DisableDmaChannel(self->io.dma);
944 /* Check for underrrun! */
945 /* Clear bit, by writing 1 into it */
946 Tx_status
= GetTXStatus(iobase
);
947 if (Tx_status
& 0x08) {
948 self
->netdev
->stats
.tx_errors
++;
949 self
->netdev
->stats
.tx_fifo_errors
++;
951 // how to clear underrrun ?
953 self
->netdev
->stats
.tx_packets
++;
954 ResetChip(iobase
, 3);
955 ResetChip(iobase
, 4);
957 /* Check if we need to change the speed */
958 if (self
->new_speed
) {
959 via_ircc_change_speed(self
, self
->new_speed
);
963 /* Finished with this frame, so prepare for next */
964 if (IsFIROn(iobase
)) {
965 if (self
->tx_fifo
.len
) {
971 "%s: tx_fifo.len=%x ,tx_fifo.ptr=%x,tx_fifo.free=%x...\n",
973 self
->tx_fifo
.len
, self
->tx_fifo
.ptr
, self
->tx_fifo
.free
);
975 // Any frames to be sent back-to-back?
976 if (self->tx_fifo.len) {
978 via_ircc_dma_xmit(self, iobase);
982 // Reset Tx FIFO info
983 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
984 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
987 // Make sure we have room for more frames
988 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) {
989 // Not busy transmitting anymore
990 // Tell the network layer, that we can accept more frames
991 netif_wake_queue(self
->netdev
);
997 * Function via_ircc_dma_receive (self)
999 * Set configuration for receive a frame.
1002 static int via_ircc_dma_receive(struct via_ircc_cb
*self
)
1006 iobase
= self
->io
.fir_base
;
1008 IRDA_DEBUG(3, "%s()\n", __func__
);
1010 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1011 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1012 self
->RxDataReady
= 0;
1013 self
->io
.direction
= IO_RECV
;
1014 self
->rx_buff
.data
= self
->rx_buff
.head
;
1015 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1016 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1019 EnableTX(iobase
, OFF
);
1020 EnableRX(iobase
, ON
);
1022 ResetChip(iobase
, 0);
1023 ResetChip(iobase
, 1);
1024 ResetChip(iobase
, 2);
1025 ResetChip(iobase
, 3);
1026 ResetChip(iobase
, 4);
1028 EnAllInt(iobase
, ON
);
1029 EnTXDMA(iobase
, OFF
);
1030 EnRXDMA(iobase
, ON
);
1031 irda_setup_dma(self
->io
.dma2
, self
->rx_buff_dma
,
1032 self
->rx_buff
.truesize
, DMA_RX_MODE
);
1033 TXStart(iobase
, OFF
);
1034 RXStart(iobase
, ON
);
1040 * Function via_ircc_dma_receive_complete (self)
1042 * Controller Finished with receiving frames,
1043 * and this routine is call by ISR
1046 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
1049 struct st_fifo
*st_fifo
;
1050 struct sk_buff
*skb
;
1054 iobase
= self
->io
.fir_base
;
1055 st_fifo
= &self
->st_fifo
;
1057 if (self
->io
.speed
< 4000000) { //Speed below FIR
1058 len
= GetRecvByte(iobase
, self
);
1059 skb
= dev_alloc_skb(len
+ 1);
1062 // Make sure IP header gets aligned
1063 skb_reserve(skb
, 1);
1064 skb_put(skb
, len
- 2);
1065 if (self
->chip_id
== 0x3076) {
1066 for (i
= 0; i
< len
- 2; i
++)
1067 skb
->data
[i
] = self
->rx_buff
.data
[i
* 2];
1069 if (self
->chip_id
== 0x3096) {
1070 for (i
= 0; i
< len
- 2; i
++)
1072 self
->rx_buff
.data
[i
];
1075 // Move to next frame
1076 self
->rx_buff
.data
+= len
;
1077 self
->netdev
->stats
.rx_bytes
+= len
;
1078 self
->netdev
->stats
.rx_packets
++;
1079 skb
->dev
= self
->netdev
;
1080 skb_reset_mac_header(skb
);
1081 skb
->protocol
= htons(ETH_P_IRDA
);
1087 len
= GetRecvByte(iobase
, self
);
1089 return TRUE
; //interrupt only, data maybe move by RxT
1090 if (((len
- 4) < 2) || ((len
- 4) > 2048)) {
1091 IRDA_DEBUG(1, "%s(): Trouble:len=%x,CurCount=%x,LastCount=%x..\n",
1092 __func__
, len
, RxCurCount(iobase
, self
),
1097 IRDA_DEBUG(2, "%s(): fifo.len=%x,len=%x,CurCount=%x..\n",
1099 st_fifo
->len
, len
- 4, RxCurCount(iobase
, self
));
1101 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1102 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1103 st_fifo
->pending_bytes
+= len
;
1106 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1108 self
->RxDataReady
= 0;
1110 // It maybe have MAX_RX_WINDOW package receive by
1111 // receive_complete before Timer IRQ
1113 if (st_fifo->len < (MAX_RX_WINDOW+2 )) {
1119 EnableRX(iobase
, OFF
);
1120 EnRXDMA(iobase
, OFF
);
1121 RXStart(iobase
, OFF
);
1123 // Put this entry back in fifo
1124 if (st_fifo
->head
> MAX_RX_WINDOW
)
1126 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1127 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1131 skb
= dev_alloc_skb(len
+ 1 - 4);
1133 * if frame size, data ptr, or skb ptr are wrong, then get next
1136 if ((skb
== NULL
) || (skb
->data
== NULL
) ||
1137 (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1138 self
->netdev
->stats
.rx_dropped
++;
1142 skb_reserve(skb
, 1);
1143 skb_put(skb
, len
- 4);
1145 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4);
1146 IRDA_DEBUG(2, "%s(): len=%x.rx_buff=%p\n", __func__
,
1147 len
- 4, self
->rx_buff
.data
);
1149 // Move to next frame
1150 self
->rx_buff
.data
+= len
;
1151 self
->netdev
->stats
.rx_bytes
+= len
;
1152 self
->netdev
->stats
.rx_packets
++;
1153 skb
->dev
= self
->netdev
;
1154 skb_reset_mac_header(skb
);
1155 skb
->protocol
= htons(ETH_P_IRDA
);
1165 * if frame is received , but no INT ,then use this routine to upload frame.
1167 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
)
1169 struct sk_buff
*skb
;
1171 struct st_fifo
*st_fifo
;
1172 st_fifo
= &self
->st_fifo
;
1174 len
= GetRecvByte(iobase
, self
);
1176 IRDA_DEBUG(2, "%s(): len=%x\n", __func__
, len
);
1178 if ((len
- 4) < 2) {
1179 self
->netdev
->stats
.rx_dropped
++;
1183 skb
= dev_alloc_skb(len
+ 1);
1185 self
->netdev
->stats
.rx_dropped
++;
1188 skb_reserve(skb
, 1);
1189 skb_put(skb
, len
- 4 + 1);
1190 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4 + 1);
1193 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1195 // Move to next frame
1196 self
->rx_buff
.data
+= len
;
1197 self
->netdev
->stats
.rx_bytes
+= len
;
1198 self
->netdev
->stats
.rx_packets
++;
1199 skb
->dev
= self
->netdev
;
1200 skb_reset_mac_header(skb
);
1201 skb
->protocol
= htons(ETH_P_IRDA
);
1203 if (st_fifo
->len
< (MAX_RX_WINDOW
+ 2)) {
1204 RXStart(iobase
, ON
);
1206 EnableRX(iobase
, OFF
);
1207 EnRXDMA(iobase
, OFF
);
1208 RXStart(iobase
, OFF
);
1214 * Implement back to back receive , use this routine to upload data.
1217 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
)
1219 struct st_fifo
*st_fifo
;
1220 struct sk_buff
*skb
;
1224 st_fifo
= &self
->st_fifo
;
1226 if (CkRxRecv(iobase
, self
)) {
1227 // if still receiving ,then return ,don't upload frame
1228 self
->RetryCount
= 0;
1229 SetTimer(iobase
, 20);
1230 self
->RxDataReady
++;
1235 if ((self
->RetryCount
>= 1) ||
1236 ((st_fifo
->pending_bytes
+ 2048) > self
->rx_buff
.truesize
) ||
1237 (st_fifo
->len
>= (MAX_RX_WINDOW
))) {
1238 while (st_fifo
->len
> 0) { //upload frame
1239 // Put this entry back in fifo
1240 if (st_fifo
->head
> MAX_RX_WINDOW
)
1242 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1243 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1247 skb
= dev_alloc_skb(len
+ 1 - 4);
1249 * if frame size, data ptr, or skb ptr are wrong,
1250 * then get next entry.
1252 if ((skb
== NULL
) || (skb
->data
== NULL
) ||
1253 (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1254 self
->netdev
->stats
.rx_dropped
++;
1257 skb_reserve(skb
, 1);
1258 skb_put(skb
, len
- 4);
1259 skb_copy_to_linear_data(skb
, self
->rx_buff
.data
, len
- 4);
1261 IRDA_DEBUG(2, "%s(): len=%x.head=%x\n", __func__
,
1262 len
- 4, st_fifo
->head
);
1264 // Move to next frame
1265 self
->rx_buff
.data
+= len
;
1266 self
->netdev
->stats
.rx_bytes
+= len
;
1267 self
->netdev
->stats
.rx_packets
++;
1268 skb
->dev
= self
->netdev
;
1269 skb_reset_mac_header(skb
);
1270 skb
->protocol
= htons(ETH_P_IRDA
);
1273 self
->RetryCount
= 0;
1276 "%s(): End of upload HostStatus=%x,RxStatus=%x\n",
1278 GetHostStatus(iobase
), GetRXStatus(iobase
));
1281 * if frame is receive complete at this routine ,then upload
1284 if ((GetRXStatus(iobase
) & 0x10) &&
1285 (RxCurCount(iobase
, self
) != self
->RxLastCount
)) {
1286 upload_rxdata(self
, iobase
);
1287 if (irda_device_txqueue_empty(self
->netdev
))
1288 via_ircc_dma_receive(self
);
1290 } // timer detect complete
1292 SetTimer(iobase
, 4);
1300 * Function via_ircc_interrupt (irq, dev_id)
1302 * An interrupt from the chip has arrived. Time to do some work
1305 static irqreturn_t
via_ircc_interrupt(int dummy
, void *dev_id
)
1307 struct net_device
*dev
= dev_id
;
1308 struct via_ircc_cb
*self
= netdev_priv(dev
);
1310 u8 iHostIntType
, iRxIntType
, iTxIntType
;
1312 iobase
= self
->io
.fir_base
;
1313 spin_lock(&self
->lock
);
1314 iHostIntType
= GetHostStatus(iobase
);
1316 IRDA_DEBUG(4, "%s(): iHostIntType %02x: %s %s %s %02x\n",
1317 __func__
, iHostIntType
,
1318 (iHostIntType
& 0x40) ? "Timer" : "",
1319 (iHostIntType
& 0x20) ? "Tx" : "",
1320 (iHostIntType
& 0x10) ? "Rx" : "",
1321 (iHostIntType
& 0x0e) >> 1);
1323 if ((iHostIntType
& 0x40) != 0) { //Timer Event
1324 self
->EventFlag
.TimeOut
++;
1325 ClearTimerInt(iobase
, 1);
1326 if (self
->io
.direction
== IO_XMIT
) {
1327 via_ircc_dma_xmit(self
, iobase
);
1329 if (self
->io
.direction
== IO_RECV
) {
1331 * frame ready hold too long, must reset.
1333 if (self
->RxDataReady
> 30) {
1335 if (irda_device_txqueue_empty(self
->netdev
)) {
1336 via_ircc_dma_receive(self
);
1338 } else { // call this to upload frame.
1339 RxTimerHandler(self
, iobase
);
1343 if ((iHostIntType
& 0x20) != 0) { //Tx Event
1344 iTxIntType
= GetTXStatus(iobase
);
1346 IRDA_DEBUG(4, "%s(): iTxIntType %02x: %s %s %s %s\n",
1347 __func__
, iTxIntType
,
1348 (iTxIntType
& 0x08) ? "FIFO underr." : "",
1349 (iTxIntType
& 0x04) ? "EOM" : "",
1350 (iTxIntType
& 0x02) ? "FIFO ready" : "",
1351 (iTxIntType
& 0x01) ? "Early EOM" : "");
1353 if (iTxIntType
& 0x4) {
1354 self
->EventFlag
.EOMessage
++; // read and will auto clean
1355 if (via_ircc_dma_xmit_complete(self
)) {
1356 if (irda_device_txqueue_empty
1358 via_ircc_dma_receive(self
);
1361 self
->EventFlag
.Unknown
++;
1365 //----------------------------------------
1366 if ((iHostIntType
& 0x10) != 0) { //Rx Event
1367 /* Check if DMA has finished */
1368 iRxIntType
= GetRXStatus(iobase
);
1370 IRDA_DEBUG(4, "%s(): iRxIntType %02x: %s %s %s %s %s %s %s\n",
1371 __func__
, iRxIntType
,
1372 (iRxIntType
& 0x80) ? "PHY err." : "",
1373 (iRxIntType
& 0x40) ? "CRC err" : "",
1374 (iRxIntType
& 0x20) ? "FIFO overr." : "",
1375 (iRxIntType
& 0x10) ? "EOF" : "",
1376 (iRxIntType
& 0x08) ? "RxData" : "",
1377 (iRxIntType
& 0x02) ? "RxMaxLen" : "",
1378 (iRxIntType
& 0x01) ? "SIR bad" : "");
1380 IRDA_DEBUG(3, "%s(): RxIRQ =0\n", __func__
);
1382 if (iRxIntType
& 0x10) {
1383 if (via_ircc_dma_receive_complete(self
, iobase
)) {
1384 //F01 if(!(IsFIROn(iobase))) via_ircc_dma_receive(self);
1385 via_ircc_dma_receive(self
);
1389 IRDA_DEBUG(4, "%s(): RxIRQ ERR:iRxIntType=%x,HostIntType=%x,CurCount=%x,RxLastCount=%x_____\n",
1390 __func__
, iRxIntType
, iHostIntType
,
1391 RxCurCount(iobase
, self
),
1394 if (iRxIntType
& 0x20) { //FIFO OverRun ERR
1395 ResetChip(iobase
, 0);
1396 ResetChip(iobase
, 1);
1397 } else { //PHY,CRC ERR
1399 if (iRxIntType
!= 0x08)
1400 hwreset(self
); //F01
1402 via_ircc_dma_receive(self
);
1406 spin_unlock(&self
->lock
);
1407 return IRQ_RETVAL(iHostIntType
);
1410 static void hwreset(struct via_ircc_cb
*self
)
1413 iobase
= self
->io
.fir_base
;
1415 IRDA_DEBUG(3, "%s()\n", __func__
);
1417 ResetChip(iobase
, 5);
1418 EnableDMA(iobase
, OFF
);
1419 EnableTX(iobase
, OFF
);
1420 EnableRX(iobase
, OFF
);
1421 EnRXDMA(iobase
, OFF
);
1422 EnTXDMA(iobase
, OFF
);
1423 RXStart(iobase
, OFF
);
1424 TXStart(iobase
, OFF
);
1427 SIRFilter(iobase
, ON
);
1431 WriteReg(iobase
, I_ST_CT_0
, 0x00);
1432 SetBaudRate(iobase
, 9600);
1433 SetPulseWidth(iobase
, 12);
1434 SetSendPreambleCount(iobase
, 0);
1435 WriteReg(iobase
, I_ST_CT_0
, 0x80);
1437 /* Restore speed. */
1438 via_ircc_change_speed(self
, self
->io
.speed
);
1440 self
->st_fifo
.len
= 0;
1444 * Function via_ircc_is_receiving (self)
1446 * Return TRUE is we are currently receiving a frame
1449 static int via_ircc_is_receiving(struct via_ircc_cb
*self
)
1454 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
1456 iobase
= self
->io
.fir_base
;
1457 if (CkRxRecv(iobase
, self
))
1460 IRDA_DEBUG(2, "%s(): status=%x....\n", __func__
, status
);
1467 * Function via_ircc_net_open (dev)
1472 static int via_ircc_net_open(struct net_device
*dev
)
1474 struct via_ircc_cb
*self
;
1478 IRDA_DEBUG(3, "%s()\n", __func__
);
1480 IRDA_ASSERT(dev
!= NULL
, return -1;);
1481 self
= netdev_priv(dev
);
1482 dev
->stats
.rx_packets
= 0;
1483 IRDA_ASSERT(self
!= NULL
, return 0;);
1484 iobase
= self
->io
.fir_base
;
1485 if (request_irq(self
->io
.irq
, via_ircc_interrupt
, 0, dev
->name
, dev
)) {
1486 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name
,
1491 * Always allocate the DMA channel after the IRQ, and clean up on
1494 if (request_dma(self
->io
.dma
, dev
->name
)) {
1495 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name
,
1497 free_irq(self
->io
.irq
, self
);
1500 if (self
->io
.dma2
!= self
->io
.dma
) {
1501 if (request_dma(self
->io
.dma2
, dev
->name
)) {
1502 IRDA_WARNING("%s, unable to allocate dma2=%d\n",
1503 driver_name
, self
->io
.dma2
);
1504 free_irq(self
->io
.irq
, self
);
1505 free_dma(self
->io
.dma
);
1511 /* turn on interrupts */
1512 EnAllInt(iobase
, ON
);
1513 EnInternalLoop(iobase
, OFF
);
1514 EnExternalLoop(iobase
, OFF
);
1517 via_ircc_dma_receive(self
);
1519 /* Ready to play! */
1520 netif_start_queue(dev
);
1523 * Open new IrLAP layer instance, now that everything should be
1524 * initialized properly
1526 sprintf(hwname
, "VIA @ 0x%x", iobase
);
1527 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1529 self
->RxLastCount
= 0;
1535 * Function via_ircc_net_close (dev)
1540 static int via_ircc_net_close(struct net_device
*dev
)
1542 struct via_ircc_cb
*self
;
1545 IRDA_DEBUG(3, "%s()\n", __func__
);
1547 IRDA_ASSERT(dev
!= NULL
, return -1;);
1548 self
= netdev_priv(dev
);
1549 IRDA_ASSERT(self
!= NULL
, return 0;);
1552 netif_stop_queue(dev
);
1553 /* Stop and remove instance of IrLAP */
1555 irlap_close(self
->irlap
);
1557 iobase
= self
->io
.fir_base
;
1558 EnTXDMA(iobase
, OFF
);
1559 EnRXDMA(iobase
, OFF
);
1560 DisableDmaChannel(self
->io
.dma
);
1562 /* Disable interrupts */
1563 EnAllInt(iobase
, OFF
);
1564 free_irq(self
->io
.irq
, dev
);
1565 free_dma(self
->io
.dma
);
1566 if (self
->io
.dma2
!= self
->io
.dma
)
1567 free_dma(self
->io
.dma2
);
1573 * Function via_ircc_net_ioctl (dev, rq, cmd)
1575 * Process IOCTL commands for this device
1578 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
1581 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
1582 struct via_ircc_cb
*self
;
1583 unsigned long flags
;
1586 IRDA_ASSERT(dev
!= NULL
, return -1;);
1587 self
= netdev_priv(dev
);
1588 IRDA_ASSERT(self
!= NULL
, return -1;);
1589 IRDA_DEBUG(1, "%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
,
1591 /* Disable interrupts & save flags */
1592 spin_lock_irqsave(&self
->lock
, flags
);
1594 case SIOCSBANDWIDTH
: /* Set bandwidth */
1595 if (!capable(CAP_NET_ADMIN
)) {
1599 via_ircc_change_speed(self
, irq
->ifr_baudrate
);
1601 case SIOCSMEDIABUSY
: /* Set media busy */
1602 if (!capable(CAP_NET_ADMIN
)) {
1606 irda_device_set_media_busy(self
->netdev
, TRUE
);
1608 case SIOCGRECEIVING
: /* Check if we are receiving right now */
1609 irq
->ifr_receiving
= via_ircc_is_receiving(self
);
1615 spin_unlock_irqrestore(&self
->lock
, flags
);
1619 MODULE_AUTHOR("VIA Technologies,inc");
1620 MODULE_DESCRIPTION("VIA IrDA Device Driver");
1621 MODULE_LICENSE("GPL");
1623 module_init(via_ircc_init
);
1624 module_exit(via_ircc_cleanup
);