1 /*****************************************************************************
5 * Description: Irda SigmaTel USB Dongle
7 * Author: Stephen Hemminger <shemminger@osdl.org>
9 * Based on earlier driver by Paul Stewart <stewart@parc.com>
11 * Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
12 * Copyright (C) 2001, Dag Brattli <dag@brattli.net>
13 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
14 * Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *****************************************************************************/
32 * This dongle does no framing, and requires polling to receive the
33 * data. The STIr4200 has bulk in and out endpoints just like
34 * usr-irda devices, but the data it sends and receives is raw; like
35 * irtty, it needs to call the wrap and unwrap functions to add and
36 * remove SOF/BOF and escape characters to/from the frame.
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
42 #include <linux/kernel.h>
43 #include <linux/types.h>
44 #include <linux/init.h>
45 #include <linux/time.h>
46 #include <linux/skbuff.h>
47 #include <linux/netdevice.h>
48 #include <linux/slab.h>
49 #include <linux/delay.h>
50 #include <linux/usb.h>
51 #include <linux/crc32.h>
52 #include <linux/kthread.h>
53 #include <linux/freezer.h>
54 #include <net/irda/irda.h>
55 #include <net/irda/irlap.h>
56 #include <net/irda/irda_device.h>
57 #include <net/irda/wrapper.h>
58 #include <net/irda/crc.h>
59 #include <asm/byteorder.h>
60 #include <asm/unaligned.h>
62 MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
63 MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200");
64 MODULE_LICENSE("GPL");
66 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
67 module_param(qos_mtt_bits
, int, 0);
68 MODULE_PARM_DESC(qos_mtt_bits
, "Minimum Turn Time");
70 static int rx_sensitivity
= 1; /* FIR 0..4, SIR 0..6 */
71 module_param(rx_sensitivity
, int, 0);
72 MODULE_PARM_DESC(rx_sensitivity
, "Set Receiver sensitivity (0-6, 0 is most sensitive)");
74 static int tx_power
= 0; /* 0 = highest ... 3 = lowest */
75 module_param(tx_power
, int, 0);
76 MODULE_PARM_DESC(tx_power
, "Set Transmitter power (0-3, 0 is highest power)");
78 #define STIR_IRDA_HEADER 4
79 #define CTRL_TIMEOUT 100 /* milliseconds */
80 #define TRANSMIT_TIMEOUT 200 /* milliseconds */
81 #define STIR_FIFO_SIZE 4096
82 #define FIFO_REGS_SIZE 3
94 REQ_WRITE_SINGLE
= 0x03,
97 /* Register offsets */
123 PDCLK_4000000
= 0x02,
141 CTRL2_SPWIDTH
= 0x08,
145 enum StirFifoCtlMask
{
147 FIFOCTL_UNDER
= 0x40,
151 FIFOCTL_EMPTY
= 0x04,
168 struct usb_device
*usbdev
; /* init: probe_irda */
169 struct net_device
*netdev
; /* network layer */
170 struct irlap_cb
*irlap
; /* The link layer we are binded to */
171 struct net_device_stats stats
; /* network statistics */
173 unsigned speed
; /* Current speed */
175 struct task_struct
*thread
; /* transmit thread */
177 struct sk_buff
*tx_pending
;
178 void *io_buf
; /* transmit/receive buffer */
181 iobuff_t rx_buff
; /* receive unwrap state machine */
182 struct timeval rx_time
;
188 /* These are the currently known USB ids */
189 static struct usb_device_id dongles
[] = {
190 /* SigmaTel, Inc, STIr4200 IrDA/USB Bridge */
191 { USB_DEVICE(0x066f, 0x4200) },
195 MODULE_DEVICE_TABLE(usb
, dongles
);
197 /* Send control message to set dongle register */
198 static int write_reg(struct stir_cb
*stir
, __u16 reg
, __u8 value
)
200 struct usb_device
*dev
= stir
->usbdev
;
202 pr_debug("%s: write reg %d = 0x%x\n",
203 stir
->netdev
->name
, reg
, value
);
204 return usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
206 USB_DIR_OUT
|USB_TYPE_VENDOR
|USB_RECIP_DEVICE
,
211 /* Send control message to read multiple registers */
212 static inline int read_reg(struct stir_cb
*stir
, __u16 reg
,
213 __u8
*data
, __u16 count
)
215 struct usb_device
*dev
= stir
->usbdev
;
217 return usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0),
219 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
224 static inline int isfir(u32 speed
)
226 return (speed
== 4000000);
230 * Prepare a FIR IrDA frame for transmission to the USB dongle. The
231 * FIR transmit frame is documented in the datasheet. It consists of
232 * a two byte 0x55 0xAA sequence, two little-endian length bytes, a
233 * sequence of exactly 16 XBOF bytes of 0x7E, two BOF bytes of 0x7E,
234 * then the data escaped as follows:
240 * Then, 4 bytes of little endian (stuffed) FCS follow, then two
241 * trailing EOF bytes of 0x7E.
243 static inline __u8
*stuff_fir(__u8
*p
, __u8 c
)
258 /* Take raw data in skb and put it wrapped into buf */
259 static unsigned wrap_fir_skb(const struct sk_buff
*skb
, __u8
*buf
)
262 __u32 fcs
= ~(crc32_le(~0, skb
->data
, skb
->len
));
270 ptr
= buf
+ STIR_IRDA_HEADER
;
271 memset(ptr
, 0x7f, 16);
278 /* Address / Control / Information */
279 for (i
= 0; i
< skb
->len
; i
++)
280 ptr
= stuff_fir(ptr
, skb
->data
[i
]);
283 ptr
= stuff_fir(ptr
, fcs
& 0xff);
284 ptr
= stuff_fir(ptr
, (fcs
>> 8) & 0xff);
285 ptr
= stuff_fir(ptr
, (fcs
>> 16) & 0xff);
286 ptr
= stuff_fir(ptr
, (fcs
>> 24) & 0xff);
292 /* Total length, minus the header */
293 wraplen
= (ptr
- buf
) - STIR_IRDA_HEADER
;
294 buf
[2] = wraplen
& 0xff;
295 buf
[3] = (wraplen
>> 8) & 0xff;
297 return wraplen
+ STIR_IRDA_HEADER
;
300 static unsigned wrap_sir_skb(struct sk_buff
*skb
, __u8
*buf
)
304 wraplen
= async_wrap_skb(skb
, buf
+ STIR_IRDA_HEADER
,
305 STIR_FIFO_SIZE
- STIR_IRDA_HEADER
);
308 buf
[2] = wraplen
& 0xff;
309 buf
[3] = (wraplen
>> 8) & 0xff;
311 return wraplen
+ STIR_IRDA_HEADER
;
315 * Frame is fully formed in the rx_buff so check crc
316 * and pass up to irlap
317 * setup for next receive
319 static void fir_eof(struct stir_cb
*stir
)
321 iobuff_t
*rx_buff
= &stir
->rx_buff
;
322 int len
= rx_buff
->len
- 4;
323 struct sk_buff
*skb
, *nskb
;
326 if (unlikely(len
<= 0)) {
327 pr_debug("%s: short frame len %d\n",
328 stir
->netdev
->name
, len
);
330 ++stir
->stats
.rx_errors
;
331 ++stir
->stats
.rx_length_errors
;
335 fcs
= ~(crc32_le(~0, rx_buff
->data
, len
));
336 if (fcs
!= le32_to_cpu(get_unaligned((u32
*)(rx_buff
->data
+len
)))) {
337 pr_debug("crc error calc 0x%x len %d\n", fcs
, len
);
338 stir
->stats
.rx_errors
++;
339 stir
->stats
.rx_crc_errors
++;
343 /* if frame is short then just copy it */
344 if (len
< IRDA_RX_COPY_THRESHOLD
) {
345 nskb
= dev_alloc_skb(len
+ 1);
346 if (unlikely(!nskb
)) {
347 ++stir
->stats
.rx_dropped
;
350 skb_reserve(nskb
, 1);
352 memcpy(nskb
->data
, rx_buff
->data
, len
);
354 nskb
= dev_alloc_skb(rx_buff
->truesize
);
355 if (unlikely(!nskb
)) {
356 ++stir
->stats
.rx_dropped
;
359 skb_reserve(nskb
, 1);
362 rx_buff
->head
= nskb
->data
;
367 skb
->mac
.raw
= skb
->data
;
368 skb
->protocol
= htons(ETH_P_IRDA
);
369 skb
->dev
= stir
->netdev
;
373 stir
->stats
.rx_packets
++;
374 stir
->stats
.rx_bytes
+= len
;
376 rx_buff
->data
= rx_buff
->head
;
380 /* Unwrap FIR stuffed data and bump it to IrLAP */
381 static void stir_fir_chars(struct stir_cb
*stir
,
382 const __u8
*bytes
, int len
)
384 iobuff_t
*rx_buff
= &stir
->rx_buff
;
387 for (i
= 0; i
< len
; i
++) {
388 __u8 byte
= bytes
[i
];
390 switch(rx_buff
->state
) {
392 /* ignore garbage till start of frame */
393 if (unlikely(byte
!= FIR_EOF
))
395 /* Now receiving frame */
396 rx_buff
->state
= BEGIN_FRAME
;
398 /* Time to initialize receive buffer */
399 rx_buff
->data
= rx_buff
->head
;
404 if (byte
== FIR_EOF
) {
405 pr_debug("%s: got EOF after escape\n",
409 rx_buff
->state
= INSIDE_FRAME
;
414 /* ignore multiple BOF/EOF */
417 rx_buff
->state
= INSIDE_FRAME
;
418 rx_buff
->in_frame
= TRUE
;
424 rx_buff
->state
= LINK_ESCAPE
;
427 /* 0x7f is not used in this framing */
428 pr_debug("%s: got XBOF without escape\n",
432 rx_buff
->state
= OUTSIDE_FRAME
;
433 rx_buff
->in_frame
= FALSE
;
440 /* add byte to rx buffer */
441 if (unlikely(rx_buff
->len
>= rx_buff
->truesize
)) {
442 pr_debug("%s: fir frame exceeds %d\n",
443 stir
->netdev
->name
, rx_buff
->truesize
);
444 ++stir
->stats
.rx_over_errors
;
448 rx_buff
->data
[rx_buff
->len
++] = byte
;
452 ++stir
->stats
.rx_frame_errors
;
455 ++stir
->stats
.rx_errors
;
456 rx_buff
->state
= OUTSIDE_FRAME
;
457 rx_buff
->in_frame
= FALSE
;
461 /* Unwrap SIR stuffed data and bump it up to IrLAP */
462 static void stir_sir_chars(struct stir_cb
*stir
,
463 const __u8
*bytes
, int len
)
467 for (i
= 0; i
< len
; i
++)
468 async_unwrap_char(stir
->netdev
, &stir
->stats
,
469 &stir
->rx_buff
, bytes
[i
]);
472 static inline void unwrap_chars(struct stir_cb
*stir
,
473 const __u8
*bytes
, int length
)
475 if (isfir(stir
->speed
))
476 stir_fir_chars(stir
, bytes
, length
);
478 stir_sir_chars(stir
, bytes
, length
);
481 /* Mode parameters for each speed */
482 static const struct {
486 { 2400, PDCLK_2400
},
487 { 9600, PDCLK_9600
},
488 { 19200, PDCLK_19200
},
489 { 38400, PDCLK_38400
},
490 { 57600, PDCLK_57600
},
491 { 115200, PDCLK_115200
},
492 { 4000000, PDCLK_4000000
},
497 * Setup chip for speed.
498 * Called at startup to initialize the chip
499 * and on speed changes.
501 * Note: Write multiple registers doesn't appear to work
503 static int change_speed(struct stir_cb
*stir
, unsigned speed
)
508 for (i
= 0; i
< ARRAY_SIZE(stir_modes
); ++i
) {
509 if (speed
== stir_modes
[i
].speed
)
513 warn("%s: invalid speed %d", stir
->netdev
->name
, speed
);
517 pr_debug("speed change from %d to %d\n", stir
->speed
, speed
);
519 /* Reset modulator */
520 err
= write_reg(stir
, REG_CTRL1
, CTRL1_SRESET
);
524 /* Undocumented magic to tweak the DPLL */
525 err
= write_reg(stir
, REG_DPLL
, 0x15);
530 err
= write_reg(stir
, REG_PDCLK
, stir_modes
[i
].pdclk
);
534 mode
= MODE_NRESET
| MODE_FASTRX
;
536 mode
|= MODE_FIR
| MODE_FFRSTEN
;
543 err
= write_reg(stir
, REG_MODE
, mode
);
547 /* This resets TEMIC style transceiver if any. */
548 err
= write_reg(stir
, REG_CTRL1
,
549 CTRL1_SDMODE
| (tx_power
& 3) << 1);
553 err
= write_reg(stir
, REG_CTRL1
, (tx_power
& 3) << 1);
557 /* Reset sensitivity */
558 err
= write_reg(stir
, REG_CTRL2
, (rx_sensitivity
& 7) << 5);
565 * Called from net/core when new frame is available.
567 static int stir_hard_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
569 struct stir_cb
*stir
= netdev_priv(netdev
);
571 netif_stop_queue(netdev
);
573 /* the IRDA wrapping routines don't deal with non linear skb */
574 SKB_LINEAR_ASSERT(skb
);
576 skb
= xchg(&stir
->tx_pending
, skb
);
577 wake_up_process(stir
->thread
);
579 /* this should never happen unless stop/wakeup problem */
589 * Wait for the transmit FIFO to have space for next data
591 * If space < 0 then wait till FIFO completely drains.
592 * FYI: can take up to 13 seconds at 2400baud.
594 static int fifo_txwait(struct stir_cb
*stir
, int space
)
597 unsigned long count
, status
;
599 /* Read FIFO status and count */
601 err
= read_reg(stir
, REG_FIFOCTL
, stir
->fifo_status
,
603 if (unlikely(err
!= FIFO_REGS_SIZE
)) {
604 warn("%s: FIFO register read error: %d",
605 stir
->netdev
->name
, err
);
610 status
= stir
->fifo_status
[0];
611 count
= (unsigned)(stir
->fifo_status
[2] & 0x1f) << 8
612 | stir
->fifo_status
[1];
614 pr_debug("fifo status 0x%lx count %lu\n", status
, count
);
616 /* is fifo receiving already, or empty */
617 if (!(status
& FIFOCTL_DIR
)
618 || (status
& FIFOCTL_EMPTY
))
621 if (signal_pending(current
))
625 if (!netif_running(stir
->netdev
)
626 || !netif_device_present(stir
->netdev
))
629 /* only waiting for some space */
630 if (space
>= 0 && STIR_FIFO_SIZE
- 4 > space
+ count
)
633 /* estimate transfer time for remaining chars */
634 msleep((count
* 8000) / stir
->speed
);
637 err
= write_reg(stir
, REG_FIFOCTL
, FIFOCTL_CLR
);
640 err
= write_reg(stir
, REG_FIFOCTL
, 0);
648 /* Wait for turnaround delay before starting transmit. */
649 static void turnaround_delay(const struct stir_cb
*stir
, long us
)
657 do_gettimeofday(&now
);
658 if (now
.tv_sec
- stir
->rx_time
.tv_sec
> 0)
660 us
-= now
.tv_usec
- stir
->rx_time
.tv_usec
;
664 ticks
= us
/ (1000000 / HZ
);
666 schedule_timeout_interruptible(1 + ticks
);
672 * Start receiver by submitting a request to the receive pipe.
673 * If nothing is available it will return after rx_interval.
675 static int receive_start(struct stir_cb
*stir
)
680 stir
->rx_buff
.in_frame
= FALSE
;
681 stir
->rx_buff
.state
= OUTSIDE_FRAME
;
683 stir
->rx_urb
->status
= 0;
684 return usb_submit_urb(stir
->rx_urb
, GFP_KERNEL
);
687 /* Stop all pending receive Urb's */
688 static void receive_stop(struct stir_cb
*stir
)
691 usb_kill_urb(stir
->rx_urb
);
693 if (stir
->rx_buff
.in_frame
)
694 stir
->stats
.collisions
++;
697 * Wrap data in socket buffer and send it.
699 static void stir_send(struct stir_cb
*stir
, struct sk_buff
*skb
)
704 /* if receiving, need to turnaround */
705 if (stir
->receiving
) {
707 turnaround_delay(stir
, irda_get_mtt(skb
));
711 if (isfir(stir
->speed
))
712 wraplen
= wrap_fir_skb(skb
, stir
->io_buf
);
714 wraplen
= wrap_sir_skb(skb
, stir
->io_buf
);
716 /* check for space available in fifo */
718 fifo_txwait(stir
, wraplen
);
720 stir
->stats
.tx_packets
++;
721 stir
->stats
.tx_bytes
+= skb
->len
;
722 stir
->netdev
->trans_start
= jiffies
;
723 pr_debug("send %d (%d)\n", skb
->len
, wraplen
);
725 if (usb_bulk_msg(stir
->usbdev
, usb_sndbulkpipe(stir
->usbdev
, 1),
726 stir
->io_buf
, wraplen
,
727 NULL
, TRANSMIT_TIMEOUT
))
728 stir
->stats
.tx_errors
++;
732 * Transmit state machine thread
734 static int stir_transmit_thread(void *arg
)
736 struct stir_cb
*stir
= arg
;
737 struct net_device
*dev
= stir
->netdev
;
740 while (!kthread_should_stop()) {
742 /* if suspending, then power off and wait */
743 if (unlikely(freezing(current
))) {
747 fifo_txwait(stir
, -1);
749 write_reg(stir
, REG_CTRL1
, CTRL1_TXPWD
|CTRL1_RXPWD
);
753 if (change_speed(stir
, stir
->speed
))
758 /* if something to send? */
759 skb
= xchg(&stir
->tx_pending
, NULL
);
761 unsigned new_speed
= irda_get_next_speed(skb
);
762 netif_wake_queue(dev
);
765 stir_send(stir
, skb
);
768 if ((new_speed
!= -1) && (stir
->speed
!= new_speed
)) {
769 if (fifo_txwait(stir
, -1) ||
770 change_speed(stir
, new_speed
))
776 /* nothing to send? start receiving */
778 && irda_device_txqueue_empty(dev
)) {
779 /* Wait otherwise chip gets confused. */
780 if (fifo_txwait(stir
, -1))
783 if (unlikely(receive_start(stir
))) {
785 info("%s: receive usb submit failed",
793 /* sleep if nothing to send */
794 set_current_state(TASK_INTERRUPTIBLE
);
803 * USB bulk receive completion callback.
804 * Wakes up every ms (usb round trip) with wrapped
807 static void stir_rcv_irq(struct urb
*urb
)
809 struct stir_cb
*stir
= urb
->context
;
812 /* in process of stopping, just drop data */
813 if (!netif_running(stir
->netdev
))
816 /* unlink, shutdown, unplug, other nasties */
817 if (urb
->status
!= 0)
820 if (urb
->actual_length
> 0) {
821 pr_debug("receive %d\n", urb
->actual_length
);
822 unwrap_chars(stir
, urb
->transfer_buffer
,
825 stir
->netdev
->last_rx
= jiffies
;
826 do_gettimeofday(&stir
->rx_time
);
829 /* kernel thread is stopping receiver don't resubmit */
830 if (!stir
->receiving
)
833 /* resubmit existing urb */
834 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
836 /* in case of error, the kernel thread will restart us */
838 warn("%s: usb receive submit error: %d",
839 stir
->netdev
->name
, err
);
841 wake_up_process(stir
->thread
);
846 * Function stir_net_open (dev)
848 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
850 static int stir_net_open(struct net_device
*netdev
)
852 struct stir_cb
*stir
= netdev_priv(netdev
);
856 err
= usb_clear_halt(stir
->usbdev
, usb_sndbulkpipe(stir
->usbdev
, 1));
859 err
= usb_clear_halt(stir
->usbdev
, usb_rcvbulkpipe(stir
->usbdev
, 2));
863 err
= change_speed(stir
, 9600);
869 /* Initialize for SIR/FIR to copy data directly into skb. */
871 stir
->rx_buff
.truesize
= IRDA_SKB_MAX_MTU
;
872 stir
->rx_buff
.skb
= dev_alloc_skb(IRDA_SKB_MAX_MTU
);
873 if (!stir
->rx_buff
.skb
)
876 skb_reserve(stir
->rx_buff
.skb
, 1);
877 stir
->rx_buff
.head
= stir
->rx_buff
.skb
->data
;
878 do_gettimeofday(&stir
->rx_time
);
880 stir
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
884 stir
->io_buf
= kmalloc(STIR_FIFO_SIZE
, GFP_KERNEL
);
888 usb_fill_bulk_urb(stir
->rx_urb
, stir
->usbdev
,
889 usb_rcvbulkpipe(stir
->usbdev
, 2),
890 stir
->io_buf
, STIR_FIFO_SIZE
,
893 stir
->fifo_status
= kmalloc(FIFO_REGS_SIZE
, GFP_KERNEL
);
894 if (!stir
->fifo_status
)
898 * Now that everything should be initialized properly,
899 * Open new IrLAP layer instance to take care of us...
900 * Note : will send immediately a speed change...
902 sprintf(hwname
, "usb#%d", stir
->usbdev
->devnum
);
903 stir
->irlap
= irlap_open(netdev
, &stir
->qos
, hwname
);
905 err("stir4200: irlap_open failed");
909 /** Start kernel thread for transmit. */
910 stir
->thread
= kthread_run(stir_transmit_thread
, stir
,
911 "%s", stir
->netdev
->name
);
912 if (IS_ERR(stir
->thread
)) {
913 err
= PTR_ERR(stir
->thread
);
914 err("stir4200: unable to start kernel thread");
918 netif_start_queue(netdev
);
923 irlap_close(stir
->irlap
);
925 kfree(stir
->fifo_status
);
929 usb_free_urb(stir
->rx_urb
);
931 kfree_skb(stir
->rx_buff
.skb
);
937 * Function stir_net_close (stir)
939 * Network device is taken down. Usually this is done by
940 * "ifconfig irda0 down"
942 static int stir_net_close(struct net_device
*netdev
)
944 struct stir_cb
*stir
= netdev_priv(netdev
);
946 /* Stop transmit processing */
947 netif_stop_queue(netdev
);
949 /* Kill transmit thread */
950 kthread_stop(stir
->thread
);
951 kfree(stir
->fifo_status
);
953 /* Mop up receive urb's */
954 usb_kill_urb(stir
->rx_urb
);
957 usb_free_urb(stir
->rx_urb
);
958 kfree_skb(stir
->rx_buff
.skb
);
960 /* Stop and remove instance of IrLAP */
962 irlap_close(stir
->irlap
);
970 * IOCTLs : Extra out-of-band network commands...
972 static int stir_net_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
974 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
975 struct stir_cb
*stir
= netdev_priv(netdev
);
979 case SIOCSBANDWIDTH
: /* Set bandwidth */
980 if (!capable(CAP_NET_ADMIN
))
983 /* Check if the device is still there */
984 if (netif_device_present(stir
->netdev
))
985 ret
= change_speed(stir
, irq
->ifr_baudrate
);
988 case SIOCSMEDIABUSY
: /* Set media busy */
989 if (!capable(CAP_NET_ADMIN
))
992 /* Check if the IrDA stack is still there */
993 if (netif_running(stir
->netdev
))
994 irda_device_set_media_busy(stir
->netdev
, TRUE
);
998 /* Only approximately true */
999 irq
->ifr_receiving
= stir
->receiving
;
1010 * Get device stats (for /proc/net/dev and ifconfig)
1012 static struct net_device_stats
*stir_net_get_stats(struct net_device
*netdev
)
1014 struct stir_cb
*stir
= netdev_priv(netdev
);
1015 return &stir
->stats
;
1019 * This routine is called by the USB subsystem for each new device
1020 * in the system. We need to check if the device is ours, and in
1021 * this case start handling it.
1022 * Note : it might be worth protecting this function by a global
1023 * spinlock... Or not, because maybe USB already deal with that...
1025 static int stir_probe(struct usb_interface
*intf
,
1026 const struct usb_device_id
*id
)
1028 struct usb_device
*dev
= interface_to_usbdev(intf
);
1029 struct stir_cb
*stir
= NULL
;
1030 struct net_device
*net
;
1033 /* Allocate network device container. */
1034 net
= alloc_irdadev(sizeof(*stir
));
1038 SET_MODULE_OWNER(net
);
1039 SET_NETDEV_DEV(net
, &intf
->dev
);
1040 stir
= netdev_priv(net
);
1044 ret
= usb_reset_configuration(dev
);
1046 err("stir4200: usb reset configuration failed");
1050 printk(KERN_INFO
"SigmaTel STIr4200 IRDA/USB found at address %d, "
1051 "Vendor: %x, Product: %x\n",
1052 dev
->devnum
, le16_to_cpu(dev
->descriptor
.idVendor
),
1053 le16_to_cpu(dev
->descriptor
.idProduct
));
1055 /* Initialize QoS for this device */
1056 irda_init_max_qos_capabilies(&stir
->qos
);
1058 /* That's the Rx capability. */
1059 stir
->qos
.baud_rate
.bits
&= IR_2400
| IR_9600
| IR_19200
|
1060 IR_38400
| IR_57600
| IR_115200
|
1062 stir
->qos
.min_turn_time
.bits
&= qos_mtt_bits
;
1063 irda_qos_bits_to_value(&stir
->qos
);
1065 /* Override the network functions we need to use */
1066 net
->hard_start_xmit
= stir_hard_xmit
;
1067 net
->open
= stir_net_open
;
1068 net
->stop
= stir_net_close
;
1069 net
->get_stats
= stir_net_get_stats
;
1070 net
->do_ioctl
= stir_net_ioctl
;
1072 ret
= register_netdev(net
);
1076 info("IrDA: Registered SigmaTel device %s", net
->name
);
1078 usb_set_intfdata(intf
, stir
);
1089 * The current device is removed, the USB layer tell us to shut it down...
1091 static void stir_disconnect(struct usb_interface
*intf
)
1093 struct stir_cb
*stir
= usb_get_intfdata(intf
);
1098 unregister_netdev(stir
->netdev
);
1099 free_netdev(stir
->netdev
);
1101 usb_set_intfdata(intf
, NULL
);
1105 /* USB suspend, so power off the transmitter/receiver */
1106 static int stir_suspend(struct usb_interface
*intf
, pm_message_t message
)
1108 struct stir_cb
*stir
= usb_get_intfdata(intf
);
1110 netif_device_detach(stir
->netdev
);
1114 /* Coming out of suspend, so reset hardware */
1115 static int stir_resume(struct usb_interface
*intf
)
1117 struct stir_cb
*stir
= usb_get_intfdata(intf
);
1119 netif_device_attach(stir
->netdev
);
1121 /* receiver restarted when send thread wakes up */
1127 * USB device callbacks
1129 static struct usb_driver irda_driver
= {
1131 .probe
= stir_probe
,
1132 .disconnect
= stir_disconnect
,
1133 .id_table
= dongles
,
1135 .suspend
= stir_suspend
,
1136 .resume
= stir_resume
,
1143 static int __init
stir_init(void)
1145 return usb_register(&irda_driver
);
1147 module_init(stir_init
);
1152 static void __exit
stir_cleanup(void)
1154 /* Deregister the driver and remove all pending instances */
1155 usb_deregister(&irda_driver
);
1157 module_exit(stir_cleanup
);