kingsun-sir.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*****************************************************************************
  2. *
  3. * Filename: kingsun-sir.c
  4. * Version: 0.1.1
  5. * Description: Irda KingSun/DonShine USB Dongle
  6. * Status: Experimental
  7. * Author: Alex Villac�s Lasso <a_villacis@palosanto.com>
  8. *
  9. * Based on stir4200 and mcs7780 drivers, with (strange?) differences
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. *****************************************************************************/
  25. /*
  26. * This is my current (2007-04-25) understanding of how this dongle is supposed
  27. * to work. This is based on reverse-engineering and examination of the packet
  28. * data sent and received by the WinXP driver using USBSnoopy. Feel free to
  29. * update here as more of this dongle is known:
  30. *
  31. * General: Unlike the other USB IrDA dongles, this particular dongle exposes,
  32. * not two bulk (in and out) endpoints, but two *interrupt* ones. This dongle,
  33. * like the bulk based ones (stir4200.c and mcs7780.c), requires polling in
  34. * order to receive data.
  35. * Transmission: Just like stir4200, this dongle uses a raw stream of data,
  36. * which needs to be wrapped and escaped in a similar way as in stir4200.c.
  37. * Reception: Poll-based, as in stir4200. Each read returns the contents of a
  38. * 8-byte buffer, of which the first byte (LSB) indicates the number of bytes
  39. * (1-7) of valid data contained within the remaining 7 bytes. For example, if
  40. * the buffer had the following contents:
  41. * 06 ff ff ff c0 01 04 aa
  42. * This means that (06) there are 6 bytes of valid data. The byte 0xaa at the
  43. * end is garbage (left over from a previous reception) and is discarded.
  44. * If a read returns an "impossible" value as the length of valid data (such as
  45. * 0x36) in the first byte, then the buffer is uninitialized (as is the case of
  46. * first plug-in) and its contents should be discarded. There is currently no
  47. * evidence that the top 5 bits of the 1st byte of the buffer can have values
  48. * other than 0 once reception begins.
  49. * Once valid bytes are collected, the assembled stream is a sequence of
  50. * wrapped IrDA frames that is unwrapped and unescaped as in stir4200.c.
  51. * BIG FAT WARNING: the dongle does *not* reset the RX buffer in any way after
  52. * a successful read from the host, which means that in absence of further
  53. * reception, repeated reads from the dongle will return the exact same
  54. * contents repeatedly. Attempts to be smart and cache a previous read seem
  55. * to result in corrupted packets, so this driver depends on the unwrap logic
  56. * to sort out any repeated reads.
  57. * Speed change: no commands observed so far to change speed, assumed fixed
  58. * 9600bps (SIR).
  59. */
  60. #include <linux/module.h>
  61. #include <linux/moduleparam.h>
  62. #include <linux/kernel.h>
  63. #include <linux/types.h>
  64. #include <linux/errno.h>
  65. #include <linux/init.h>
  66. #include <linux/slab.h>
  67. #include <linux/module.h>
  68. #include <linux/kref.h>
  69. #include <linux/usb.h>
  70. #include <linux/device.h>
  71. #include <linux/crc32.h>
  72. #include <asm/unaligned.h>
  73. #include <asm/byteorder.h>
  74. #include <asm/uaccess.h>
  75. #include <net/irda/irda.h>
  76. #include <net/irda/wrapper.h>
  77. #include <net/irda/crc.h>
  78. /*
  79. * According to lsusb, 0x07c0 is assigned to
  80. * "Code Mercenaries Hard- und Software GmbH"
  81. */
  82. #define KING_VENDOR_ID 0x07c0
  83. #define KING_PRODUCT_ID 0x4200
  84. /* These are the currently known USB ids */
  85. static struct usb_device_id dongles[] = {
  86. /* KingSun Co,Ltd IrDA/USB Bridge */
  87. { USB_DEVICE(KING_VENDOR_ID, KING_PRODUCT_ID) },
  88. { }
  89. };
  90. MODULE_DEVICE_TABLE(usb, dongles);
  91. #define KINGSUN_MTT 0x07
  92. #define KINGSUN_FIFO_SIZE 4096
  93. #define KINGSUN_EP_IN 0
  94. #define KINGSUN_EP_OUT 1
  95. struct kingsun_cb {
  96. struct usb_device *usbdev; /* init: probe_irda */
  97. struct net_device *netdev; /* network layer */
  98. struct irlap_cb *irlap; /* The link layer we are binded to */
  99. struct net_device_stats stats; /* network statistics */
  100. struct qos_info qos;
  101. __u8 *in_buf; /* receive buffer */
  102. __u8 *out_buf; /* transmit buffer */
  103. __u8 max_rx; /* max. atomic read from dongle
  104. (usually 8), also size of in_buf */
  105. __u8 max_tx; /* max. atomic write to dongle
  106. (usually 8) */
  107. iobuff_t rx_buff; /* receive unwrap state machine */
  108. struct timeval rx_time;
  109. spinlock_t lock;
  110. int receiving;
  111. __u8 ep_in;
  112. __u8 ep_out;
  113. struct urb *tx_urb;
  114. struct urb *rx_urb;
  115. };
  116. /* Callback transmission routine */
  117. static void kingsun_send_irq(struct urb *urb)
  118. {
  119. struct kingsun_cb *kingsun = urb->context;
  120. struct net_device *netdev = kingsun->netdev;
  121. /* in process of stopping, just drop data */
  122. if (!netif_running(kingsun->netdev)) {
  123. err("kingsun_send_irq: Network not running!");
  124. return;
  125. }
  126. /* unlink, shutdown, unplug, other nasties */
  127. if (urb->status != 0) {
  128. err("kingsun_send_irq: urb asynchronously failed - %d",
  129. urb->status);
  130. }
  131. netif_wake_queue(netdev);
  132. }
  133. /*
  134. * Called from net/core when new frame is available.
  135. */
  136. static int kingsun_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
  137. {
  138. struct kingsun_cb *kingsun;
  139. int wraplen;
  140. int ret = 0;
  141. if (skb == NULL || netdev == NULL)
  142. return -EINVAL;
  143. netif_stop_queue(netdev);
  144. /* the IRDA wrapping routines don't deal with non linear skb */
  145. SKB_LINEAR_ASSERT(skb);
  146. kingsun = netdev_priv(netdev);
  147. spin_lock(&kingsun->lock);
  148. /* Append data to the end of whatever data remains to be transmitted */
  149. wraplen = async_wrap_skb(skb,
  150. kingsun->out_buf,
  151. KINGSUN_FIFO_SIZE);
  152. /* Calculate how much data can be transmitted in this urb */
  153. usb_fill_int_urb(kingsun->tx_urb, kingsun->usbdev,
  154. usb_sndintpipe(kingsun->usbdev, kingsun->ep_out),
  155. kingsun->out_buf, wraplen, kingsun_send_irq,
  156. kingsun, 1);
  157. if ((ret = usb_submit_urb(kingsun->tx_urb, GFP_ATOMIC))) {
  158. err("kingsun_hard_xmit: failed tx_urb submit: %d", ret);
  159. switch (ret) {
  160. case -ENODEV:
  161. case -EPIPE:
  162. break;
  163. default:
  164. kingsun->stats.tx_errors++;
  165. netif_start_queue(netdev);
  166. }
  167. } else {
  168. kingsun->stats.tx_packets++;
  169. kingsun->stats.tx_bytes += skb->len;
  170. }
  171. dev_kfree_skb(skb);
  172. spin_unlock(&kingsun->lock);
  173. return ret;
  174. }
  175. /* Receive callback function */
  176. static void kingsun_rcv_irq(struct urb *urb)
  177. {
  178. struct kingsun_cb *kingsun = urb->context;
  179. int ret;
  180. /* in process of stopping, just drop data */
  181. if (!netif_running(kingsun->netdev)) {
  182. kingsun->receiving = 0;
  183. return;
  184. }
  185. /* unlink, shutdown, unplug, other nasties */
  186. if (urb->status != 0) {
  187. err("kingsun_rcv_irq: urb asynchronously failed - %d",
  188. urb->status);
  189. kingsun->receiving = 0;
  190. return;
  191. }
  192. if (urb->actual_length == kingsun->max_rx) {
  193. __u8 *bytes = urb->transfer_buffer;
  194. int i;
  195. /* The very first byte in the buffer indicates the length of
  196. valid data in the read. This byte must be in the range
  197. 1..kingsun->max_rx -1 . Values outside this range indicate
  198. an uninitialized Rx buffer when the dongle has just been
  199. plugged in. */
  200. if (bytes[0] >= 1 && bytes[0] < kingsun->max_rx) {
  201. for (i = 1; i <= bytes[0]; i++) {
  202. async_unwrap_char(kingsun->netdev,
  203. &kingsun->stats,
  204. &kingsun->rx_buff, bytes[i]);
  205. }
  206. kingsun->netdev->last_rx = jiffies;
  207. do_gettimeofday(&kingsun->rx_time);
  208. kingsun->receiving =
  209. (kingsun->rx_buff.state != OUTSIDE_FRAME)
  210. ? 1 : 0;
  211. }
  212. } else if (urb->actual_length > 0) {
  213. err("%s(): Unexpected response length, expected %d got %d",
  214. __FUNCTION__, kingsun->max_rx, urb->actual_length);
  215. }
  216. /* This urb has already been filled in kingsun_net_open */
  217. ret = usb_submit_urb(urb, GFP_ATOMIC);
  218. }
  219. /*
  220. * Function kingsun_net_open (dev)
  221. *
  222. * Network device is taken up. Usually this is done by "ifconfig irda0 up"
  223. */
  224. static int kingsun_net_open(struct net_device *netdev)
  225. {
  226. struct kingsun_cb *kingsun = netdev_priv(netdev);
  227. int err = -ENOMEM;
  228. char hwname[16];
  229. /* At this point, urbs are NULL, and skb is NULL (see kingsun_probe) */
  230. kingsun->receiving = 0;
  231. /* Initialize for SIR to copy data directly into skb. */
  232. kingsun->rx_buff.in_frame = FALSE;
  233. kingsun->rx_buff.state = OUTSIDE_FRAME;
  234. kingsun->rx_buff.truesize = IRDA_SKB_MAX_MTU;
  235. kingsun->rx_buff.skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
  236. if (!kingsun->rx_buff.skb)
  237. goto free_mem;
  238. skb_reserve(kingsun->rx_buff.skb, 1);
  239. kingsun->rx_buff.head = kingsun->rx_buff.skb->data;
  240. do_gettimeofday(&kingsun->rx_time);
  241. kingsun->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
  242. if (!kingsun->rx_urb)
  243. goto free_mem;
  244. kingsun->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
  245. if (!kingsun->tx_urb)
  246. goto free_mem;
  247. /*
  248. * Now that everything should be initialized properly,
  249. * Open new IrLAP layer instance to take care of us...
  250. */
  251. sprintf(hwname, "usb#%d", kingsun->usbdev->devnum);
  252. kingsun->irlap = irlap_open(netdev, &kingsun->qos, hwname);
  253. if (!kingsun->irlap) {
  254. err("kingsun-sir: irlap_open failed");
  255. goto free_mem;
  256. }
  257. /* Start first reception */
  258. usb_fill_int_urb(kingsun->rx_urb, kingsun->usbdev,
  259. usb_rcvintpipe(kingsun->usbdev, kingsun->ep_in),
  260. kingsun->in_buf, kingsun->max_rx,
  261. kingsun_rcv_irq, kingsun, 1);
  262. kingsun->rx_urb->status = 0;
  263. err = usb_submit_urb(kingsun->rx_urb, GFP_KERNEL);
  264. if (err) {
  265. err("kingsun-sir: first urb-submit failed: %d", err);
  266. goto close_irlap;
  267. }
  268. netif_start_queue(netdev);
  269. /* Situation at this point:
  270. - all work buffers allocated
  271. - urbs allocated and ready to fill
  272. - max rx packet known (in max_rx)
  273. - unwrap state machine initialized, in state outside of any frame
  274. - receive request in progress
  275. - IrLAP layer started, about to hand over packets to send
  276. */
  277. return 0;
  278. close_irlap:
  279. irlap_close(kingsun->irlap);
  280. free_mem:
  281. if (kingsun->tx_urb) {
  282. usb_free_urb(kingsun->tx_urb);
  283. kingsun->tx_urb = NULL;
  284. }
  285. if (kingsun->rx_urb) {
  286. usb_free_urb(kingsun->rx_urb);
  287. kingsun->rx_urb = NULL;
  288. }
  289. if (kingsun->rx_buff.skb) {
  290. kfree_skb(kingsun->rx_buff.skb);
  291. kingsun->rx_buff.skb = NULL;
  292. kingsun->rx_buff.head = NULL;
  293. }
  294. return err;
  295. }
  296. /*
  297. * Function kingsun_net_close (kingsun)
  298. *
  299. * Network device is taken down. Usually this is done by
  300. * "ifconfig irda0 down"
  301. */
  302. static int kingsun_net_close(struct net_device *netdev)
  303. {
  304. struct kingsun_cb *kingsun = netdev_priv(netdev);
  305. /* Stop transmit processing */
  306. netif_stop_queue(netdev);
  307. /* Mop up receive && transmit urb's */
  308. usb_kill_urb(kingsun->tx_urb);
  309. usb_kill_urb(kingsun->rx_urb);
  310. usb_free_urb(kingsun->tx_urb);
  311. usb_free_urb(kingsun->rx_urb);
  312. kingsun->tx_urb = NULL;
  313. kingsun->rx_urb = NULL;
  314. kfree_skb(kingsun->rx_buff.skb);
  315. kingsun->rx_buff.skb = NULL;
  316. kingsun->rx_buff.head = NULL;
  317. kingsun->rx_buff.in_frame = FALSE;
  318. kingsun->rx_buff.state = OUTSIDE_FRAME;
  319. kingsun->receiving = 0;
  320. /* Stop and remove instance of IrLAP */
  321. if (kingsun->irlap)
  322. irlap_close(kingsun->irlap);
  323. kingsun->irlap = NULL;
  324. return 0;
  325. }
  326. /*
  327. * IOCTLs : Extra out-of-band network commands...
  328. */
  329. static int kingsun_net_ioctl(struct net_device *netdev, struct ifreq *rq,
  330. int cmd)
  331. {
  332. struct if_irda_req *irq = (struct if_irda_req *) rq;
  333. struct kingsun_cb *kingsun = netdev_priv(netdev);
  334. int ret = 0;
  335. switch (cmd) {
  336. case SIOCSBANDWIDTH: /* Set bandwidth */
  337. if (!capable(CAP_NET_ADMIN))
  338. return -EPERM;
  339. /* Check if the device is still there */
  340. if (netif_device_present(kingsun->netdev))
  341. /* No observed commands for speed change */
  342. ret = -EOPNOTSUPP;
  343. break;
  344. case SIOCSMEDIABUSY: /* Set media busy */
  345. if (!capable(CAP_NET_ADMIN))
  346. return -EPERM;
  347. /* Check if the IrDA stack is still there */
  348. if (netif_running(kingsun->netdev))
  349. irda_device_set_media_busy(kingsun->netdev, TRUE);
  350. break;
  351. case SIOCGRECEIVING:
  352. /* Only approximately true */
  353. irq->ifr_receiving = kingsun->receiving;
  354. break;
  355. default:
  356. ret = -EOPNOTSUPP;
  357. }
  358. return ret;
  359. }
  360. /*
  361. * Get device stats (for /proc/net/dev and ifconfig)
  362. */
  363. static struct net_device_stats *
  364. kingsun_net_get_stats(struct net_device *netdev)
  365. {
  366. struct kingsun_cb *kingsun = netdev_priv(netdev);
  367. return &kingsun->stats;
  368. }
  369. /*
  370. * This routine is called by the USB subsystem for each new device
  371. * in the system. We need to check if the device is ours, and in
  372. * this case start handling it.
  373. */
  374. static int kingsun_probe(struct usb_interface *intf,
  375. const struct usb_device_id *id)
  376. {
  377. struct usb_host_interface *interface;
  378. struct usb_endpoint_descriptor *endpoint;
  379. struct usb_device *dev = interface_to_usbdev(intf);
  380. struct kingsun_cb *kingsun = NULL;
  381. struct net_device *net = NULL;
  382. int ret = -ENOMEM;
  383. int pipe, maxp_in, maxp_out;
  384. __u8 ep_in;
  385. __u8 ep_out;
  386. /* Check that there really are two interrupt endpoints.
  387. Check based on the one in drivers/usb/input/usbmouse.c
  388. */
  389. interface = intf->cur_altsetting;
  390. if (interface->desc.bNumEndpoints != 2) {
  391. err("kingsun-sir: expected 2 endpoints, found %d",
  392. interface->desc.bNumEndpoints);
  393. return -ENODEV;
  394. }
  395. endpoint = &interface->endpoint[KINGSUN_EP_IN].desc;
  396. if (!usb_endpoint_is_int_in(endpoint)) {
  397. err("kingsun-sir: endpoint 0 is not interrupt IN");
  398. return -ENODEV;
  399. }
  400. ep_in = endpoint->bEndpointAddress;
  401. pipe = usb_rcvintpipe(dev, ep_in);
  402. maxp_in = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  403. if (maxp_in > 255 || maxp_in <= 1) {
  404. err("%s: endpoint 0 has max packet size %d not in range",
  405. __FILE__, maxp_in);
  406. return -ENODEV;
  407. }
  408. endpoint = &interface->endpoint[KINGSUN_EP_OUT].desc;
  409. if (!usb_endpoint_is_int_out(endpoint)) {
  410. err("kingsun-sir: endpoint 1 is not interrupt OUT");
  411. return -ENODEV;
  412. }
  413. ep_out = endpoint->bEndpointAddress;
  414. pipe = usb_sndintpipe(dev, ep_out);
  415. maxp_out = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  416. /* Allocate network device container. */
  417. net = alloc_irdadev(sizeof(*kingsun));
  418. if(!net)
  419. goto err_out1;
  420. SET_MODULE_OWNER(net);
  421. SET_NETDEV_DEV(net, &intf->dev);
  422. kingsun = netdev_priv(net);
  423. kingsun->irlap = NULL;
  424. kingsun->tx_urb = NULL;
  425. kingsun->rx_urb = NULL;
  426. kingsun->ep_in = ep_in;
  427. kingsun->ep_out = ep_out;
  428. kingsun->in_buf = NULL;
  429. kingsun->out_buf = NULL;
  430. kingsun->max_rx = (__u8)maxp_in;
  431. kingsun->max_tx = (__u8)maxp_out;
  432. kingsun->netdev = net;
  433. kingsun->usbdev = dev;
  434. kingsun->rx_buff.in_frame = FALSE;
  435. kingsun->rx_buff.state = OUTSIDE_FRAME;
  436. kingsun->rx_buff.skb = NULL;
  437. kingsun->receiving = 0;
  438. spin_lock_init(&kingsun->lock);
  439. /* Allocate input buffer */
  440. kingsun->in_buf = (__u8 *)kmalloc(kingsun->max_rx, GFP_KERNEL);
  441. if (!kingsun->in_buf)
  442. goto free_mem;
  443. /* Allocate output buffer */
  444. kingsun->out_buf = (__u8 *)kmalloc(KINGSUN_FIFO_SIZE, GFP_KERNEL);
  445. if (!kingsun->out_buf)
  446. goto free_mem;
  447. printk(KERN_INFO "KingSun/DonShine IRDA/USB found at address %d, "
  448. "Vendor: %x, Product: %x\n",
  449. dev->devnum, le16_to_cpu(dev->descriptor.idVendor),
  450. le16_to_cpu(dev->descriptor.idProduct));
  451. /* Initialize QoS for this device */
  452. irda_init_max_qos_capabilies(&kingsun->qos);
  453. /* That's the Rx capability. */
  454. kingsun->qos.baud_rate.bits &= IR_9600;
  455. kingsun->qos.min_turn_time.bits &= KINGSUN_MTT;
  456. irda_qos_bits_to_value(&kingsun->qos);
  457. /* Override the network functions we need to use */
  458. net->hard_start_xmit = kingsun_hard_xmit;
  459. net->open = kingsun_net_open;
  460. net->stop = kingsun_net_close;
  461. net->get_stats = kingsun_net_get_stats;
  462. net->do_ioctl = kingsun_net_ioctl;
  463. ret = register_netdev(net);
  464. if (ret != 0)
  465. goto free_mem;
  466. info("IrDA: Registered KingSun/DonShine device %s", net->name);
  467. usb_set_intfdata(intf, kingsun);
  468. /* Situation at this point:
  469. - all work buffers allocated
  470. - urbs not allocated, set to NULL
  471. - max rx packet known (in max_rx)
  472. - unwrap state machine (partially) initialized, but skb == NULL
  473. */
  474. return 0;
  475. free_mem:
  476. if (kingsun->out_buf) kfree(kingsun->out_buf);
  477. if (kingsun->in_buf) kfree(kingsun->in_buf);
  478. free_netdev(net);
  479. err_out1:
  480. return ret;
  481. }
  482. /*
  483. * The current device is removed, the USB layer tell us to shut it down...
  484. */
  485. static void kingsun_disconnect(struct usb_interface *intf)
  486. {
  487. struct kingsun_cb *kingsun = usb_get_intfdata(intf);
  488. if (!kingsun)
  489. return;
  490. unregister_netdev(kingsun->netdev);
  491. /* Mop up receive && transmit urb's */
  492. if (kingsun->tx_urb != NULL) {
  493. usb_kill_urb(kingsun->tx_urb);
  494. usb_free_urb(kingsun->tx_urb);
  495. kingsun->tx_urb = NULL;
  496. }
  497. if (kingsun->rx_urb != NULL) {
  498. usb_kill_urb(kingsun->rx_urb);
  499. usb_free_urb(kingsun->rx_urb);
  500. kingsun->rx_urb = NULL;
  501. }
  502. kfree(kingsun->out_buf);
  503. kfree(kingsun->in_buf);
  504. free_netdev(kingsun->netdev);
  505. usb_set_intfdata(intf, NULL);
  506. }
  507. #ifdef CONFIG_PM
  508. /* USB suspend, so power off the transmitter/receiver */
  509. static int kingsun_suspend(struct usb_interface *intf, pm_message_t message)
  510. {
  511. struct kingsun_cb *kingsun = usb_get_intfdata(intf);
  512. netif_device_detach(kingsun->netdev);
  513. if (kingsun->tx_urb != NULL) usb_kill_urb(kingsun->tx_urb);
  514. if (kingsun->rx_urb != NULL) usb_kill_urb(kingsun->rx_urb);
  515. return 0;
  516. }
  517. /* Coming out of suspend, so reset hardware */
  518. static int kingsun_resume(struct usb_interface *intf)
  519. {
  520. struct kingsun_cb *kingsun = usb_get_intfdata(intf);
  521. if (kingsun->rx_urb != NULL)
  522. usb_submit_urb(kingsun->rx_urb, GFP_KERNEL);
  523. netif_device_attach(kingsun->netdev);
  524. return 0;
  525. }
  526. #endif
  527. /*
  528. * USB device callbacks
  529. */
  530. static struct usb_driver irda_driver = {
  531. .name = "kingsun-sir",
  532. .probe = kingsun_probe,
  533. .disconnect = kingsun_disconnect,
  534. .id_table = dongles,
  535. #ifdef CONFIG_PM
  536. .suspend = kingsun_suspend,
  537. .resume = kingsun_resume,
  538. #endif
  539. };
  540. /*
  541. * Module insertion
  542. */
  543. static int __init kingsun_init(void)
  544. {
  545. return usb_register(&irda_driver);
  546. }
  547. module_init(kingsun_init);
  548. /*
  549. * Module removal
  550. */
  551. static void __exit kingsun_cleanup(void)
  552. {
  553. /* Deregister the driver and remove all pending instances */
  554. usb_deregister(&irda_driver);
  555. }
  556. module_exit(kingsun_cleanup);
  557. MODULE_AUTHOR("Alex Villac�s Lasso <a_villacis@palosanto.com>");
  558. MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine");
  559. MODULE_LICENSE("GPL");