2 * lirc_imon.c: LIRC/VFD/LCD driver for SoundGraph iMON IR/VFD/LCD
3 * including the iMON PAD model
5 * Copyright(C) 2004 Venky Raju(dev@venky.ws)
6 * Copyright(C) 2009 Jarod Wilson <jarod@wilsonet.com>
8 * lirc_imon is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <linux/uaccess.h>
30 #include <linux/usb.h>
32 #include <media/lirc.h>
33 #include <media/lirc_dev.h>
35 #define MOD_AUTHOR "Venky Raju <dev@venky.ws>"
36 #define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display"
37 #define MOD_NAME "lirc_imon"
38 #define MOD_VERSION "0.8"
40 #define DISPLAY_MINOR_BASE 144
41 #define DEVICE_NAME "lcd%d"
43 #define BUF_CHUNK_SIZE 4
46 #define BIT_DURATION 250 /* each bit received is 250us */
48 /*** P R O T O T Y P E S ***/
50 /* USB Callback prototypes */
51 static int imon_probe(struct usb_interface *interface,
52 const struct usb_device_id *id);
53 static void imon_disconnect(struct usb_interface *interface);
54 static void usb_rx_callback(struct urb *urb);
55 static void usb_tx_callback(struct urb *urb);
57 /* suspend/resume support */
58 static int imon_resume(struct usb_interface *intf);
59 static int imon_suspend(struct usb_interface *intf, pm_message_t message);
61 /* Display file_operations function prototypes */
62 static int display_open(struct inode *inode, struct file *file);
63 static int display_close(struct inode *inode, struct file *file);
65 /* VFD write operation */
66 static ssize_t vfd_write(struct file *file, const char __user *buf,
67 size_t n_bytes, loff_t *pos);
69 /* LIRC driver function prototypes */
70 static int ir_open(void *data);
71 static void ir_close(void *data);
73 /*** G L O B A L S ***/
74 #define IMON_DATA_BUF_SZ 35
77 struct usb_device *usbdev;
78 /* Newer devices have two interfaces */
79 int display; /* not all controllers do */
80 int display_isopen; /* display port has been opened */
81 int ir_isopen; /* IR port open */
82 int dev_present; /* USB device presence */
83 struct mutex ctx_lock; /* to lock this object */
84 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
86 int vfd_proto_6p; /* some VFD require a 6th packet */
88 struct lirc_driver *driver;
89 struct usb_endpoint_descriptor *rx_endpoint;
90 struct usb_endpoint_descriptor *tx_endpoint;
93 unsigned char usb_rx_buf[8];
94 unsigned char usb_tx_buf[8];
97 int count; /* length of 0 or 1 sequence */
98 int prev_bit; /* logic level of sequence */
99 int initial_space; /* initial space flag */
103 unsigned char data_buf[IMON_DATA_BUF_SZ]; /* user data buffer */
104 struct completion finished; /* wait for write to finish */
105 atomic_t busy; /* write in progress */
106 int status; /* status of tx completion */
110 static const struct file_operations display_fops = {
111 .owner = THIS_MODULE,
112 .open = &display_open,
114 .release = &display_close,
115 .llseek = noop_llseek,
119 * USB Device ID for iMON USB Control Boards
121 * The Windows drivers contain 6 different inf files, more or less one for
122 * each new device until the 0x0034-0x0046 devices, which all use the same
123 * driver. Some of the devices in the 34-46 range haven't been definitively
124 * identified yet. Early devices have either a TriGem Computer, Inc. or a
125 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
126 * devices use the SoundGraph vendor ID (0x15c2).
128 static struct usb_device_id imon_usb_id_table[] = {
129 /* TriGem iMON (IR only) -- TG_iMON.inf */
130 { USB_DEVICE(0x0aa8, 0x8001) },
132 /* SoundGraph iMON (IR only) -- sg_imon.inf */
133 { USB_DEVICE(0x04e8, 0xff30) },
135 /* SoundGraph iMON VFD (IR & VFD) -- iMON_VFD.inf */
136 { USB_DEVICE(0x0aa8, 0xffda) },
138 /* SoundGraph iMON SS (IR & VFD) -- iMON_SS.inf */
139 { USB_DEVICE(0x15c2, 0xffda) },
144 /* Some iMON VFD models requires a 6th packet for VFD writes */
145 static struct usb_device_id vfd_proto_6p_list[] = {
146 { USB_DEVICE(0x15c2, 0xffda) },
150 /* Some iMON devices have no lcd/vfd, don't set one up */
151 static struct usb_device_id ir_only_list[] = {
152 { USB_DEVICE(0x0aa8, 0x8001) },
153 { USB_DEVICE(0x04e8, 0xff30) },
157 /* USB Device data */
158 static struct usb_driver imon_driver = {
161 .disconnect = imon_disconnect,
162 .suspend = imon_suspend,
163 .resume = imon_resume,
164 .id_table = imon_usb_id_table,
167 static struct usb_class_driver imon_class = {
169 .fops = &display_fops,
170 .minor_base = DISPLAY_MINOR_BASE,
173 /* to prevent races between open() and disconnect(), probing, etc */
174 static DEFINE_MUTEX(driver_lock);
178 /*** M O D U L E C O D E ***/
180 MODULE_AUTHOR(MOD_AUTHOR);
181 MODULE_DESCRIPTION(MOD_DESC);
182 MODULE_VERSION(MOD_VERSION);
183 MODULE_LICENSE("GPL");
184 MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
185 module_param(debug, int, S_IRUGO | S_IWUSR);
186 MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)");
188 static void free_imon_context(struct imon_context *context)
190 struct device *dev = context->driver->dev;
192 usb_free_urb(context->tx_urb);
193 usb_free_urb(context->rx_urb);
194 lirc_buffer_free(context->driver->rbuf);
195 kfree(context->driver->rbuf);
196 kfree(context->driver);
199 dev_dbg(dev, "%s: iMON context freed\n", __func__);
202 static void deregister_from_lirc(struct imon_context *context)
205 int minor = context->driver->minor;
207 retval = lirc_unregister_driver(minor);
209 dev_err(&context->usbdev->dev,
210 "unable to deregister from lirc(%d)", retval);
212 dev_info(&context->usbdev->dev,
213 "Deregistered iMON driver (minor:%d)\n", minor);
217 * Called when the Display device (e.g. /dev/lcd0)
218 * is opened by the application.
220 static int display_open(struct inode *inode, struct file *file)
222 struct usb_interface *interface;
223 struct imon_context *context = NULL;
227 /* prevent races with disconnect */
228 mutex_lock(&driver_lock);
230 subminor = iminor(inode);
231 interface = usb_find_interface(&imon_driver, subminor);
233 pr_err("%s: could not find interface for minor %d\n",
238 context = usb_get_intfdata(interface);
241 dev_err(&interface->dev, "no context found for minor %d\n",
247 mutex_lock(&context->ctx_lock);
249 if (!context->display) {
250 dev_err(&interface->dev,
251 "%s: display not supported by device\n", __func__);
253 } else if (context->display_isopen) {
254 dev_err(&interface->dev,
255 "%s: display port is already open\n", __func__);
258 context->display_isopen = 1;
259 file->private_data = context;
260 dev_info(context->driver->dev, "display port opened\n");
263 mutex_unlock(&context->ctx_lock);
266 mutex_unlock(&driver_lock);
271 * Called when the display device (e.g. /dev/lcd0)
272 * is closed by the application.
274 static int display_close(struct inode *inode, struct file *file)
276 struct imon_context *context = NULL;
279 context = file->private_data;
282 pr_err("%s: no context for device\n", __func__);
286 mutex_lock(&context->ctx_lock);
288 if (!context->display) {
289 dev_err(&context->usbdev->dev,
290 "%s: display not supported by device\n", __func__);
292 } else if (!context->display_isopen) {
293 dev_err(&context->usbdev->dev,
294 "%s: display is not open\n", __func__);
297 context->display_isopen = 0;
298 dev_info(context->driver->dev, "display port closed\n");
299 if (!context->dev_present && !context->ir_isopen) {
301 * Device disconnected before close and IR port is not
302 * open. If IR port is open, context will be deleted by
305 mutex_unlock(&context->ctx_lock);
306 free_imon_context(context);
311 mutex_unlock(&context->ctx_lock);
316 * Sends a packet to the device -- this function must be called
317 * with context->ctx_lock held.
319 static int send_packet(struct imon_context *context)
325 /* Check if we need to use control or interrupt urb */
326 pipe = usb_sndintpipe(context->usbdev,
327 context->tx_endpoint->bEndpointAddress);
328 interval = context->tx_endpoint->bInterval;
330 usb_fill_int_urb(context->tx_urb, context->usbdev, pipe,
332 sizeof(context->usb_tx_buf),
333 usb_tx_callback, context, interval);
335 context->tx_urb->actual_length = 0;
337 init_completion(&context->tx.finished);
338 atomic_set(&context->tx.busy, 1);
340 retval = usb_submit_urb(context->tx_urb, GFP_KERNEL);
342 atomic_set(&context->tx.busy, 0);
343 dev_err(&context->usbdev->dev, "error submitting urb(%d)\n",
346 /* Wait for transmission to complete (or abort) */
347 mutex_unlock(&context->ctx_lock);
348 retval = wait_for_completion_interruptible(
349 &context->tx.finished);
351 dev_err(&context->usbdev->dev,
352 "%s: task interrupted\n", __func__);
353 mutex_lock(&context->ctx_lock);
355 retval = context->tx.status;
357 dev_err(&context->usbdev->dev,
358 "packet tx failed (%d)\n", retval);
365 * Writes data to the VFD. The iMON VFD is 2x16 characters
366 * and requires data in 5 consecutive USB interrupt packets,
367 * each packet but the last carrying 7 bytes.
369 * I don't know if the VFD board supports features such as
370 * scrolling, clearing rows, blanking, etc. so at
371 * the caller must provide a full screen of data. If fewer
372 * than 32 bytes are provided spaces will be appended to
373 * generate a full screen.
375 static ssize_t vfd_write(struct file *file, const char __user *buf,
376 size_t n_bytes, loff_t *pos)
382 struct imon_context *context;
383 const unsigned char vfd_packet6[] = {
384 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
385 int *data_buf = NULL;
387 context = file->private_data;
389 pr_err("%s: no context for device\n", __func__);
393 mutex_lock(&context->ctx_lock);
395 if (!context->dev_present) {
396 dev_err(&context->usbdev->dev,
397 "%s: no iMON device present\n", __func__);
402 if (n_bytes <= 0 || n_bytes > IMON_DATA_BUF_SZ - 3) {
403 dev_err(&context->usbdev->dev,
404 "%s: invalid payload size\n", __func__);
409 data_buf = memdup_user(buf, n_bytes);
410 if (IS_ERR(data_buf)) {
411 retval = PTR_ERR(data_buf);
416 memcpy(context->tx.data_buf, data_buf, n_bytes);
418 /* Pad with spaces */
419 for (i = n_bytes; i < IMON_DATA_BUF_SZ - 3; ++i)
420 context->tx.data_buf[i] = ' ';
422 for (i = IMON_DATA_BUF_SZ - 3; i < IMON_DATA_BUF_SZ; ++i)
423 context->tx.data_buf[i] = 0xFF;
429 memcpy(context->usb_tx_buf, context->tx.data_buf + offset, 7);
430 context->usb_tx_buf[7] = (unsigned char)seq;
432 retval = send_packet(context);
434 dev_err(&context->usbdev->dev,
435 "send packet failed for packet #%d\n",
443 } while (offset < IMON_DATA_BUF_SZ);
445 if (context->vfd_proto_6p) {
447 memcpy(context->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
448 context->usb_tx_buf[7] = (unsigned char)seq;
449 retval = send_packet(context);
451 dev_err(&context->usbdev->dev,
452 "send packet failed for packet #%d\n",
457 mutex_unlock(&context->ctx_lock);
460 return (!retval) ? n_bytes : retval;
464 * Callback function for USB core API: transmit data
466 static void usb_tx_callback(struct urb *urb)
468 struct imon_context *context;
472 context = (struct imon_context *)urb->context;
476 context->tx.status = urb->status;
478 /* notify waiters that write has finished */
479 atomic_set(&context->tx.busy, 0);
480 complete(&context->tx.finished);
484 * Called by lirc_dev when the application opens /dev/lirc
486 static int ir_open(void *data)
488 struct imon_context *context;
490 /* prevent races with disconnect */
491 mutex_lock(&driver_lock);
495 /* initial IR protocol decode variables */
496 context->rx.count = 0;
497 context->rx.initial_space = 1;
498 context->rx.prev_bit = 0;
500 context->ir_isopen = 1;
501 dev_info(context->driver->dev, "IR port opened\n");
503 mutex_unlock(&driver_lock);
508 * Called by lirc_dev when the application closes /dev/lirc
510 static void ir_close(void *data)
512 struct imon_context *context;
516 pr_err("%s: no context for device\n", __func__);
520 mutex_lock(&context->ctx_lock);
522 context->ir_isopen = 0;
523 dev_info(context->driver->dev, "IR port closed\n");
525 if (!context->dev_present) {
527 * Device disconnected while IR port was still open. Driver
528 * was not deregistered at disconnect time, so do it now.
530 deregister_from_lirc(context);
532 if (!context->display_isopen) {
533 mutex_unlock(&context->ctx_lock);
534 free_imon_context(context);
538 * If display port is open, context will be deleted by
543 mutex_unlock(&context->ctx_lock);
547 * Convert bit count to time duration (in us) and submit
548 * the value to lirc_dev.
550 static void submit_data(struct imon_context *context)
552 unsigned char buf[4];
553 int value = context->rx.count;
556 dev_dbg(context->driver->dev, "submitting data to LIRC\n");
558 value *= BIT_DURATION;
560 if (context->rx.prev_bit)
563 for (i = 0; i < 4; ++i)
564 buf[i] = value >> (i * 8);
566 lirc_buffer_write(context->driver->rbuf, buf);
567 wake_up(&context->driver->rbuf->wait_poll);
571 * Process the incoming packet
573 static void imon_incoming_packet(struct imon_context *context,
574 struct urb *urb, int intf)
576 int len = urb->actual_length;
577 unsigned char *buf = urb->transfer_buffer;
578 struct device *dev = context->driver->dev;
583 * just bail out if no listening IR client
585 if (!context->ir_isopen)
589 dev_warn(dev, "imon %s: invalid incoming packet size (len = %d, intf%d)\n",
590 __func__, len, intf);
595 dev_info(dev, "raw packet: %*ph\n", len, buf);
597 * Translate received data to pulse and space lengths.
598 * Received data is active low, i.e. pulses are 0 and
601 * My original algorithm was essentially similar to
602 * Changwoo Ryu's with the exception that he switched
603 * the incoming bits to active high and also fed an
604 * initial space to LIRC at the start of a new sequence
605 * if the previous bit was a pulse.
607 * I've decided to adopt his algorithm.
610 if (buf[7] == 1 && context->rx.initial_space) {
611 /* LIRC requires a leading space */
612 context->rx.prev_bit = 0;
613 context->rx.count = 4;
614 submit_data(context);
615 context->rx.count = 0;
618 for (octet = 0; octet < 5; ++octet) {
620 for (bit = 0; bit < 8; ++bit) {
621 int curr_bit = !(buf[octet] & mask);
623 if (curr_bit != context->rx.prev_bit) {
624 if (context->rx.count) {
625 submit_data(context);
626 context->rx.count = 0;
628 context->rx.prev_bit = curr_bit;
636 if (context->rx.count) {
637 submit_data(context);
638 context->rx.count = 0;
640 context->rx.initial_space = context->rx.prev_bit;
645 * Callback function for USB core API: receive data
647 static void usb_rx_callback(struct urb *urb)
649 struct imon_context *context;
655 context = (struct imon_context *)urb->context;
659 switch (urb->status) {
660 case -ENOENT: /* usbcore unlink successful! */
664 imon_incoming_packet(context, urb, intfnum);
668 dev_warn(context->driver->dev, "imon %s: status(%d): ignored\n",
669 __func__, urb->status);
673 usb_submit_urb(context->rx_urb, GFP_ATOMIC);
677 * Callback function for USB core API: Probe
679 static int imon_probe(struct usb_interface *interface,
680 const struct usb_device_id *id)
682 struct usb_device *usbdev = NULL;
683 struct usb_host_interface *iface_desc = NULL;
684 struct usb_endpoint_descriptor *rx_endpoint = NULL;
685 struct usb_endpoint_descriptor *tx_endpoint = NULL;
686 struct urb *rx_urb = NULL;
687 struct urb *tx_urb = NULL;
688 struct lirc_driver *driver = NULL;
689 struct lirc_buffer *rbuf = NULL;
690 struct device *dev = &interface->dev;
694 int retval = -ENOMEM;
695 int display_ep_found = 0;
697 int vfd_proto_6p = 0;
698 struct imon_context *context = NULL;
702 /* prevent races probing devices w/multiple interfaces */
703 mutex_lock(&driver_lock);
705 context = kzalloc(sizeof(*context), GFP_KERNEL);
710 * Try to auto-detect the type of display if the user hasn't set
711 * it by hand via the display_type modparam. Default is VFD.
713 if (usb_match_id(interface, ir_only_list))
714 context->display = 0;
716 context->display = 1;
718 usbdev = usb_get_dev(interface_to_usbdev(interface));
719 iface_desc = interface->cur_altsetting;
720 num_endpts = iface_desc->desc.bNumEndpoints;
721 ifnum = iface_desc->desc.bInterfaceNumber;
722 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
723 product = le16_to_cpu(usbdev->descriptor.idProduct);
725 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
726 __func__, vendor, product, ifnum);
729 * Scan the endpoint list and set:
730 * first input endpoint = IR endpoint
731 * first output endpoint = display endpoint
733 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
734 struct usb_endpoint_descriptor *ep;
738 ep = &iface_desc->endpoint[i].desc;
739 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
740 ep_type = usb_endpoint_type(ep);
743 ep_dir == USB_DIR_IN &&
744 ep_type == USB_ENDPOINT_XFER_INT) {
748 dev_dbg(dev, "%s: found IR endpoint\n", __func__);
750 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
751 ep_type == USB_ENDPOINT_XFER_INT) {
753 display_ep_found = 1;
754 dev_dbg(dev, "%s: found display endpoint\n", __func__);
759 * Some iMON receivers have no display. Unfortunately, it seems
760 * that SoundGraph recycles device IDs between devices both with
763 if (context->display == 0) {
764 display_ep_found = 0;
765 dev_dbg(dev, "%s: device has no display\n", __func__);
768 /* Input endpoint is mandatory */
770 dev_err(dev, "%s: no valid input (IR) endpoint found.\n",
776 /* Determine if display requires 6 packets */
777 if (display_ep_found) {
778 if (usb_match_id(interface, vfd_proto_6p_list))
781 dev_dbg(dev, "%s: vfd_proto_6p: %d\n",
782 __func__, vfd_proto_6p);
785 driver = kzalloc(sizeof(*driver), GFP_KERNEL);
789 rbuf = kmalloc(sizeof(*rbuf), GFP_KERNEL);
793 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) {
794 dev_err(dev, "%s: lirc_buffer_init failed\n", __func__);
797 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
800 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
804 mutex_init(&context->ctx_lock);
805 context->vfd_proto_6p = vfd_proto_6p;
807 strcpy(driver->name, MOD_NAME);
809 driver->code_length = BUF_CHUNK_SIZE * 8;
810 driver->sample_rate = 0;
811 driver->features = LIRC_CAN_REC_MODE2;
812 driver->data = context;
814 driver->set_use_inc = ir_open;
815 driver->set_use_dec = ir_close;
816 driver->dev = &interface->dev;
817 driver->owner = THIS_MODULE;
819 mutex_lock(&context->ctx_lock);
821 context->driver = driver;
822 /* start out in keyboard mode */
824 lirc_minor = lirc_register_driver(driver);
825 if (lirc_minor < 0) {
826 dev_err(dev, "%s: lirc_register_driver failed\n", __func__);
830 dev_info(dev, "Registered iMON driver (lirc minor: %d)\n",
833 /* Needed while unregistering! */
834 driver->minor = lirc_minor;
836 context->usbdev = usbdev;
837 context->dev_present = 1;
838 context->rx_endpoint = rx_endpoint;
839 context->rx_urb = rx_urb;
842 * tx is used to send characters to lcd/vfd, associate RF
843 * remotes, set IR protocol, and maybe more...
845 context->tx_endpoint = tx_endpoint;
846 context->tx_urb = tx_urb;
848 if (display_ep_found)
849 context->display = 1;
851 usb_fill_int_urb(context->rx_urb, context->usbdev,
852 usb_rcvintpipe(context->usbdev,
853 context->rx_endpoint->bEndpointAddress),
854 context->usb_rx_buf, sizeof(context->usb_rx_buf),
855 usb_rx_callback, context,
856 context->rx_endpoint->bInterval);
858 retval = usb_submit_urb(context->rx_urb, GFP_KERNEL);
860 dev_err(dev, "usb_submit_urb failed for intf0 (%d)\n", retval);
861 goto unregister_lirc;
864 usb_set_intfdata(interface, context);
866 if (context->display && ifnum == 0) {
867 dev_dbg(dev, "%s: Registering iMON display with sysfs\n",
870 if (usb_register_dev(interface, &imon_class)) {
871 /* Not a fatal error, so ignore */
872 dev_info(dev, "%s: could not get a minor number for display\n",
877 dev_info(dev, "iMON device (%04x:%04x, intf%d) on usb<%d:%d> initialized\n",
878 vendor, product, ifnum, usbdev->bus->busnum, usbdev->devnum);
880 /* Everything went fine. Just unlock and return retval (with is 0) */
881 mutex_unlock(&context->ctx_lock);
885 lirc_unregister_driver(driver->minor);
888 mutex_unlock(&context->ctx_lock);
889 usb_free_urb(tx_urb);
892 usb_free_urb(rx_urb);
895 lirc_buffer_free(rbuf);
907 mutex_unlock(&driver_lock);
913 * Callback function for USB core API: disconnect
915 static void imon_disconnect(struct usb_interface *interface)
917 struct imon_context *context;
920 /* prevent races with ir_open()/display_open() */
921 mutex_lock(&driver_lock);
923 context = usb_get_intfdata(interface);
924 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
926 mutex_lock(&context->ctx_lock);
928 usb_set_intfdata(interface, NULL);
930 /* Abort ongoing write */
931 if (atomic_read(&context->tx.busy)) {
932 usb_kill_urb(context->tx_urb);
933 complete_all(&context->tx.finished);
936 context->dev_present = 0;
937 usb_kill_urb(context->rx_urb);
938 if (context->display)
939 usb_deregister_dev(interface, &imon_class);
941 if (!context->ir_isopen && !context->dev_present) {
942 deregister_from_lirc(context);
943 mutex_unlock(&context->ctx_lock);
944 if (!context->display_isopen)
945 free_imon_context(context);
947 mutex_unlock(&context->ctx_lock);
949 mutex_unlock(&driver_lock);
951 dev_info(&interface->dev, "%s: iMON device (intf%d) disconnected\n",
955 static int imon_suspend(struct usb_interface *intf, pm_message_t message)
957 struct imon_context *context = usb_get_intfdata(intf);
959 usb_kill_urb(context->rx_urb);
964 static int imon_resume(struct usb_interface *intf)
966 struct imon_context *context = usb_get_intfdata(intf);
968 usb_fill_int_urb(context->rx_urb, context->usbdev,
969 usb_rcvintpipe(context->usbdev,
970 context->rx_endpoint->bEndpointAddress),
971 context->usb_rx_buf, sizeof(context->usb_rx_buf),
972 usb_rx_callback, context,
973 context->rx_endpoint->bInterval);
975 return usb_submit_urb(context->rx_urb, GFP_ATOMIC);
978 module_usb_driver(imon_driver);