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/slab.h>
52 #include <linux/usb.h>
53 #include <linux/device.h>
54 #include <linux/crc32.h>
56 #include <asm/unaligned.h>
57 #include <asm/byteorder.h>
58 #include <asm/uaccess.h>
60 #include <net/irda/irda.h>
61 #include <net/irda/wrapper.h>
62 #include <net/irda/crc.h>
66 #define MCS_VENDOR_ID 0x9710
67 #define MCS_PRODUCT_ID 0x7780
69 static struct usb_device_id mcs_table
[] = {
70 /* MosChip Corp., MCS7780 FIR-USB Adapter */
71 {USB_DEVICE(MCS_VENDOR_ID
, MCS_PRODUCT_ID
)},
75 MODULE_AUTHOR("Brian Pugh <bpugh@cs.pdx.edu>");
76 MODULE_DESCRIPTION("IrDA-USB Dongle Driver for MosChip MCS7780");
77 MODULE_VERSION("0.3alpha");
78 MODULE_LICENSE("GPL");
80 MODULE_DEVICE_TABLE(usb
, mcs_table
);
82 static int qos_mtt_bits
= 0x07 /* > 1ms */ ;
83 module_param(qos_mtt_bits
, int, 0);
84 MODULE_PARM_DESC(qos_mtt_bits
, "Minimum Turn Time");
86 static int receive_mode
= 0x1;
87 module_param(receive_mode
, int, 0);
88 MODULE_PARM_DESC(receive_mode
,
89 "Receive mode of the device (1:fast, 0:slow, default:1)");
91 static int sir_tweak
= 1;
92 module_param(sir_tweak
, int, 0444);
93 MODULE_PARM_DESC(sir_tweak
,
94 "Default pulse width (1:1.6us, 0:3/16 bit, default:1).");
96 static int transceiver_type
= MCS_TSC_VISHAY
;
97 module_param(transceiver_type
, int, 0444);
98 MODULE_PARM_DESC(transceiver_type
, "IR transceiver type, see mcs7780.h.");
100 static struct usb_driver mcs_driver
= {
103 .disconnect
= mcs_disconnect
,
104 .id_table
= mcs_table
,
107 /* speed flag selection by direct addressing.
108 addr = (speed >> 8) & 0x0f
110 0x1 57600 0x2 115200 0x4 1152000 0x5 9600
111 0x6 38400 0x9 2400 0xa 576000 0xb 19200
113 4Mbps (or 2400) must be checked separately. Since it also has
114 to be programmed in a different manner that is not a big problem.
116 static __u16 mcs_speed_set
[16] = { 0,
130 /* Set given 16 bit register with a 16 bit value. Send control message
131 * to set dongle register. */
132 static int mcs_set_reg(struct mcs_cb
*mcs
, __u16 reg
, __u16 val
)
134 struct usb_device
*dev
= mcs
->usbdev
;
135 return usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0), MCS_WRREQ
,
136 MCS_WR_RTYPE
, val
, reg
, NULL
, 0,
137 msecs_to_jiffies(MCS_CTRL_TIMEOUT
));
140 /* Get 16 bit register value. Send contol message to read dongle register. */
141 static int mcs_get_reg(struct mcs_cb
*mcs
, __u16 reg
, __u16
* val
)
143 struct usb_device
*dev
= mcs
->usbdev
;
144 int ret
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0), MCS_RDREQ
,
145 MCS_RD_RTYPE
, 0, reg
, val
, 2,
146 msecs_to_jiffies(MCS_CTRL_TIMEOUT
));
151 /* Setup a communication between mcs7780 and TFDU chips. It is described
152 * in more detail in the data sheet. The setup sequence puts the the
153 * vishay tranceiver into high speed mode. It will also receive SIR speed
154 * packets but at reduced sensitivity.
158 static inline int mcs_setup_transceiver_vishay(struct mcs_cb
*mcs
)
163 /* mcs_get_reg should read exactly two bytes from the dongle */
164 ret
= mcs_get_reg(mcs
, MCS_XCVR_REG
, &rval
);
165 if (unlikely(ret
!= 2)) {
170 /* The MCS_XCVR_CONF bit puts the transceiver into configuration
171 * mode. The MCS_MODE0 bit must start out high (1) and then
172 * transition to low and the MCS_STFIR and MCS_MODE1 bits must
175 rval
|= (MCS_MODE0
| MCS_XCVR_CONF
);
178 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
183 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
187 rval
&= ~MCS_XCVR_CONF
;
188 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
197 /* Setup a communication between mcs7780 and agilent chip. */
198 static inline int mcs_setup_transceiver_agilent(struct mcs_cb
*mcs
)
200 net_warn_ratelimited("This transceiver type is not supported yet\n");
204 /* Setup a communication between mcs7780 and sharp chip. */
205 static inline int mcs_setup_transceiver_sharp(struct mcs_cb
*mcs
)
207 net_warn_ratelimited("This transceiver type is not supported yet\n");
211 /* Common setup for all transceivers */
212 static inline int mcs_setup_transceiver(struct mcs_cb
*mcs
)
218 msg
= "Basic transceiver setup error";
220 /* read value of MODE Register, set the DRIVER and RESET bits
221 * and write value back out to MODE Register
223 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
224 if(unlikely(ret
!= 2))
226 rval
|= MCS_DRIVER
; /* put the mcs7780 into configuration mode. */
227 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
231 rval
= 0; /* set min pulse width to 0 initially. */
232 ret
= mcs_set_reg(mcs
, MCS_MINRXPW_REG
, rval
);
236 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
237 if(unlikely(ret
!= 2))
240 rval
&= ~MCS_FIR
; /* turn off fir mode. */
242 rval
|= MCS_SIR16US
; /* 1.6us pulse width */
244 rval
&= ~MCS_SIR16US
; /* 3/16 bit time pulse width */
246 /* make sure ask mode and back to back packets are off. */
247 rval
&= ~(MCS_BBTG
| MCS_ASK
);
249 rval
&= ~MCS_SPEED_MASK
;
250 rval
|= MCS_SPEED_9600
; /* make sure initial speed is 9600. */
252 mcs
->new_speed
= 0; /* new_speed is set to 0 */
253 rval
&= ~MCS_PLLPWDN
; /* disable power down. */
255 /* make sure device determines direction and that the auto send sip
258 rval
|= MCS_DTD
| MCS_SIPEN
;
260 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
264 msg
= "transceiver model specific setup error";
265 switch (mcs
->transceiver_type
) {
267 ret
= mcs_setup_transceiver_vishay(mcs
);
271 ret
= mcs_setup_transceiver_sharp(mcs
);
274 case MCS_TSC_AGILENT
:
275 ret
= mcs_setup_transceiver_agilent(mcs
);
279 net_warn_ratelimited("Unknown transceiver type: %d\n",
280 mcs
->transceiver_type
);
286 /* If transceiver is not SHARP, then if receive mode set
287 * on the RXFAST bit in the XCVR Register otherwise unset it
289 if (mcs
->transceiver_type
!= MCS_TSC_SHARP
) {
291 ret
= mcs_get_reg(mcs
, MCS_XCVR_REG
, &rval
);
292 if (unlikely(ret
!= 2))
294 if (mcs
->receive_mode
)
298 ret
= mcs_set_reg(mcs
, MCS_XCVR_REG
, rval
);
303 msg
= "transceiver reset";
305 ret
= mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
306 if (unlikely(ret
!= 2))
309 /* reset the mcs7780 so all changes take effect. */
311 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
318 net_err_ratelimited("%s\n", msg
);
322 /* Wraps the data in format for SIR */
323 static inline int mcs_wrap_sir_skb(struct sk_buff
*skb
, __u8
* buf
)
327 /* 2: full frame length, including "the length" */
328 wraplen
= async_wrap_skb(skb
, buf
+ 2, 4094);
331 buf
[0] = wraplen
& 0xff;
332 buf
[1] = (wraplen
>> 8) & 0xff;
337 /* Wraps the data in format for FIR */
338 static unsigned mcs_wrap_fir_skb(const struct sk_buff
*skb
, __u8
*buf
)
340 unsigned int len
= 0;
341 __u32 fcs
= ~(crc32_le(~0, skb
->data
, skb
->len
));
343 /* add 2 bytes for length value and 4 bytes for fcs. */
346 /* The mcs7780 requires that the first two bytes are the packet
347 * length in little endian order. Note: the length value includes
348 * the two bytes for the length value itself.
351 buf
[1] = (len
>> 8) & 0xff;
352 /* copy the data into the tx buffer. */
353 skb_copy_from_linear_data(skb
, buf
+ 2, skb
->len
);
354 /* put the fcs in the last four bytes in little endian order. */
355 buf
[len
- 4] = fcs
& 0xff;
356 buf
[len
- 3] = (fcs
>> 8) & 0xff;
357 buf
[len
- 2] = (fcs
>> 16) & 0xff;
358 buf
[len
- 1] = (fcs
>> 24) & 0xff;
363 /* Wraps the data in format for MIR */
364 static unsigned mcs_wrap_mir_skb(const struct sk_buff
*skb
, __u8
*buf
)
367 int len
= skb
->len
+ 4;
369 fcs
= ~(irda_calc_crc16(~fcs
, skb
->data
, skb
->len
));
370 /* put the total packet length in first. Note: packet length
371 * value includes the two bytes that hold the packet length
375 buf
[1] = (len
>> 8) & 0xff;
377 skb_copy_from_linear_data(skb
, buf
+ 2, skb
->len
);
378 /* put the fcs in last two bytes in little endian order. */
379 buf
[len
- 2] = fcs
& 0xff;
380 buf
[len
- 1] = (fcs
>> 8) & 0xff;
385 /* Unwrap received packets at MIR speed. A 16 bit crc_ccitt checksum is
386 * used for the fcs. When performed over the entire packet the result
387 * should be GOOD_FCS = 0xf0b8. Hands the unwrapped data off to the IrDA
388 * layer via a sk_buff.
390 static void mcs_unwrap_mir(struct mcs_cb
*mcs
, __u8
*buf
, int len
)
396 /* Assume that the frames are going to fill a single packet
397 * rather than span multiple packets.
401 if(unlikely(new_len
<= 0)) {
402 net_err_ratelimited("%s short frame length %d\n",
403 mcs
->netdev
->name
, new_len
);
404 ++mcs
->netdev
->stats
.rx_errors
;
405 ++mcs
->netdev
->stats
.rx_length_errors
;
409 fcs
= irda_calc_crc16(~fcs
, buf
, len
);
411 if(fcs
!= GOOD_FCS
) {
412 net_err_ratelimited("crc error calc 0x%x len %d\n",
414 mcs
->netdev
->stats
.rx_errors
++;
415 mcs
->netdev
->stats
.rx_crc_errors
++;
419 skb
= dev_alloc_skb(new_len
+ 1);
421 ++mcs
->netdev
->stats
.rx_dropped
;
426 skb_copy_to_linear_data(skb
, buf
, new_len
);
427 skb_put(skb
, new_len
);
428 skb_reset_mac_header(skb
);
429 skb
->protocol
= htons(ETH_P_IRDA
);
430 skb
->dev
= mcs
->netdev
;
434 mcs
->netdev
->stats
.rx_packets
++;
435 mcs
->netdev
->stats
.rx_bytes
+= new_len
;
438 /* Unwrap received packets at FIR speed. A 32 bit crc_ccitt checksum is
439 * used for the fcs. Hands the unwrapped data off to the IrDA
440 * layer via a sk_buff.
442 static void mcs_unwrap_fir(struct mcs_cb
*mcs
, __u8
*buf
, int len
)
448 /* Assume that the frames are going to fill a single packet
449 * rather than span multiple packets. This is most likely a false
454 if(unlikely(new_len
<= 0)) {
455 net_err_ratelimited("%s short frame length %d\n",
456 mcs
->netdev
->name
, new_len
);
457 ++mcs
->netdev
->stats
.rx_errors
;
458 ++mcs
->netdev
->stats
.rx_length_errors
;
462 fcs
= ~(crc32_le(~0, buf
, new_len
));
463 if(fcs
!= get_unaligned_le32(buf
+ new_len
)) {
464 net_err_ratelimited("crc error calc 0x%x len %d\n",
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
);
505 usb_free_urb(mcs
->tx_urb
);
513 /* Sets up state to be initially outside frame, gets receive urb,
514 * sets status to successful and then submits the urb to start
515 * receiving the data.
517 static inline int mcs_receive_start(struct mcs_cb
*mcs
)
519 mcs
->rx_buff
.in_frame
= FALSE
;
520 mcs
->rx_buff
.state
= OUTSIDE_FRAME
;
522 usb_fill_bulk_urb(mcs
->rx_urb
, mcs
->usbdev
,
523 usb_rcvbulkpipe(mcs
->usbdev
, mcs
->ep_in
),
524 mcs
->in_buf
, 4096, mcs_receive_irq
, mcs
);
526 mcs
->rx_urb
->status
= 0;
527 return usb_submit_urb(mcs
->rx_urb
, GFP_KERNEL
);
530 /* Finds the in and out endpoints for the mcs control block */
531 static inline int mcs_find_endpoints(struct mcs_cb
*mcs
,
532 struct usb_host_endpoint
*ep
, int epnum
)
537 /* If no place to store the endpoints just return */
541 /* cycle through all endpoints, find the first two that are DIR_IN */
542 for (i
= 0; i
< epnum
; i
++) {
543 if (ep
[i
].desc
.bEndpointAddress
& USB_DIR_IN
)
544 mcs
->ep_in
= ep
[i
].desc
.bEndpointAddress
;
546 mcs
->ep_out
= ep
[i
].desc
.bEndpointAddress
;
548 /* MosChip says that the chip has only two bulk
549 * endpoints. Find one for each direction and move on.
551 if ((mcs
->ep_in
!= 0) && (mcs
->ep_out
!= 0)) {
560 static void mcs_speed_work(struct work_struct
*work
)
562 struct mcs_cb
*mcs
= container_of(work
, struct mcs_cb
, work
);
563 struct net_device
*netdev
= mcs
->netdev
;
565 mcs_speed_change(mcs
);
566 netif_wake_queue(netdev
);
569 /* Function to change the speed of the mcs7780. Fully supports SIR,
570 * MIR, and FIR speeds.
572 static int mcs_speed_change(struct mcs_cb
*mcs
)
580 nspeed
= mcs_speed_set
[(mcs
->new_speed
>> 8) & 0x0f];
583 mcs_get_reg(mcs
, MCS_RESV_REG
, &rval
);
584 } while(cnt
++ < 100 && (rval
& MCS_IRINTX
));
587 net_err_ratelimited("unable to change speed\n");
592 mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
594 /* MINRXPW values recommended by MosChip */
595 if (mcs
->new_speed
<= 115200) {
598 if ((rst
= (mcs
->speed
> 115200)))
599 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 0);
601 } else if (mcs
->new_speed
<= 1152000) {
604 if ((rst
= !(mcs
->speed
== 576000 || mcs
->speed
== 1152000)))
605 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 5);
610 if ((rst
= (mcs
->speed
!= 4000000)))
611 mcs_set_reg(mcs
, MCS_MINRXPW_REG
, 5);
615 rval
&= ~MCS_SPEED_MASK
;
618 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
623 switch (mcs
->transceiver_type
) {
625 ret
= mcs_setup_transceiver_vishay(mcs
);
629 ret
= mcs_setup_transceiver_sharp(mcs
);
632 case MCS_TSC_AGILENT
:
633 ret
= mcs_setup_transceiver_agilent(mcs
);
638 net_warn_ratelimited("Unknown transceiver type: %d\n",
639 mcs
->transceiver_type
);
644 mcs_get_reg(mcs
, MCS_MODE_REG
, &rval
);
646 ret
= mcs_set_reg(mcs
, MCS_MODE_REG
, rval
);
648 mcs
->speed
= mcs
->new_speed
;
654 /* Ioctl calls not supported at this time. Can be an area of future work. */
655 static int mcs_net_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
657 /* struct if_irda_req *irq = (struct if_irda_req *)rq; */
658 /* struct mcs_cb *mcs = netdev_priv(netdev); */
669 /* Network device is taken down, done by "ifconfig irda0 down" */
670 static int mcs_net_close(struct net_device
*netdev
)
673 struct mcs_cb
*mcs
= netdev_priv(netdev
);
675 /* Stop transmit processing */
676 netif_stop_queue(netdev
);
678 kfree_skb(mcs
->rx_buff
.skb
);
680 /* kill and free the receive and transmit URBs */
681 usb_kill_urb(mcs
->rx_urb
);
682 usb_free_urb(mcs
->rx_urb
);
683 usb_kill_urb(mcs
->tx_urb
);
684 usb_free_urb(mcs
->tx_urb
);
686 /* Stop and remove instance of IrLAP */
688 irlap_close(mcs
->irlap
);
694 /* Network device is taken up, done by "ifconfig irda0 up" */
695 static int mcs_net_open(struct net_device
*netdev
)
697 struct mcs_cb
*mcs
= netdev_priv(netdev
);
701 ret
= usb_clear_halt(mcs
->usbdev
,
702 usb_sndbulkpipe(mcs
->usbdev
, mcs
->ep_in
));
705 ret
= usb_clear_halt(mcs
->usbdev
,
706 usb_rcvbulkpipe(mcs
->usbdev
, mcs
->ep_out
));
710 ret
= mcs_setup_transceiver(mcs
);
716 /* Initialize for SIR/FIR to copy data directly into skb. */
718 mcs
->rx_buff
.truesize
= IRDA_SKB_MAX_MTU
;
719 mcs
->rx_buff
.skb
= dev_alloc_skb(IRDA_SKB_MAX_MTU
);
720 if (!mcs
->rx_buff
.skb
)
723 skb_reserve(mcs
->rx_buff
.skb
, 1);
724 mcs
->rx_buff
.head
= mcs
->rx_buff
.skb
->data
;
727 * Now that everything should be initialized properly,
728 * Open new IrLAP layer instance to take care of us...
729 * Note : will send immediately a speed change...
731 sprintf(hwname
, "usb#%d", mcs
->usbdev
->devnum
);
732 mcs
->irlap
= irlap_open(netdev
, &mcs
->qos
, hwname
);
734 net_err_ratelimited("mcs7780: irlap_open failed\n");
738 if (!mcs_setup_urbs(mcs
))
741 ret
= mcs_receive_start(mcs
);
745 netif_start_queue(netdev
);
749 usb_free_urb(mcs
->rx_urb
);
750 usb_free_urb(mcs
->tx_urb
);
752 irlap_close(mcs
->irlap
);
754 kfree_skb(mcs
->rx_buff
.skb
);
759 /* Receive callback function. */
760 static void mcs_receive_irq(struct urb
*urb
)
763 struct mcs_cb
*mcs
= urb
->context
;
767 if (!netif_running(mcs
->netdev
))
773 if (urb
->actual_length
> 0) {
774 bytes
= urb
->transfer_buffer
;
776 /* MCS returns frames without BOF and EOF
777 * I assume it returns whole frames.
780 if(mcs
->speed
< 576000) {
781 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
782 &mcs
->rx_buff
, 0xc0);
784 for (i
= 0; i
< urb
->actual_length
; i
++)
785 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
786 &mcs
->rx_buff
, bytes
[i
]);
788 async_unwrap_char(mcs
->netdev
, &mcs
->netdev
->stats
,
789 &mcs
->rx_buff
, 0xc1);
792 else if(mcs
->speed
== 576000 || mcs
->speed
== 1152000) {
793 mcs_unwrap_mir(mcs
, urb
->transfer_buffer
,
798 mcs_unwrap_fir(mcs
, urb
->transfer_buffer
,
803 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
806 /* Transmit callback function. */
807 static void mcs_send_irq(struct urb
*urb
)
809 struct mcs_cb
*mcs
= urb
->context
;
810 struct net_device
*ndev
= mcs
->netdev
;
812 if (unlikely(mcs
->new_speed
))
813 schedule_work(&mcs
->work
);
815 netif_wake_queue(ndev
);
818 /* Transmit callback function. */
819 static netdev_tx_t
mcs_hard_xmit(struct sk_buff
*skb
,
820 struct net_device
*ndev
)
827 netif_stop_queue(ndev
);
828 mcs
= netdev_priv(ndev
);
830 spin_lock_irqsave(&mcs
->lock
, flags
);
832 mcs
->new_speed
= irda_get_next_speed(skb
);
833 if (likely(mcs
->new_speed
== mcs
->speed
))
837 if(mcs
->speed
< 576000) {
838 wraplen
= mcs_wrap_sir_skb(skb
, mcs
->out_buf
);
841 else if(mcs
->speed
== 576000 || mcs
->speed
== 1152000) {
842 wraplen
= mcs_wrap_mir_skb(skb
, mcs
->out_buf
);
846 wraplen
= mcs_wrap_fir_skb(skb
, mcs
->out_buf
);
848 usb_fill_bulk_urb(mcs
->tx_urb
, mcs
->usbdev
,
849 usb_sndbulkpipe(mcs
->usbdev
, mcs
->ep_out
),
850 mcs
->out_buf
, wraplen
, mcs_send_irq
, mcs
);
852 if ((ret
= usb_submit_urb(mcs
->tx_urb
, GFP_ATOMIC
))) {
853 net_err_ratelimited("failed tx_urb: %d\n", ret
);
859 mcs
->netdev
->stats
.tx_errors
++;
860 netif_start_queue(ndev
);
863 mcs
->netdev
->stats
.tx_packets
++;
864 mcs
->netdev
->stats
.tx_bytes
+= skb
->len
;
868 spin_unlock_irqrestore(&mcs
->lock
, flags
);
872 static const struct net_device_ops mcs_netdev_ops
= {
873 .ndo_open
= mcs_net_open
,
874 .ndo_stop
= mcs_net_close
,
875 .ndo_start_xmit
= mcs_hard_xmit
,
876 .ndo_do_ioctl
= mcs_net_ioctl
,
880 * This function is called by the USB subsystem for each new device in the
881 * system. Need to verify the device and if it is, then start handling it.
883 static int mcs_probe(struct usb_interface
*intf
,
884 const struct usb_device_id
*id
)
886 struct usb_device
*udev
= interface_to_usbdev(intf
);
887 struct net_device
*ndev
= NULL
;
891 ndev
= alloc_irdadev(sizeof(*mcs
));
895 pr_debug("MCS7780 USB-IrDA bridge found at %d.\n", udev
->devnum
);
897 SET_NETDEV_DEV(ndev
, &intf
->dev
);
899 ret
= usb_reset_configuration(udev
);
901 net_err_ratelimited("mcs7780: usb reset configuration failed\n");
905 mcs
= netdev_priv(ndev
);
908 spin_lock_init(&mcs
->lock
);
910 /* Initialize QoS for this device */
911 irda_init_max_qos_capabilies(&mcs
->qos
);
913 /* That's the Rx capability. */
914 mcs
->qos
.baud_rate
.bits
&=
915 IR_2400
| IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
916 | IR_576000
| IR_1152000
| (IR_4000000
<< 8);
919 mcs
->qos
.min_turn_time
.bits
&= qos_mtt_bits
;
920 irda_qos_bits_to_value(&mcs
->qos
);
922 /* Speed change work initialisation*/
923 INIT_WORK(&mcs
->work
, mcs_speed_work
);
925 ndev
->netdev_ops
= &mcs_netdev_ops
;
927 if (!intf
->cur_altsetting
) {
932 ret
= mcs_find_endpoints(mcs
, intf
->cur_altsetting
->endpoint
,
933 intf
->cur_altsetting
->desc
.bNumEndpoints
);
939 ret
= register_netdev(ndev
);
943 pr_debug("IrDA: Registered MosChip MCS7780 device as %s\n",
946 mcs
->transceiver_type
= transceiver_type
;
947 mcs
->sir_tweak
= sir_tweak
;
948 mcs
->receive_mode
= receive_mode
;
950 usb_set_intfdata(intf
, mcs
);
960 /* The current device is removed, the USB layer tells us to shut down. */
961 static void mcs_disconnect(struct usb_interface
*intf
)
963 struct mcs_cb
*mcs
= usb_get_intfdata(intf
);
968 cancel_work_sync(&mcs
->work
);
970 unregister_netdev(mcs
->netdev
);
971 free_netdev(mcs
->netdev
);
973 usb_set_intfdata(intf
, NULL
);
974 pr_debug("MCS7780 now disconnected.\n");
977 module_usb_driver(mcs_driver
);