1 /*****************************************************************************
5 * Description: Irda MosChip USB Dongle Driver
6 * Authors: Lukasz Stelmach <stlman@poczta.fm>
7 * Brian Pugh <bpugh@cs.pdx.edu>
8 * Judy Fischbach <jfisch@cs.pdx.edu>
10 * Based on stir4200 driver, but some things done differently.
11 * Based on earlier driver by Paul Stewart <stewart@parc.com>
13 * Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
14 * Copyright (C) 2001, Dag Brattli <dag@brattli.net>
15 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
16 * Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org>
17 * Copyright (C) 2005, Lukasz Stelmach <stlman@poczta.fm>
18 * Copyright (C) 2005, Brian Pugh <bpugh@cs.pdx.edu>
19 * Copyright (C) 2005, Judy Fischbach <jfisch@cs.pdx.edu>
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *****************************************************************************/
38 * MCS7780 is a simple USB to IrDA bridge by MosChip. It is neither
39 * compatibile with irda-usb nor with stir4200. Although it is quite
40 * similar to the later as far as general idea of operation is concerned.
41 * That is it requires the software to do all the framing job at SIR speeds.
42 * The hardware does take care of the framing at MIR and FIR speeds.
43 * It supports all speeds from 2400 through 4Mbps
46 #include <linux/module.h>
47 #include <linux/moduleparam.h>
48 #include <linux/kernel.h>
49 #include <linux/types.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/usb.h>
54 #include <linux/device.h>
55 #include <linux/crc32.h>
57 #include <asm/unaligned.h>
58 #include <asm/byteorder.h>
59 #include <asm/uaccess.h>
61 #include <net/irda/irda.h>
62 #include <net/irda/wrapper.h>
63 #include <net/irda/crc.h>
67 #define MCS_VENDOR_ID 0x9710
68 #define MCS_PRODUCT_ID 0x7780
70 static struct usb_device_id mcs_table
[] = {
71 /* MosChip Corp., MCS7780 FIR-USB Adapter */
72 {USB_DEVICE(MCS_VENDOR_ID
, MCS_PRODUCT_ID
)},
76 MODULE_AUTHOR("Brian Pugh <bpugh@cs.pdx.edu>");
77 MODULE_DESCRIPTION("IrDA-USB Dongle Driver for MosChip MCS7780");
78 MODULE_VERSION("0.3alpha");
79 MODULE_LICENSE("GPL");
81 MODULE_DEVICE_TABLE(usb
, mcs_table
);
83 static int qos_mtt_bits
= 0x07 /* > 1ms */ ;
84 module_param(qos_mtt_bits
, int, 0);
85 MODULE_PARM_DESC(qos_mtt_bits
, "Minimum Turn Time");
87 static int receive_mode
= 0x1;
88 module_param(receive_mode
, int, 0);
89 MODULE_PARM_DESC(receive_mode
,
90 "Receive mode of the device (1:fast, 0:slow, default:1)");
92 static int sir_tweak
= 1;
93 module_param(sir_tweak
, int, 0444);
94 MODULE_PARM_DESC(sir_tweak
,
95 "Default pulse width (1:1.6us, 0:3/16 bit, default:1).");
97 static int transceiver_type
= MCS_TSC_VISHAY
;
98 module_param(transceiver_type
, int, 0444);
99 MODULE_PARM_DESC(transceiver_type
, "IR transceiver type, see mcs7780.h.");
101 static struct usb_driver mcs_driver
= {
104 .disconnect
= mcs_disconnect
,
105 .id_table
= mcs_table
,
108 /* speed flag selection by direct addressing.
109 addr = (speed >> 8) & 0x0f
111 0x1 57600 0x2 115200 0x4 1152000 0x5 9600
112 0x6 38400 0x9 2400 0xa 576000 0xb 19200
114 4Mbps (or 2400) must be checked separately. Since it also has
115 to be programmed in a different manner that is not a big problem.
117 static __u16 mcs_speed_set
[16] = { 0,
131 /* Set given 16 bit register with a 16 bit value. Send control message
132 * to set dongle register. */
133 static int mcs_set_reg(struct mcs_cb
*mcs
, __u16 reg
, __u16 val
)
135 struct usb_device
*dev
= mcs
->usbdev
;
136 return usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0), MCS_WRREQ
,
137 MCS_WR_RTYPE
, val
, reg
, NULL
, 0,
138 msecs_to_jiffies(MCS_CTRL_TIMEOUT
));
141 /* Get 16 bit register value. Send contol message to read dongle register. */
142 static int mcs_get_reg(struct mcs_cb
*mcs
, __u16 reg
, __u16
* val
)
144 struct usb_device
*dev
= mcs
->usbdev
;
145 int ret
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0), MCS_RDREQ
,
146 MCS_RD_RTYPE
, 0, reg
, val
, 2,
147 msecs_to_jiffies(MCS_CTRL_TIMEOUT
));
152 /* Setup a communication between mcs7780 and TFDU chips. It is described
153 * in more detail in the data sheet. The setup sequence puts the the
154 * vishay tranceiver into high speed mode. It will also receive SIR speed
155 * packets but at reduced sensitivity.
159 static inline int mcs_setup_transceiver_vishay(struct mcs_cb
*mcs
)
164 /* mcs_get_reg should read exactly two bytes from the dongle */
165 ret
= mcs_get_reg(mcs
, MCS_XCVR_REG
, &rval
);
166 if (unlikely(ret
!= 2)) {
171 /* The MCS_XCVR_CONF bit puts the transceiver into configuration
172 * mode. The MCS_MODE0 bit must start out high (1) and then
173 * transition to low and the MCS_STFIR and MCS_MODE1 bits must
176 rval
|= (MCS_MODE0
| MCS_XCVR_CONF
);
179 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
184 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
188 rval
&= ~MCS_XCVR_CONF
;
189 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
198 /* Setup a communication between mcs7780 and agilent chip. */
199 static inline int mcs_setup_transceiver_agilent(struct mcs_cb
*mcs
)
201 IRDA_WARNING("This transceiver type is not supported yet.\n");
205 /* Setup a communication between mcs7780 and sharp chip. */
206 static inline int mcs_setup_transceiver_sharp(struct mcs_cb
*mcs
)
208 IRDA_WARNING("This transceiver type is not supported yet.\n");
212 /* Common setup for all transceivers */
213 static inline int mcs_setup_transceiver(struct mcs_cb
*mcs
)
219 msg
= "Basic transceiver setup error.";
221 /* read value of MODE Register, set the DRIVER and RESET bits
222 * and write value back out to MODE Register
224 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
225 if(unlikely(ret
!= 2))
227 rval
|= MCS_DRIVER
; /* put the mcs7780 into configuration mode. */
228 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
232 rval
= 0; /* set min pulse width to 0 initially. */
233 ret
= mcs_set_reg(mcs
, MCS_MINRXPW_REG
, rval
);
237 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
238 if(unlikely(ret
!= 2))
241 rval
&= ~MCS_FIR
; /* turn off fir mode. */
243 rval
|= MCS_SIR16US
; /* 1.6us pulse width */
245 rval
&= ~MCS_SIR16US
; /* 3/16 bit time pulse width */
247 /* make sure ask mode and back to back packets are off. */
248 rval
&= ~(MCS_BBTG
| MCS_ASK
);
250 rval
&= ~MCS_SPEED_MASK
;
251 rval
|= MCS_SPEED_9600
; /* make sure initial speed is 9600. */
253 mcs
->new_speed
= 0; /* new_speed is set to 0 */
254 rval
&= ~MCS_PLLPWDN
; /* disable power down. */
256 /* make sure device determines direction and that the auto send sip
259 rval
|= MCS_DTD
| MCS_SIPEN
;
261 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
265 msg
= "transceiver model specific setup error.";
266 switch (mcs
->transceiver_type
) {
268 ret
= mcs_setup_transceiver_vishay(mcs
);
272 ret
= mcs_setup_transceiver_sharp(mcs
);
275 case MCS_TSC_AGILENT
:
276 ret
= mcs_setup_transceiver_agilent(mcs
);
280 IRDA_WARNING("Unknown transceiver type: %d\n",
281 mcs
->transceiver_type
);
287 /* If transceiver is not SHARP, then if receive mode set
288 * on the RXFAST bit in the XCVR Register otherwise unset it
290 if (mcs
->transceiver_type
!= MCS_TSC_SHARP
) {
292 ret
= mcs_get_reg(mcs
, MCS_XCVR_REG
, &rval
);
293 if (unlikely(ret
!= 2))
295 if (mcs
->receive_mode
)
299 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
304 msg
= "transceiver reset.";
306 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
307 if (unlikely(ret
!= 2))
310 /* reset the mcs7780 so all changes take effect. */
312 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
319 IRDA_ERROR("%s\n", msg
);
323 /* Wraps the data in format for SIR */
324 static inline int mcs_wrap_sir_skb(struct sk_buff
*skb
, __u8
* buf
)
328 /* 2: full frame length, including "the length" */
329 wraplen
= async_wrap_skb(skb
, buf
+ 2, 4094);
332 buf
[0] = wraplen
& 0xff;
333 buf
[1] = (wraplen
>> 8) & 0xff;
338 /* Wraps the data in format for FIR */
339 static unsigned mcs_wrap_fir_skb(const struct sk_buff
*skb
, __u8
*buf
)
341 unsigned int len
= 0;
342 __u32 fcs
= ~(crc32_le(~0, skb
->data
, skb
->len
));
344 /* add 2 bytes for length value and 4 bytes for fcs. */
347 /* The mcs7780 requires that the first two bytes are the packet
348 * length in little endian order. Note: the length value includes
349 * the two bytes for the length value itself.
352 buf
[1] = (len
>> 8) & 0xff;
353 /* copy the data into the tx buffer. */
354 skb_copy_from_linear_data(skb
, buf
+ 2, skb
->len
);
355 /* put the fcs in the last four bytes in little endian order. */
356 buf
[len
- 4] = fcs
& 0xff;
357 buf
[len
- 3] = (fcs
>> 8) & 0xff;
358 buf
[len
- 2] = (fcs
>> 16) & 0xff;
359 buf
[len
- 1] = (fcs
>> 24) & 0xff;
364 /* Wraps the data in format for MIR */
365 static unsigned mcs_wrap_mir_skb(const struct sk_buff
*skb
, __u8
*buf
)
368 int len
= skb
->len
+ 4;
370 fcs
= ~(irda_calc_crc16(~fcs
, skb
->data
, skb
->len
));
371 /* put the total packet length in first. Note: packet length
372 * value includes the two bytes that hold the packet length
376 buf
[1] = (len
>> 8) & 0xff;
378 skb_copy_from_linear_data(skb
, buf
+ 2, skb
->len
);
379 /* put the fcs in last two bytes in little endian order. */
380 buf
[len
- 2] = fcs
& 0xff;
381 buf
[len
- 1] = (fcs
>> 8) & 0xff;
386 /* Unwrap received packets at MIR speed. A 16 bit crc_ccitt checksum is
387 * used for the fcs. When performed over the entire packet the result
388 * should be GOOD_FCS = 0xf0b8. Hands the unwrapped data off to the IrDA
389 * layer via a sk_buff.
391 static void mcs_unwrap_mir(struct mcs_cb
*mcs
, __u8
*buf
, int len
)
397 /* Assume that the frames are going to fill a single packet
398 * rather than span multiple packets.
402 if(unlikely(new_len
<= 0)) {
403 IRDA_ERROR("%s short frame length %d\n",
404 mcs
->netdev
->name
, new_len
);
405 ++mcs
->netdev
->stats
.rx_errors
;
406 ++mcs
->netdev
->stats
.rx_length_errors
;
410 fcs
= irda_calc_crc16(~fcs
, buf
, len
);
412 if(fcs
!= GOOD_FCS
) {
413 IRDA_ERROR("crc error calc 0x%x len %d\n",
415 mcs
->netdev
->stats
.rx_errors
++;
416 mcs
->netdev
->stats
.rx_crc_errors
++;
420 skb
= dev_alloc_skb(new_len
+ 1);
422 ++mcs
->netdev
->stats
.rx_dropped
;
427 skb_copy_to_linear_data(skb
, buf
, new_len
);
428 skb_put(skb
, new_len
);
429 skb_reset_mac_header(skb
);
430 skb
->protocol
= htons(ETH_P_IRDA
);
431 skb
->dev
= mcs
->netdev
;
435 mcs
->netdev
->stats
.rx_packets
++;
436 mcs
->netdev
->stats
.rx_bytes
+= new_len
;
439 /* Unwrap received packets at FIR speed. A 32 bit crc_ccitt checksum is
440 * used for the fcs. Hands the unwrapped data off to the IrDA
441 * layer via a sk_buff.
443 static void mcs_unwrap_fir(struct mcs_cb
*mcs
, __u8
*buf
, int len
)
449 /* Assume that the frames are going to fill a single packet
450 * rather than span multiple packets. This is most likely a false
455 if(unlikely(new_len
<= 0)) {
456 IRDA_ERROR("%s short frame length %d\n",
457 mcs
->netdev
->name
, new_len
);
458 ++mcs
->netdev
->stats
.rx_errors
;
459 ++mcs
->netdev
->stats
.rx_length_errors
;
463 fcs
= ~(crc32_le(~0, buf
, new_len
));
464 if(fcs
!= get_unaligned_le32(buf
+ new_len
)) {
465 IRDA_ERROR("crc error calc 0x%x len %d\n", fcs
, new_len
);
466 mcs
->netdev
->stats
.rx_errors
++;
467 mcs
->netdev
->stats
.rx_crc_errors
++;
471 skb
= dev_alloc_skb(new_len
+ 1);
473 ++mcs
->netdev
->stats
.rx_dropped
;
478 skb_copy_to_linear_data(skb
, buf
, new_len
);
479 skb_put(skb
, new_len
);
480 skb_reset_mac_header(skb
);
481 skb
->protocol
= htons(ETH_P_IRDA
);
482 skb
->dev
= mcs
->netdev
;
486 mcs
->netdev
->stats
.rx_packets
++;
487 mcs
->netdev
->stats
.rx_bytes
+= new_len
;
491 /* Allocates urbs for both receive and transmit.
492 * If alloc fails return error code 0 (fail) otherwise
493 * return error code 1 (success).
495 static inline int mcs_setup_urbs(struct mcs_cb
*mcs
)
499 mcs
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
503 mcs
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
510 /* Sets up state to be initially outside frame, gets receive urb,
511 * sets status to successful and then submits the urb to start
512 * receiving the data.
514 static inline int mcs_receive_start(struct mcs_cb
*mcs
)
516 mcs
->rx_buff
.in_frame
= FALSE
;
517 mcs
->rx_buff
.state
= OUTSIDE_FRAME
;
519 usb_fill_bulk_urb(mcs
->rx_urb
, mcs
->usbdev
,
520 usb_rcvbulkpipe(mcs
->usbdev
, mcs
->ep_in
),
521 mcs
->in_buf
, 4096, mcs_receive_irq
, mcs
);
523 mcs
->rx_urb
->status
= 0;
524 return usb_submit_urb(mcs
->rx_urb
, GFP_KERNEL
);
527 /* Finds the in and out endpoints for the mcs control block */
528 static inline int mcs_find_endpoints(struct mcs_cb
*mcs
,
529 struct usb_host_endpoint
*ep
, int epnum
)
534 /* If no place to store the endpoints just return */
538 /* cycle through all endpoints, find the first two that are DIR_IN */
539 for (i
= 0; i
< epnum
; i
++) {
540 if (ep
[i
].desc
.bEndpointAddress
& USB_DIR_IN
)
541 mcs
->ep_in
= ep
[i
].desc
.bEndpointAddress
;
543 mcs
->ep_out
= ep
[i
].desc
.bEndpointAddress
;
545 /* MosChip says that the chip has only two bulk
546 * endpoints. Find one for each direction and move on.
548 if ((mcs
->ep_in
!= 0) && (mcs
->ep_out
!= 0)) {
557 static void mcs_speed_work(struct work_struct
*work
)
559 struct mcs_cb
*mcs
= container_of(work
, struct mcs_cb
, work
);
560 struct net_device
*netdev
= mcs
->netdev
;
562 mcs_speed_change(mcs
);
563 netif_wake_queue(netdev
);
566 /* Function to change the speed of the mcs7780. Fully supports SIR,
567 * MIR, and FIR speeds.
569 static int mcs_speed_change(struct mcs_cb
*mcs
)
577 nspeed
= mcs_speed_set
[(mcs
->new_speed
>> 8) & 0x0f];
580 mcs_get_reg(mcs
, MCS_RESV_REG
, &rval
);
581 } while(cnt
++ < 100 && (rval
& MCS_IRINTX
));
584 IRDA_ERROR("unable to change speed\n");
589 mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
591 /* MINRXPW values recommended by MosChip */
592 if (mcs
->new_speed
<= 115200) {
595 if ((rst
= (mcs
->speed
> 115200)))
596 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 0);
598 } else if (mcs
->new_speed
<= 1152000) {
601 if ((rst
= !(mcs
->speed
== 576000 || mcs
->speed
== 1152000)))
602 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 5);
607 if ((rst
= (mcs
->speed
!= 4000000)))
608 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 5);
612 rval
&= ~MCS_SPEED_MASK
;
615 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
620 switch (mcs
->transceiver_type
) {
622 ret
= mcs_setup_transceiver_vishay(mcs
);
626 ret
= mcs_setup_transceiver_sharp(mcs
);
629 case MCS_TSC_AGILENT
:
630 ret
= mcs_setup_transceiver_agilent(mcs
);
635 IRDA_WARNING("Unknown transceiver type: %d\n",
636 mcs
->transceiver_type
);
641 mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
643 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
645 mcs
->speed
= mcs
->new_speed
;
651 /* Ioctl calls not supported at this time. Can be an area of future work. */
652 static int mcs_net_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
654 /* struct if_irda_req *irq = (struct if_irda_req *)rq; */
655 /* struct mcs_cb *mcs = netdev_priv(netdev); */
666 /* Network device is taken down, done by "ifconfig irda0 down" */
667 static int mcs_net_close(struct net_device
*netdev
)
670 struct mcs_cb
*mcs
= netdev_priv(netdev
);
672 /* Stop transmit processing */
673 netif_stop_queue(netdev
);
675 kfree_skb(mcs
->rx_buff
.skb
);
677 /* kill and free the receive and transmit URBs */
678 usb_kill_urb(mcs
->rx_urb
);
679 usb_free_urb(mcs
->rx_urb
);
680 usb_kill_urb(mcs
->tx_urb
);
681 usb_free_urb(mcs
->tx_urb
);
683 /* Stop and remove instance of IrLAP */
685 irlap_close(mcs
->irlap
);
691 /* Network device is taken up, done by "ifconfig irda0 up" */
692 static int mcs_net_open(struct net_device
*netdev
)
694 struct mcs_cb
*mcs
= netdev_priv(netdev
);
698 ret
= usb_clear_halt(mcs
->usbdev
,
699 usb_sndbulkpipe(mcs
->usbdev
, mcs
->ep_in
));
702 ret
= usb_clear_halt(mcs
->usbdev
,
703 usb_rcvbulkpipe(mcs
->usbdev
, mcs
->ep_out
));
707 ret
= mcs_setup_transceiver(mcs
);
713 /* Initialize for SIR/FIR to copy data directly into skb. */
715 mcs
->rx_buff
.truesize
= IRDA_SKB_MAX_MTU
;
716 mcs
->rx_buff
.skb
= dev_alloc_skb(IRDA_SKB_MAX_MTU
);
717 if (!mcs
->rx_buff
.skb
)
720 skb_reserve(mcs
->rx_buff
.skb
, 1);
721 mcs
->rx_buff
.head
= mcs
->rx_buff
.skb
->data
;
722 do_gettimeofday(&mcs
->rx_time
);
725 * Now that everything should be initialized properly,
726 * Open new IrLAP layer instance to take care of us...
727 * Note : will send immediately a speed change...
729 sprintf(hwname
, "usb#%d", mcs
->usbdev
->devnum
);
730 mcs
->irlap
= irlap_open(netdev
, &mcs
->qos
, hwname
);
732 IRDA_ERROR("mcs7780: irlap_open failed\n");
736 if (!mcs_setup_urbs(mcs
))
739 ret
= mcs_receive_start(mcs
);
743 netif_start_queue(netdev
);
747 irlap_close(mcs
->irlap
);
749 kfree_skb(mcs
->rx_buff
.skb
);
754 /* Receive callback function. */
755 static void mcs_receive_irq(struct urb
*urb
)
758 struct mcs_cb
*mcs
= urb
->context
;
762 if (!netif_running(mcs
->netdev
))
768 if (urb
->actual_length
> 0) {
769 bytes
= urb
->transfer_buffer
;
771 /* MCS returns frames without BOF and EOF
772 * I assume it returns whole frames.
775 if(mcs
->speed
< 576000) {
776 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
777 &mcs
->rx_buff
, 0xc0);
779 for (i
= 0; i
< urb
->actual_length
; i
++)
780 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
781 &mcs
->rx_buff
, bytes
[i
]);
783 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
784 &mcs
->rx_buff
, 0xc1);
787 else if(mcs
->speed
== 576000 || mcs
->speed
== 1152000) {
788 mcs_unwrap_mir(mcs
, urb
->transfer_buffer
,
793 mcs_unwrap_fir(mcs
, urb
->transfer_buffer
,
796 do_gettimeofday(&mcs
->rx_time
);
799 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
802 /* Transmit callback function. */
803 static void mcs_send_irq(struct urb
*urb
)
805 struct mcs_cb
*mcs
= urb
->context
;
806 struct net_device
*ndev
= mcs
->netdev
;
808 if (unlikely(mcs
->new_speed
))
809 schedule_work(&mcs
->work
);
811 netif_wake_queue(ndev
);
814 /* Transmit callback function. */
815 static netdev_tx_t
mcs_hard_xmit(struct sk_buff
*skb
,
816 struct net_device
*ndev
)
823 netif_stop_queue(ndev
);
824 mcs
= netdev_priv(ndev
);
826 spin_lock_irqsave(&mcs
->lock
, flags
);
828 mcs
->new_speed
= irda_get_next_speed(skb
);
829 if (likely(mcs
->new_speed
== mcs
->speed
))
833 if(mcs
->speed
< 576000) {
834 wraplen
= mcs_wrap_sir_skb(skb
, mcs
->out_buf
);
837 else if(mcs
->speed
== 576000 || mcs
->speed
== 1152000) {
838 wraplen
= mcs_wrap_mir_skb(skb
, mcs
->out_buf
);
842 wraplen
= mcs_wrap_fir_skb(skb
, mcs
->out_buf
);
844 usb_fill_bulk_urb(mcs
->tx_urb
, mcs
->usbdev
,
845 usb_sndbulkpipe(mcs
->usbdev
, mcs
->ep_out
),
846 mcs
->out_buf
, wraplen
, mcs_send_irq
, mcs
);
848 if ((ret
= usb_submit_urb(mcs
->tx_urb
, GFP_ATOMIC
))) {
849 IRDA_ERROR("failed tx_urb: %d\n", ret
);
855 mcs
->netdev
->stats
.tx_errors
++;
856 netif_start_queue(ndev
);
859 mcs
->netdev
->stats
.tx_packets
++;
860 mcs
->netdev
->stats
.tx_bytes
+= skb
->len
;
864 spin_unlock_irqrestore(&mcs
->lock
, flags
);
868 static const struct net_device_ops mcs_netdev_ops
= {
869 .ndo_open
= mcs_net_open
,
870 .ndo_stop
= mcs_net_close
,
871 .ndo_start_xmit
= mcs_hard_xmit
,
872 .ndo_do_ioctl
= mcs_net_ioctl
,
876 * This function is called by the USB subsystem for each new device in the
877 * system. Need to verify the device and if it is, then start handling it.
879 static int mcs_probe(struct usb_interface
*intf
,
880 const struct usb_device_id
*id
)
882 struct usb_device
*udev
= interface_to_usbdev(intf
);
883 struct net_device
*ndev
= NULL
;
887 ndev
= alloc_irdadev(sizeof(*mcs
));
891 IRDA_DEBUG(1, "MCS7780 USB-IrDA bridge found at %d.\n", udev
->devnum
);
893 SET_NETDEV_DEV(ndev
, &intf
->dev
);
895 ret
= usb_reset_configuration(udev
);
897 IRDA_ERROR("mcs7780: usb reset configuration failed\n");
901 mcs
= netdev_priv(ndev
);
904 spin_lock_init(&mcs
->lock
);
906 /* Initialize QoS for this device */
907 irda_init_max_qos_capabilies(&mcs
->qos
);
909 /* That's the Rx capability. */
910 mcs
->qos
.baud_rate
.bits
&=
911 IR_2400
| IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
912 | IR_576000
| IR_1152000
| (IR_4000000
<< 8);
915 mcs
->qos
.min_turn_time
.bits
&= qos_mtt_bits
;
916 irda_qos_bits_to_value(&mcs
->qos
);
918 /* Speed change work initialisation*/
919 INIT_WORK(&mcs
->work
, mcs_speed_work
);
921 ndev
->netdev_ops
= &mcs_netdev_ops
;
923 if (!intf
->cur_altsetting
)
926 ret
= mcs_find_endpoints(mcs
, intf
->cur_altsetting
->endpoint
,
927 intf
->cur_altsetting
->desc
.bNumEndpoints
);
933 ret
= register_netdev(ndev
);
937 IRDA_DEBUG(1, "IrDA: Registered MosChip MCS7780 device as %s\n",
940 mcs
->transceiver_type
= transceiver_type
;
941 mcs
->sir_tweak
= sir_tweak
;
942 mcs
->receive_mode
= receive_mode
;
944 usb_set_intfdata(intf
, mcs
);
954 /* The current device is removed, the USB layer tells us to shut down. */
955 static void mcs_disconnect(struct usb_interface
*intf
)
957 struct mcs_cb
*mcs
= usb_get_intfdata(intf
);
962 cancel_work_sync(&mcs
->work
);
964 unregister_netdev(mcs
->netdev
);
965 free_netdev(mcs
->netdev
);
967 usb_set_intfdata(intf
, NULL
);
968 IRDA_DEBUG(0, "MCS7780 now disconnected.\n");
971 module_usb_driver(mcs_driver
);