Import 2.3.4pre3
[davej-history.git] / drivers / net / irda / uircc.c
blobf3454c531d94e92d66f0888b423e8ac3adc39fa4
1 /*********************************************************************
2 *
3 * Filename: uircc.c
4 * Version: 0.3
5 * Description: Driver for the Sharp Universal Infrared
6 * Communications Controller (UIRCC v 1.3)
7 * Status: Experimental.
8 * Author: Dag Brattli <dagb@cs.uit.no>
9 * Created at: Sat Dec 26 10:59:03 1998
10 * Modified at: Mon May 10 22:11:09 1999
11 * Modified by: Dag Brattli <dagb@cs.uit.no>
13 * Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * Neither Dag Brattli nor University of Tromsø admit liability nor
21 * provide warranty for any of this software. This material is
22 * provided "AS-IS" and at no charge.
24 * Applicable Models : Tecra 510CDT, 500C Series, 530CDT, 520CDT,
25 * 740CDT, Portege 300CT, 660CDT, Satellite 220C Series,
26 * Satellite Pro, 440C Series, 470CDT, 460C Series, 480C Series
28 ********************************************************************/
30 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/skbuff.h>
35 #include <linux/netdevice.h>
36 #include <linux/ioport.h>
37 #include <linux/delay.h>
38 #include <linux/malloc.h>
39 #include <linux/delay.h>
40 #include <linux/init.h>
41 #include <linux/init.h>
43 #include <asm/io.h>
44 #include <asm/dma.h>
45 #include <asm/byteorder.h>
47 #include <net/irda/wrapper.h>
48 #include <net/irda/irda.h>
49 #include <net/irda/irmod.h>
50 #include <net/irda/irlap_frame.h>
51 #include <net/irda/irda_device.h>
53 #include <net/irda/uircc.h>
54 #include <net/irda/irport.h>
56 static char *driver_name = "uircc";
58 #define CHIP_IO_EXTENT 16
60 static unsigned int io[] = { 0x300, ~0, ~0, ~0 };
61 static unsigned int io2[] = { 0x3e8, 0, 0, 0};
62 static unsigned int irq[] = { 11, 0, 0, 0 };
63 static unsigned int dma[] = { 5, 0, 0, 0 };
65 static struct uircc_cb *dev_self[] = { NULL, NULL, NULL, NULL};
67 /* Some prototypes */
68 static int uircc_open(int i, unsigned int iobase, unsigned int board_addr,
69 unsigned int irq, unsigned int dma);
70 #ifdef MODULE
71 static int uircc_close(struct irda_device *idev);
72 #endif /* MODULE */
73 static int uircc_probe(int iobase, int board_addr, int irq, int dma);
74 static int uircc_dma_receive(struct irda_device *idev);
75 static int uircc_dma_receive_complete(struct irda_device *idev, int iobase);
76 static int uircc_hard_xmit(struct sk_buff *skb, struct device *dev);
77 static void uircc_dma_write(struct irda_device *idev, int iobase);
78 static void uircc_change_speed(struct irda_device *idev, int baud);
79 static void uircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
80 static void uircc_wait_until_sent(struct irda_device *idev);
81 static int uircc_is_receiving(struct irda_device *idev);
82 static int uircc_toshiba_cmd(int *retval, int arg0, int arg1, int arg2);
83 static int uircc_net_init(struct device *dev);
84 static int uircc_net_open(struct device *dev);
85 static int uircc_net_close(struct device *dev);
88 * Function uircc_init ()
90 * Initialize chip. Just try to find out how many chips we are dealing with
91 * and where they are
93 __initfunc(int uircc_init(void))
95 int i;
97 for ( i=0; (io[i] < 2000) && (i < 4); i++) {
98 int ioaddr = io[i];
99 if (check_region(ioaddr, CHIP_IO_EXTENT) < 0)
100 continue;
101 if (uircc_open(i, io[i], io2[i], irq[i], dma[i]) == 0)
102 return 0;
104 return -ENODEV;
108 * Function uircc_cleanup ()
110 * Close all configured chips
113 #ifdef MODULE
114 static void uircc_cleanup(void)
116 int i;
118 DEBUG(4, __FUNCTION__ "()\n");
120 for (i=0; i < 4; i++) {
121 if (dev_self[i])
122 uircc_close(&(dev_self[i]->idev));
125 #endif /* MODULE */
128 * Function uircc_open (iobase, irq)
130 * Open driver instance
133 static int uircc_open(int i, unsigned int iobase, unsigned int iobase2,
134 unsigned int irq, unsigned int dma)
136 struct uircc_cb *self;
137 struct irda_device *idev;
138 int ret;
140 DEBUG(4, __FUNCTION__ "()\n");
142 if ((uircc_probe(iobase, iobase2, irq, dma)) == -1)
143 return -1;
146 * Allocate new instance of the driver
148 self = kmalloc( sizeof(struct uircc_cb), GFP_KERNEL);
149 if (self == NULL) {
150 printk(KERN_ERR "IrDA: Can't allocate memory for "
151 "IrDA control block!\n");
152 return -ENOMEM;
154 memset(self, 0, sizeof(struct uircc_cb));
156 /* Need to store self somewhere */
157 dev_self[i] = self;
159 idev = &self->idev;
161 /* Initialize IO */
162 idev->io.iobase = iobase;
163 idev->io.iobase2 = iobase2; /* Used by irport */
164 idev->io.irq = irq;
165 idev->io.io_ext = CHIP_IO_EXTENT;
166 idev->io.io_ext2 = 8; /* Used by irport */
167 idev->io.dma = dma;
168 idev->io.fifo_size = 16;
170 /* Lock the port that we need */
171 ret = check_region(idev->io.iobase, idev->io.io_ext);
172 if (ret < 0) {
173 DEBUG(0, __FUNCTION__ "(), can't get iobase of 0x%03x\n",
174 idev->io.iobase);
175 /* uircc_cleanup( self->idev); */
176 return -ENODEV;
178 ret = check_region(idev->io.iobase2, idev->io.io_ext2);
179 if (ret < 0) {
180 DEBUG(0, __FUNCTION__ "(), can't get iobase of 0x%03x\n",
181 idev->io.iobase2);
182 /* uircc_cleanup( self->idev); */
183 return -ENODEV;
185 request_region(idev->io.iobase, idev->io.io_ext, idev->name);
186 request_region(idev->io.iobase2, idev->io.io_ext2, idev->name);
188 /* Initialize QoS for this device */
189 irda_init_max_qos_capabilies(&idev->qos);
191 /* The only value we must override it the baudrate */
192 idev->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
193 IR_115200/*IR_576000|IR_1152000 |(IR_4000000 << 8)*/;
195 idev->qos.min_turn_time.bits = 0x0f;
196 irda_qos_bits_to_value(&idev->qos);
198 idev->flags = IFF_FIR|IFF_SIR|IFF_DMA|IFF_PIO;
200 /* Specify which buffer allocation policy we need */
201 idev->rx_buff.flags = GFP_KERNEL | GFP_DMA;
202 idev->tx_buff.flags = GFP_KERNEL | GFP_DMA;
204 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
205 idev->rx_buff.truesize = 4000;
206 idev->tx_buff.truesize = 4000;
208 /* Initialize callbacks */
209 idev->change_speed = uircc_change_speed;
210 idev->wait_until_sent = uircc_wait_until_sent;
211 idev->is_receiving = uircc_is_receiving;
213 /* Override the network functions we need to use */
214 idev->netdev.init = uircc_net_init;
215 idev->netdev.hard_start_xmit = uircc_hard_xmit;
216 idev->netdev.open = uircc_net_open;
217 idev->netdev.stop = uircc_net_close;
219 irport_start(iobase2);
221 /* Open the IrDA device */
222 irda_device_open(idev, driver_name, self);
224 return 0;
228 * Function uircc_close (idev)
230 * Close driver instance
233 #ifdef MODULE
234 static int uircc_close(struct irda_device *idev)
236 struct uircc_cb *self;
237 int iobase;
238 int status;
240 DEBUG(4, __FUNCTION__ "()\n");
242 ASSERT(idev != NULL, return -1;);
243 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return -1;);
245 iobase = idev->io.iobase;
246 self = (struct uircc_cb *) idev->priv;
248 /* Some magic to disable FIR and enable SIR */
249 uircc_toshiba_cmd(&status, 0xffff, 0x001b, 0x0000);
251 /* Disable modem */
252 outb(0x00, iobase+UIRCC_CR10);
254 irport_stop(idev->io.iobase2);
256 /* Release the PORT that this driver is using */
257 DEBUG(4, __FUNCTION__ "(), Releasing Region %03x\n", idev->io.iobase);
258 release_region(idev->io.iobase, idev->io.io_ext);
260 if (idev->io.iobase2) {
261 DEBUG(4, __FUNCTION__ "(), Releasing Region %03x\n",
262 idev->io.iobase2);
263 release_region(idev->io.iobase2, idev->io.io_ext2);
265 irda_device_close(idev);
267 kfree(self);
269 return 0;
271 #endif /* MODULE */
274 * Function uircc_probe (iobase, board_addr, irq, dma)
276 * Returns non-negative on success.
279 static int uircc_probe(int iobase, int iobase2, int irq, int dma)
281 int version;
283 DEBUG(4, __FUNCTION__ "()\n");
285 /* read the chip version, should be 0x03 */
286 version = inb(iobase+UIRCC_SR8);
288 if (version != 0x03) {
289 DEBUG(0, __FUNCTION__ "(), Wrong chip version");
290 return -1;
292 printk(KERN_INFO "Sharp UIRCC IrDA driver loaded. Version: 0x%02x\n",
293 version);
295 /* Reset chip */
296 outb(UIRCC_CR0_SYS_RST, iobase+UIRCC_CR0);
298 /* Initialize some registers */
299 outb(0x03, iobase+UIRCC_CR15);
300 outb(0, iobase+UIRCC_CR11);
301 outb(0, iobase+UIRCC_CR9);
303 DEBUG(0, __FUNCTION__ "(), sr15=%#x\n", inb(iobase+UIRCC_SR15));
305 /* Enable DMA single mode */
306 outb(UIRCC_CR1_RX_DMA|UIRCC_CR1_TX_DMA|UIRCC_CR1_MUST_SET,
307 iobase+UIRCC_CR1);
309 /* Disable interrupts */
310 outb(0xff, iobase+UIRCC_CR2);
312 /* Set self poll address */
314 return 0;
318 * Function uircc_change_speed (idev, baud)
320 * Change the speed of the device
323 static void uircc_change_speed(struct irda_device *idev, int speed)
325 struct uircc_cb *self;
326 int iobase;
327 int modem = UIRCC_CR10_SIR;
328 int status;
330 DEBUG(0, __FUNCTION__ "()\n");
332 /* Just test the high speed stuff */
333 /*speed = 4000000;*/
335 ASSERT(idev != NULL, return;);
336 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
338 self = idev->priv;
339 iobase = idev->io.iobase;
341 /* Update accounting for new speed */
342 idev->io.baudrate = speed;
344 /* Disable interrupts */
345 outb(0xff, iobase+UIRCC_CR2);
347 switch (speed) {
348 case 9600:
349 case 19200:
350 case 37600:
351 case 57600:
352 case 115200:
353 irport_start(idev->io.iobase2);
354 irport_change_speed(idev, speed);
356 /* Some magic to disable FIR and enable SIR */
357 uircc_toshiba_cmd(&status, 0xffff, 0x001b, 0x0000);
359 modem = UIRCC_CR10_SIR;
360 break;
361 case 576000:
363 DEBUG(0, __FUNCTION__ "(), handling baud of 576000\n");
364 break;
365 case 1152000:
367 DEBUG(0, __FUNCTION__ "(), handling baud of 1152000\n");
368 break;
369 case 4000000:
370 irport_stop(idev->io.iobase2);
372 /* Some magic to disable SIR and enable FIR */
373 uircc_toshiba_cmd(&status, 0xffff, 0x001b, 0x0001);
375 modem = UIRCC_CR10_FIR;
376 DEBUG(0, __FUNCTION__ "(), handling baud of 4000000\n");
378 /* Set self pole address */
379 //outb(0xfe, iobase+UIRCC_CR8);
381 /* outb(0x10, iobase+UIRCC_CR11); */
382 break;
383 default:
384 DEBUG( 0, __FUNCTION__ "(), unknown baud rate of %d\n", speed);
385 break;
388 /* Set appropriate speed mode */
389 outb(modem, iobase+UIRCC_CR10);
391 idev->netdev.tbusy = 0;
393 /* Enable some interrupts so we can receive frames */
394 if (speed > 115200) {
395 /* Enable DMA single mode */
396 outb(UIRCC_CR1_RX_DMA|UIRCC_CR1_TX_DMA|UIRCC_CR1_MUST_SET,
397 iobase+UIRCC_CR1);
399 /* Enable all interrupts */
400 outb(0, iobase+UIRCC_CR2);
401 uircc_dma_receive(idev);
406 * Function uircc_hard_xmit (skb, dev)
408 * Transmit the frame!
411 static int uircc_hard_xmit(struct sk_buff *skb, struct device *dev)
413 struct irda_device *idev;
414 int iobase;
415 int mtt;
417 idev = (struct irda_device *) dev->priv;
419 ASSERT(idev != NULL, return 0;);
420 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return 0;);
422 iobase = idev->io.iobase;
424 DEBUG(4, __FUNCTION__ "(%ld), skb->len=%d\n", jiffies, (int) skb->len);
426 /* Reset carrier latch */
427 /*outb(0x02, iobase+UIRCC_CR0);*/
429 /* Use irport for SIR speeds */
430 if (idev->io.baudrate <= 115200) {
431 return irport_hard_xmit(skb, dev);
434 DEBUG(0, __FUNCTION__ "(), sr0=%#x, sr1=%#x, sr2=%#x, sr3=%#x, sr10=%#x, sr11=%#x\n",
435 inb(iobase+UIRCC_SR0), inb(iobase+UIRCC_SR3),
436 inb(iobase+UIRCC_SR2), inb(iobase+UIRCC_SR3),
437 inb(iobase+UIRCC_SR10), inb(iobase+UIRCC_SR11));
439 /* Lock transmit buffer */
440 if (irda_lock((void *) &dev->tbusy) == FALSE)
441 return -EBUSY;
443 memcpy(idev->tx_buff.data, skb->data, skb->len);
445 /* Make sure that the length is a multiple of 16 bits */
446 if (skb->len & 0x01)
447 skb->len++;
449 idev->tx_buff.len = skb->len;
450 idev->tx_buff.data = idev->tx_buff.head;
452 mtt = irda_get_mtt(skb);
454 /* Use udelay for delays less than 50 us. */
455 if (mtt)
456 udelay(mtt);
458 /* Enable transmit interrupts */
459 outb(0, iobase+UIRCC_CR2);
461 uircc_dma_write(idev, iobase);
463 dev_kfree_skb(skb);
465 return 0;
469 * Function uircc_dma_write (idev, iobase)
471 * Transmit data using DMA
474 static void uircc_dma_write(struct irda_device *idev, int iobase)
476 struct uircc_cb *self;
478 DEBUG(4, __FUNCTION__ "()\n");
480 ASSERT(idev != NULL, return;);
481 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
483 self = idev->priv;
485 /* Receiving disable */
486 self->cr3 &= ~UIRCC_CR3_RECV_EN;
487 outb(self->cr3, iobase+UIRCC_CR3);
489 /* Set modem */
490 outb(0x80, iobase+UIRCC_CR10);
492 /* Enable transmit DMA */
493 outb(UIRCC_CR1_TX_DMA|UIRCC_CR1_MUST_SET, iobase+UIRCC_CR1);
495 ASSERT((((__u32)(idev->tx_buff.data)) & 0x01) != 0x01, return;);
497 setup_dma(idev->io.dma, idev->tx_buff.data, idev->tx_buff.len,
498 DMA_MODE_WRITE);
500 idev->io.direction = IO_XMIT;
502 /* Set frame length (should be the real length without padding */
503 outb(idev->tx_buff.len & 0xff, iobase+UIRCC_CR4); /* Low byte */
504 outb(idev->tx_buff.len >> 8, iobase+UIRCC_CR5); /* High byte */
506 /* Enable transmit and transmit CRC */
507 self->cr3 |= (UIRCC_CR3_XMIT_EN|UIRCC_CR3_TX_CRC_EN);
508 outb(self->cr3, iobase+UIRCC_CR3);
512 * Function uircc_dma_xmit_complete (idev)
514 * The transfer of a frame in finished. This function will only be called
515 * by the interrupt handler
518 static void uircc_dma_xmit_complete( struct irda_device *idev, int underrun)
520 struct uircc_cb *self;
521 int iobase;
522 int len;
524 DEBUG(4, __FUNCTION__ "()\n");
526 ASSERT(idev != NULL, return;);
527 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
529 self = idev->priv;
531 iobase = idev->io.iobase;
533 /* Select TX counter */
534 outb(UIRCC_CR0_CNT_SWT, iobase+UIRCC_CR0);
536 /* Read TX length counter */
537 len = inb(iobase+UIRCC_SR4); /* Low byte */
538 len |= inb(iobase+UIRCC_SR5) << 8; /* High byte */
540 DEBUG(4, __FUNCTION__ "(), sent %d bytes\n", len);
542 /* Disable transmit */
543 self->cr3 &= ~UIRCC_CR3_XMIT_EN;
544 outb(self->cr3, iobase+UIRCC_CR3);
546 /* Transmit reset (just to be sure) */
547 outb(UIRCC_CR0_XMIT_RST, iobase+UIRCC_CR0);
549 /* Check for underrrun! */
550 if (underrun) {
551 idev->stats.tx_errors++;
552 idev->stats.tx_fifo_errors++;
553 } else {
554 idev->stats.tx_packets++;
555 idev->stats.tx_bytes += idev->tx_buff.len;
558 /* Unlock tx_buff and request another frame */
559 idev->netdev.tbusy = 0; /* Unlock */
560 idev->media_busy = FALSE;
562 /* Tell the network layer, that we can accept more frames */
563 mark_bh(NET_BH);
567 * Function uircc_dma_receive (idev)
569 * Get ready for receiving a frame. The device will initiate a DMA
570 * if it starts to receive a frame.
573 static int uircc_dma_receive(struct irda_device *idev)
575 struct uircc_cb *self;
576 int iobase;
578 ASSERT(idev != NULL, return -1;);
579 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return -1;);
581 DEBUG(4, __FUNCTION__ "\n");
583 self = idev->priv;
584 iobase= idev->io.iobase;
586 /* Transmit disable */
587 /* self->cr3 &= ~UIRCC_CR3_XMIT_EN; */
588 self->cr3 = 0;
589 outb(self->cr3, iobase+UIRCC_CR3);
591 /* Transmit reset (just in case) */
592 outb(UIRCC_CR0_XMIT_RST|0x17, iobase+UIRCC_CR0);
594 /* Set modem */
595 outb(0x08, iobase+UIRCC_CR10);
597 /* Enable receiving with CRC */
598 self->cr3 = (UIRCC_CR3_RECV_EN|UIRCC_CR3_RX_CRC_EN);
599 outb(self->cr3, iobase+UIRCC_CR3);
601 /* Make sure Rx DMA is set */
602 outb(UIRCC_CR1_RX_DMA|UIRCC_CR1_MUST_SET, iobase+UIRCC_CR1);
604 /* Rx reset */
605 /* outb(UIRCC_CR0_RECV_RST, iobase+UIRCC_CR0); */
607 setup_dma(idev->io.dma, idev->rx_buff.data,
608 idev->rx_buff.truesize, DMA_MODE_READ);
610 /* driver->media_busy = FALSE; */
611 idev->io.direction = IO_RECV;
612 idev->rx_buff.data = idev->rx_buff.head;
614 #if 0
615 /* Enable receiving with CRC */
616 self->cr3 = (UIRCC_CR3_RECV_EN|UIRCC_CR3_RX_CRC_EN);
617 outb(self->cr3, iobase+UIRCC_CR3);
618 #endif
619 DEBUG(4, __FUNCTION__ "(), cr3=%#x\n", self->cr3);
621 /* Address check? */
623 return 0;
627 * Function uircc_dma_receive_complete (idev)
629 * Finished with receiving frames
633 static int uircc_dma_receive_complete(struct irda_device *idev, int iobase)
635 struct sk_buff *skb;
636 struct uircc_cb *self;
637 int len;
639 self = idev->priv;
641 DEBUG(0, __FUNCTION__ "()\n");
643 /* Check for CRC or framing error */
644 if (inb(iobase+UIRCC_SR0) & UIRCC_SR0_RX_CRCFRM) {
645 DEBUG(0, __FUNCTION__ "(), CRC or FRAME error\n");
646 return -1;
649 /* Select receive length counter */
650 outb(0x00, iobase+UIRCC_CR0);
652 /* Read frame length */
653 len = inb(iobase+UIRCC_SR4); /* Low byte */
654 len |= inb(iobase+UIRCC_SR5) << 8; /* High byte */
656 DEBUG(0, __FUNCTION__ "(), len=%d\n", len);
658 /* Receiving disable */
659 self->cr3 &= ~UIRCC_CR3_RECV_EN;
660 outb(self->cr3, iobase+UIRCC_CR3);
662 skb = dev_alloc_skb(len+1);
663 if (skb == NULL) {
664 printk(KERN_INFO __FUNCTION__
665 "(), memory squeeze, dropping frame.\n");
666 /* Restore bank register */
667 return FALSE;
670 /* Make sure IP header gets aligned */
671 skb_reserve(skb, 1);
673 /* Copy frame without CRC */
674 /* if ( idev->io.baudrate < 4000000) { */
675 /* skb_put( skb, len-2); */
676 /* memcpy( skb->data, idev->rx_buff.head, len-2); */
677 /* } else { */
678 /* skb_put( skb, len-4); */
679 /* memcpy( skb->data, idev->rx_buff.head, len-4); */
680 /* } */
682 skb_put(skb, len);
683 memcpy(skb->data, idev->rx_buff.data, len);
684 idev->stats.rx_packets++;
686 skb->dev = &idev->netdev;
687 skb->mac.raw = skb->data;
688 skb->protocol = htons(ETH_P_IRDA);
689 netif_rx(skb);
691 return TRUE;
695 * Function uircc_interrupt (irq, dev_id, regs)
697 * An interrupt from the chip has arrived. Time to do some work
700 static void uircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
702 __u8 sr3;
703 int iobase;
705 struct irda_device *idev = (struct irda_device *) dev_id;
707 if (idev == NULL) {
708 printk( KERN_WARNING "%s: irq %d for unknown device.\n",
709 driver_name, irq);
710 return;
713 if (idev->io.baudrate <= 115200)
714 return irport_interrupt( irq, dev_id, regs);
716 iobase = idev->io.iobase;
718 /* Read interrupt status */
719 sr3 = inb( iobase+UIRCC_SR3);
720 if (!sr3) {
721 DEBUG(4,"**\n");
722 return;
724 idev->netdev.interrupt = 1;
726 DEBUG(4, __FUNCTION__ "(), sr3=%#x, sr2=%#x, sr10=%#x\n",
727 inb( iobase+UIRCC_SR3), inb( iobase+UIRCC_SR2),
728 inb( iobase+UIRCC_SR10));
731 * Check what interrupt this is. The UIRCC will not report two
732 * different interrupts at the same time!
734 switch(sr3) {
735 case UIRCC_SR3_RX_EOF: /* Check for end of frame */
736 uircc_dma_receive_complete(idev, iobase);
737 break;
738 case UIRCC_SR3_TXUR: /* Check for transmit underrun */
739 uircc_dma_xmit_complete(idev, TRUE);
740 uircc_dma_receive(idev);
741 outb(0, iobase+UIRCC_CR2);
742 break;
743 case UIRCC_SR3_TX_DONE:
744 uircc_dma_xmit_complete(idev, FALSE);
745 uircc_dma_receive(idev);
747 outb(0x0d, iobase+UIRCC_CR2);
748 break;
749 case UIRCC_SR3_TMR_OUT:
750 /* Disable timer */
751 outb(inb(iobase+UIRCC_CR11) & ~UIRCC_CR11_TMR_EN,
752 iobase+UIRCC_CR11);
753 break;
754 default:
755 DEBUG(0, __FUNCTION__ "(), unknown interrupt status=%#x\n",
756 sr3);
757 break;
759 idev->netdev.interrupt = 0;
763 * Function uircc_wait_until_sent (idev)
765 * This function should put the current thread to sleep until all data
766 * have been sent, so it is safe to change the speed.
768 static void uircc_wait_until_sent( struct irda_device *idev)
770 /* Just delay 60 ms */
771 current->state = TASK_INTERRUPTIBLE;
772 schedule_timeout(6);
776 * Function uircc_is_receiving (idev)
778 * Return TRUE is we are currently receiving a frame
781 static int uircc_is_receiving( struct irda_device *idev)
783 int status = FALSE;
784 /* int iobase; */
786 ASSERT(idev != NULL, return FALSE;);
787 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return FALSE;);
789 if (idev->io.baudrate > 115200) {
791 } else
792 status = (idev->rx_buff.state != OUTSIDE_FRAME);
794 return status;
798 * Function uircc_net_init (dev)
800 * Initialize network device
803 static int uircc_net_init( struct device *dev)
805 DEBUG( 4, __FUNCTION__ "()\n");
807 /* Setup to be a normal IrDA network device driver */
808 irda_device_setup(dev);
810 /* Insert overrides below this line! */
812 return 0;
817 * Function uircc_net_open (dev)
819 * Start the device
822 static int uircc_net_open(struct device *dev)
824 struct irda_device *idev;
825 int iobase;
827 DEBUG( 4, __FUNCTION__ "()\n");
829 ASSERT(dev != NULL, return -1;);
830 idev = (struct irda_device *) dev->priv;
832 ASSERT(idev != NULL, return 0;);
833 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return 0;);
835 iobase = idev->io.iobase;
837 if (request_irq(idev->io.irq, uircc_interrupt, 0, idev->name,
838 (void *) idev)) {
839 return -EAGAIN;
842 * Always allocate the DMA channel after the IRQ,
843 * and clean up on failure.
845 if (request_dma(idev->io.dma, idev->name)) {
846 free_irq(idev->io.irq, idev);
847 return -EAGAIN;
850 /* Ready to play! */
851 dev->tbusy = 0;
852 dev->interrupt = 0;
853 dev->start = 1;
855 /* turn on interrupts */
857 MOD_INC_USE_COUNT;
859 return 0;
863 * Function uircc_net_close (dev)
865 * Stop the device
868 static int uircc_net_close(struct device *dev)
870 struct irda_device *idev;
871 int iobase;
873 DEBUG(4, __FUNCTION__ "()\n");
875 /* Stop device */
876 dev->tbusy = 1;
877 dev->start = 0;
879 ASSERT(dev != NULL, return -1;);
880 idev = (struct irda_device *) dev->priv;
882 ASSERT(idev != NULL, return 0;);
883 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return 0;);
885 iobase = idev->io.iobase;
887 disable_dma(idev->io.dma);
889 /* Disable interrupts */
891 free_irq(idev->io.irq, idev);
892 free_dma(idev->io.dma);
894 MOD_DEC_USE_COUNT;
896 return 0;
900 * Function uircc_toshiba_cmd (arg0, arg1, arg2)
902 * disable FIR: uircc_toshiba_cmd(&status, 0xffff, 0x001b, 0x0000);
903 * enable FIR: uircc_toshiba_cmd(&status, 0xffff, 0x001b, 0x0001);
904 * IRDA status: uircc_toshiba_cmd(&status, 0xfefe, 0x001b, 0x0000);
906 static int uircc_toshiba_cmd(int *retval, int arg0, int arg1, int arg2)
908 char return_code = 0;
910 __asm__ volatile ("inb $0xb2,%%al; "
911 "movb %%ah,%%al; "
912 : /* Output */
913 "=al" (return_code),
914 "=ecx" (*retval)
915 : /* Input */
916 "ax" (arg0),
917 "bx" (arg1),
918 "cx" (arg2)
921 * Return
922 * 0x00 = OK
923 * 0x80 = Function not supported by system
924 * 0x83 = Input data error
926 return (int) return_code;
929 #ifdef MODULE
932 * Function init_module (void)
937 int init_module(void)
939 return uircc_init();
943 * Function cleanup_module (void)
948 void cleanup_module(void)
950 uircc_cleanup();
952 #endif /* MODULE */