1 /*********************************************************************
5 * Description: Half duplex serial port SIR driver for IrDA.
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Aug 3 13:49:59 1997
9 * Modified at: Fri Jan 28 20:22:38 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 * Sources: serial.c by Linus Torvalds
13 * Copyright (c) 1997, 1998, 1999-2000 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 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * This driver is ment to be a small half duplex serial driver to be
31 * used for IR-chipsets that has a UART (16550) compatibility mode.
32 * Eventually it will replace irtty, because of irtty has some
33 * problems that is hard to get around when we don't have control
34 * over the serial driver. This driver may also be used by FIR
35 * drivers to handle SIR mode for them.
37 ********************************************************************/
39 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/types.h>
43 #include <linux/ioport.h>
44 #include <linux/malloc.h>
45 #include <linux/string.h>
46 #include <linux/skbuff.h>
47 #include <linux/serial_reg.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/spinlock.h>
51 #include <linux/rtnetlink.h>
53 #include <asm/system.h>
54 #include <asm/bitops.h>
57 #include <net/irda/irda.h>
58 #include <net/irda/irmod.h>
59 #include <net/irda/wrapper.h>
60 #include <net/irda/irport.h>
65 * Currently you'll need to set these values using insmod like this:
66 * insmod irport io=0x3e8 irq=11
68 static unsigned int io
[] = { ~0, ~0, ~0, ~0 };
69 static unsigned int irq
[] = { 0, 0, 0, 0 };
71 static unsigned int qos_mtt_bits
= 0x03;
73 static struct irport_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
};
74 static char *driver_name
= "irport";
76 static void irport_write_wakeup(struct irport_cb
*self
);
77 static int irport_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
78 static void irport_receive(struct irport_cb
*self
);
80 static int irport_net_init(struct net_device
*dev
);
81 static int irport_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
,
83 static int irport_is_receiving(struct irport_cb
*self
);
84 static int irport_set_dtr_rts(struct net_device
*dev
, int dtr
, int rts
);
85 static int irport_raw_write(struct net_device
*dev
, __u8
*buf
, int len
);
86 static struct net_device_stats
*irport_net_get_stats(struct net_device
*dev
);
87 static int irport_change_speed_complete(struct irda_task
*task
);
88 static void irport_timeout(struct net_device
*dev
);
90 EXPORT_SYMBOL(irport_open
);
91 EXPORT_SYMBOL(irport_close
);
92 EXPORT_SYMBOL(irport_start
);
93 EXPORT_SYMBOL(irport_stop
);
94 EXPORT_SYMBOL(irport_interrupt
);
95 EXPORT_SYMBOL(irport_hard_xmit
);
96 EXPORT_SYMBOL(irport_timeout
);
97 EXPORT_SYMBOL(irport_change_speed
);
98 EXPORT_SYMBOL(irport_net_open
);
99 EXPORT_SYMBOL(irport_net_close
);
101 int __init
irport_init(void)
105 for (i
=0; (io
[i
] < 2000) && (i
< 4); i
++) {
107 if (check_region(ioaddr
, IO_EXTENT
))
109 if (irport_open(i
, io
[i
], irq
[i
]) != NULL
)
113 * Maybe something failed, but we can still be usable for FIR drivers
119 * Function irport_cleanup ()
121 * Close all configured ports
125 static void irport_cleanup(void)
129 IRDA_DEBUG( 4, __FUNCTION__
"()\n");
131 for (i
=0; i
< 4; i
++) {
133 irport_close(dev_self
[i
]);
139 irport_open(int i
, unsigned int iobase
, unsigned int irq
)
141 struct net_device
*dev
;
142 struct irport_cb
*self
;
146 IRDA_DEBUG(0, __FUNCTION__
"()\n");
149 * Allocate new instance of the driver
151 self
= kmalloc(sizeof(struct irport_cb
), GFP_KERNEL
);
153 ERROR(__FUNCTION__
"(), can't allocate memory for "
157 memset(self
, 0, sizeof(struct irport_cb
));
158 spin_lock_init(&self
->lock
);
160 /* Need to store self somewhere */
166 self
->io
.sir_base
= iobase
;
167 self
->io
.sir_ext
= IO_EXTENT
;
169 self
->io
.fifo_size
= 16;
171 /* Lock the port that we need */
172 ret
= check_region(self
->io
.sir_base
, self
->io
.sir_ext
);
174 IRDA_DEBUG(0, __FUNCTION__
"(), can't get iobase of 0x%03x\n",
178 request_region(self
->io
.sir_base
, self
->io
.sir_ext
, driver_name
);
180 /* Initialize QoS for this device */
181 irda_init_max_qos_capabilies(&self
->qos
);
183 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
186 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
187 irda_qos_bits_to_value(&self
->qos
);
189 self
->flags
= IFF_SIR
|IFF_PIO
;
191 /* Specify how much memory we want */
192 self
->rx_buff
.truesize
= 4000;
193 self
->tx_buff
.truesize
= 4000;
195 /* Allocate memory if needed */
196 if (self
->rx_buff
.truesize
> 0) {
197 self
->rx_buff
.head
= (__u8
*) kmalloc(self
->rx_buff
.truesize
,
199 if (self
->rx_buff
.head
== NULL
)
201 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
203 if (self
->tx_buff
.truesize
> 0) {
204 self
->tx_buff
.head
= (__u8
*) kmalloc(self
->tx_buff
.truesize
,
206 if (self
->tx_buff
.head
== NULL
) {
207 kfree(self
->rx_buff
.head
);
210 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
212 self
->rx_buff
.in_frame
= FALSE
;
213 self
->rx_buff
.state
= OUTSIDE_FRAME
;
214 self
->tx_buff
.data
= self
->tx_buff
.head
;
215 self
->rx_buff
.data
= self
->rx_buff
.head
;
216 self
->mode
= IRDA_IRLAP
;
218 if (!(dev
= dev_alloc("irda%d", &err
))) {
219 ERROR(__FUNCTION__
"(), dev_alloc() failed!\n");
224 /* May be overridden by piggyback drivers */
225 dev
->priv
= (void *) self
;
226 self
->interrupt
= irport_interrupt
;
227 self
->change_speed
= irport_change_speed
;
229 /* Override the network functions we need to use */
230 dev
->init
= irport_net_init
;
231 dev
->hard_start_xmit
= irport_hard_xmit
;
232 dev
->tx_timeout
= irport_timeout
;
233 dev
->watchdog_timeo
= HZ
; /* Allow time enough for speed change */
234 dev
->open
= irport_net_open
;
235 dev
->stop
= irport_net_close
;
236 dev
->get_stats
= irport_net_get_stats
;
237 dev
->do_ioctl
= irport_net_ioctl
;
239 /* Make ifconfig display some details */
240 dev
->base_addr
= iobase
;
244 err
= register_netdevice(dev
);
247 ERROR(__FUNCTION__
"(), register_netdev() failed!\n");
250 MESSAGE("IrDA: Registered device %s\n", dev
->name
);
255 int irport_close(struct irport_cb
*self
)
257 ASSERT(self
!= NULL
, return -1;);
259 /* We are not using any dongle anymore! */
261 irda_device_dongle_cleanup(self
->dongle
);
264 /* Remove netdevice */
267 unregister_netdevice(self
->netdev
);
271 /* Release the IO-port that this driver is using */
272 IRDA_DEBUG(0 , __FUNCTION__
"(), Releasing Region %03x\n",
274 release_region(self
->io
.sir_base
, self
->io
.sir_ext
);
276 if (self
->tx_buff
.head
)
277 kfree(self
->tx_buff
.head
);
279 if (self
->rx_buff
.head
)
280 kfree(self
->rx_buff
.head
);
282 /* Remove ourselves */
283 dev_self
[self
->index
] = NULL
;
289 void irport_start(struct irport_cb
*self
)
294 iobase
= self
->io
.sir_base
;
296 spin_lock_irqsave(&self
->lock
, flags
);
300 /* Initialize UART */
301 outb(UART_LCR_WLEN8
, iobase
+UART_LCR
); /* Reset DLAB */
302 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), iobase
+UART_MCR
);
304 /* Turn on interrups */
305 outb(UART_IER_RLSI
| UART_IER_RDI
|UART_IER_THRI
, iobase
+UART_IER
);
307 spin_unlock_irqrestore(&self
->lock
, flags
);
310 void irport_stop(struct irport_cb
*self
)
315 iobase
= self
->io
.sir_base
;
317 spin_lock_irqsave(&self
->lock
, flags
);
320 outb(0, iobase
+UART_MCR
);
322 /* Turn off interrupts */
323 outb(0, iobase
+UART_IER
);
325 spin_unlock_irqrestore(&self
->lock
, flags
);
329 * Function irport_probe (void)
334 int irport_probe(int iobase
)
336 IRDA_DEBUG(4, __FUNCTION__
"(), iobase=%#x\n", iobase
);
342 * Function irport_change_speed (self, speed)
344 * Set speed of IrDA port to specified baudrate
347 void irport_change_speed(void *priv
, __u32 speed
)
349 struct irport_cb
*self
= (struct irport_cb
*) priv
;
352 int fcr
; /* FIFO control reg */
353 int lcr
; /* Line control reg */
356 IRDA_DEBUG(2, __FUNCTION__
"(), Setting speed to: %d\n", speed
);
358 ASSERT(self
!= NULL
, return;);
360 iobase
= self
->io
.sir_base
;
362 /* Update accounting for new speed */
363 self
->io
.speed
= speed
;
365 spin_lock_irqsave(&self
->lock
, flags
);
367 /* Turn off interrupts */
368 outb(0, iobase
+UART_IER
);
370 divisor
= SPEED_MAX
/speed
;
372 fcr
= UART_FCR_ENABLE_FIFO
;
375 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
376 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
377 * about this timeout since it will always be fast enough.
379 if (self
->io
.speed
< 38400)
380 fcr
|= UART_FCR_TRIGGER_1
;
382 fcr
|= UART_FCR_TRIGGER_14
;
384 /* IrDA ports use 8N1 */
385 lcr
= UART_LCR_WLEN8
;
387 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
388 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
389 outb(divisor
>> 8, iobase
+UART_DLM
);
390 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
391 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
393 /* Turn on interrups */
394 outb(/*UART_IER_RLSI|*/UART_IER_RDI
/*|UART_IER_THRI*/, iobase
+UART_IER
);
396 spin_unlock_irqrestore(&self
->lock
, flags
);
400 * Function __irport_change_speed (instance, state, param)
402 * State machine for changing speed of the device. We do it this way since
403 * we cannot use schedule_timeout() when we are in interrupt context
405 int __irport_change_speed(struct irda_task
*task
)
407 struct irport_cb
*self
;
408 __u32 speed
= (__u32
) task
->param
;
411 IRDA_DEBUG(2, __FUNCTION__
"(), <%ld>\n", jiffies
);
413 self
= (struct irport_cb
*) task
->instance
;
415 ASSERT(self
!= NULL
, return -1;);
417 switch (task
->state
) {
420 /* Are we ready to change speed yet? */
421 if (self
->tx_buff
.len
> 0) {
422 task
->state
= IRDA_TASK_WAIT
;
424 /* Try again later */
425 ret
= MSECS_TO_JIFFIES(20);
430 irda_task_next_state(task
, IRDA_TASK_CHILD_INIT
);
432 irda_task_next_state(task
, IRDA_TASK_CHILD_DONE
);
434 case IRDA_TASK_CHILD_INIT
:
435 /* Go to default speed */
436 self
->change_speed(self
->priv
, 9600);
438 /* Change speed of dongle */
439 if (irda_task_execute(self
->dongle
,
440 self
->dongle
->issue
->change_speed
,
441 NULL
, task
, (void *) speed
))
443 /* Dongle need more time to change its speed */
444 irda_task_next_state(task
, IRDA_TASK_CHILD_WAIT
);
446 /* Give dongle 1 sec to finish */
447 ret
= MSECS_TO_JIFFIES(1000);
449 /* Child finished immediately */
450 irda_task_next_state(task
, IRDA_TASK_CHILD_DONE
);
452 case IRDA_TASK_CHILD_WAIT
:
454 "(), changing speed of dongle timed out!\n");
457 case IRDA_TASK_CHILD_DONE
:
458 /* Finally we are ready to change the speed */
459 self
->change_speed(self
->priv
, speed
);
461 irda_task_next_state(task
, IRDA_TASK_DONE
);
464 ERROR(__FUNCTION__
"(), unknown state %d\n", task
->state
);
465 irda_task_next_state(task
, IRDA_TASK_DONE
);
473 * Function irport_write_wakeup (tty)
475 * Called by the driver when there's room for more data. If we have
476 * more packets to send, we send them here.
479 static void irport_write_wakeup(struct irport_cb
*self
)
485 ASSERT(self
!= NULL
, return;);
487 IRDA_DEBUG(4, __FUNCTION__
"()\n");
489 iobase
= self
->io
.sir_base
;
491 /* Finished with frame? */
492 if (self
->tx_buff
.len
> 0) {
493 /* Write data left in transmit buffer */
494 actual
= irport_write(iobase
, self
->io
.fifo_size
,
495 self
->tx_buff
.data
, self
->tx_buff
.len
);
496 self
->tx_buff
.data
+= actual
;
497 self
->tx_buff
.len
-= actual
;
500 * Now serial buffer is almost free & we can start
501 * transmission of another packet. But first we must check
502 * if we need to change the speed of the hardware
504 if (self
->new_speed
) {
505 IRDA_DEBUG(5, __FUNCTION__
"(), Changing speed!\n");
506 irda_task_execute(self
, __irport_change_speed
,
507 irport_change_speed_complete
,
508 NULL
, (void *) self
->new_speed
);
511 /* Tell network layer that we want more frames */
512 netif_wake_queue(self
->netdev
);
514 self
->stats
.tx_packets
++;
517 * Reset Rx FIFO to make sure that all reflected transmit data
518 * is discarded. This is needed for half duplex operation
520 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
;
521 if (self
->io
.speed
< 38400)
522 fcr
|= UART_FCR_TRIGGER_1
;
524 fcr
|= UART_FCR_TRIGGER_14
;
526 outb(fcr
, iobase
+UART_FCR
);
528 /* Turn on receive interrupts */
529 outb(UART_IER_RDI
, iobase
+UART_IER
);
534 * Function irport_write (driver)
536 * Fill Tx FIFO with transmit data
539 static int irport_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
543 /* Tx FIFO should be empty! */
544 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
545 IRDA_DEBUG(0, __FUNCTION__
"(), failed, fifo not empty!\n");
549 /* Fill FIFO with current frame */
550 while ((fifo_size
-- > 0) && (actual
< len
)) {
551 /* Transmit next byte */
552 outb(buf
[actual
], iobase
+UART_TX
);
561 * Function irport_change_speed_complete (task)
563 * Called when the change speed operation completes
566 static int irport_change_speed_complete(struct irda_task
*task
)
568 struct irport_cb
*self
;
570 IRDA_DEBUG(0, __FUNCTION__
"()\n");
572 self
= (struct irport_cb
*) task
->instance
;
574 ASSERT(self
!= NULL
, return -1;);
575 ASSERT(self
->netdev
!= NULL
, return -1;);
577 /* Finished changing speed, so we are not busy any longer */
578 /* Signal network layer so it can try to send the frame */
580 netif_wake_queue(self
->netdev
);
586 * Function irport_timeout (struct net_device *dev)
588 * The networking layer thinks we timed out.
592 static void irport_timeout(struct net_device
*dev
)
594 struct irport_cb
*self
;
597 self
= (struct irport_cb
*) dev
->priv
;
598 iobase
= self
->io
.sir_base
;
600 WARNING("%s: transmit timed out\n", dev
->name
);
602 self
->change_speed(self
->priv
, self
->io
.speed
);
603 dev
->trans_start
= jiffies
;
604 netif_wake_queue(dev
);
608 * Function irport_hard_start_xmit (struct sk_buff *skb, struct net_device *dev)
610 * Transmits the current frame until FIFO is full, then
611 * waits until the next transmitt interrupt, and continues until the
612 * frame is transmited.
614 int irport_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
616 struct irport_cb
*self
;
621 ASSERT(dev
!= NULL
, return 0;);
623 self
= (struct irport_cb
*) dev
->priv
;
624 ASSERT(self
!= NULL
, return 0;);
626 iobase
= self
->io
.sir_base
;
628 netif_stop_queue(dev
);
630 /* Check if we need to change the speed */
631 if ((speed
= irda_get_speed(skb
)) != self
->io
.speed
) {
632 /* Check for empty frame */
634 irda_task_execute(self
, __irport_change_speed
,
635 irport_change_speed_complete
,
636 NULL
, (void *) speed
);
639 self
->new_speed
= speed
;
642 spin_lock_irqsave(&self
->lock
, flags
);
645 self
->tx_buff
.data
= self
->tx_buff
.head
;
647 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
648 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
649 self
->tx_buff
.truesize
);
651 self
->stats
.tx_bytes
+= self
->tx_buff
.len
;
653 /* Turn on transmit finished interrupt. Will fire immediately! */
654 outb(UART_IER_THRI
, iobase
+UART_IER
);
656 spin_unlock_irqrestore(&self
->lock
, flags
);
664 * Function irport_receive (self)
666 * Receive one frame from the infrared port
669 static void irport_receive(struct irport_cb
*self
)
674 ASSERT(self
!= NULL
, return;);
676 iobase
= self
->io
.sir_base
;
679 * Receive all characters in Rx FIFO, unwrap and unstuff them.
680 * async_unwrap_char will deliver all found frames
683 async_unwrap_char(self
->netdev
, &self
->stats
, &self
->rx_buff
,
684 inb(iobase
+UART_RX
));
686 /* Make sure we don't stay here to long */
687 if (boguscount
++ > 32) {
688 IRDA_DEBUG(2,__FUNCTION__
"(), breaking!\n");
691 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
695 * Function irport_interrupt (irq, dev_id, regs)
699 void irport_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
701 struct net_device
*dev
= (struct net_device
*) dev_id
;
702 struct irport_cb
*self
;
708 WARNING(__FUNCTION__
"() irq %d for unknown device.\n", irq
);
711 self
= (struct irport_cb
*) dev
->priv
;
713 spin_lock(&self
->lock
);
715 iobase
= self
->io
.sir_base
;
717 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
719 /* Clear interrupt */
720 lsr
= inb(iobase
+UART_LSR
);
722 IRDA_DEBUG(4, __FUNCTION__
723 "(), iir=%02x, lsr=%02x, iobase=%#x\n",
728 IRDA_DEBUG(2, __FUNCTION__
"(), RLSI\n");
731 /* Receive interrupt */
732 irport_receive(self
);
735 if (lsr
& UART_LSR_THRE
)
736 /* Transmitter ready for data */
737 irport_write_wakeup(self
);
740 IRDA_DEBUG(0, __FUNCTION__
"(), unhandled IIR=%#x\n", iir
);
744 /* Make sure we don't stay here to long */
745 if (boguscount
++ > 100)
748 iir
= inb(iobase
+ UART_IIR
) & UART_IIR_ID
;
750 spin_unlock(&self
->lock
);
753 static int irport_net_init(struct net_device
*dev
)
755 /* Set up to be a normal IrDA network device driver */
756 irda_device_setup(dev
);
758 /* Insert overrides below this line! */
764 * Function irport_net_open (dev)
766 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
769 int irport_net_open(struct net_device
*dev
)
771 struct irport_cb
*self
;
774 ASSERT(dev
!= NULL
, return -1;);
775 self
= (struct irport_cb
*) dev
->priv
;
777 iobase
= self
->io
.sir_base
;
779 if (request_irq(self
->io
.irq
, self
->interrupt
, 0, dev
->name
,
787 * Open new IrLAP layer instance, now that everything should be
788 * initialized properly
790 self
->irlap
= irlap_open(dev
, &self
->qos
);
792 /* FIXME: change speed of dongle */
795 netif_start_queue(dev
);
803 * Function irport_net_close (self)
805 * Network device is taken down. Usually this is done by
806 * "ifconfig irda0 down"
808 int irport_net_close(struct net_device
*dev
)
810 struct irport_cb
*self
;
813 IRDA_DEBUG(4, __FUNCTION__
"()\n");
815 ASSERT(dev
!= NULL
, return -1;);
816 self
= (struct irport_cb
*) dev
->priv
;
818 ASSERT(self
!= NULL
, return -1;);
820 iobase
= self
->io
.sir_base
;
823 netif_stop_queue(dev
);
825 /* Stop and remove instance of IrLAP */
827 irlap_close(self
->irlap
);
832 free_irq(self
->io
.irq
, dev
);
840 * Function irport_wait_until_sent (self)
842 * Delay exectution until finished transmitting
846 void irport_wait_until_sent(struct irport_cb
*self
)
850 iobase
= self
->io
.sir_base
;
852 /* Wait until Tx FIFO is empty */
853 while (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
854 IRDA_DEBUG(2, __FUNCTION__
"(), waiting!\n");
855 current
->state
= TASK_INTERRUPTIBLE
;
856 schedule_timeout(MSECS_TO_JIFFIES(60));
862 * Function irport_is_receiving (self)
864 * Returns true is we are currently receiving data
867 static int irport_is_receiving(struct irport_cb
*self
)
869 return (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
873 * Function irport_set_dtr_rts (tty, dtr, rts)
875 * This function can be used by dongles etc. to set or reset the status
876 * of the dtr and rts lines
878 static int irport_set_dtr_rts(struct net_device
*dev
, int dtr
, int rts
)
880 struct irport_cb
*self
= dev
->priv
;
883 ASSERT(self
!= NULL
, return -1;);
885 iobase
= self
->io
.sir_base
;
892 outb(dtr
|rts
|UART_MCR_OUT2
, iobase
+UART_MCR
);
897 static int irport_raw_write(struct net_device
*dev
, __u8
*buf
, int len
)
899 struct irport_cb
*self
= (struct irport_cb
*) dev
->priv
;
903 ASSERT(self
!= NULL
, return -1;);
905 iobase
= self
->io
.sir_base
;
907 /* Tx FIFO should be empty! */
908 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
909 IRDA_DEBUG( 0, __FUNCTION__
"(), failed, fifo not empty!\n");
913 /* Fill FIFO with current frame */
914 while (actual
< len
) {
915 /* Transmit next byte */
916 outb(buf
[actual
], iobase
+UART_TX
);
924 * Function irport_net_ioctl (dev, rq, cmd)
926 * Process IOCTL commands for this device
929 static int irport_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
931 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
932 struct irport_cb
*self
;
937 ASSERT(dev
!= NULL
, return -1;);
941 ASSERT(self
!= NULL
, return -1;);
943 IRDA_DEBUG(2, __FUNCTION__
"(), %s, (cmd=0x%X)\n", dev
->name
, cmd
);
945 /* Disable interrupts & save flags */
950 case SIOCSBANDWIDTH
: /* Set bandwidth */
951 if (!capable(CAP_NET_ADMIN
))
953 irda_task_execute(self
, __irport_change_speed
, NULL
, NULL
,
954 (void *) irq
->ifr_baudrate
);
956 case SIOCSDONGLE
: /* Set dongle */
957 if (!capable(CAP_NET_ADMIN
))
959 /* Initialize dongle */
960 dongle
= irda_device_dongle_init(dev
, irq
->ifr_dongle
);
964 dongle
->set_mode
= NULL
;
966 dongle
->write
= irport_raw_write
;
967 dongle
->set_dtr_rts
= irport_set_dtr_rts
;
969 self
->dongle
= dongle
;
971 /* Now initialize the dongle! */
972 dongle
->issue
->open(dongle
, &self
->qos
);
975 irda_task_execute(dongle
, dongle
->issue
->reset
, NULL
, NULL
,
978 case SIOCSMEDIABUSY
: /* Set media busy */
979 if (!capable(CAP_NET_ADMIN
))
981 irda_device_set_media_busy(self
->netdev
, TRUE
);
983 case SIOCGRECEIVING
: /* Check if we are receiving right now */
984 irq
->ifr_receiving
= irport_is_receiving(self
);
987 if (!capable(CAP_NET_ADMIN
))
989 irport_set_dtr_rts(dev
, irq
->ifr_dtr
, irq
->ifr_rts
);
995 restore_flags(flags
);
1000 static struct net_device_stats
*irport_net_get_stats(struct net_device
*dev
)
1002 struct irport_cb
*self
= (struct irport_cb
*) dev
->priv
;
1004 return &self
->stats
;
1008 MODULE_PARM(io
, "1-4i");
1009 MODULE_PARM_DESC(io
, "Base I/O adresses");
1010 MODULE_PARM(irq
, "1-4i");
1011 MODULE_PARM_DESC(irq
, "IRQ lines");
1013 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1014 MODULE_DESCRIPTION("Half duplex serial driver for IrDA SIR mode");
1016 void cleanup_module(void)
1021 int init_module(void)
1023 return irport_init();