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 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/uaccess.h>
29 #include <linux/usb.h>
31 #include <media/lirc.h>
32 #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 *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 /* Driver init/exit prototypes */
74 static int __init
imon_init(void);
75 static void __exit
imon_exit(void);
77 /*** G L O B A L S ***/
78 #define IMON_DATA_BUF_SZ 35
81 struct usb_device
*usbdev
;
82 /* Newer devices have two interfaces */
83 int display
; /* not all controllers do */
84 int display_isopen
; /* display port has been opened */
85 int ir_isopen
; /* IR port open */
86 int dev_present
; /* USB device presence */
87 struct mutex ctx_lock
; /* to lock this object */
88 wait_queue_head_t remove_ok
; /* For unexpected USB disconnects */
90 int vfd_proto_6p
; /* some VFD require a 6th packet */
92 struct lirc_driver
*driver
;
93 struct usb_endpoint_descriptor
*rx_endpoint
;
94 struct usb_endpoint_descriptor
*tx_endpoint
;
97 unsigned char usb_rx_buf
[8];
98 unsigned char usb_tx_buf
[8];
101 int count
; /* length of 0 or 1 sequence */
102 int prev_bit
; /* logic level of sequence */
103 int initial_space
; /* initial space flag */
107 unsigned char data_buf
[IMON_DATA_BUF_SZ
]; /* user data buffer */
108 struct completion finished
; /* wait for write to finish */
109 atomic_t busy
; /* write in progress */
110 int status
; /* status of tx completion */
114 static const struct file_operations display_fops
= {
115 .owner
= THIS_MODULE
,
116 .open
= &display_open
,
118 .release
= &display_close
122 * USB Device ID for iMON USB Control Boards
124 * The Windows drivers contain 6 different inf files, more or less one for
125 * each new device until the 0x0034-0x0046 devices, which all use the same
126 * driver. Some of the devices in the 34-46 range haven't been definitively
127 * identified yet. Early devices have either a TriGem Computer, Inc. or a
128 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
129 * devices use the SoundGraph vendor ID (0x15c2).
131 static struct usb_device_id imon_usb_id_table
[] = {
132 /* TriGem iMON (IR only) -- TG_iMON.inf */
133 { USB_DEVICE(0x0aa8, 0x8001) },
135 /* SoundGraph iMON (IR only) -- sg_imon.inf */
136 { USB_DEVICE(0x04e8, 0xff30) },
138 /* SoundGraph iMON VFD (IR & VFD) -- iMON_VFD.inf */
139 { USB_DEVICE(0x0aa8, 0xffda) },
141 /* SoundGraph iMON SS (IR & VFD) -- iMON_SS.inf */
142 { USB_DEVICE(0x15c2, 0xffda) },
147 /* Some iMON VFD models requires a 6th packet for VFD writes */
148 static struct usb_device_id vfd_proto_6p_list
[] = {
149 { USB_DEVICE(0x15c2, 0xffda) },
153 /* Some iMON devices have no lcd/vfd, don't set one up */
154 static struct usb_device_id ir_only_list
[] = {
155 { USB_DEVICE(0x0aa8, 0x8001) },
156 { USB_DEVICE(0x04e8, 0xff30) },
160 /* USB Device data */
161 static struct usb_driver imon_driver
= {
164 .disconnect
= imon_disconnect
,
165 .suspend
= imon_suspend
,
166 .resume
= imon_resume
,
167 .id_table
= imon_usb_id_table
,
170 static struct usb_class_driver imon_class
= {
172 .fops
= &display_fops
,
173 .minor_base
= DISPLAY_MINOR_BASE
,
176 /* to prevent races between open() and disconnect(), probing, etc */
177 static DEFINE_MUTEX(driver_lock
);
181 /*** M O D U L E C O D E ***/
183 MODULE_AUTHOR(MOD_AUTHOR
);
184 MODULE_DESCRIPTION(MOD_DESC
);
185 MODULE_VERSION(MOD_VERSION
);
186 MODULE_LICENSE("GPL");
187 MODULE_DEVICE_TABLE(usb
, imon_usb_id_table
);
188 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
189 MODULE_PARM_DESC(debug
, "Debug messages: 0=no, 1=yes(default: no)");
191 static void free_imon_context(struct imon_context
*context
)
193 struct device
*dev
= context
->driver
->dev
;
194 usb_free_urb(context
->tx_urb
);
195 usb_free_urb(context
->rx_urb
);
196 lirc_buffer_free(context
->driver
->rbuf
);
197 kfree(context
->driver
->rbuf
);
198 kfree(context
->driver
);
201 dev_dbg(dev
, "%s: iMON context freed\n", __func__
);
204 static void deregister_from_lirc(struct imon_context
*context
)
207 int minor
= context
->driver
->minor
;
209 retval
= lirc_unregister_driver(minor
);
211 err("%s: unable to deregister from lirc(%d)",
214 printk(KERN_INFO MOD_NAME
": Deregistered iMON driver "
215 "(minor:%d)\n", minor
);
220 * Called when the Display device (e.g. /dev/lcd0)
221 * is opened by the application.
223 static int display_open(struct inode
*inode
, struct file
*file
)
225 struct usb_interface
*interface
;
226 struct imon_context
*context
= NULL
;
230 /* prevent races with disconnect */
231 mutex_lock(&driver_lock
);
233 subminor
= iminor(inode
);
234 interface
= usb_find_interface(&imon_driver
, subminor
);
236 err("%s: could not find interface for minor %d",
241 context
= usb_get_intfdata(interface
);
244 err("%s: no context found for minor %d",
250 mutex_lock(&context
->ctx_lock
);
252 if (!context
->display
) {
253 err("%s: display not supported by device", __func__
);
255 } else if (context
->display_isopen
) {
256 err("%s: display port is already open", __func__
);
259 context
->display_isopen
= 1;
260 file
->private_data
= context
;
261 dev_info(context
->driver
->dev
, "display port opened\n");
264 mutex_unlock(&context
->ctx_lock
);
267 mutex_unlock(&driver_lock
);
272 * Called when the display device (e.g. /dev/lcd0)
273 * is closed by the application.
275 static int display_close(struct inode
*inode
, struct file
*file
)
277 struct imon_context
*context
= NULL
;
280 context
= (struct imon_context
*)file
->private_data
;
283 err("%s: no context for device", __func__
);
287 mutex_lock(&context
->ctx_lock
);
289 if (!context
->display
) {
290 err("%s: display not supported by device", __func__
);
292 } else if (!context
->display_isopen
) {
293 err("%s: display is not open", __func__
);
296 context
->display_isopen
= 0;
297 dev_info(context
->driver
->dev
, "display port closed\n");
298 if (!context
->dev_present
&& !context
->ir_isopen
) {
300 * Device disconnected before close and IR port is not
301 * open. If IR port is open, context will be deleted by
304 mutex_unlock(&context
->ctx_lock
);
305 free_imon_context(context
);
310 mutex_unlock(&context
->ctx_lock
);
315 * Sends a packet to the device -- this function must be called
316 * with context->ctx_lock held.
318 static int send_packet(struct imon_context
*context
)
324 /* Check if we need to use control or interrupt urb */
325 pipe
= usb_sndintpipe(context
->usbdev
,
326 context
->tx_endpoint
->bEndpointAddress
);
327 interval
= context
->tx_endpoint
->bInterval
;
329 usb_fill_int_urb(context
->tx_urb
, context
->usbdev
, pipe
,
331 sizeof(context
->usb_tx_buf
),
332 usb_tx_callback
, context
, interval
);
334 context
->tx_urb
->actual_length
= 0;
336 init_completion(&context
->tx
.finished
);
337 atomic_set(&(context
->tx
.busy
), 1);
339 retval
= usb_submit_urb(context
->tx_urb
, GFP_KERNEL
);
341 atomic_set(&(context
->tx
.busy
), 0);
342 err("%s: error submitting urb(%d)", __func__
, retval
);
344 /* Wait for transmission to complete (or abort) */
345 mutex_unlock(&context
->ctx_lock
);
346 retval
= wait_for_completion_interruptible(
347 &context
->tx
.finished
);
349 err("%s: task interrupted", __func__
);
350 mutex_lock(&context
->ctx_lock
);
352 retval
= context
->tx
.status
;
354 err("%s: packet tx failed (%d)", __func__
, retval
);
361 * Writes data to the VFD. The iMON VFD is 2x16 characters
362 * and requires data in 5 consecutive USB interrupt packets,
363 * each packet but the last carrying 7 bytes.
365 * I don't know if the VFD board supports features such as
366 * scrolling, clearing rows, blanking, etc. so at
367 * the caller must provide a full screen of data. If fewer
368 * than 32 bytes are provided spaces will be appended to
369 * generate a full screen.
371 static ssize_t
vfd_write(struct file
*file
, const char *buf
,
372 size_t n_bytes
, loff_t
*pos
)
378 struct imon_context
*context
;
379 const unsigned char vfd_packet6
[] = {
380 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
383 context
= (struct imon_context
*)file
->private_data
;
385 err("%s: no context for device", __func__
);
389 mutex_lock(&context
->ctx_lock
);
391 if (!context
->dev_present
) {
392 err("%s: no iMON device present", __func__
);
397 if (n_bytes
<= 0 || n_bytes
> IMON_DATA_BUF_SZ
- 3) {
398 err("%s: invalid payload size", __func__
);
403 data_buf
= memdup_user(buf
, n_bytes
);
404 if (IS_ERR(data_buf
)) {
405 retval
= PTR_ERR(data_buf
);
409 memcpy(context
->tx
.data_buf
, data_buf
, n_bytes
);
411 /* Pad with spaces */
412 for (i
= n_bytes
; i
< IMON_DATA_BUF_SZ
- 3; ++i
)
413 context
->tx
.data_buf
[i
] = ' ';
415 for (i
= IMON_DATA_BUF_SZ
- 3; i
< IMON_DATA_BUF_SZ
; ++i
)
416 context
->tx
.data_buf
[i
] = 0xFF;
422 memcpy(context
->usb_tx_buf
, context
->tx
.data_buf
+ offset
, 7);
423 context
->usb_tx_buf
[7] = (unsigned char) seq
;
425 retval
= send_packet(context
);
427 err("%s: send packet failed for packet #%d",
435 } while (offset
< IMON_DATA_BUF_SZ
);
437 if (context
->vfd_proto_6p
) {
439 memcpy(context
->usb_tx_buf
, &vfd_packet6
, sizeof(vfd_packet6
));
440 context
->usb_tx_buf
[7] = (unsigned char) seq
;
441 retval
= send_packet(context
);
443 err("%s: send packet failed for packet #%d",
448 mutex_unlock(&context
->ctx_lock
);
450 return (!retval
) ? n_bytes
: retval
;
454 * Callback function for USB core API: transmit data
456 static void usb_tx_callback(struct urb
*urb
)
458 struct imon_context
*context
;
462 context
= (struct imon_context
*)urb
->context
;
466 context
->tx
.status
= urb
->status
;
468 /* notify waiters that write has finished */
469 atomic_set(&context
->tx
.busy
, 0);
470 complete(&context
->tx
.finished
);
476 * Called by lirc_dev when the application opens /dev/lirc
478 static int ir_open(void *data
)
481 struct imon_context
*context
;
483 /* prevent races with disconnect */
484 mutex_lock(&driver_lock
);
486 context
= (struct imon_context
*)data
;
488 /* initial IR protocol decode variables */
489 context
->rx
.count
= 0;
490 context
->rx
.initial_space
= 1;
491 context
->rx
.prev_bit
= 0;
493 context
->ir_isopen
= 1;
494 dev_info(context
->driver
->dev
, "IR port opened\n");
496 mutex_unlock(&driver_lock
);
501 * Called by lirc_dev when the application closes /dev/lirc
503 static void ir_close(void *data
)
505 struct imon_context
*context
;
507 context
= (struct imon_context
*)data
;
509 err("%s: no context for device", __func__
);
513 mutex_lock(&context
->ctx_lock
);
515 context
->ir_isopen
= 0;
516 dev_info(context
->driver
->dev
, "IR port closed\n");
518 if (!context
->dev_present
) {
520 * Device disconnected while IR port was still open. Driver
521 * was not deregistered at disconnect time, so do it now.
523 deregister_from_lirc(context
);
525 if (!context
->display_isopen
) {
526 mutex_unlock(&context
->ctx_lock
);
527 free_imon_context(context
);
531 * If display port is open, context will be deleted by
536 mutex_unlock(&context
->ctx_lock
);
541 * Convert bit count to time duration (in us) and submit
542 * the value to lirc_dev.
544 static void submit_data(struct imon_context
*context
)
546 unsigned char buf
[4];
547 int value
= context
->rx
.count
;
550 dev_dbg(context
->driver
->dev
, "submitting data to LIRC\n");
552 value
*= BIT_DURATION
;
554 if (context
->rx
.prev_bit
)
557 for (i
= 0; i
< 4; ++i
)
558 buf
[i
] = value
>>(i
*8);
560 lirc_buffer_write(context
->driver
->rbuf
, buf
);
561 wake_up(&context
->driver
->rbuf
->wait_poll
);
565 static inline int tv2int(const struct timeval
*a
, const struct timeval
*b
)
570 if (b
->tv_usec
> a
->tv_usec
) {
575 usecs
+= a
->tv_usec
- b
->tv_usec
;
577 sec
+= a
->tv_sec
- b
->tv_sec
;
589 * Process the incoming packet
591 static void imon_incoming_packet(struct imon_context
*context
,
592 struct urb
*urb
, int intf
)
594 int len
= urb
->actual_length
;
595 unsigned char *buf
= urb
->transfer_buffer
;
596 struct device
*dev
= context
->driver
->dev
;
602 * just bail out if no listening IR client
604 if (!context
->ir_isopen
)
608 dev_warn(dev
, "imon %s: invalid incoming packet "
609 "size (len = %d, intf%d)\n", __func__
, len
, intf
);
614 printk(KERN_INFO
"raw packet: ");
615 for (i
= 0; i
< len
; ++i
)
616 printk("%02x ", buf
[i
]);
621 * Translate received data to pulse and space lengths.
622 * Received data is active low, i.e. pulses are 0 and
625 * My original algorithm was essentially similar to
626 * Changwoo Ryu's with the exception that he switched
627 * the incoming bits to active high and also fed an
628 * initial space to LIRC at the start of a new sequence
629 * if the previous bit was a pulse.
631 * I've decided to adopt his algorithm.
634 if (buf
[7] == 1 && context
->rx
.initial_space
) {
635 /* LIRC requires a leading space */
636 context
->rx
.prev_bit
= 0;
637 context
->rx
.count
= 4;
638 submit_data(context
);
639 context
->rx
.count
= 0;
642 for (octet
= 0; octet
< 5; ++octet
) {
644 for (bit
= 0; bit
< 8; ++bit
) {
645 int curr_bit
= !(buf
[octet
] & mask
);
646 if (curr_bit
!= context
->rx
.prev_bit
) {
647 if (context
->rx
.count
) {
648 submit_data(context
);
649 context
->rx
.count
= 0;
651 context
->rx
.prev_bit
= curr_bit
;
659 if (context
->rx
.count
) {
660 submit_data(context
);
661 context
->rx
.count
= 0;
663 context
->rx
.initial_space
= context
->rx
.prev_bit
;
668 * Callback function for USB core API: receive data
670 static void usb_rx_callback(struct urb
*urb
)
672 struct imon_context
*context
;
680 context
= (struct imon_context
*)urb
->context
;
684 buf
= urb
->transfer_buffer
;
685 len
= urb
->actual_length
;
687 switch (urb
->status
) {
688 case -ENOENT
: /* usbcore unlink successful! */
692 imon_incoming_packet(context
, urb
, intfnum
);
696 dev_warn(context
->driver
->dev
, "imon %s: status(%d): ignored\n",
697 __func__
, urb
->status
);
701 usb_submit_urb(context
->rx_urb
, GFP_ATOMIC
);
707 * Callback function for USB core API: Probe
709 static int imon_probe(struct usb_interface
*interface
,
710 const struct usb_device_id
*id
)
712 struct usb_device
*usbdev
= NULL
;
713 struct usb_host_interface
*iface_desc
= NULL
;
714 struct usb_endpoint_descriptor
*rx_endpoint
= NULL
;
715 struct usb_endpoint_descriptor
*tx_endpoint
= NULL
;
716 struct urb
*rx_urb
= NULL
;
717 struct urb
*tx_urb
= NULL
;
718 struct lirc_driver
*driver
= NULL
;
719 struct lirc_buffer
*rbuf
= NULL
;
720 struct device
*dev
= &interface
->dev
;
725 int display_ep_found
= 0;
727 int alloc_status
= 0;
728 int vfd_proto_6p
= 0;
730 struct imon_context
*context
= NULL
;
734 context
= kzalloc(sizeof(struct imon_context
), GFP_KERNEL
);
736 err("%s: kzalloc failed for context", __func__
);
738 goto alloc_status_switch
;
742 * Try to auto-detect the type of display if the user hasn't set
743 * it by hand via the display_type modparam. Default is VFD.
745 if (usb_match_id(interface
, ir_only_list
))
746 context
->display
= 0;
748 context
->display
= 1;
750 code_length
= BUF_CHUNK_SIZE
* 8;
752 usbdev
= usb_get_dev(interface_to_usbdev(interface
));
753 iface_desc
= interface
->cur_altsetting
;
754 num_endpts
= iface_desc
->desc
.bNumEndpoints
;
755 ifnum
= iface_desc
->desc
.bInterfaceNumber
;
756 vendor
= le16_to_cpu(usbdev
->descriptor
.idVendor
);
757 product
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
759 dev_dbg(dev
, "%s: found iMON device (%04x:%04x, intf%d)\n",
760 __func__
, vendor
, product
, ifnum
);
762 /* prevent races probing devices w/multiple interfaces */
763 mutex_lock(&driver_lock
);
766 * Scan the endpoint list and set:
767 * first input endpoint = IR endpoint
768 * first output endpoint = display endpoint
770 for (i
= 0; i
< num_endpts
&& !(ir_ep_found
&& display_ep_found
); ++i
) {
771 struct usb_endpoint_descriptor
*ep
;
774 ep
= &iface_desc
->endpoint
[i
].desc
;
775 ep_dir
= ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
;
776 ep_type
= ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
;
779 ep_dir
== USB_DIR_IN
&&
780 ep_type
== USB_ENDPOINT_XFER_INT
) {
784 dev_dbg(dev
, "%s: found IR endpoint\n", __func__
);
786 } else if (!display_ep_found
&& ep_dir
== USB_DIR_OUT
&&
787 ep_type
== USB_ENDPOINT_XFER_INT
) {
789 display_ep_found
= 1;
790 dev_dbg(dev
, "%s: found display endpoint\n", __func__
);
795 * Some iMON receivers have no display. Unfortunately, it seems
796 * that SoundGraph recycles device IDs between devices both with
799 if (context
->display
== 0) {
800 display_ep_found
= 0;
801 dev_dbg(dev
, "%s: device has no display\n", __func__
);
804 /* Input endpoint is mandatory */
806 err("%s: no valid input (IR) endpoint found.", __func__
);
809 goto alloc_status_switch
;
812 /* Determine if display requires 6 packets */
813 if (display_ep_found
) {
814 if (usb_match_id(interface
, vfd_proto_6p_list
))
817 dev_dbg(dev
, "%s: vfd_proto_6p: %d\n",
818 __func__
, vfd_proto_6p
);
821 driver
= kzalloc(sizeof(struct lirc_driver
), GFP_KERNEL
);
823 err("%s: kzalloc failed for lirc_driver", __func__
);
825 goto alloc_status_switch
;
827 rbuf
= kmalloc(sizeof(struct lirc_buffer
), GFP_KERNEL
);
829 err("%s: kmalloc failed for lirc_buffer", __func__
);
831 goto alloc_status_switch
;
833 if (lirc_buffer_init(rbuf
, BUF_CHUNK_SIZE
, BUF_SIZE
)) {
834 err("%s: lirc_buffer_init failed", __func__
);
836 goto alloc_status_switch
;
838 rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
840 err("%s: usb_alloc_urb failed for IR urb", __func__
);
842 goto alloc_status_switch
;
844 tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
846 err("%s: usb_alloc_urb failed for display urb",
849 goto alloc_status_switch
;
852 mutex_init(&context
->ctx_lock
);
853 context
->vfd_proto_6p
= vfd_proto_6p
;
855 strcpy(driver
->name
, MOD_NAME
);
857 driver
->code_length
= sizeof(int) * 8;
858 driver
->sample_rate
= 0;
859 driver
->features
= LIRC_CAN_REC_MODE2
;
860 driver
->data
= context
;
862 driver
->set_use_inc
= ir_open
;
863 driver
->set_use_dec
= ir_close
;
864 driver
->dev
= &interface
->dev
;
865 driver
->owner
= THIS_MODULE
;
867 mutex_lock(&context
->ctx_lock
);
869 context
->driver
= driver
;
870 /* start out in keyboard mode */
872 lirc_minor
= lirc_register_driver(driver
);
873 if (lirc_minor
< 0) {
874 err("%s: lirc_register_driver failed", __func__
);
876 goto alloc_status_switch
;
878 dev_info(dev
, "Registered iMON driver "
879 "(lirc minor: %d)\n", lirc_minor
);
881 /* Needed while unregistering! */
882 driver
->minor
= lirc_minor
;
884 context
->usbdev
= usbdev
;
885 context
->dev_present
= 1;
886 context
->rx_endpoint
= rx_endpoint
;
887 context
->rx_urb
= rx_urb
;
890 * tx is used to send characters to lcd/vfd, associate RF
891 * remotes, set IR protocol, and maybe more...
893 context
->tx_endpoint
= tx_endpoint
;
894 context
->tx_urb
= tx_urb
;
896 if (display_ep_found
)
897 context
->display
= 1;
899 usb_fill_int_urb(context
->rx_urb
, context
->usbdev
,
900 usb_rcvintpipe(context
->usbdev
,
901 context
->rx_endpoint
->bEndpointAddress
),
902 context
->usb_rx_buf
, sizeof(context
->usb_rx_buf
),
903 usb_rx_callback
, context
,
904 context
->rx_endpoint
->bInterval
);
906 retval
= usb_submit_urb(context
->rx_urb
, GFP_KERNEL
);
909 err("%s: usb_submit_urb failed for intf0 (%d)",
911 mutex_unlock(&context
->ctx_lock
);
915 usb_set_intfdata(interface
, context
);
917 if (context
->display
&& ifnum
== 0) {
918 dev_dbg(dev
, "%s: Registering iMON display with sysfs\n",
921 if (usb_register_dev(interface
, &imon_class
)) {
922 /* Not a fatal error, so ignore */
923 dev_info(dev
, "%s: could not get a minor number for "
924 "display\n", __func__
);
928 dev_info(dev
, "iMON device (%04x:%04x, intf%d) on "
929 "usb<%d:%d> initialized\n", vendor
, product
, ifnum
,
930 usbdev
->bus
->busnum
, usbdev
->devnum
);
933 mutex_unlock(&context
->ctx_lock
);
935 switch (alloc_status
) {
937 usb_free_urb(tx_urb
);
939 usb_free_urb(rx_urb
);
942 lirc_buffer_free(rbuf
);
951 if (retval
!= -ENODEV
)
959 mutex_unlock(&driver_lock
);
965 * Callback function for USB core API: disconnect
967 static void imon_disconnect(struct usb_interface
*interface
)
969 struct imon_context
*context
;
972 /* prevent races with ir_open()/display_open() */
973 mutex_lock(&driver_lock
);
975 context
= usb_get_intfdata(interface
);
976 ifnum
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
978 mutex_lock(&context
->ctx_lock
);
980 usb_set_intfdata(interface
, NULL
);
982 /* Abort ongoing write */
983 if (atomic_read(&context
->tx
.busy
)) {
984 usb_kill_urb(context
->tx_urb
);
985 complete_all(&context
->tx
.finished
);
988 context
->dev_present
= 0;
989 usb_kill_urb(context
->rx_urb
);
990 if (context
->display
)
991 usb_deregister_dev(interface
, &imon_class
);
993 if (!context
->ir_isopen
&& !context
->dev_present
) {
994 deregister_from_lirc(context
);
995 mutex_unlock(&context
->ctx_lock
);
996 if (!context
->display_isopen
)
997 free_imon_context(context
);
999 mutex_unlock(&context
->ctx_lock
);
1001 mutex_unlock(&driver_lock
);
1003 printk(KERN_INFO
"%s: iMON device (intf%d) disconnected\n",
1007 static int imon_suspend(struct usb_interface
*intf
, pm_message_t message
)
1009 struct imon_context
*context
= usb_get_intfdata(intf
);
1011 usb_kill_urb(context
->rx_urb
);
1016 static int imon_resume(struct usb_interface
*intf
)
1019 struct imon_context
*context
= usb_get_intfdata(intf
);
1021 usb_fill_int_urb(context
->rx_urb
, context
->usbdev
,
1022 usb_rcvintpipe(context
->usbdev
,
1023 context
->rx_endpoint
->bEndpointAddress
),
1024 context
->usb_rx_buf
, sizeof(context
->usb_rx_buf
),
1025 usb_rx_callback
, context
,
1026 context
->rx_endpoint
->bInterval
);
1028 rc
= usb_submit_urb(context
->rx_urb
, GFP_ATOMIC
);
1033 static int __init
imon_init(void)
1037 printk(KERN_INFO MOD_NAME
": " MOD_DESC
", v" MOD_VERSION
"\n");
1039 rc
= usb_register(&imon_driver
);
1041 err("%s: usb register failed(%d)", __func__
, rc
);
1048 static void __exit
imon_exit(void)
1050 usb_deregister(&imon_driver
);
1051 printk(KERN_INFO MOD_NAME
": module removed. Goodbye!\n");
1054 module_init(imon_init
);
1055 module_exit(imon_exit
);