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/irda_device.h>
56 #include <net/irda/wrapper.h>
57 #include <net/irda/crc.h>
58 #include <asm/byteorder.h>
59 #include <asm/unaligned.h>
61 MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
62 MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200");
63 MODULE_LICENSE("GPL");
65 static int qos_mtt_bits = 0x07; /* 1 ms or more */
66 module_param(qos_mtt_bits, int, 0);
67 MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
69 static int rx_sensitivity = 1; /* FIR 0..4, SIR 0..6 */
70 module_param(rx_sensitivity, int, 0);
71 MODULE_PARM_DESC(rx_sensitivity, "Set Receiver sensitivity (0-6, 0 is most sensitive)");
73 static int tx_power = 0; /* 0 = highest ... 3 = lowest */
74 module_param(tx_power, int, 0);
75 MODULE_PARM_DESC(tx_power, "Set Transmitter power (0-3, 0 is highest power)");
77 #define STIR_IRDA_HEADER 4
78 #define CTRL_TIMEOUT 100 /* milliseconds */
79 #define TRANSMIT_TIMEOUT 200 /* milliseconds */
80 #define STIR_FIFO_SIZE 4096
81 #define FIFO_REGS_SIZE 3
93 REQ_WRITE_SINGLE = 0x03,
96 /* Register offsets */
122 PDCLK_4000000 = 0x02,
140 CTRL2_SPWIDTH = 0x08,
144 enum StirFifoCtlMask {
147 FIFOCTL_EMPTY = 0x04,
164 struct usb_device *usbdev; /* init: probe_irda */
165 struct net_device *netdev; /* network layer */
166 struct irlap_cb *irlap; /* The link layer we are binded to */
167 struct net_device_stats stats; /* network statistics */
169 unsigned speed; /* Current speed */
171 struct task_struct *thread; /* transmit thread */
173 struct sk_buff *tx_pending;
174 void *io_buf; /* transmit/receive buffer */
177 iobuff_t rx_buff; /* receive unwrap state machine */
178 struct timeval rx_time;
184 /* These are the currently known USB ids */
185 static struct usb_device_id dongles[] = {
186 /* SigmaTel, Inc, STIr4200 IrDA/USB Bridge */
187 { USB_DEVICE(0x066f, 0x4200) },
191 MODULE_DEVICE_TABLE(usb, dongles);
193 /* Send control message to set dongle register */
194 static int write_reg(struct stir_cb *stir, __u16 reg, __u8 value)
196 struct usb_device *dev = stir->usbdev;
198 pr_debug("%s: write reg %d = 0x%x\n",
199 stir->netdev->name, reg, value);
200 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
202 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_DEVICE,
207 /* Send control message to read multiple registers */
208 static inline int read_reg(struct stir_cb *stir, __u16 reg,
209 __u8 *data, __u16 count)
211 struct usb_device *dev = stir->usbdev;
213 return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
215 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
220 static inline int isfir(u32 speed)
222 return (speed == 4000000);
226 * Prepare a FIR IrDA frame for transmission to the USB dongle. The
227 * FIR transmit frame is documented in the datasheet. It consists of
228 * a two byte 0x55 0xAA sequence, two little-endian length bytes, a
229 * sequence of exactly 16 XBOF bytes of 0x7E, two BOF bytes of 0x7E,
230 * then the data escaped as follows:
236 * Then, 4 bytes of little endian (stuffed) FCS follow, then two
237 * trailing EOF bytes of 0x7E.
239 static inline __u8 *stuff_fir(__u8 *p, __u8 c)
254 /* Take raw data in skb and put it wrapped into buf */
255 static unsigned wrap_fir_skb(const struct sk_buff *skb, __u8 *buf)
258 __u32 fcs = ~(crc32_le(~0, skb->data, skb->len));
266 ptr = buf + STIR_IRDA_HEADER;
267 memset(ptr, 0x7f, 16);
274 /* Address / Control / Information */
275 for (i = 0; i < skb->len; i++)
276 ptr = stuff_fir(ptr, skb->data[i]);
279 ptr = stuff_fir(ptr, fcs & 0xff);
280 ptr = stuff_fir(ptr, (fcs >> 8) & 0xff);
281 ptr = stuff_fir(ptr, (fcs >> 16) & 0xff);
282 ptr = stuff_fir(ptr, (fcs >> 24) & 0xff);
288 /* Total length, minus the header */
289 wraplen = (ptr - buf) - STIR_IRDA_HEADER;
290 buf[2] = wraplen & 0xff;
291 buf[3] = (wraplen >> 8) & 0xff;
293 return wraplen + STIR_IRDA_HEADER;
296 static unsigned wrap_sir_skb(struct sk_buff *skb, __u8 *buf)
300 wraplen = async_wrap_skb(skb, buf + STIR_IRDA_HEADER,
301 STIR_FIFO_SIZE - STIR_IRDA_HEADER);
304 buf[2] = wraplen & 0xff;
305 buf[3] = (wraplen >> 8) & 0xff;
307 return wraplen + STIR_IRDA_HEADER;
311 * Frame is fully formed in the rx_buff so check crc
312 * and pass up to irlap
313 * setup for next receive
315 static void fir_eof(struct stir_cb *stir)
317 iobuff_t *rx_buff = &stir->rx_buff;
318 int len = rx_buff->len - 4;
319 struct sk_buff *skb, *nskb;
322 if (unlikely(len <= 0)) {
323 pr_debug("%s: short frame len %d\n",
324 stir->netdev->name, len);
326 ++stir->stats.rx_errors;
327 ++stir->stats.rx_length_errors;
331 fcs = ~(crc32_le(~0, rx_buff->data, len));
332 if (fcs != get_unaligned_le32(rx_buff->data + len)) {
333 pr_debug("crc error calc 0x%x len %d\n", fcs, len);
334 stir->stats.rx_errors++;
335 stir->stats.rx_crc_errors++;
339 /* if frame is short then just copy it */
340 if (len < IRDA_RX_COPY_THRESHOLD) {
341 nskb = dev_alloc_skb(len + 1);
342 if (unlikely(!nskb)) {
343 ++stir->stats.rx_dropped;
346 skb_reserve(nskb, 1);
348 skb_copy_to_linear_data(nskb, rx_buff->data, len);
350 nskb = dev_alloc_skb(rx_buff->truesize);
351 if (unlikely(!nskb)) {
352 ++stir->stats.rx_dropped;
355 skb_reserve(nskb, 1);
358 rx_buff->head = nskb->data;
363 skb_reset_mac_header(skb);
364 skb->protocol = htons(ETH_P_IRDA);
365 skb->dev = stir->netdev;
369 stir->stats.rx_packets++;
370 stir->stats.rx_bytes += len;
372 rx_buff->data = rx_buff->head;
376 /* Unwrap FIR stuffed data and bump it to IrLAP */
377 static void stir_fir_chars(struct stir_cb *stir,
378 const __u8 *bytes, int len)
380 iobuff_t *rx_buff = &stir->rx_buff;
383 for (i = 0; i < len; i++) {
384 __u8 byte = bytes[i];
386 switch(rx_buff->state) {
388 /* ignore garbage till start of frame */
389 if (unlikely(byte != FIR_EOF))
391 /* Now receiving frame */
392 rx_buff->state = BEGIN_FRAME;
394 /* Time to initialize receive buffer */
395 rx_buff->data = rx_buff->head;
400 if (byte == FIR_EOF) {
401 pr_debug("%s: got EOF after escape\n",
405 rx_buff->state = INSIDE_FRAME;
410 /* ignore multiple BOF/EOF */
413 rx_buff->state = INSIDE_FRAME;
414 rx_buff->in_frame = TRUE;
420 rx_buff->state = LINK_ESCAPE;
423 /* 0x7f is not used in this framing */
424 pr_debug("%s: got XBOF without escape\n",
428 rx_buff->state = OUTSIDE_FRAME;
429 rx_buff->in_frame = FALSE;
436 /* add byte to rx buffer */
437 if (unlikely(rx_buff->len >= rx_buff->truesize)) {
438 pr_debug("%s: fir frame exceeds %d\n",
439 stir->netdev->name, rx_buff->truesize);
440 ++stir->stats.rx_over_errors;
444 rx_buff->data[rx_buff->len++] = byte;
448 ++stir->stats.rx_frame_errors;
451 ++stir->stats.rx_errors;
452 rx_buff->state = OUTSIDE_FRAME;
453 rx_buff->in_frame = FALSE;
457 /* Unwrap SIR stuffed data and bump it up to IrLAP */
458 static void stir_sir_chars(struct stir_cb *stir,
459 const __u8 *bytes, int len)
463 for (i = 0; i < len; i++)
464 async_unwrap_char(stir->netdev, &stir->stats,
465 &stir->rx_buff, bytes[i]);
468 static inline void unwrap_chars(struct stir_cb *stir,
469 const __u8 *bytes, int length)
471 if (isfir(stir->speed))
472 stir_fir_chars(stir, bytes, length);
474 stir_sir_chars(stir, bytes, length);
477 /* Mode parameters for each speed */
478 static const struct {
482 { 2400, PDCLK_2400 },
483 { 9600, PDCLK_9600 },
484 { 19200, PDCLK_19200 },
485 { 38400, PDCLK_38400 },
486 { 57600, PDCLK_57600 },
487 { 115200, PDCLK_115200 },
488 { 4000000, PDCLK_4000000 },
493 * Setup chip for speed.
494 * Called at startup to initialize the chip
495 * and on speed changes.
497 * Note: Write multiple registers doesn't appear to work
499 static int change_speed(struct stir_cb *stir, unsigned speed)
504 for (i = 0; i < ARRAY_SIZE(stir_modes); ++i) {
505 if (speed == stir_modes[i].speed)
509 dev_warn(&stir->netdev->dev, "invalid speed %d\n", speed);
513 pr_debug("speed change from %d to %d\n", stir->speed, speed);
515 /* Reset modulator */
516 err = write_reg(stir, REG_CTRL1, CTRL1_SRESET);
520 /* Undocumented magic to tweak the DPLL */
521 err = write_reg(stir, REG_DPLL, 0x15);
526 err = write_reg(stir, REG_PDCLK, stir_modes[i].pdclk);
530 mode = MODE_NRESET | MODE_FASTRX;
532 mode |= MODE_FIR | MODE_FFRSTEN;
539 err = write_reg(stir, REG_MODE, mode);
543 /* This resets TEMIC style transceiver if any. */
544 err = write_reg(stir, REG_CTRL1,
545 CTRL1_SDMODE | (tx_power & 3) << 1);
549 err = write_reg(stir, REG_CTRL1, (tx_power & 3) << 1);
553 /* Reset sensitivity */
554 err = write_reg(stir, REG_CTRL2, (rx_sensitivity & 7) << 5);
561 * Called from net/core when new frame is available.
563 static int stir_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
565 struct stir_cb *stir = netdev_priv(netdev);
567 netif_stop_queue(netdev);
569 /* the IRDA wrapping routines don't deal with non linear skb */
570 SKB_LINEAR_ASSERT(skb);
572 skb = xchg(&stir->tx_pending, skb);
573 wake_up_process(stir->thread);
575 /* this should never happen unless stop/wakeup problem */
585 * Wait for the transmit FIFO to have space for next data
587 * If space < 0 then wait till FIFO completely drains.
588 * FYI: can take up to 13 seconds at 2400baud.
590 static int fifo_txwait(struct stir_cb *stir, int space)
593 unsigned long count, status;
594 unsigned long prev_count = 0x1fff;
596 /* Read FIFO status and count */
597 for (;; prev_count = count) {
598 err = read_reg(stir, REG_FIFOCTL, stir->fifo_status,
600 if (unlikely(err != FIFO_REGS_SIZE)) {
601 dev_warn(&stir->netdev->dev,
602 "FIFO register read error: %d\n", err);
607 status = stir->fifo_status[0];
608 count = (unsigned)(stir->fifo_status[2] & 0x1f) << 8
609 | stir->fifo_status[1];
611 pr_debug("fifo status 0x%lx count %lu\n", status, count);
613 /* is fifo receiving already, or empty */
614 if (!(status & FIFOCTL_DIR)
615 || (status & FIFOCTL_EMPTY))
618 if (signal_pending(current))
622 if (!netif_running(stir->netdev)
623 || !netif_device_present(stir->netdev))
626 /* only waiting for some space */
627 if (space >= 0 && STIR_FIFO_SIZE - 4 > space + count)
631 if (prev_count < count)
634 /* estimate transfer time for remaining chars */
635 msleep((count * 8000) / stir->speed);
638 err = write_reg(stir, REG_FIFOCTL, FIFOCTL_CLR);
641 err = write_reg(stir, REG_FIFOCTL, 0);
649 /* Wait for turnaround delay before starting transmit. */
650 static void turnaround_delay(const struct stir_cb *stir, long us)
658 do_gettimeofday(&now);
659 if (now.tv_sec - stir->rx_time.tv_sec > 0)
661 us -= now.tv_usec - stir->rx_time.tv_usec;
665 ticks = us / (1000000 / HZ);
667 schedule_timeout_interruptible(1 + ticks);
673 * Start receiver by submitting a request to the receive pipe.
674 * If nothing is available it will return after rx_interval.
676 static int receive_start(struct stir_cb *stir)
681 stir->rx_buff.in_frame = FALSE;
682 stir->rx_buff.state = OUTSIDE_FRAME;
684 stir->rx_urb->status = 0;
685 return usb_submit_urb(stir->rx_urb, GFP_KERNEL);
688 /* Stop all pending receive Urb's */
689 static void receive_stop(struct stir_cb *stir)
692 usb_kill_urb(stir->rx_urb);
694 if (stir->rx_buff.in_frame)
695 stir->stats.collisions++;
698 * Wrap data in socket buffer and send it.
700 static void stir_send(struct stir_cb *stir, struct sk_buff *skb)
705 /* if receiving, need to turnaround */
706 if (stir->receiving) {
708 turnaround_delay(stir, irda_get_mtt(skb));
712 if (isfir(stir->speed))
713 wraplen = wrap_fir_skb(skb, stir->io_buf);
715 wraplen = wrap_sir_skb(skb, stir->io_buf);
717 /* check for space available in fifo */
719 fifo_txwait(stir, wraplen);
721 stir->stats.tx_packets++;
722 stir->stats.tx_bytes += skb->len;
723 stir->netdev->trans_start = jiffies;
724 pr_debug("send %d (%d)\n", skb->len, wraplen);
726 if (usb_bulk_msg(stir->usbdev, usb_sndbulkpipe(stir->usbdev, 1),
727 stir->io_buf, wraplen,
728 NULL, TRANSMIT_TIMEOUT))
729 stir->stats.tx_errors++;
733 * Transmit state machine thread
735 static int stir_transmit_thread(void *arg)
737 struct stir_cb *stir = arg;
738 struct net_device *dev = stir->netdev;
741 while (!kthread_should_stop()) {
743 /* if suspending, then power off and wait */
744 if (unlikely(freezing(current))) {
748 fifo_txwait(stir, -1);
750 write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD);
754 if (change_speed(stir, stir->speed))
759 /* if something to send? */
760 skb = xchg(&stir->tx_pending, NULL);
762 unsigned new_speed = irda_get_next_speed(skb);
763 netif_wake_queue(dev);
766 stir_send(stir, skb);
769 if ((new_speed != -1) && (stir->speed != new_speed)) {
770 if (fifo_txwait(stir, -1) ||
771 change_speed(stir, new_speed))
777 /* nothing to send? start receiving */
779 && irda_device_txqueue_empty(dev)) {
780 /* Wait otherwise chip gets confused. */
781 if (fifo_txwait(stir, -1))
784 if (unlikely(receive_start(stir))) {
787 "%s: receive usb submit failed\n",
795 /* sleep if nothing to send */
796 set_current_state(TASK_INTERRUPTIBLE);
805 * USB bulk receive completion callback.
806 * Wakes up every ms (usb round trip) with wrapped
809 static void stir_rcv_irq(struct urb *urb)
811 struct stir_cb *stir = urb->context;
814 /* in process of stopping, just drop data */
815 if (!netif_running(stir->netdev))
818 /* unlink, shutdown, unplug, other nasties */
819 if (urb->status != 0)
822 if (urb->actual_length > 0) {
823 pr_debug("receive %d\n", urb->actual_length);
824 unwrap_chars(stir, urb->transfer_buffer,
827 stir->netdev->last_rx = jiffies;
828 do_gettimeofday(&stir->rx_time);
831 /* kernel thread is stopping receiver don't resubmit */
832 if (!stir->receiving)
835 /* resubmit existing urb */
836 err = usb_submit_urb(urb, GFP_ATOMIC);
838 /* in case of error, the kernel thread will restart us */
840 dev_warn(&stir->netdev->dev, "usb receive submit error: %d\n",
843 wake_up_process(stir->thread);
848 * Function stir_net_open (dev)
850 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
852 static int stir_net_open(struct net_device *netdev)
854 struct stir_cb *stir = netdev_priv(netdev);
858 err = usb_clear_halt(stir->usbdev, usb_sndbulkpipe(stir->usbdev, 1));
861 err = usb_clear_halt(stir->usbdev, usb_rcvbulkpipe(stir->usbdev, 2));
865 err = change_speed(stir, 9600);
871 /* Initialize for SIR/FIR to copy data directly into skb. */
873 stir->rx_buff.truesize = IRDA_SKB_MAX_MTU;
874 stir->rx_buff.skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
875 if (!stir->rx_buff.skb)
878 skb_reserve(stir->rx_buff.skb, 1);
879 stir->rx_buff.head = stir->rx_buff.skb->data;
880 do_gettimeofday(&stir->rx_time);
882 stir->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
886 stir->io_buf = kmalloc(STIR_FIFO_SIZE, GFP_KERNEL);
890 usb_fill_bulk_urb(stir->rx_urb, stir->usbdev,
891 usb_rcvbulkpipe(stir->usbdev, 2),
892 stir->io_buf, STIR_FIFO_SIZE,
895 stir->fifo_status = kmalloc(FIFO_REGS_SIZE, GFP_KERNEL);
896 if (!stir->fifo_status)
900 * Now that everything should be initialized properly,
901 * Open new IrLAP layer instance to take care of us...
902 * Note : will send immediately a speed change...
904 sprintf(hwname, "usb#%d", stir->usbdev->devnum);
905 stir->irlap = irlap_open(netdev, &stir->qos, hwname);
907 err("stir4200: irlap_open failed");
911 /** Start kernel thread for transmit. */
912 stir->thread = kthread_run(stir_transmit_thread, stir,
913 "%s", stir->netdev->name);
914 if (IS_ERR(stir->thread)) {
915 err = PTR_ERR(stir->thread);
916 err("stir4200: unable to start kernel thread");
920 netif_start_queue(netdev);
925 irlap_close(stir->irlap);
927 kfree(stir->fifo_status);
931 usb_free_urb(stir->rx_urb);
933 kfree_skb(stir->rx_buff.skb);
939 * Function stir_net_close (stir)
941 * Network device is taken down. Usually this is done by
942 * "ifconfig irda0 down"
944 static int stir_net_close(struct net_device *netdev)
946 struct stir_cb *stir = netdev_priv(netdev);
948 /* Stop transmit processing */
949 netif_stop_queue(netdev);
951 /* Kill transmit thread */
952 kthread_stop(stir->thread);
953 kfree(stir->fifo_status);
955 /* Mop up receive urb's */
956 usb_kill_urb(stir->rx_urb);
959 usb_free_urb(stir->rx_urb);
960 kfree_skb(stir->rx_buff.skb);
962 /* Stop and remove instance of IrLAP */
964 irlap_close(stir->irlap);
972 * IOCTLs : Extra out-of-band network commands...
974 static int stir_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
976 struct if_irda_req *irq = (struct if_irda_req *) rq;
977 struct stir_cb *stir = netdev_priv(netdev);
981 case SIOCSBANDWIDTH: /* Set bandwidth */
982 if (!capable(CAP_NET_ADMIN))
985 /* Check if the device is still there */
986 if (netif_device_present(stir->netdev))
987 ret = change_speed(stir, irq->ifr_baudrate);
990 case SIOCSMEDIABUSY: /* Set media busy */
991 if (!capable(CAP_NET_ADMIN))
994 /* Check if the IrDA stack is still there */
995 if (netif_running(stir->netdev))
996 irda_device_set_media_busy(stir->netdev, TRUE);
1000 /* Only approximately true */
1001 irq->ifr_receiving = stir->receiving;
1012 * Get device stats (for /proc/net/dev and ifconfig)
1014 static struct net_device_stats *stir_net_get_stats(struct net_device *netdev)
1016 struct stir_cb *stir = netdev_priv(netdev);
1017 return &stir->stats;
1021 * This routine is called by the USB subsystem for each new device
1022 * in the system. We need to check if the device is ours, and in
1023 * this case start handling it.
1024 * Note : it might be worth protecting this function by a global
1025 * spinlock... Or not, because maybe USB already deal with that...
1027 static int stir_probe(struct usb_interface *intf,
1028 const struct usb_device_id *id)
1030 struct usb_device *dev = interface_to_usbdev(intf);
1031 struct stir_cb *stir = NULL;
1032 struct net_device *net;
1035 /* Allocate network device container. */
1036 net = alloc_irdadev(sizeof(*stir));
1040 SET_NETDEV_DEV(net, &intf->dev);
1041 stir = netdev_priv(net);
1045 ret = usb_reset_configuration(dev);
1047 err("stir4200: usb reset configuration failed");
1051 printk(KERN_INFO "SigmaTel STIr4200 IRDA/USB found at address %d, "
1052 "Vendor: %x, Product: %x\n",
1053 dev->devnum, le16_to_cpu(dev->descriptor.idVendor),
1054 le16_to_cpu(dev->descriptor.idProduct));
1056 /* Initialize QoS for this device */
1057 irda_init_max_qos_capabilies(&stir->qos);
1059 /* That's the Rx capability. */
1060 stir->qos.baud_rate.bits &= IR_2400 | IR_9600 | IR_19200 |
1061 IR_38400 | IR_57600 | IR_115200 |
1063 stir->qos.min_turn_time.bits &= qos_mtt_bits;
1064 irda_qos_bits_to_value(&stir->qos);
1066 /* Override the network functions we need to use */
1067 net->hard_start_xmit = stir_hard_xmit;
1068 net->open = stir_net_open;
1069 net->stop = stir_net_close;
1070 net->get_stats = stir_net_get_stats;
1071 net->do_ioctl = stir_net_ioctl;
1073 ret = register_netdev(net);
1077 dev_info(&intf->dev, "IrDA: Registered SigmaTel device %s\n",
1080 usb_set_intfdata(intf, stir);
1091 * The current device is removed, the USB layer tell us to shut it down...
1093 static void stir_disconnect(struct usb_interface *intf)
1095 struct stir_cb *stir = usb_get_intfdata(intf);
1100 unregister_netdev(stir->netdev);
1101 free_netdev(stir->netdev);
1103 usb_set_intfdata(intf, NULL);
1107 /* USB suspend, so power off the transmitter/receiver */
1108 static int stir_suspend(struct usb_interface *intf, pm_message_t message)
1110 struct stir_cb *stir = usb_get_intfdata(intf);
1112 netif_device_detach(stir->netdev);
1116 /* Coming out of suspend, so reset hardware */
1117 static int stir_resume(struct usb_interface *intf)
1119 struct stir_cb *stir = usb_get_intfdata(intf);
1121 netif_device_attach(stir->netdev);
1123 /* receiver restarted when send thread wakes up */
1129 * USB device callbacks
1131 static struct usb_driver irda_driver = {
1133 .probe = stir_probe,
1134 .disconnect = stir_disconnect,
1135 .id_table = dongles,
1137 .suspend = stir_suspend,
1138 .resume = stir_resume,
1145 static int __init stir_init(void)
1147 return usb_register(&irda_driver);
1149 module_init(stir_init);
1154 static void __exit stir_cleanup(void)
1156 /* Deregister the driver and remove all pending instances */
1157 usb_deregister(&irda_driver);
1159 module_exit(stir_cleanup);