46 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/types.h>
50 #include <linux/errno.h>
52 #include <linux/slab.h>
54 #include <linux/device.h>
57 #include <asm/unaligned.h>
58 #include <asm/byteorder.h>
59 #include <asm/uaccess.h>
67 #define MCS_VENDOR_ID 0x9710
68 #define MCS_PRODUCT_ID 0x7780
83 static int qos_mtt_bits = 0x07 ;
87 static int receive_mode = 0x1;
90 "Receive mode of the device (1:fast, 0:slow, default:1)");
92 static int sir_tweak = 1;
95 "Default pulse width (1:1.6us, 0:3/16 bit, default:1).");
101 static struct usb_driver mcs_driver = {
104 .disconnect = mcs_disconnect,
105 .id_table = mcs_table,
117 static __u16 mcs_speed_set[16] = { 0,
144 struct usb_device *dev = mcs->
usbdev;
159 static inline int mcs_setup_transceiver_vishay(
struct mcs_cb *mcs)
199 static inline int mcs_setup_transceiver_agilent(
struct mcs_cb *mcs)
201 IRDA_WARNING(
"This transceiver type is not supported yet.\n");
206 static inline int mcs_setup_transceiver_sharp(
struct mcs_cb *mcs)
208 IRDA_WARNING(
"This transceiver type is not supported yet.\n");
213 static inline int mcs_setup_transceiver(
struct mcs_cb *mcs)
219 msg =
"Basic transceiver setup error.";
265 msg =
"transceiver model specific setup error.";
268 ret = mcs_setup_transceiver_vishay(mcs);
272 ret = mcs_setup_transceiver_sharp(mcs);
276 ret = mcs_setup_transceiver_agilent(mcs);
304 msg =
"transceiver reset.";
332 buf[0] = wraplen & 0xff;
333 buf[1] = (wraplen >> 8) & 0xff;
341 unsigned int len = 0;
352 buf[1] = (len >> 8) & 0xff;
354 skb_copy_from_linear_data(skb, buf + 2, skb->
len);
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;
376 buf[1] = (len >> 8) & 0xff;
378 skb_copy_from_linear_data(skb, buf + 2, skb->
len);
380 buf[len - 2] = fcs & 0xff;
381 buf[len - 1] = (fcs >> 8) & 0xff;
391 static void mcs_unwrap_mir(
struct mcs_cb *mcs,
__u8 *
buf,
int len)
404 mcs->
netdev->name, new_len);
405 ++mcs->
netdev->stats.rx_errors;
406 ++mcs->
netdev->stats.rx_length_errors;
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);
429 skb_reset_mac_header(skb);
435 mcs->
netdev->stats.rx_packets++;
436 mcs->
netdev->stats.rx_bytes += new_len;
443 static void mcs_unwrap_fir(
struct mcs_cb *mcs,
__u8 *buf,
int len)
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));
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);
480 skb_reset_mac_header(skb);
486 mcs->
netdev->stats.rx_packets++;
487 mcs->
netdev->stats.rx_bytes += new_len;
495 static inline int mcs_setup_urbs(
struct mcs_cb *mcs)
514 static inline int mcs_receive_start(
struct mcs_cb *mcs)
521 mcs->
in_buf, 4096, mcs_receive_irq, mcs);
528 static inline int mcs_find_endpoints(
struct mcs_cb *mcs,
529 struct usb_host_endpoint *ep,
int epnum)
539 for (i = 0; i < epnum; i++) {
541 mcs->
ep_in = ep[
i].desc.bEndpointAddress;
543 mcs->
ep_out = ep[
i].desc.bEndpointAddress;
562 mcs_speed_change(mcs);
563 netif_wake_queue(netdev);
569 static int mcs_speed_change(
struct mcs_cb *mcs)
577 nspeed = mcs_speed_set[(mcs->
new_speed >> 8) & 0x0f];
595 if ((rst = (mcs->
speed > 115200)))
601 if ((rst = !(mcs->
speed == 576000 || mcs->
speed == 1152000)))
607 if ((rst = (mcs->
speed != 4000000)))
622 ret = mcs_setup_transceiver_vishay(mcs);
626 ret = mcs_setup_transceiver_sharp(mcs);
630 ret = mcs_setup_transceiver_agilent(mcs);
667 static int mcs_net_close(
struct net_device *netdev)
670 struct mcs_cb *mcs = netdev_priv(netdev);
673 netif_stop_queue(netdev);
692 static int mcs_net_open(
struct net_device *netdev)
694 struct mcs_cb *mcs = netdev_priv(netdev);
707 ret = mcs_setup_transceiver(mcs);
736 if (!mcs_setup_urbs(mcs))
739 ret = mcs_receive_start(mcs);
743 netif_start_queue(netdev);
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;
775 if(mcs->
speed < 576000) {
779 for (i = 0; i < urb->actual_length; i++)
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,
803 static void mcs_send_irq(
struct urb *urb)
805 struct mcs_cb *mcs = urb->context;
811 netif_wake_queue(ndev);
823 netif_stop_queue(ndev);
824 mcs = netdev_priv(ndev);
828 mcs->
new_speed = irda_get_next_speed(skb);
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);
846 mcs->
out_buf, wraplen, mcs_send_irq, mcs);
855 mcs->
netdev->stats.tx_errors++;
856 netif_start_queue(ndev);
859 mcs->
netdev->stats.tx_packets++;
864 spin_unlock_irqrestore(&mcs->
lock, flags);
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,
882 struct usb_device *
udev = interface_to_usbdev(intf);
891 IRDA_DEBUG(1,
"MCS7780 USB-IrDA bridge found at %d.\n", udev->devnum);
897 IRDA_ERROR(
"mcs7780: usb reset configuration failed\n");
901 mcs = netdev_priv(ndev);
910 mcs->
qos.baud_rate.bits &=
915 mcs->
qos.min_turn_time.bits &= qos_mtt_bits;
923 if (!intf->cur_altsetting) {
928 ret = mcs_find_endpoints(mcs, intf->cur_altsetting->endpoint,
929 intf->cur_altsetting->desc.bNumEndpoints);
939 IRDA_DEBUG(1,
"IrDA: Registered MosChip MCS7780 device as %s\n",
946 usb_set_intfdata(intf, mcs);
959 struct mcs_cb *mcs = usb_get_intfdata(intf);
969 usb_set_intfdata(intf,
NULL);