Linux 4.19.133
[linux/fpc-iii.git] / drivers / mfd / dln2.c
blob6ea0dd37b4535a1497313d05c60d4ee90598c4ed
1 /*
2 * Driver for the Diolan DLN-2 USB adapter
4 * Copyright (c) 2014 Intel Corporation
6 * Derived from:
7 * i2c-diolan-u2c.c
8 * Copyright (c) 2010-2011 Ericsson AB
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
20 #include <linux/i2c.h>
21 #include <linux/mutex.h>
22 #include <linux/platform_device.h>
23 #include <linux/mfd/core.h>
24 #include <linux/mfd/dln2.h>
25 #include <linux/rculist.h>
27 struct dln2_header {
28 __le16 size;
29 __le16 id;
30 __le16 echo;
31 __le16 handle;
34 struct dln2_response {
35 struct dln2_header hdr;
36 __le16 result;
39 #define DLN2_GENERIC_MODULE_ID 0x00
40 #define DLN2_GENERIC_CMD(cmd) DLN2_CMD(cmd, DLN2_GENERIC_MODULE_ID)
41 #define CMD_GET_DEVICE_VER DLN2_GENERIC_CMD(0x30)
42 #define CMD_GET_DEVICE_SN DLN2_GENERIC_CMD(0x31)
44 #define DLN2_HW_ID 0x200
45 #define DLN2_USB_TIMEOUT 200 /* in ms */
46 #define DLN2_MAX_RX_SLOTS 16
47 #define DLN2_MAX_URBS 16
48 #define DLN2_RX_BUF_SIZE 512
50 enum dln2_handle {
51 DLN2_HANDLE_EVENT = 0, /* don't change, hardware defined */
52 DLN2_HANDLE_CTRL,
53 DLN2_HANDLE_GPIO,
54 DLN2_HANDLE_I2C,
55 DLN2_HANDLE_SPI,
56 DLN2_HANDLES
60 * Receive context used between the receive demultiplexer and the transfer
61 * routine. While sending a request the transfer routine will look for a free
62 * receive context and use it to wait for a response and to receive the URB and
63 * thus the response data.
65 struct dln2_rx_context {
66 /* completion used to wait for a response */
67 struct completion done;
69 /* if non-NULL the URB contains the response */
70 struct urb *urb;
72 /* if true then this context is used to wait for a response */
73 bool in_use;
77 * Receive contexts for a particular DLN2 module (i2c, gpio, etc.). We use the
78 * handle header field to identify the module in dln2_dev.mod_rx_slots and then
79 * the echo header field to index the slots field and find the receive context
80 * for a particular request.
82 struct dln2_mod_rx_slots {
83 /* RX slots bitmap */
84 DECLARE_BITMAP(bmap, DLN2_MAX_RX_SLOTS);
86 /* used to wait for a free RX slot */
87 wait_queue_head_t wq;
89 /* used to wait for an RX operation to complete */
90 struct dln2_rx_context slots[DLN2_MAX_RX_SLOTS];
92 /* avoid races between alloc/free_rx_slot and dln2_rx_transfer */
93 spinlock_t lock;
96 enum dln2_endpoint {
97 DLN2_EP_OUT = 0,
98 DLN2_EP_IN = 1,
101 struct dln2_dev {
102 struct usb_device *usb_dev;
103 struct usb_interface *interface;
104 u8 ep_in;
105 u8 ep_out;
107 struct urb *rx_urb[DLN2_MAX_URBS];
108 void *rx_buf[DLN2_MAX_URBS];
110 struct dln2_mod_rx_slots mod_rx_slots[DLN2_HANDLES];
112 struct list_head event_cb_list;
113 spinlock_t event_cb_lock;
115 bool disconnect;
116 int active_transfers;
117 wait_queue_head_t disconnect_wq;
118 spinlock_t disconnect_lock;
121 struct dln2_event_cb_entry {
122 struct list_head list;
123 u16 id;
124 struct platform_device *pdev;
125 dln2_event_cb_t callback;
128 int dln2_register_event_cb(struct platform_device *pdev, u16 id,
129 dln2_event_cb_t event_cb)
131 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
132 struct dln2_event_cb_entry *i, *entry;
133 unsigned long flags;
134 int ret = 0;
136 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
137 if (!entry)
138 return -ENOMEM;
140 entry->id = id;
141 entry->callback = event_cb;
142 entry->pdev = pdev;
144 spin_lock_irqsave(&dln2->event_cb_lock, flags);
146 list_for_each_entry(i, &dln2->event_cb_list, list) {
147 if (i->id == id) {
148 ret = -EBUSY;
149 break;
153 if (!ret)
154 list_add_rcu(&entry->list, &dln2->event_cb_list);
156 spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
158 if (ret)
159 kfree(entry);
161 return ret;
163 EXPORT_SYMBOL(dln2_register_event_cb);
165 void dln2_unregister_event_cb(struct platform_device *pdev, u16 id)
167 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
168 struct dln2_event_cb_entry *i;
169 unsigned long flags;
170 bool found = false;
172 spin_lock_irqsave(&dln2->event_cb_lock, flags);
174 list_for_each_entry(i, &dln2->event_cb_list, list) {
175 if (i->id == id) {
176 list_del_rcu(&i->list);
177 found = true;
178 break;
182 spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
184 if (found) {
185 synchronize_rcu();
186 kfree(i);
189 EXPORT_SYMBOL(dln2_unregister_event_cb);
192 * Returns true if a valid transfer slot is found. In this case the URB must not
193 * be resubmitted immediately in dln2_rx as we need the data when dln2_transfer
194 * is woke up. It will be resubmitted there.
196 static bool dln2_transfer_complete(struct dln2_dev *dln2, struct urb *urb,
197 u16 handle, u16 rx_slot)
199 struct device *dev = &dln2->interface->dev;
200 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
201 struct dln2_rx_context *rxc;
202 unsigned long flags;
203 bool valid_slot = false;
205 if (rx_slot >= DLN2_MAX_RX_SLOTS)
206 goto out;
208 rxc = &rxs->slots[rx_slot];
210 spin_lock_irqsave(&rxs->lock, flags);
211 if (rxc->in_use && !rxc->urb) {
212 rxc->urb = urb;
213 complete(&rxc->done);
214 valid_slot = true;
216 spin_unlock_irqrestore(&rxs->lock, flags);
218 out:
219 if (!valid_slot)
220 dev_warn(dev, "bad/late response %d/%d\n", handle, rx_slot);
222 return valid_slot;
225 static void dln2_run_event_callbacks(struct dln2_dev *dln2, u16 id, u16 echo,
226 void *data, int len)
228 struct dln2_event_cb_entry *i;
230 rcu_read_lock();
232 list_for_each_entry_rcu(i, &dln2->event_cb_list, list) {
233 if (i->id == id) {
234 i->callback(i->pdev, echo, data, len);
235 break;
239 rcu_read_unlock();
242 static void dln2_rx(struct urb *urb)
244 struct dln2_dev *dln2 = urb->context;
245 struct dln2_header *hdr = urb->transfer_buffer;
246 struct device *dev = &dln2->interface->dev;
247 u16 id, echo, handle, size;
248 u8 *data;
249 int len;
250 int err;
252 switch (urb->status) {
253 case 0:
254 /* success */
255 break;
256 case -ECONNRESET:
257 case -ENOENT:
258 case -ESHUTDOWN:
259 case -EPIPE:
260 /* this urb is terminated, clean up */
261 dev_dbg(dev, "urb shutting down with status %d\n", urb->status);
262 return;
263 default:
264 dev_dbg(dev, "nonzero urb status received %d\n", urb->status);
265 goto out;
268 if (urb->actual_length < sizeof(struct dln2_header)) {
269 dev_err(dev, "short response: %d\n", urb->actual_length);
270 goto out;
273 handle = le16_to_cpu(hdr->handle);
274 id = le16_to_cpu(hdr->id);
275 echo = le16_to_cpu(hdr->echo);
276 size = le16_to_cpu(hdr->size);
278 if (size != urb->actual_length) {
279 dev_err(dev, "size mismatch: handle %x cmd %x echo %x size %d actual %d\n",
280 handle, id, echo, size, urb->actual_length);
281 goto out;
284 if (handle >= DLN2_HANDLES) {
285 dev_warn(dev, "invalid handle %d\n", handle);
286 goto out;
289 data = urb->transfer_buffer + sizeof(struct dln2_header);
290 len = urb->actual_length - sizeof(struct dln2_header);
292 if (handle == DLN2_HANDLE_EVENT) {
293 dln2_run_event_callbacks(dln2, id, echo, data, len);
294 } else {
295 /* URB will be re-submitted in _dln2_transfer (free_rx_slot) */
296 if (dln2_transfer_complete(dln2, urb, handle, echo))
297 return;
300 out:
301 err = usb_submit_urb(urb, GFP_ATOMIC);
302 if (err < 0)
303 dev_err(dev, "failed to resubmit RX URB: %d\n", err);
306 static void *dln2_prep_buf(u16 handle, u16 cmd, u16 echo, const void *obuf,
307 int *obuf_len, gfp_t gfp)
309 int len;
310 void *buf;
311 struct dln2_header *hdr;
313 len = *obuf_len + sizeof(*hdr);
314 buf = kmalloc(len, gfp);
315 if (!buf)
316 return NULL;
318 hdr = (struct dln2_header *)buf;
319 hdr->id = cpu_to_le16(cmd);
320 hdr->size = cpu_to_le16(len);
321 hdr->echo = cpu_to_le16(echo);
322 hdr->handle = cpu_to_le16(handle);
324 memcpy(buf + sizeof(*hdr), obuf, *obuf_len);
326 *obuf_len = len;
328 return buf;
331 static int dln2_send_wait(struct dln2_dev *dln2, u16 handle, u16 cmd, u16 echo,
332 const void *obuf, int obuf_len)
334 int ret = 0;
335 int len = obuf_len;
336 void *buf;
337 int actual;
339 buf = dln2_prep_buf(handle, cmd, echo, obuf, &len, GFP_KERNEL);
340 if (!buf)
341 return -ENOMEM;
343 ret = usb_bulk_msg(dln2->usb_dev,
344 usb_sndbulkpipe(dln2->usb_dev, dln2->ep_out),
345 buf, len, &actual, DLN2_USB_TIMEOUT);
347 kfree(buf);
349 return ret;
352 static bool find_free_slot(struct dln2_dev *dln2, u16 handle, int *slot)
354 struct dln2_mod_rx_slots *rxs;
355 unsigned long flags;
357 if (dln2->disconnect) {
358 *slot = -ENODEV;
359 return true;
362 rxs = &dln2->mod_rx_slots[handle];
364 spin_lock_irqsave(&rxs->lock, flags);
366 *slot = find_first_zero_bit(rxs->bmap, DLN2_MAX_RX_SLOTS);
368 if (*slot < DLN2_MAX_RX_SLOTS) {
369 struct dln2_rx_context *rxc = &rxs->slots[*slot];
371 set_bit(*slot, rxs->bmap);
372 rxc->in_use = true;
375 spin_unlock_irqrestore(&rxs->lock, flags);
377 return *slot < DLN2_MAX_RX_SLOTS;
380 static int alloc_rx_slot(struct dln2_dev *dln2, u16 handle)
382 int ret;
383 int slot;
386 * No need to timeout here, the wait is bounded by the timeout in
387 * _dln2_transfer.
389 ret = wait_event_interruptible(dln2->mod_rx_slots[handle].wq,
390 find_free_slot(dln2, handle, &slot));
391 if (ret < 0)
392 return ret;
394 return slot;
397 static void free_rx_slot(struct dln2_dev *dln2, u16 handle, int slot)
399 struct dln2_mod_rx_slots *rxs;
400 struct urb *urb = NULL;
401 unsigned long flags;
402 struct dln2_rx_context *rxc;
404 rxs = &dln2->mod_rx_slots[handle];
406 spin_lock_irqsave(&rxs->lock, flags);
408 clear_bit(slot, rxs->bmap);
410 rxc = &rxs->slots[slot];
411 rxc->in_use = false;
412 urb = rxc->urb;
413 rxc->urb = NULL;
414 reinit_completion(&rxc->done);
416 spin_unlock_irqrestore(&rxs->lock, flags);
418 if (urb) {
419 int err;
420 struct device *dev = &dln2->interface->dev;
422 err = usb_submit_urb(urb, GFP_KERNEL);
423 if (err < 0)
424 dev_err(dev, "failed to resubmit RX URB: %d\n", err);
427 wake_up_interruptible(&rxs->wq);
430 static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
431 const void *obuf, unsigned obuf_len,
432 void *ibuf, unsigned *ibuf_len)
434 int ret = 0;
435 int rx_slot;
436 struct dln2_response *rsp;
437 struct dln2_rx_context *rxc;
438 struct device *dev = &dln2->interface->dev;
439 const unsigned long timeout = msecs_to_jiffies(DLN2_USB_TIMEOUT);
440 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
441 int size;
443 spin_lock(&dln2->disconnect_lock);
444 if (!dln2->disconnect)
445 dln2->active_transfers++;
446 else
447 ret = -ENODEV;
448 spin_unlock(&dln2->disconnect_lock);
450 if (ret)
451 return ret;
453 rx_slot = alloc_rx_slot(dln2, handle);
454 if (rx_slot < 0) {
455 ret = rx_slot;
456 goto out_decr;
459 ret = dln2_send_wait(dln2, handle, cmd, rx_slot, obuf, obuf_len);
460 if (ret < 0) {
461 dev_err(dev, "USB write failed: %d\n", ret);
462 goto out_free_rx_slot;
465 rxc = &rxs->slots[rx_slot];
467 ret = wait_for_completion_interruptible_timeout(&rxc->done, timeout);
468 if (ret <= 0) {
469 if (!ret)
470 ret = -ETIMEDOUT;
471 goto out_free_rx_slot;
472 } else {
473 ret = 0;
476 if (dln2->disconnect) {
477 ret = -ENODEV;
478 goto out_free_rx_slot;
481 /* if we got here we know that the response header has been checked */
482 rsp = rxc->urb->transfer_buffer;
483 size = le16_to_cpu(rsp->hdr.size);
485 if (size < sizeof(*rsp)) {
486 ret = -EPROTO;
487 goto out_free_rx_slot;
490 if (le16_to_cpu(rsp->result) > 0x80) {
491 dev_dbg(dev, "%d received response with error %d\n",
492 handle, le16_to_cpu(rsp->result));
493 ret = -EREMOTEIO;
494 goto out_free_rx_slot;
497 if (!ibuf)
498 goto out_free_rx_slot;
500 if (*ibuf_len > size - sizeof(*rsp))
501 *ibuf_len = size - sizeof(*rsp);
503 memcpy(ibuf, rsp + 1, *ibuf_len);
505 out_free_rx_slot:
506 free_rx_slot(dln2, handle, rx_slot);
507 out_decr:
508 spin_lock(&dln2->disconnect_lock);
509 dln2->active_transfers--;
510 spin_unlock(&dln2->disconnect_lock);
511 if (dln2->disconnect)
512 wake_up(&dln2->disconnect_wq);
514 return ret;
517 int dln2_transfer(struct platform_device *pdev, u16 cmd,
518 const void *obuf, unsigned obuf_len,
519 void *ibuf, unsigned *ibuf_len)
521 struct dln2_platform_data *dln2_pdata;
522 struct dln2_dev *dln2;
523 u16 handle;
525 dln2 = dev_get_drvdata(pdev->dev.parent);
526 dln2_pdata = dev_get_platdata(&pdev->dev);
527 handle = dln2_pdata->handle;
529 return _dln2_transfer(dln2, handle, cmd, obuf, obuf_len, ibuf,
530 ibuf_len);
532 EXPORT_SYMBOL(dln2_transfer);
534 static int dln2_check_hw(struct dln2_dev *dln2)
536 int ret;
537 __le32 hw_type;
538 int len = sizeof(hw_type);
540 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_VER,
541 NULL, 0, &hw_type, &len);
542 if (ret < 0)
543 return ret;
544 if (len < sizeof(hw_type))
545 return -EREMOTEIO;
547 if (le32_to_cpu(hw_type) != DLN2_HW_ID) {
548 dev_err(&dln2->interface->dev, "Device ID 0x%x not supported\n",
549 le32_to_cpu(hw_type));
550 return -ENODEV;
553 return 0;
556 static int dln2_print_serialno(struct dln2_dev *dln2)
558 int ret;
559 __le32 serial_no;
560 int len = sizeof(serial_no);
561 struct device *dev = &dln2->interface->dev;
563 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_SN, NULL, 0,
564 &serial_no, &len);
565 if (ret < 0)
566 return ret;
567 if (len < sizeof(serial_no))
568 return -EREMOTEIO;
570 dev_info(dev, "Diolan DLN2 serial %u\n", le32_to_cpu(serial_no));
572 return 0;
575 static int dln2_hw_init(struct dln2_dev *dln2)
577 int ret;
579 ret = dln2_check_hw(dln2);
580 if (ret < 0)
581 return ret;
583 return dln2_print_serialno(dln2);
586 static void dln2_free_rx_urbs(struct dln2_dev *dln2)
588 int i;
590 for (i = 0; i < DLN2_MAX_URBS; i++) {
591 usb_free_urb(dln2->rx_urb[i]);
592 kfree(dln2->rx_buf[i]);
596 static void dln2_stop_rx_urbs(struct dln2_dev *dln2)
598 int i;
600 for (i = 0; i < DLN2_MAX_URBS; i++)
601 usb_kill_urb(dln2->rx_urb[i]);
604 static void dln2_free(struct dln2_dev *dln2)
606 dln2_free_rx_urbs(dln2);
607 usb_put_dev(dln2->usb_dev);
608 kfree(dln2);
611 static int dln2_setup_rx_urbs(struct dln2_dev *dln2,
612 struct usb_host_interface *hostif)
614 int i;
615 const int rx_max_size = DLN2_RX_BUF_SIZE;
617 for (i = 0; i < DLN2_MAX_URBS; i++) {
618 dln2->rx_buf[i] = kmalloc(rx_max_size, GFP_KERNEL);
619 if (!dln2->rx_buf[i])
620 return -ENOMEM;
622 dln2->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
623 if (!dln2->rx_urb[i])
624 return -ENOMEM;
626 usb_fill_bulk_urb(dln2->rx_urb[i], dln2->usb_dev,
627 usb_rcvbulkpipe(dln2->usb_dev, dln2->ep_in),
628 dln2->rx_buf[i], rx_max_size, dln2_rx, dln2);
631 return 0;
634 static int dln2_start_rx_urbs(struct dln2_dev *dln2, gfp_t gfp)
636 struct device *dev = &dln2->interface->dev;
637 int ret;
638 int i;
640 for (i = 0; i < DLN2_MAX_URBS; i++) {
641 ret = usb_submit_urb(dln2->rx_urb[i], gfp);
642 if (ret < 0) {
643 dev_err(dev, "failed to submit RX URB: %d\n", ret);
644 return ret;
648 return 0;
651 static struct dln2_platform_data dln2_pdata_gpio = {
652 .handle = DLN2_HANDLE_GPIO,
655 /* Only one I2C port seems to be supported on current hardware */
656 static struct dln2_platform_data dln2_pdata_i2c = {
657 .handle = DLN2_HANDLE_I2C,
658 .port = 0,
661 /* Only one SPI port supported */
662 static struct dln2_platform_data dln2_pdata_spi = {
663 .handle = DLN2_HANDLE_SPI,
664 .port = 0,
667 static const struct mfd_cell dln2_devs[] = {
669 .name = "dln2-gpio",
670 .platform_data = &dln2_pdata_gpio,
671 .pdata_size = sizeof(struct dln2_platform_data),
674 .name = "dln2-i2c",
675 .platform_data = &dln2_pdata_i2c,
676 .pdata_size = sizeof(struct dln2_platform_data),
679 .name = "dln2-spi",
680 .platform_data = &dln2_pdata_spi,
681 .pdata_size = sizeof(struct dln2_platform_data),
685 static void dln2_stop(struct dln2_dev *dln2)
687 int i, j;
689 /* don't allow starting new transfers */
690 spin_lock(&dln2->disconnect_lock);
691 dln2->disconnect = true;
692 spin_unlock(&dln2->disconnect_lock);
694 /* cancel in progress transfers */
695 for (i = 0; i < DLN2_HANDLES; i++) {
696 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[i];
697 unsigned long flags;
699 spin_lock_irqsave(&rxs->lock, flags);
701 /* cancel all response waiters */
702 for (j = 0; j < DLN2_MAX_RX_SLOTS; j++) {
703 struct dln2_rx_context *rxc = &rxs->slots[j];
705 if (rxc->in_use)
706 complete(&rxc->done);
709 spin_unlock_irqrestore(&rxs->lock, flags);
712 /* wait for transfers to end */
713 wait_event(dln2->disconnect_wq, !dln2->active_transfers);
715 dln2_stop_rx_urbs(dln2);
718 static void dln2_disconnect(struct usb_interface *interface)
720 struct dln2_dev *dln2 = usb_get_intfdata(interface);
722 dln2_stop(dln2);
724 mfd_remove_devices(&interface->dev);
726 dln2_free(dln2);
729 static int dln2_probe(struct usb_interface *interface,
730 const struct usb_device_id *usb_id)
732 struct usb_host_interface *hostif = interface->cur_altsetting;
733 struct usb_endpoint_descriptor *epin;
734 struct usb_endpoint_descriptor *epout;
735 struct device *dev = &interface->dev;
736 struct dln2_dev *dln2;
737 int ret;
738 int i, j;
740 if (hostif->desc.bInterfaceNumber != 0 ||
741 hostif->desc.bNumEndpoints < 2)
742 return -ENODEV;
744 epout = &hostif->endpoint[DLN2_EP_OUT].desc;
745 if (!usb_endpoint_is_bulk_out(epout))
746 return -ENODEV;
747 epin = &hostif->endpoint[DLN2_EP_IN].desc;
748 if (!usb_endpoint_is_bulk_in(epin))
749 return -ENODEV;
751 dln2 = kzalloc(sizeof(*dln2), GFP_KERNEL);
752 if (!dln2)
753 return -ENOMEM;
755 dln2->ep_out = epout->bEndpointAddress;
756 dln2->ep_in = epin->bEndpointAddress;
757 dln2->usb_dev = usb_get_dev(interface_to_usbdev(interface));
758 dln2->interface = interface;
759 usb_set_intfdata(interface, dln2);
760 init_waitqueue_head(&dln2->disconnect_wq);
762 for (i = 0; i < DLN2_HANDLES; i++) {
763 init_waitqueue_head(&dln2->mod_rx_slots[i].wq);
764 spin_lock_init(&dln2->mod_rx_slots[i].lock);
765 for (j = 0; j < DLN2_MAX_RX_SLOTS; j++)
766 init_completion(&dln2->mod_rx_slots[i].slots[j].done);
769 spin_lock_init(&dln2->event_cb_lock);
770 spin_lock_init(&dln2->disconnect_lock);
771 INIT_LIST_HEAD(&dln2->event_cb_list);
773 ret = dln2_setup_rx_urbs(dln2, hostif);
774 if (ret)
775 goto out_free;
777 ret = dln2_start_rx_urbs(dln2, GFP_KERNEL);
778 if (ret)
779 goto out_stop_rx;
781 ret = dln2_hw_init(dln2);
782 if (ret < 0) {
783 dev_err(dev, "failed to initialize hardware\n");
784 goto out_stop_rx;
787 ret = mfd_add_hotplug_devices(dev, dln2_devs, ARRAY_SIZE(dln2_devs));
788 if (ret != 0) {
789 dev_err(dev, "failed to add mfd devices to core\n");
790 goto out_stop_rx;
793 return 0;
795 out_stop_rx:
796 dln2_stop_rx_urbs(dln2);
798 out_free:
799 dln2_free(dln2);
801 return ret;
804 static int dln2_suspend(struct usb_interface *iface, pm_message_t message)
806 struct dln2_dev *dln2 = usb_get_intfdata(iface);
808 dln2_stop(dln2);
810 return 0;
813 static int dln2_resume(struct usb_interface *iface)
815 struct dln2_dev *dln2 = usb_get_intfdata(iface);
817 dln2->disconnect = false;
819 return dln2_start_rx_urbs(dln2, GFP_NOIO);
822 static const struct usb_device_id dln2_table[] = {
823 { USB_DEVICE(0xa257, 0x2013) },
827 MODULE_DEVICE_TABLE(usb, dln2_table);
829 static struct usb_driver dln2_driver = {
830 .name = "dln2",
831 .probe = dln2_probe,
832 .disconnect = dln2_disconnect,
833 .id_table = dln2_table,
834 .suspend = dln2_suspend,
835 .resume = dln2_resume,
838 module_usb_driver(dln2_driver);
840 MODULE_AUTHOR("Octavian Purdila <octavian.purdila@intel.com>");
841 MODULE_DESCRIPTION("Core driver for the Diolan DLN2 interface adapter");
842 MODULE_LICENSE("GPL v2");