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/slab.h>
49 #include <linux/init.h>
50 #include <linux/rtnetlink.h>
51 #include <linux/pci.h>
52 #include <linux/dma-mapping.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 /* FIXME : we should not need this, because instances should be automatically
79 * managed by the PCI layer. Especially that we seem to only be using the
80 * first entry. Jean II */
81 /* Max 4 instances for now */
82 static struct via_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
85 static int via_ircc_open(int i
, chipio_t
* info
, unsigned int id
);
86 static int via_ircc_close(struct via_ircc_cb
*self
);
87 static int via_ircc_dma_receive(struct via_ircc_cb
*self
);
88 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
90 static int via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
91 struct net_device
*dev
);
92 static int via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
93 struct net_device
*dev
);
94 static void via_hw_init(struct via_ircc_cb
*self
);
95 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 baud
);
96 static irqreturn_t
via_ircc_interrupt(int irq
, void *dev_id
,
97 struct pt_regs
*regs
);
98 static int via_ircc_is_receiving(struct via_ircc_cb
*self
);
99 static int via_ircc_read_dongle_id(int iobase
);
101 static int via_ircc_net_open(struct net_device
*dev
);
102 static int via_ircc_net_close(struct net_device
*dev
);
103 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
105 static struct net_device_stats
*via_ircc_net_get_stats(struct net_device
107 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
109 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
);
110 static void hwreset(struct via_ircc_cb
*self
);
111 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
);
112 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
);
113 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
);
114 static void __devexit
via_remove_one (struct pci_dev
*pdev
);
116 /* FIXME : Should use udelay() instead, even if we are x86 only - Jean II */
117 static void iodelay(int udelay
)
122 for (i
= 0; i
< udelay
; i
++) {
127 static struct pci_device_id via_pci_tbl
[] = {
128 { PCI_VENDOR_ID_VIA
, 0x8231, PCI_ANY_ID
, PCI_ANY_ID
,0,0,0 },
129 { PCI_VENDOR_ID_VIA
, 0x3109, PCI_ANY_ID
, PCI_ANY_ID
,0,0,1 },
130 { PCI_VENDOR_ID_VIA
, 0x3074, PCI_ANY_ID
, PCI_ANY_ID
,0,0,2 },
131 { PCI_VENDOR_ID_VIA
, 0x3147, PCI_ANY_ID
, PCI_ANY_ID
,0,0,3 },
132 { PCI_VENDOR_ID_VIA
, 0x3177, PCI_ANY_ID
, PCI_ANY_ID
,0,0,4 },
136 MODULE_DEVICE_TABLE(pci
,via_pci_tbl
);
139 static struct pci_driver via_driver
= {
140 .name
= VIA_MODULE_NAME
,
141 .id_table
= via_pci_tbl
,
142 .probe
= via_init_one
,
143 .remove
= __devexit_p(via_remove_one
),
148 * Function via_ircc_init ()
150 * Initialize chip. Just find out chip type and resource.
152 static int __init
via_ircc_init(void)
156 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
158 rc
= pci_register_driver(&via_driver
);
160 IRDA_DEBUG(0, "%s(): error rc = %d, returning -ENODEV...\n",
167 static int __devinit
via_init_one (struct pci_dev
*pcidev
, const struct pci_device_id
*id
)
170 u8 temp
,oldPCI_40
,oldPCI_44
,bTmp
,bTmp1
;
171 u16 Chipset
,FirDRQ1
,FirDRQ0
,FirIRQ
,FirIOBase
;
174 IRDA_DEBUG(2, "%s(): Device ID=(0X%X)\n", __FUNCTION__
, id
->device
);
176 rc
= pci_enable_device (pcidev
);
178 IRDA_DEBUG(0, "%s(): error rc = %d\n", __FUNCTION__
, rc
);
182 // South Bridge exist
183 if ( ReadLPCReg(0x20) != 0x3C )
188 if (Chipset
==0x3076) {
189 IRDA_DEBUG(2, "%s(): Chipset = 3076\n", __FUNCTION__
);
191 WriteLPCReg(7,0x0c );
192 temp
=ReadLPCReg(0x30);//check if BIOS Enable Fir
193 if((temp
&0x01)==1) { // BIOS close or no FIR
194 WriteLPCReg(0x1d, 0x82 );
195 WriteLPCReg(0x23,0x18);
196 temp
=ReadLPCReg(0xF0);
198 temp
=(ReadLPCReg(0x74)&0x03); //DMA
200 temp
=(ReadLPCReg(0x74)&0x0C) >> 2;
203 temp
=(ReadLPCReg(0x74)&0x0C) >> 2; //DMA
207 FirIRQ
=(ReadLPCReg(0x70)&0x0f); //IRQ
208 FirIOBase
=ReadLPCReg(0x60 ) << 8; //IO Space :high byte
209 FirIOBase
=FirIOBase
| ReadLPCReg(0x61) ; //low byte
210 FirIOBase
=FirIOBase
;
211 info
.fir_base
=FirIOBase
;
215 pci_read_config_byte(pcidev
,0x40,&bTmp
);
216 pci_write_config_byte(pcidev
,0x40,((bTmp
| 0x08) & 0xfe));
217 pci_read_config_byte(pcidev
,0x42,&bTmp
);
218 pci_write_config_byte(pcidev
,0x42,(bTmp
| 0xf0));
219 pci_write_config_byte(pcidev
,0x5a,0xc0);
220 WriteLPCReg(0x28, 0x70 );
221 if (via_ircc_open(0, &info
,0x3076) == 0)
224 rc
= -ENODEV
; //IR not turn on
225 } else { //Not VT1211
226 IRDA_DEBUG(2, "%s(): Chipset = 3096\n", __FUNCTION__
);
228 pci_read_config_byte(pcidev
,0x67,&bTmp
);//check if BIOS Enable Fir
229 if((bTmp
&0x01)==1) { // BIOS enable FIR
230 //Enable Double DMA clock
231 pci_read_config_byte(pcidev
,0x42,&oldPCI_40
);
232 pci_write_config_byte(pcidev
,0x42,oldPCI_40
| 0x80);
233 pci_read_config_byte(pcidev
,0x40,&oldPCI_40
);
234 pci_write_config_byte(pcidev
,0x40,oldPCI_40
& 0xf7);
235 pci_read_config_byte(pcidev
,0x44,&oldPCI_44
);
236 pci_write_config_byte(pcidev
,0x44,0x4e);
237 //---------- read configuration from Function0 of south bridge
239 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
240 FirDRQ0
= (bTmp1
& 0x30) >> 4;
241 pci_read_config_byte(pcidev
,0x44,&bTmp1
);
242 FirDRQ1
= (bTmp1
& 0xc0) >> 6;
244 pci_read_config_byte(pcidev
,0x44,&bTmp1
); //DMA
245 FirDRQ0
= (bTmp1
& 0x30) >> 4 ;
248 pci_read_config_byte(pcidev
,0x47,&bTmp1
); //IRQ
249 FirIRQ
= bTmp1
& 0x0f;
251 pci_read_config_byte(pcidev
,0x69,&bTmp
);
252 FirIOBase
= bTmp
<< 8;//hight byte
253 pci_read_config_byte(pcidev
,0x68,&bTmp
);
254 FirIOBase
= (FirIOBase
| bTmp
) & 0xfff0;
255 //-------------------------
256 info
.fir_base
=FirIOBase
;
260 if (via_ircc_open(0, &info
,0x3096) == 0)
263 rc
= -ENODEV
; //IR not turn on !!!!!
266 IRDA_DEBUG(2, "%s(): End - rc = %d\n", __FUNCTION__
, rc
);
271 * Function via_ircc_clean ()
273 * Close all configured chips
276 static void via_ircc_clean(void)
280 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
282 for (i
=0; i
< 4; i
++) {
284 via_ircc_close(dev_self
[i
]);
288 static void __devexit
via_remove_one (struct pci_dev
*pdev
)
290 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
292 /* FIXME : This is ugly. We should use pci_get_drvdata(pdev);
293 * to get our driver instance and call directly via_ircc_close().
294 * See vlsi_ir for details...
298 /* FIXME : This should be in via_ircc_close(), because here we may
299 * theoritically disable still configured devices :-( - Jean II */
300 pci_disable_device(pdev
);
303 static void __exit
via_ircc_cleanup(void)
305 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
307 /* FIXME : This should be redundant, as pci_unregister_driver()
308 * should call via_remove_one() on each device.
312 /* Cleanup all instances of the driver */
313 pci_unregister_driver (&via_driver
);
317 * Function via_ircc_open (iobase, irq)
319 * Open driver instance
322 static __devinit
int via_ircc_open(int i
, chipio_t
* info
, unsigned int id
)
324 struct net_device
*dev
;
325 struct via_ircc_cb
*self
;
328 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
330 /* Allocate new instance of the driver */
331 dev
= alloc_irdadev(sizeof(struct via_ircc_cb
));
337 spin_lock_init(&self
->lock
);
339 /* FIXME : We should store our driver instance in the PCI layer,
340 * using pci_set_drvdata(), not in this array.
341 * See vlsi_ir for details... - Jean II */
342 /* FIXME : 'i' is always 0 (see via_init_one()) :-( - Jean II */
343 /* Need to store self somewhere */
346 /* Initialize Resource */
347 self
->io
.cfg_base
= info
->cfg_base
;
348 self
->io
.fir_base
= info
->fir_base
;
349 self
->io
.irq
= info
->irq
;
350 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
351 self
->io
.dma
= info
->dma
;
352 self
->io
.dma2
= info
->dma2
;
353 self
->io
.fifo_size
= 32;
355 self
->st_fifo
.len
= 0;
356 self
->RxDataReady
= 0;
358 /* Reserve the ioports that we need */
359 if (!request_region(self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
)) {
360 IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n",
361 __FUNCTION__
, self
->io
.fir_base
);
366 /* Initialize QoS for this device */
367 irda_init_max_qos_capabilies(&self
->qos
);
369 /* Check if user has supplied the dongle id or not */
371 dongle_id
= via_ircc_read_dongle_id(self
->io
.fir_base
);
372 self
->io
.dongle_id
= dongle_id
;
374 /* The only value we must override it the baudrate */
375 /* Maximum speeds and capabilities are dongle-dependant. */
376 switch( self
->io
.dongle_id
){
378 self
->qos
.baud_rate
.bits
=
379 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
|
380 IR_576000
| IR_1152000
| (IR_4000000
<< 8);
383 self
->qos
.baud_rate
.bits
=
384 IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
;
388 /* Following was used for testing:
390 * self->qos.baud_rate.bits = IR_9600;
392 * Is is no good, as it prohibits (error-prone) speed-changes.
395 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
396 irda_qos_bits_to_value(&self
->qos
);
398 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
399 self
->rx_buff
.truesize
= 14384 + 2048;
400 self
->tx_buff
.truesize
= 14384 + 2048;
402 /* Allocate memory if needed */
404 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
405 &self
->rx_buff_dma
, GFP_KERNEL
);
406 if (self
->rx_buff
.head
== NULL
) {
410 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
413 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
414 &self
->tx_buff_dma
, GFP_KERNEL
);
415 if (self
->tx_buff
.head
== NULL
) {
419 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
421 self
->rx_buff
.in_frame
= FALSE
;
422 self
->rx_buff
.state
= OUTSIDE_FRAME
;
423 self
->tx_buff
.data
= self
->tx_buff
.head
;
424 self
->rx_buff
.data
= self
->rx_buff
.head
;
426 /* Reset Tx queue info */
427 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
428 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
430 /* Keep track of module usage */
431 SET_MODULE_OWNER(dev
);
433 /* Override the network functions we need to use */
434 dev
->hard_start_xmit
= via_ircc_hard_xmit_sir
;
435 dev
->open
= via_ircc_net_open
;
436 dev
->stop
= via_ircc_net_close
;
437 dev
->do_ioctl
= via_ircc_net_ioctl
;
438 dev
->get_stats
= via_ircc_net_get_stats
;
440 err
= register_netdev(dev
);
444 IRDA_MESSAGE("IrDA: Registered device %s (via-ircc)\n", dev
->name
);
446 /* Initialise the hardware..
448 self
->io
.speed
= 9600;
452 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
453 self
->tx_buff
.head
, self
->tx_buff_dma
);
455 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
456 self
->rx_buff
.head
, self
->rx_buff_dma
);
458 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
466 * Function via_ircc_close (self)
468 * Close driver instance
471 static int via_ircc_close(struct via_ircc_cb
*self
)
475 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
477 IRDA_ASSERT(self
!= NULL
, return -1;);
479 iobase
= self
->io
.fir_base
;
481 ResetChip(iobase
, 5); //hardware reset.
482 /* Remove netdevice */
483 unregister_netdev(self
->netdev
);
485 /* Release the PORT that this driver is using */
486 IRDA_DEBUG(2, "%s(), Releasing Region %03x\n",
487 __FUNCTION__
, self
->io
.fir_base
);
488 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
489 if (self
->tx_buff
.head
)
490 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
491 self
->tx_buff
.head
, self
->tx_buff_dma
);
492 if (self
->rx_buff
.head
)
493 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
494 self
->rx_buff
.head
, self
->rx_buff_dma
);
495 dev_self
[self
->index
] = NULL
;
497 free_netdev(self
->netdev
);
503 * Function via_hw_init(self)
505 * Returns non-negative on success.
507 * Formerly via_ircc_setup
509 static void via_hw_init(struct via_ircc_cb
*self
)
511 int iobase
= self
->io
.fir_base
;
513 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
515 SetMaxRxPacketSize(iobase
, 0x0fff); //set to max:4095
517 EnRXFIFOReadyInt(iobase
, OFF
);
518 EnRXFIFOHalfLevelInt(iobase
, OFF
);
519 EnTXFIFOHalfLevelInt(iobase
, OFF
);
520 EnTXFIFOUnderrunEOMInt(iobase
, ON
);
521 EnTXFIFOReadyInt(iobase
, OFF
);
522 InvertTX(iobase
, OFF
);
523 InvertRX(iobase
, OFF
);
525 if (ReadLPCReg(0x20) == 0x3c)
526 WriteLPCReg(0xF0, 0); // for VT1211
528 EnRXSpecInt(iobase
, ON
);
530 /* The following is basically hwreset */
531 /* If this is the case, why not just call hwreset() ? Jean II */
532 ResetChip(iobase
, 5);
533 EnableDMA(iobase
, OFF
);
534 EnableTX(iobase
, OFF
);
535 EnableRX(iobase
, OFF
);
536 EnRXDMA(iobase
, OFF
);
537 EnTXDMA(iobase
, OFF
);
538 RXStart(iobase
, OFF
);
539 TXStart(iobase
, OFF
);
542 SIRFilter(iobase
, ON
);
546 WriteReg(iobase
, I_ST_CT_0
, 0x00);
547 SetBaudRate(iobase
, 9600);
548 SetPulseWidth(iobase
, 12);
549 SetSendPreambleCount(iobase
, 0);
551 self
->io
.speed
= 9600;
552 self
->st_fifo
.len
= 0;
554 via_ircc_change_dongle_speed(iobase
, self
->io
.speed
,
557 WriteReg(iobase
, I_ST_CT_0
, 0x80);
561 * Function via_ircc_read_dongle_id (void)
564 static int via_ircc_read_dongle_id(int iobase
)
566 int dongle_id
= 9; /* Default to IBM */
568 IRDA_ERROR("via-ircc: dongle probing not supported, please specify dongle_id module parameter.\n");
573 * Function via_ircc_change_dongle_speed (iobase, speed, dongle_id)
574 * Change speed of the attach dongle
575 * only implement two type of dongle currently.
577 static void via_ircc_change_dongle_speed(int iobase
, int speed
,
582 /* speed is unused, as we use IsSIROn()/IsMIROn() */
585 IRDA_DEBUG(1, "%s(): change_dongle_speed to %d for 0x%x, %d\n",
586 __FUNCTION__
, speed
, iobase
, dongle_id
);
590 /* Note: The dongle_id's listed here are derived from
593 case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
594 UseOneRX(iobase
, ON
); // use one RX pin RX1,RX2
595 InvertTX(iobase
, OFF
);
596 InvertRX(iobase
, OFF
);
598 EnRX2(iobase
, ON
); //sir to rx2
599 EnGPIOtoRX2(iobase
, OFF
);
601 if (IsSIROn(iobase
)) { //sir
603 SlowIRRXLowActive(iobase
, ON
);
605 SlowIRRXLowActive(iobase
, OFF
);
607 if (IsMIROn(iobase
)) { //mir
609 SlowIRRXLowActive(iobase
, OFF
);
612 if (IsFIROn(iobase
)) { //fir
614 SlowIRRXLowActive(iobase
, OFF
);
621 case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
622 UseOneRX(iobase
, ON
); //use ONE RX....RX1
623 InvertTX(iobase
, OFF
);
624 InvertRX(iobase
, OFF
); // invert RX pin
627 EnGPIOtoRX2(iobase
, OFF
);
628 if (IsSIROn(iobase
)) { //sir
630 SlowIRRXLowActive(iobase
, ON
);
633 SlowIRRXLowActive(iobase
, OFF
);
635 if (IsMIROn(iobase
)) { //mir
637 SlowIRRXLowActive(iobase
, OFF
);
640 SlowIRRXLowActive(iobase
, ON
);
642 if (IsFIROn(iobase
)) { //fir
644 SlowIRRXLowActive(iobase
, OFF
);
649 SlowIRRXLowActive(iobase
, ON
);
652 WriteTX(iobase
, OFF
);
658 UseOneRX(iobase
, OFF
); // use two RX pin RX1,RX2
659 InvertTX(iobase
, OFF
);
660 InvertRX(iobase
, OFF
);
661 SlowIRRXLowActive(iobase
, OFF
);
662 if (IsSIROn(iobase
)) { //sir
663 EnGPIOtoRX2(iobase
, OFF
);
664 WriteGIO(iobase
, OFF
);
665 EnRX2(iobase
, OFF
); //sir to rx2
667 EnGPIOtoRX2(iobase
, OFF
);
668 WriteGIO(iobase
, OFF
);
669 EnRX2(iobase
, OFF
); //fir to rx
673 case 0x11: /* Temic TFDS4500 */
675 IRDA_DEBUG(2, "%s: Temic TFDS4500: One RX pin, TX normal, RX inverted.\n", __FUNCTION__
);
677 UseOneRX(iobase
, ON
); //use ONE RX....RX1
678 InvertTX(iobase
, OFF
);
679 InvertRX(iobase
, ON
); // invert RX pin
681 EnRX2(iobase
, ON
); //sir to rx2
682 EnGPIOtoRX2(iobase
, OFF
);
684 if( IsSIROn(iobase
) ){ //sir
687 SlowIRRXLowActive(iobase
, ON
);
690 SlowIRRXLowActive(iobase
, OFF
);
693 IRDA_DEBUG(0, "%s: Warning: TFDS4500 not running in SIR mode !\n", __FUNCTION__
);
697 case 0x0ff: /* Vishay */
700 else if (IsMIROn(iobase
))
702 else if (IsFIROn(iobase
))
704 else if (IsVFIROn(iobase
))
706 SI_SetMode(iobase
, mode
);
710 IRDA_ERROR("%s: Error: dongle_id %d unsupported !\n",
711 __FUNCTION__
, dongle_id
);
716 * Function via_ircc_change_speed (self, baud)
718 * Change the speed of the device
721 static void via_ircc_change_speed(struct via_ircc_cb
*self
, __u32 speed
)
723 struct net_device
*dev
= self
->netdev
;
727 iobase
= self
->io
.fir_base
;
728 /* Update accounting for new speed */
729 self
->io
.speed
= speed
;
730 IRDA_DEBUG(1, "%s: change_speed to %d bps.\n", __FUNCTION__
, speed
);
732 WriteReg(iobase
, I_ST_CT_0
, 0x0);
734 /* Controller mode sellection */
742 value
= (115200/speed
)-1;
747 /* FIXME: this can't be right, as it's the same as 115200,
748 * and 576000 is MIR, not SIR. */
761 SetPulseWidth(iobase
, 0);
762 SetSendPreambleCount(iobase
, 14);
776 /* Set baudrate to 0x19[2..7] */
777 bTmp
= (ReadReg(iobase
, I_CF_H_1
) & 0x03);
779 WriteReg(iobase
, I_CF_H_1
, bTmp
);
781 /* Some dongles may need to be informed about speed changes. */
782 via_ircc_change_dongle_speed(iobase
, speed
, self
->io
.dongle_id
);
784 /* Set FIFO size to 64 */
788 WriteReg(iobase
, I_ST_CT_0
, 0x80);
790 // EnTXFIFOHalfLevelInt(iobase,ON);
792 /* Enable some interrupts so we can receive frames */
793 //EnAllInt(iobase,ON);
795 if (IsSIROn(iobase
)) {
796 SIRFilter(iobase
, ON
);
797 SIRRecvAny(iobase
, ON
);
799 SIRFilter(iobase
, OFF
);
800 SIRRecvAny(iobase
, OFF
);
803 if (speed
> 115200) {
804 /* Install FIR xmit handler */
805 dev
->hard_start_xmit
= via_ircc_hard_xmit_fir
;
806 via_ircc_dma_receive(self
);
808 /* Install SIR xmit handler */
809 dev
->hard_start_xmit
= via_ircc_hard_xmit_sir
;
811 netif_wake_queue(dev
);
815 * Function via_ircc_hard_xmit (skb, dev)
817 * Transmit the frame!
820 static int via_ircc_hard_xmit_sir(struct sk_buff
*skb
,
821 struct net_device
*dev
)
823 struct via_ircc_cb
*self
;
828 self
= (struct via_ircc_cb
*) dev
->priv
;
829 IRDA_ASSERT(self
!= NULL
, return 0;);
830 iobase
= self
->io
.fir_base
;
832 netif_stop_queue(dev
);
833 /* Check if we need to change the speed */
834 speed
= irda_get_next_speed(skb
);
835 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
836 /* Check for empty frame */
838 via_ircc_change_speed(self
, speed
);
839 dev
->trans_start
= jiffies
;
843 self
->new_speed
= speed
;
847 SIRFilter(iobase
, ON
);
851 WriteReg(iobase
, I_ST_CT_0
, 0x00);
853 spin_lock_irqsave(&self
->lock
, flags
);
854 self
->tx_buff
.data
= self
->tx_buff
.head
;
856 async_wrap_skb(skb
, self
->tx_buff
.data
,
857 self
->tx_buff
.truesize
);
859 self
->stats
.tx_bytes
+= self
->tx_buff
.len
;
860 /* Send this frame with old speed */
861 SetBaudRate(iobase
, self
->io
.speed
);
862 SetPulseWidth(iobase
, 12);
863 SetSendPreambleCount(iobase
, 0);
864 WriteReg(iobase
, I_ST_CT_0
, 0x80);
866 EnableTX(iobase
, ON
);
867 EnableRX(iobase
, OFF
);
869 ResetChip(iobase
, 0);
870 ResetChip(iobase
, 1);
871 ResetChip(iobase
, 2);
872 ResetChip(iobase
, 3);
873 ResetChip(iobase
, 4);
875 EnAllInt(iobase
, ON
);
877 EnRXDMA(iobase
, OFF
);
879 irda_setup_dma(self
->io
.dma
, self
->tx_buff_dma
, self
->tx_buff
.len
,
882 SetSendByte(iobase
, self
->tx_buff
.len
);
883 RXStart(iobase
, OFF
);
886 dev
->trans_start
= jiffies
;
887 spin_unlock_irqrestore(&self
->lock
, flags
);
892 static int via_ircc_hard_xmit_fir(struct sk_buff
*skb
,
893 struct net_device
*dev
)
895 struct via_ircc_cb
*self
;
900 self
= (struct via_ircc_cb
*) dev
->priv
;
901 iobase
= self
->io
.fir_base
;
903 if (self
->st_fifo
.len
)
905 if (self
->chip_id
== 0x3076)
909 netif_stop_queue(dev
);
910 speed
= irda_get_next_speed(skb
);
911 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
913 via_ircc_change_speed(self
, speed
);
914 dev
->trans_start
= jiffies
;
918 self
->new_speed
= speed
;
920 spin_lock_irqsave(&self
->lock
, flags
);
921 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
922 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
924 self
->tx_fifo
.tail
+= skb
->len
;
925 self
->stats
.tx_bytes
+= skb
->len
;
926 memcpy(self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
, skb
->data
,
929 self
->tx_fifo
.free
++;
930 //F01 if (self->tx_fifo.len == 1) {
931 via_ircc_dma_xmit(self
, iobase
);
933 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) netif_wake_queue(self->netdev);
934 dev
->trans_start
= jiffies
;
936 spin_unlock_irqrestore(&self
->lock
, flags
);
941 static int via_ircc_dma_xmit(struct via_ircc_cb
*self
, u16 iobase
)
943 EnTXDMA(iobase
, OFF
);
944 self
->io
.direction
= IO_XMIT
;
946 EnableTX(iobase
, ON
);
947 EnableRX(iobase
, OFF
);
948 ResetChip(iobase
, 0);
949 ResetChip(iobase
, 1);
950 ResetChip(iobase
, 2);
951 ResetChip(iobase
, 3);
952 ResetChip(iobase
, 4);
953 EnAllInt(iobase
, ON
);
955 EnRXDMA(iobase
, OFF
);
956 irda_setup_dma(self
->io
.dma
,
957 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
958 self
->tx_buff
.head
) + self
->tx_buff_dma
,
959 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
, DMA_TX_MODE
);
960 IRDA_DEBUG(1, "%s: tx_fifo.ptr=%x,len=%x,tx_fifo.len=%x..\n",
961 __FUNCTION__
, self
->tx_fifo
.ptr
,
962 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
965 SetSendByte(iobase
, self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
);
966 RXStart(iobase
, OFF
);
973 * Function via_ircc_dma_xmit_complete (self)
975 * The transfer of a frame in finished. This function will only be called
976 * by the interrupt handler
979 static int via_ircc_dma_xmit_complete(struct via_ircc_cb
*self
)
985 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
987 iobase
= self
->io
.fir_base
;
989 // DisableDmaChannel(self->io.dma);
990 /* Check for underrrun! */
991 /* Clear bit, by writing 1 into it */
992 Tx_status
= GetTXStatus(iobase
);
993 if (Tx_status
& 0x08) {
994 self
->stats
.tx_errors
++;
995 self
->stats
.tx_fifo_errors
++;
997 // how to clear underrrun ?
999 self
->stats
.tx_packets
++;
1000 ResetChip(iobase
, 3);
1001 ResetChip(iobase
, 4);
1003 /* Check if we need to change the speed */
1004 if (self
->new_speed
) {
1005 via_ircc_change_speed(self
, self
->new_speed
);
1006 self
->new_speed
= 0;
1009 /* Finished with this frame, so prepare for next */
1010 if (IsFIROn(iobase
)) {
1011 if (self
->tx_fifo
.len
) {
1012 self
->tx_fifo
.len
--;
1013 self
->tx_fifo
.ptr
++;
1017 "%s: tx_fifo.len=%x ,tx_fifo.ptr=%x,tx_fifo.free=%x...\n",
1019 self
->tx_fifo
.len
, self
->tx_fifo
.ptr
, self
->tx_fifo
.free
);
1021 // Any frames to be sent back-to-back?
1022 if (self->tx_fifo.len) {
1023 // Not finished yet!
1024 via_ircc_dma_xmit(self, iobase);
1028 // Reset Tx FIFO info
1029 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1030 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1033 // Make sure we have room for more frames
1034 //F01 if (self->tx_fifo.free < (MAX_TX_WINDOW -1 )) {
1035 // Not busy transmitting anymore
1036 // Tell the network layer, that we can accept more frames
1037 netif_wake_queue(self
->netdev
);
1043 * Function via_ircc_dma_receive (self)
1045 * Set configuration for receive a frame.
1048 static int via_ircc_dma_receive(struct via_ircc_cb
*self
)
1052 iobase
= self
->io
.fir_base
;
1054 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
1056 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1057 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1058 self
->RxDataReady
= 0;
1059 self
->io
.direction
= IO_RECV
;
1060 self
->rx_buff
.data
= self
->rx_buff
.head
;
1061 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1062 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1065 EnableTX(iobase
, OFF
);
1066 EnableRX(iobase
, ON
);
1068 ResetChip(iobase
, 0);
1069 ResetChip(iobase
, 1);
1070 ResetChip(iobase
, 2);
1071 ResetChip(iobase
, 3);
1072 ResetChip(iobase
, 4);
1074 EnAllInt(iobase
, ON
);
1075 EnTXDMA(iobase
, OFF
);
1076 EnRXDMA(iobase
, ON
);
1077 irda_setup_dma(self
->io
.dma2
, self
->rx_buff_dma
,
1078 self
->rx_buff
.truesize
, DMA_RX_MODE
);
1079 TXStart(iobase
, OFF
);
1080 RXStart(iobase
, ON
);
1086 * Function via_ircc_dma_receive_complete (self)
1088 * Controller Finished with receiving frames,
1089 * and this routine is call by ISR
1092 static int via_ircc_dma_receive_complete(struct via_ircc_cb
*self
,
1095 struct st_fifo
*st_fifo
;
1096 struct sk_buff
*skb
;
1100 iobase
= self
->io
.fir_base
;
1101 st_fifo
= &self
->st_fifo
;
1103 if (self
->io
.speed
< 4000000) { //Speed below FIR
1104 len
= GetRecvByte(iobase
, self
);
1105 skb
= dev_alloc_skb(len
+ 1);
1108 // Make sure IP header gets aligned
1109 skb_reserve(skb
, 1);
1110 skb_put(skb
, len
- 2);
1111 if (self
->chip_id
== 0x3076) {
1112 for (i
= 0; i
< len
- 2; i
++)
1113 skb
->data
[i
] = self
->rx_buff
.data
[i
* 2];
1115 if (self
->chip_id
== 0x3096) {
1116 for (i
= 0; i
< len
- 2; i
++)
1118 self
->rx_buff
.data
[i
];
1121 // Move to next frame
1122 self
->rx_buff
.data
+= len
;
1123 self
->stats
.rx_bytes
+= len
;
1124 self
->stats
.rx_packets
++;
1125 skb
->dev
= self
->netdev
;
1126 skb
->mac
.raw
= skb
->data
;
1127 skb
->protocol
= htons(ETH_P_IRDA
);
1133 len
= GetRecvByte(iobase
, self
);
1135 return TRUE
; //interrupt only, data maybe move by RxT
1136 if (((len
- 4) < 2) || ((len
- 4) > 2048)) {
1137 IRDA_DEBUG(1, "%s(): Trouble:len=%x,CurCount=%x,LastCount=%x..\n",
1138 __FUNCTION__
, len
, RxCurCount(iobase
, self
),
1143 IRDA_DEBUG(2, "%s(): fifo.len=%x,len=%x,CurCount=%x..\n",
1145 st_fifo
->len
, len
- 4, RxCurCount(iobase
, self
));
1147 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1148 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1149 st_fifo
->pending_bytes
+= len
;
1152 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1154 self
->RxDataReady
= 0;
1156 // It maybe have MAX_RX_WINDOW package receive by
1157 // receive_complete before Timer IRQ
1159 if (st_fifo->len < (MAX_RX_WINDOW+2 )) {
1165 EnableRX(iobase
, OFF
);
1166 EnRXDMA(iobase
, OFF
);
1167 RXStart(iobase
, OFF
);
1169 // Put this entry back in fifo
1170 if (st_fifo
->head
> MAX_RX_WINDOW
)
1172 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1173 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1177 skb
= dev_alloc_skb(len
+ 1 - 4);
1179 * if frame size,data ptr,or skb ptr are wrong ,the get next
1182 if ((skb
== NULL
) || (skb
->data
== NULL
)
1183 || (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1184 self
->stats
.rx_dropped
++;
1187 skb_reserve(skb
, 1);
1188 skb_put(skb
, len
- 4);
1190 memcpy(skb
->data
, self
->rx_buff
.data
, len
- 4);
1191 IRDA_DEBUG(2, "%s(): len=%x.rx_buff=%p\n", __FUNCTION__
,
1192 len
- 4, self
->rx_buff
.data
);
1194 // Move to next frame
1195 self
->rx_buff
.data
+= len
;
1196 self
->stats
.rx_bytes
+= len
;
1197 self
->stats
.rx_packets
++;
1198 skb
->dev
= self
->netdev
;
1199 skb
->mac
.raw
= skb
->data
;
1200 skb
->protocol
= htons(ETH_P_IRDA
);
1210 * if frame is received , but no INT ,then use this routine to upload frame.
1212 static int upload_rxdata(struct via_ircc_cb
*self
, int iobase
)
1214 struct sk_buff
*skb
;
1216 struct st_fifo
*st_fifo
;
1217 st_fifo
= &self
->st_fifo
;
1219 len
= GetRecvByte(iobase
, self
);
1221 IRDA_DEBUG(2, "%s(): len=%x\n", __FUNCTION__
, len
);
1223 skb
= dev_alloc_skb(len
+ 1);
1224 if ((skb
== NULL
) || ((len
- 4) < 2)) {
1225 self
->stats
.rx_dropped
++;
1228 skb_reserve(skb
, 1);
1229 skb_put(skb
, len
- 4 + 1);
1230 memcpy(skb
->data
, self
->rx_buff
.data
, len
- 4 + 1);
1233 if (st_fifo
->tail
> MAX_RX_WINDOW
)
1235 // Move to next frame
1236 self
->rx_buff
.data
+= len
;
1237 self
->stats
.rx_bytes
+= len
;
1238 self
->stats
.rx_packets
++;
1239 skb
->dev
= self
->netdev
;
1240 skb
->mac
.raw
= skb
->data
;
1241 skb
->protocol
= htons(ETH_P_IRDA
);
1243 if (st_fifo
->len
< (MAX_RX_WINDOW
+ 2)) {
1244 RXStart(iobase
, ON
);
1246 EnableRX(iobase
, OFF
);
1247 EnRXDMA(iobase
, OFF
);
1248 RXStart(iobase
, OFF
);
1254 * Implement back to back receive , use this routine to upload data.
1257 static int RxTimerHandler(struct via_ircc_cb
*self
, int iobase
)
1259 struct st_fifo
*st_fifo
;
1260 struct sk_buff
*skb
;
1264 st_fifo
= &self
->st_fifo
;
1266 if (CkRxRecv(iobase
, self
)) {
1267 // if still receiving ,then return ,don't upload frame
1268 self
->RetryCount
= 0;
1269 SetTimer(iobase
, 20);
1270 self
->RxDataReady
++;
1275 if ((self
->RetryCount
>= 1) ||
1276 ((st_fifo
->pending_bytes
+ 2048) > self
->rx_buff
.truesize
)
1277 || (st_fifo
->len
>= (MAX_RX_WINDOW
))) {
1278 while (st_fifo
->len
> 0) { //upload frame
1279 // Put this entry back in fifo
1280 if (st_fifo
->head
> MAX_RX_WINDOW
)
1282 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1283 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1287 skb
= dev_alloc_skb(len
+ 1 - 4);
1289 * if frame size, data ptr, or skb ptr are wrong,
1290 * then get next entry.
1292 if ((skb
== NULL
) || (skb
->data
== NULL
)
1293 || (self
->rx_buff
.data
== NULL
) || (len
< 6)) {
1294 self
->stats
.rx_dropped
++;
1297 skb_reserve(skb
, 1);
1298 skb_put(skb
, len
- 4);
1299 memcpy(skb
->data
, self
->rx_buff
.data
, len
- 4);
1301 IRDA_DEBUG(2, "%s(): len=%x.head=%x\n", __FUNCTION__
,
1302 len
- 4, st_fifo
->head
);
1304 // Move to next frame
1305 self
->rx_buff
.data
+= len
;
1306 self
->stats
.rx_bytes
+= len
;
1307 self
->stats
.rx_packets
++;
1308 skb
->dev
= self
->netdev
;
1309 skb
->mac
.raw
= skb
->data
;
1310 skb
->protocol
= htons(ETH_P_IRDA
);
1313 self
->RetryCount
= 0;
1316 "%s(): End of upload HostStatus=%x,RxStatus=%x\n",
1318 GetHostStatus(iobase
), GetRXStatus(iobase
));
1321 * if frame is receive complete at this routine ,then upload
1324 if ((GetRXStatus(iobase
) & 0x10)
1325 && (RxCurCount(iobase
, self
) != self
->RxLastCount
)) {
1326 upload_rxdata(self
, iobase
);
1327 if (irda_device_txqueue_empty(self
->netdev
))
1328 via_ircc_dma_receive(self
);
1330 } // timer detect complete
1332 SetTimer(iobase
, 4);
1340 * Function via_ircc_interrupt (irq, dev_id, regs)
1342 * An interrupt from the chip has arrived. Time to do some work
1345 static irqreturn_t
via_ircc_interrupt(int irq
, void *dev_id
,
1346 struct pt_regs
*regs
)
1348 struct net_device
*dev
= (struct net_device
*) dev_id
;
1349 struct via_ircc_cb
*self
;
1351 u8 iHostIntType
, iRxIntType
, iTxIntType
;
1354 IRDA_WARNING("%s: irq %d for unknown device.\n", driver_name
,
1358 self
= (struct via_ircc_cb
*) dev
->priv
;
1359 iobase
= self
->io
.fir_base
;
1360 spin_lock(&self
->lock
);
1361 iHostIntType
= GetHostStatus(iobase
);
1363 IRDA_DEBUG(4, "%s(): iHostIntType %02x: %s %s %s %02x\n",
1364 __FUNCTION__
, iHostIntType
,
1365 (iHostIntType
& 0x40) ? "Timer" : "",
1366 (iHostIntType
& 0x20) ? "Tx" : "",
1367 (iHostIntType
& 0x10) ? "Rx" : "",
1368 (iHostIntType
& 0x0e) >> 1);
1370 if ((iHostIntType
& 0x40) != 0) { //Timer Event
1371 self
->EventFlag
.TimeOut
++;
1372 ClearTimerInt(iobase
, 1);
1373 if (self
->io
.direction
== IO_XMIT
) {
1374 via_ircc_dma_xmit(self
, iobase
);
1376 if (self
->io
.direction
== IO_RECV
) {
1378 * frame ready hold too long, must reset.
1380 if (self
->RxDataReady
> 30) {
1382 if (irda_device_txqueue_empty(self
->netdev
)) {
1383 via_ircc_dma_receive(self
);
1385 } else { // call this to upload frame.
1386 RxTimerHandler(self
, iobase
);
1390 if ((iHostIntType
& 0x20) != 0) { //Tx Event
1391 iTxIntType
= GetTXStatus(iobase
);
1393 IRDA_DEBUG(4, "%s(): iTxIntType %02x: %s %s %s %s\n",
1394 __FUNCTION__
, iTxIntType
,
1395 (iTxIntType
& 0x08) ? "FIFO underr." : "",
1396 (iTxIntType
& 0x04) ? "EOM" : "",
1397 (iTxIntType
& 0x02) ? "FIFO ready" : "",
1398 (iTxIntType
& 0x01) ? "Early EOM" : "");
1400 if (iTxIntType
& 0x4) {
1401 self
->EventFlag
.EOMessage
++; // read and will auto clean
1402 if (via_ircc_dma_xmit_complete(self
)) {
1403 if (irda_device_txqueue_empty
1405 via_ircc_dma_receive(self
);
1408 self
->EventFlag
.Unknown
++;
1412 //----------------------------------------
1413 if ((iHostIntType
& 0x10) != 0) { //Rx Event
1414 /* Check if DMA has finished */
1415 iRxIntType
= GetRXStatus(iobase
);
1417 IRDA_DEBUG(4, "%s(): iRxIntType %02x: %s %s %s %s %s %s %s\n",
1418 __FUNCTION__
, iRxIntType
,
1419 (iRxIntType
& 0x80) ? "PHY err." : "",
1420 (iRxIntType
& 0x40) ? "CRC err" : "",
1421 (iRxIntType
& 0x20) ? "FIFO overr." : "",
1422 (iRxIntType
& 0x10) ? "EOF" : "",
1423 (iRxIntType
& 0x08) ? "RxData" : "",
1424 (iRxIntType
& 0x02) ? "RxMaxLen" : "",
1425 (iRxIntType
& 0x01) ? "SIR bad" : "");
1427 IRDA_DEBUG(3, "%s(): RxIRQ =0\n", __FUNCTION__
);
1429 if (iRxIntType
& 0x10) {
1430 if (via_ircc_dma_receive_complete(self
, iobase
)) {
1431 //F01 if(!(IsFIROn(iobase))) via_ircc_dma_receive(self);
1432 via_ircc_dma_receive(self
);
1436 IRDA_DEBUG(4, "%s(): RxIRQ ERR:iRxIntType=%x,HostIntType=%x,CurCount=%x,RxLastCount=%x_____\n",
1437 __FUNCTION__
, iRxIntType
, iHostIntType
,
1438 RxCurCount(iobase
, self
),
1441 if (iRxIntType
& 0x20) { //FIFO OverRun ERR
1442 ResetChip(iobase
, 0);
1443 ResetChip(iobase
, 1);
1444 } else { //PHY,CRC ERR
1446 if (iRxIntType
!= 0x08)
1447 hwreset(self
); //F01
1449 via_ircc_dma_receive(self
);
1453 spin_unlock(&self
->lock
);
1454 return IRQ_RETVAL(iHostIntType
);
1457 static void hwreset(struct via_ircc_cb
*self
)
1460 iobase
= self
->io
.fir_base
;
1462 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
1464 ResetChip(iobase
, 5);
1465 EnableDMA(iobase
, OFF
);
1466 EnableTX(iobase
, OFF
);
1467 EnableRX(iobase
, OFF
);
1468 EnRXDMA(iobase
, OFF
);
1469 EnTXDMA(iobase
, OFF
);
1470 RXStart(iobase
, OFF
);
1471 TXStart(iobase
, OFF
);
1474 SIRFilter(iobase
, ON
);
1478 WriteReg(iobase
, I_ST_CT_0
, 0x00);
1479 SetBaudRate(iobase
, 9600);
1480 SetPulseWidth(iobase
, 12);
1481 SetSendPreambleCount(iobase
, 0);
1482 WriteReg(iobase
, I_ST_CT_0
, 0x80);
1484 /* Restore speed. */
1485 via_ircc_change_speed(self
, self
->io
.speed
);
1487 self
->st_fifo
.len
= 0;
1491 * Function via_ircc_is_receiving (self)
1493 * Return TRUE is we are currently receiving a frame
1496 static int via_ircc_is_receiving(struct via_ircc_cb
*self
)
1501 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
1503 iobase
= self
->io
.fir_base
;
1504 if (CkRxRecv(iobase
, self
))
1507 IRDA_DEBUG(2, "%s(): status=%x....\n", __FUNCTION__
, status
);
1514 * Function via_ircc_net_open (dev)
1519 static int via_ircc_net_open(struct net_device
*dev
)
1521 struct via_ircc_cb
*self
;
1525 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
1527 IRDA_ASSERT(dev
!= NULL
, return -1;);
1528 self
= (struct via_ircc_cb
*) dev
->priv
;
1529 self
->stats
.rx_packets
= 0;
1530 IRDA_ASSERT(self
!= NULL
, return 0;);
1531 iobase
= self
->io
.fir_base
;
1532 if (request_irq(self
->io
.irq
, via_ircc_interrupt
, 0, dev
->name
, dev
)) {
1533 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name
,
1538 * Always allocate the DMA channel after the IRQ, and clean up on
1541 if (request_dma(self
->io
.dma
, dev
->name
)) {
1542 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name
,
1544 free_irq(self
->io
.irq
, self
);
1547 if (self
->io
.dma2
!= self
->io
.dma
) {
1548 if (request_dma(self
->io
.dma2
, dev
->name
)) {
1549 IRDA_WARNING("%s, unable to allocate dma2=%d\n",
1550 driver_name
, self
->io
.dma2
);
1551 free_irq(self
->io
.irq
, self
);
1557 /* turn on interrupts */
1558 EnAllInt(iobase
, ON
);
1559 EnInternalLoop(iobase
, OFF
);
1560 EnExternalLoop(iobase
, OFF
);
1563 via_ircc_dma_receive(self
);
1565 /* Ready to play! */
1566 netif_start_queue(dev
);
1569 * Open new IrLAP layer instance, now that everything should be
1570 * initialized properly
1572 sprintf(hwname
, "VIA @ 0x%x", iobase
);
1573 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1575 self
->RxLastCount
= 0;
1581 * Function via_ircc_net_close (dev)
1586 static int via_ircc_net_close(struct net_device
*dev
)
1588 struct via_ircc_cb
*self
;
1591 IRDA_DEBUG(3, "%s()\n", __FUNCTION__
);
1593 IRDA_ASSERT(dev
!= NULL
, return -1;);
1594 self
= (struct via_ircc_cb
*) dev
->priv
;
1595 IRDA_ASSERT(self
!= NULL
, return 0;);
1598 netif_stop_queue(dev
);
1599 /* Stop and remove instance of IrLAP */
1601 irlap_close(self
->irlap
);
1603 iobase
= self
->io
.fir_base
;
1604 EnTXDMA(iobase
, OFF
);
1605 EnRXDMA(iobase
, OFF
);
1606 DisableDmaChannel(self
->io
.dma
);
1608 /* Disable interrupts */
1609 EnAllInt(iobase
, OFF
);
1610 free_irq(self
->io
.irq
, dev
);
1611 free_dma(self
->io
.dma
);
1617 * Function via_ircc_net_ioctl (dev, rq, cmd)
1619 * Process IOCTL commands for this device
1622 static int via_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
1625 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
1626 struct via_ircc_cb
*self
;
1627 unsigned long flags
;
1630 IRDA_ASSERT(dev
!= NULL
, return -1;);
1632 IRDA_ASSERT(self
!= NULL
, return -1;);
1633 IRDA_DEBUG(1, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__
, dev
->name
,
1635 /* Disable interrupts & save flags */
1636 spin_lock_irqsave(&self
->lock
, flags
);
1638 case SIOCSBANDWIDTH
: /* Set bandwidth */
1639 if (!capable(CAP_NET_ADMIN
)) {
1643 via_ircc_change_speed(self
, irq
->ifr_baudrate
);
1645 case SIOCSMEDIABUSY
: /* Set media busy */
1646 if (!capable(CAP_NET_ADMIN
)) {
1650 irda_device_set_media_busy(self
->netdev
, TRUE
);
1652 case SIOCGRECEIVING
: /* Check if we are receiving right now */
1653 irq
->ifr_receiving
= via_ircc_is_receiving(self
);
1659 spin_unlock_irqrestore(&self
->lock
, flags
);
1663 static struct net_device_stats
*via_ircc_net_get_stats(struct net_device
1666 struct via_ircc_cb
*self
= (struct via_ircc_cb
*) dev
->priv
;
1668 return &self
->stats
;
1671 MODULE_AUTHOR("VIA Technologies,inc");
1672 MODULE_DESCRIPTION("VIA IrDA Device Driver");
1673 MODULE_LICENSE("GPL");
1675 module_init(via_ircc_init
);
1676 module_exit(via_ircc_cleanup
);