2 em2820-video.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
5 Ludovico Cavedon <cavedon@sssup.it>
6 Mauro Carvalho Chehab <mchehab@brturbo.com.br>
8 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
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.
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.
25 #include <linux/init.h>
26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/usb.h>
30 #include <linux/i2c.h>
31 #include <linux/video_decoder.h>
34 #include <media/tuner.h>
36 #define DRIVER_AUTHOR "Markus Rechberger <mrechberger@gmail.com>, " \
37 "Ludovico Cavedon <cavedon@sssup.it>, " \
38 "Mauro Carvalho Chehab <mchehab@brturbo.com.br>"
40 #define DRIVER_NAME "em2820"
41 #define DRIVER_DESC "Empia em2820 based USB video device driver"
42 #define EM2820_VERSION_CODE KERNEL_VERSION(0, 0, 1)
44 #define em2820_videodbg(fmt, arg...) do {\
46 printk(KERN_INFO "%s %s :"fmt, \
47 dev->name, __FUNCTION__ , ##arg); } while (0)
49 MODULE_AUTHOR(DRIVER_AUTHOR);
50 MODULE_DESCRIPTION(DRIVER_DESC);
51 MODULE_LICENSE("GPL");
53 static unsigned int card[] = {[0 ... (EM2820_MAXBOARDS - 1)] = UNSET };
55 module_param_array(card, int, NULL, 0444);
56 MODULE_PARM_DESC(card,"card type");
58 static int tuner = -1;
59 module_param(tuner, int, 0444);
60 MODULE_PARM_DESC(tuner, "tuner type");
62 static unsigned int video_debug = 0;
63 module_param(video_debug,int,0644);
64 MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
66 /* supported tv norms */
67 static struct em2820_tvnorm tvnorms[] = {
71 .mode = VIDEO_MODE_PAL,
75 .mode = VIDEO_MODE_NTSC,
79 .mode = VIDEO_MODE_SECAM,
83 .mode = VIDEO_MODE_PAL,
87 #define TVNORMS ARRAY_SIZE(tvnorms)
89 /* supported controls */
90 static struct v4l2_queryctrl em2820_qctrl[] = {
92 .id = V4L2_CID_BRIGHTNESS,
93 .type = V4L2_CTRL_TYPE_INTEGER,
101 .id = V4L2_CID_CONTRAST,
102 .type = V4L2_CTRL_TYPE_INTEGER,
107 .default_value = 0x10,
110 .id = V4L2_CID_SATURATION,
111 .type = V4L2_CTRL_TYPE_INTEGER,
112 .name = "Saturation",
116 .default_value = 0x10,
119 .id = V4L2_CID_AUDIO_VOLUME,
120 .type = V4L2_CTRL_TYPE_INTEGER,
125 .default_value = 0x1f,
128 .id = V4L2_CID_AUDIO_MUTE,
129 .type = V4L2_CTRL_TYPE_BOOLEAN,
137 .id = V4L2_CID_RED_BALANCE,
138 .type = V4L2_CTRL_TYPE_INTEGER,
139 .name = "Red chroma balance",
146 .id = V4L2_CID_BLUE_BALANCE,
147 .type = V4L2_CTRL_TYPE_INTEGER,
148 .name = "Blue chroma balance",
155 .id = V4L2_CID_GAMMA,
156 .type = V4L2_CTRL_TYPE_INTEGER,
161 .default_value = 0x20,
166 static struct usb_driver em2820_usb_driver;
168 static DECLARE_MUTEX(em2820_sysfs_lock);
169 static DECLARE_RWSEM(em2820_disconnect);
171 /********************* v4l2 interface ******************************************/
173 static inline unsigned long kvirt_to_pa(unsigned long adr)
175 unsigned long kva, ret;
177 kva = (unsigned long)page_address(vmalloc_to_page((void *)adr));
178 kva |= adr & (PAGE_SIZE - 1);
185 * inits registers with sane defaults
187 static int em2820_config(struct em2820 *dev)
190 /* Sets I2C speed to 100 KHz */
191 em2820_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
193 /* enable vbi capturing */
194 em2820_audio_usb_mute(dev, 1);
195 dev->mute = 1; /* maybe not the right place... */
197 em2820_audio_analog_set(dev);
198 em2820_audio_analog_setup(dev);
199 em2820_outfmt_set_yuv422(dev);
200 em2820_colorlevels_set_default(dev);
201 em2820_compression_disable(dev);
207 * em2820_config_i2c()
208 * configure i2c attached devices
210 void em2820_config_i2c(struct em2820 *dev)
212 struct v4l2_frequency f;
213 struct video_decoder_init em2820_vdi = {.data = NULL };
216 /* configure decoder */
217 em2820_i2c_call_clients(dev, DECODER_INIT, &em2820_vdi);
218 em2820_i2c_call_clients(dev, DECODER_SET_INPUT, &dev->ctl_input);
219 /* em2820_i2c_call_clients(dev,DECODER_SET_PICTURE, &dev->vpic); */
220 /* em2820_i2c_call_clients(dev,DECODER_SET_NORM,&dev->tvnorm->id); */
221 /* em2820_i2c_call_clients(dev,DECODER_ENABLE_OUTPUT,&output); */
222 /* em2820_i2c_call_clients(dev,DECODER_DUMP, NULL); */
224 /* configure tuner */
226 f.type = V4L2_TUNER_ANALOG_TV;
227 f.frequency = 9076; /* FIXME:remove magic number */
228 dev->ctl_freq = f.frequency;
229 em2820_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
231 /* configure tda9887 */
234 /* em2820_i2c_call_clients(dev,VIDIOC_S_STD,&dev->tvnorm->id); */
238 * em2820_empty_framequeues()
239 * prepare queues for incoming and outgoing frames
241 static void em2820_empty_framequeues(struct em2820 *dev)
245 INIT_LIST_HEAD(&dev->inqueue);
246 INIT_LIST_HEAD(&dev->outqueue);
248 for (i = 0; i < EM2820_NUM_FRAMES; i++) {
249 dev->frame[i].state = F_UNUSED;
250 dev->frame[i].buf.bytesused = 0;
256 * inits the device and starts isoc transfer
258 static int em2820_v4l2_open(struct inode *inode, struct file *filp)
260 struct video_device *vdev = video_devdata(filp);
261 int minor = iminor(inode);
262 struct em2820 *dev = (struct em2820 *)video_get_drvdata(vdev);
265 em2820_videodbg("users=%d", dev->users);
267 if (!down_read_trylock(&em2820_disconnect))
271 em2820_warn("this driver can be opened only once\n");
272 up_read(&em2820_disconnect);
276 /* if(dev->vbi_dev->minor == minor){
277 dev->type=V4L2_BUF_TYPE_VBI_CAPTURE;
279 if (dev->vdev->minor == minor) {
280 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
283 init_MUTEX(&dev->fileop_lock); /* to 1 == available */
284 spin_lock_init(&dev->queue_lock);
285 init_waitqueue_head(&dev->wait_frame);
286 init_waitqueue_head(&dev->wait_stream);
290 em2820_set_alternate(dev);
292 dev->width = norm_maxw(dev);
293 dev->height = norm_maxh(dev);
294 dev->frame_size = dev->width * dev->height * 2;
295 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
296 dev->bytesperline = dev->width * 2;
300 em2820_capture_start(dev, 1);
301 em2820_resolution_set(dev);
303 /* start the transfer */
304 errCode = em2820_init_isoc(dev);
309 filp->private_data = dev;
311 dev->stream = STREAM_OFF;
315 em2820_empty_framequeues(dev);
317 dev->state |= DEV_INITIALIZED;
321 up_read(&em2820_disconnect);
326 * em2820_realease_resources()
327 * unregisters the v4l2,i2c and usb devices
328 * called when the device gets disconected or at module unload
330 static void em2820_release_resources(struct em2820 *dev)
332 down(&em2820_sysfs_lock);
334 em2820_info("V4L2 device /dev/video%d deregistered\n",
336 video_set_drvdata(dev->vdev, NULL);
337 video_unregister_device(dev->vdev);
338 /* video_unregister_device(dev->vbi_dev); */
339 em2820_i2c_unregister(dev);
340 usb_put_dev(dev->udev);
341 up(&em2820_sysfs_lock);
345 * em2820_v4l2_close()
346 * stops streaming and deallocates all resources allocated by the v4l2 calls and ioctls
348 static int em2820_v4l2_close(struct inode *inode, struct file *file)
350 struct video_device *vdev = video_devdata(file);
351 struct em2820 *dev = (struct em2820 *)video_get_drvdata(vdev);
354 em2820_videodbg("users=%d", dev->users);
358 em2820_uninit_isoc(dev);
360 em2820_release_buffers(dev);
362 /* the device is already disconnect, free the remaining resources */
363 if (dev->state & DEV_DISCONNECTED) {
364 em2820_release_resources(dev);
370 /* set alternate 0 */
372 em2820_videodbg("setting alternate 0");
373 errCode = usb_set_interface(dev->udev, 0, 0);
375 em2820_errdev ("cannot change alternate number to 0 (error=%i)\n",
380 wake_up_interruptible_nr(&dev->open, 1);
387 * will allocate buffers when called for the first time
390 em2820_v4l2_read(struct file *filp, char __user * buf, size_t count,
393 struct em2820 *dev = video_get_drvdata(video_devdata(filp));
394 struct em2820_frame_t *f, *i;
395 unsigned long lock_flags;
398 if (down_interruptible(&dev->fileop_lock))
401 if (dev->state & DEV_DISCONNECTED) {
402 em2820_videodbg("device not present");
403 up(&dev->fileop_lock);
407 if (dev->state & DEV_MISCONFIGURED) {
408 em2820_videodbg("device misconfigured; close and open it again");
409 up(&dev->fileop_lock);
413 if (dev->io == IO_MMAP) {
414 em2820_videodbg ("IO method is set to mmap; close and open"
415 " the device again to choose the read method");
416 up(&dev->fileop_lock);
420 if (dev->io == IO_NONE) {
421 if (!em2820_request_buffers(dev, EM2820_NUM_READ_FRAMES)) {
422 em2820_errdev("read failed, not enough memory\n");
423 up(&dev->fileop_lock);
427 dev->stream = STREAM_ON;
428 em2820_queue_unusedframes(dev);
432 up(&dev->fileop_lock);
436 if (list_empty(&dev->outqueue)) {
437 if (filp->f_flags & O_NONBLOCK) {
438 up(&dev->fileop_lock);
441 ret = wait_event_interruptible
443 (!list_empty(&dev->outqueue)) ||
444 (dev->state & DEV_DISCONNECTED));
446 up(&dev->fileop_lock);
449 if (dev->state & DEV_DISCONNECTED) {
450 up(&dev->fileop_lock);
455 f = list_entry(dev->outqueue.prev, struct em2820_frame_t, frame);
457 spin_lock_irqsave(&dev->queue_lock, lock_flags);
458 list_for_each_entry(i, &dev->outqueue, frame)
460 INIT_LIST_HEAD(&dev->outqueue);
461 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
463 em2820_queue_unusedframes(dev);
465 if (count > f->buf.length)
466 count = f->buf.length;
468 if (copy_to_user(buf, f->bufmem, count)) {
469 up(&dev->fileop_lock);
474 up(&dev->fileop_lock);
481 * will allocate buffers when called for the first time
483 static unsigned int em2820_v4l2_poll(struct file *filp, poll_table * wait)
485 struct em2820 *dev = video_get_drvdata(video_devdata(filp));
486 unsigned int mask = 0;
488 if (down_interruptible(&dev->fileop_lock))
491 if (dev->state & DEV_DISCONNECTED) {
492 em2820_videodbg("device not present");
493 } else if (dev->state & DEV_MISCONFIGURED) {
494 em2820_videodbg("device is misconfigured; close and open it again");
496 if (dev->io == IO_NONE) {
497 if (!em2820_request_buffers
498 (dev, EM2820_NUM_READ_FRAMES)) {
500 ("poll() failed, not enough memory\n");
503 dev->stream = STREAM_ON;
507 if (dev->io == IO_READ) {
508 em2820_queue_unusedframes(dev);
509 poll_wait(filp, &dev->wait_frame, wait);
511 if (!list_empty(&dev->outqueue))
512 mask |= POLLIN | POLLRDNORM;
514 up(&dev->fileop_lock);
520 up(&dev->fileop_lock);
527 static void em2820_vm_open(struct vm_area_struct *vma)
529 struct em2820_frame_t *f = vma->vm_private_data;
536 static void em2820_vm_close(struct vm_area_struct *vma)
538 /* NOTE: buffers are not freed here */
539 struct em2820_frame_t *f = vma->vm_private_data;
543 static struct vm_operations_struct em2820_vm_ops = {
544 .open = em2820_vm_open,
545 .close = em2820_vm_close,
551 static int em2820_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
553 struct em2820 *dev = video_get_drvdata(video_devdata(filp));
554 unsigned long size = vma->vm_end - vma->vm_start,
555 start = vma->vm_start, pos, page;
557 if (down_interruptible(&dev->fileop_lock))
560 if (dev->state & DEV_DISCONNECTED) {
561 em2820_videodbg("mmap: device not present");
562 up(&dev->fileop_lock);
566 if (dev->state & DEV_MISCONFIGURED) {
567 em2820_videodbg ("mmap: Device is misconfigured; close and "
569 up(&dev->fileop_lock);
573 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
574 size != PAGE_ALIGN(dev->frame[0].buf.length)) {
575 up(&dev->fileop_lock);
579 for (i = 0; i < dev->num_frames; i++) {
580 if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
583 if (i == dev->num_frames) {
584 em2820_videodbg("mmap: user supplied mapping address is out of range");
585 up(&dev->fileop_lock);
589 /* VM_IO is eventually going to replace PageReserved altogether */
590 vma->vm_flags |= VM_IO;
591 vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
593 pos = (unsigned long)dev->frame[i].bufmem;
594 while (size > 0) { /* size is page-aligned */
595 page = vmalloc_to_pfn((void *)pos);
596 if (remap_pfn_range(vma, start, page, PAGE_SIZE,
597 vma->vm_page_prot)) {
598 em2820_videodbg("mmap: rename page map failed");
599 up(&dev->fileop_lock);
607 vma->vm_ops = &em2820_vm_ops;
608 vma->vm_private_data = &dev->frame[i];
611 up(&dev->fileop_lock);
617 * return the current saturation, brightness or contrast, mute state
619 static int em2820_get_ctrl(struct em2820 *dev, struct v4l2_control *ctrl)
623 case V4L2_CID_AUDIO_MUTE:
624 ctrl->value = dev->mute;
626 case V4L2_CID_AUDIO_VOLUME:
627 ctrl->value = dev->volume;
629 case V4L2_CID_BRIGHTNESS:
630 if ((tmp = em2820_brightness_get(dev)) < 0)
632 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
634 case V4L2_CID_CONTRAST:
635 if ((ctrl->value = em2820_contrast_get(dev)) < 0)
638 case V4L2_CID_SATURATION:
639 if ((ctrl->value = em2820_saturation_get(dev)) < 0)
642 case V4L2_CID_RED_BALANCE:
643 if ((tmp = em2820_v_balance_get(dev)) < 0)
645 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
647 case V4L2_CID_BLUE_BALANCE:
648 if ((tmp = em2820_u_balance_get(dev)) < 0)
650 ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
653 if ((ctrl->value = em2820_gamma_get(dev)) < 0)
663 * mute or set new saturation, brightness or contrast
665 static int em2820_set_ctrl(struct em2820 *dev, const struct v4l2_control *ctrl)
668 case V4L2_CID_AUDIO_MUTE:
669 if (ctrl->value != dev->mute) {
670 dev->mute = ctrl->value;
671 em2820_audio_usb_mute(dev, ctrl->value);
672 return em2820_audio_analog_set(dev);
675 case V4L2_CID_AUDIO_VOLUME:
676 dev->volume = ctrl->value;
677 return em2820_audio_analog_set(dev);
678 case V4L2_CID_BRIGHTNESS:
679 return em2820_brightness_set(dev, ctrl->value);
680 case V4L2_CID_CONTRAST:
681 return em2820_contrast_set(dev, ctrl->value);
682 case V4L2_CID_SATURATION:
683 return em2820_saturation_set(dev, ctrl->value);
684 case V4L2_CID_RED_BALANCE:
685 return em2820_v_balance_set(dev, ctrl->value);
686 case V4L2_CID_BLUE_BALANCE:
687 return em2820_u_balance_set(dev, ctrl->value);
689 return em2820_gamma_set(dev, ctrl->value);
696 * em2820_stream_interrupt()
699 static int em2820_stream_interrupt(struct em2820 *dev)
703 /* stop reading from the device */
705 dev->stream = STREAM_INTERRUPT;
706 ret = wait_event_timeout(dev->wait_stream,
707 (dev->stream == STREAM_OFF) ||
708 (dev->state & DEV_DISCONNECTED),
710 if (dev->state & DEV_DISCONNECTED)
713 dev->state |= DEV_MISCONFIGURED;
714 em2820_videodbg("device is misconfigured; close and "
715 "open /dev/video%d again", dev->vdev->minor);
722 static int em2820_set_norm(struct em2820 *dev, int width, int height)
724 unsigned int hscale, vscale;
725 unsigned int maxh, maxw;
727 maxw = norm_maxw(dev);
728 maxh = norm_maxh(dev);
730 /* width must even because of the YUYV format */
731 /* height must be even because of interlacing */
744 if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
746 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
748 if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
750 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
752 /* set new image size */
754 dev->height = height;
755 dev->frame_size = dev->width * dev->height * 2;
756 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
757 dev->bytesperline = dev->width * 2;
758 dev->hscale = hscale;
759 dev->vscale = vscale;
761 em2820_resolution_set(dev);
766 static void video_mux(struct em2820 *dev, int index)
770 input = INPUT(index)->vmux;
771 dev->ctl_input = index;
773 em2820_i2c_call_clients(dev, DECODER_SET_INPUT, &input);
775 dev->ctl_ainput = INPUT(index)->amux;
777 switch (dev->ctl_ainput) {
779 ainput = EM2820_AUDIO_SRC_TUNER;
782 ainput = EM2820_AUDIO_SRC_LINE;
785 em2820_audio_source(dev, ainput);
789 * em2820_v4l2_do_ioctl()
790 * This function is _not_ called directly, but from
791 * em2820_v4l2_ioctl. Userspace
792 * copying is done already, arg is a kernel pointer.
794 static int em2820_do_ioctl(struct inode *inode, struct file *filp,
795 struct em2820 *dev, unsigned int cmd, void *arg,
796 v4l2_kioctl driver_ioctl)
801 /* ---------- tv norms ---------- */
804 struct v4l2_standard *e = arg;
810 ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
811 tvnorms[e->index].name);
819 v4l2_std_id *id = arg;
821 *id = dev->tvnorm->id;
826 v4l2_std_id *id = arg;
829 for (i = 0; i < TVNORMS; i++)
830 if (*id == tvnorms[i].id)
833 for (i = 0; i < TVNORMS; i++)
834 if (*id & tvnorms[i].id)
840 dev->tvnorm = &tvnorms[i];
842 em2820_set_norm(dev, dev->width, dev->height);
845 dev->width=norm_maxw(dev);
846 dev->height=norm_maxh(dev);
847 dev->frame_size=dev->width*dev->height*2;
848 dev->field_size=dev->frame_size>>1;
849 dev->bytesperline=dev->width*2;
853 em2820_resolution_set(dev);
856 em2820_uninit_isoc(dev);
857 em2820_set_alternate(dev);
858 em2820_capture_start(dev, 1);
859 em2820_resolution_set(dev);
860 em2820_init_isoc(dev);
862 em2820_i2c_call_clients(dev, DECODER_SET_NORM,
864 em2820_i2c_call_clients(dev, VIDIOC_S_STD,
872 /* ------ input switching ---------- */
873 case VIDIOC_ENUMINPUT:
875 struct v4l2_input *i = arg;
877 static const char *iname[] = {
878 [EM2820_VMUX_COMPOSITE1] = "Composite1",
879 [EM2820_VMUX_COMPOSITE2] = "Composite2",
880 [EM2820_VMUX_COMPOSITE3] = "Composite3",
881 [EM2820_VMUX_COMPOSITE4] = "Composite4",
882 [EM2820_VMUX_SVIDEO] = "S-Video",
883 [EM2820_VMUX_TELEVISION] = "Television",
884 [EM2820_VMUX_CABLE] = "Cable TV",
885 [EM2820_VMUX_DVB] = "DVB",
886 [EM2820_VMUX_DEBUG] = "for debug only",
890 if (n >= MAX_EM2820_INPUT)
892 if (0 == INPUT(n)->type)
894 memset(i, 0, sizeof(*i));
896 i->type = V4L2_INPUT_TYPE_CAMERA;
897 strcpy(i->name, iname[INPUT(n)->type]);
898 if ((EM2820_VMUX_TELEVISION == INPUT(n)->type) ||
899 (EM2820_VMUX_CABLE == INPUT(n)->type))
900 i->type = V4L2_INPUT_TYPE_TUNER;
901 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
902 i->std |= tvnorms[n].id;
918 if (*index >= MAX_EM2820_INPUT)
920 if (0 == INPUT(*index)->type)
924 video_mux(dev, *index);
932 struct v4l2_audio *a = arg;
933 unsigned int index = a->index;
937 memset(a, 0, sizeof(*a));
938 index = dev->ctl_ainput;
941 strcpy(a->name, "Television");
943 strcpy(a->name, "Line In");
945 a->capability = V4L2_AUDCAP_STEREO;
952 struct v4l2_audio *a = arg;
953 if (a->index != dev->ctl_ainput)
959 /* --- controls ---------------------------------------------- */
960 case VIDIOC_QUERYCTRL:
962 struct v4l2_queryctrl *qc = arg;
964 n = sizeof(em2820_qctrl) / sizeof(em2820_qctrl[0]);
965 for (i = 0; i < n; i++)
966 if (qc->id && qc->id == em2820_qctrl[i].id) {
967 memcpy(qc, &(em2820_qctrl[i]),
977 struct v4l2_control *ctrl = arg;
980 return em2820_get_ctrl(dev, ctrl);
983 case VIDIOC_S_CTRL_OLD: /* ??? */
986 struct v4l2_control *ctrl = arg;
990 n = sizeof(em2820_qctrl) / sizeof(em2820_qctrl[0]);
991 for (i = 0; i < n; i++)
992 if (ctrl->id == em2820_qctrl[i].id) {
994 em2820_qctrl[i].minimum
996 em2820_qctrl[i].maximum)
999 return em2820_set_ctrl(dev, ctrl);
1004 /* --- tuner ioctls ------------------------------------------ */
1005 case VIDIOC_G_TUNER:
1007 struct v4l2_tuner *t = arg;
1013 memset(t, 0, sizeof(*t));
1014 strcpy(t->name, "Tuner");
1015 t->type = V4L2_TUNER_ANALOG_TV;
1016 t->capability = V4L2_TUNER_CAP_NORM;
1017 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1018 /* t->signal = 0xffff;*/
1019 /* em2820_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/
1020 /* No way to get signal strength? */
1022 em2820_i2c_call_clients(dev, DECODER_GET_STATUS,
1026 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1028 em2820_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x", t->signal,
1032 case VIDIOC_S_TUNER:
1034 struct v4l2_tuner *t = arg;
1039 memset(t, 0, sizeof(*t));
1040 strcpy(t->name, "Tuner");
1041 t->type = V4L2_TUNER_ANALOG_TV;
1042 t->capability = V4L2_TUNER_CAP_NORM;
1043 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1044 /* t->signal = 0xffff; */
1045 /* No way to get signal strength? */
1047 em2820_i2c_call_clients(dev, DECODER_GET_STATUS,
1051 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1053 em2820_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n",
1057 case VIDIOC_G_FREQUENCY:
1059 struct v4l2_frequency *f = arg;
1061 memset(f, 0, sizeof(*f));
1062 f->type = V4L2_TUNER_ANALOG_TV;
1063 f->frequency = dev->ctl_freq;
1067 case VIDIOC_S_FREQUENCY:
1069 struct v4l2_frequency *f = arg;
1074 if (V4L2_TUNER_ANALOG_TV != f->type)
1078 dev->ctl_freq = f->frequency;
1079 em2820_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
1084 case VIDIOC_CROPCAP:
1086 struct v4l2_cropcap *cc = arg;
1088 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1090 cc->bounds.left = 0;
1092 cc->bounds.width = dev->width;
1093 cc->bounds.height = dev->height;
1094 cc->defrect = cc->bounds;
1095 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1096 cc->pixelaspect.denominator = 59;
1099 case VIDIOC_STREAMON:
1103 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1104 || dev->io != IO_MMAP)
1107 if (list_empty(&dev->inqueue))
1110 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
1112 em2820_videodbg("VIDIOC_STREAMON: starting stream");
1116 case VIDIOC_STREAMOFF:
1121 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1122 || dev->io != IO_MMAP)
1125 if (dev->stream == STREAM_ON) {
1126 em2820_videodbg ("VIDIOC_STREAMOFF: interrupting stream");
1127 if ((ret = em2820_stream_interrupt(dev)))
1130 em2820_empty_framequeues(dev);
1135 return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
1142 * em2820_v4l2_do_ioctl()
1143 * This function is _not_ called directly, but from
1144 * em2820_v4l2_ioctl. Userspace
1145 * copying is done already, arg is a kernel pointer.
1147 static int em2820_video_do_ioctl(struct inode *inode, struct file *filp,
1148 unsigned int cmd, void *arg)
1150 struct em2820 *dev = filp->private_data;
1155 if (video_debug > 1)
1156 em2820_print_ioctl(dev->name,cmd);
1160 /* --- capabilities ------------------------------------------ */
1161 case VIDIOC_QUERYCAP:
1163 struct v4l2_capability *cap = arg;
1165 memset(cap, 0, sizeof(*cap));
1166 strlcpy(cap->driver, "em2820", sizeof(cap->driver));
1167 strlcpy(cap->card, em2820_boards[dev->model].name,
1169 strlcpy(cap->bus_info, dev->udev->dev.bus_id,
1170 sizeof(cap->bus_info));
1171 cap->version = EM2820_VERSION_CODE;
1173 V4L2_CAP_VIDEO_CAPTURE |
1175 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1177 cap->capabilities |= V4L2_CAP_TUNER;
1181 /* --- capture ioctls ---------------------------------------- */
1182 case VIDIOC_ENUM_FMT:
1184 struct v4l2_fmtdesc *fmtd = arg;
1186 if (fmtd->index != 0)
1188 memset(fmtd, 0, sizeof(*fmtd));
1189 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1190 strcpy(fmtd->description, "Packed YUY2");
1191 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
1192 memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
1198 struct v4l2_format *format = arg;
1200 em2820_videodbg("VIDIOC_G_FMT: type=%s",
1202 V4L2_BUF_TYPE_VIDEO_CAPTURE ?
1203 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
1204 V4L2_BUF_TYPE_VBI_CAPTURE ?
1205 "V4L2_BUF_TYPE_VBI_CAPTURE " :
1208 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1211 format->fmt.pix.width = dev->width;
1212 format->fmt.pix.height = dev->height;
1213 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1214 format->fmt.pix.bytesperline = dev->bytesperline;
1215 format->fmt.pix.sizeimage = dev->frame_size;
1216 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1217 format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
1219 em2820_videodbg("VIDIOC_G_FMT: %dx%d", dev->width,
1224 case VIDIOC_TRY_FMT:
1227 struct v4l2_format *format = arg;
1230 int width = format->fmt.pix.width;
1231 int height = format->fmt.pix.height;
1232 unsigned int hscale, vscale;
1233 unsigned int maxh, maxw;
1235 maxw = norm_maxw(dev);
1236 maxh = norm_maxh(dev);
1238 /* int both_fields; */
1240 em2820_videodbg("%s: type=%s",
1242 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1245 V4L2_BUF_TYPE_VIDEO_CAPTURE ?
1246 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
1247 V4L2_BUF_TYPE_VBI_CAPTURE ?
1248 "V4L2_BUF_TYPE_VBI_CAPTURE " :
1251 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1254 em2820_videodbg("%s: requested %dx%d",
1256 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1257 "VIDIOC_S_FMT", format->fmt.pix.width,
1258 format->fmt.pix.height);
1260 /* FIXME: Move some code away from here */
1261 /* width must even because of the YUYV format */
1262 /* height must be even because of interlacing */
1277 /* we only know how to scale to 50% */
1278 if(height % (maxh / 2))
1280 if(width % (maxw / 2))
1282 /* larger resoltion don't seem to work either */
1283 if(width == maxw && height == maxh)
1288 (((unsigned long)maxw) << 12) / width - 4096L) >=
1292 (((unsigned long)maxw) << 12) / (hscale + 4096L);
1295 (((unsigned long)maxh) << 12) / height - 4096L) >=
1299 (((unsigned long)maxh) << 12) / (vscale + 4096L);
1301 format->fmt.pix.width = width;
1302 format->fmt.pix.height = height;
1303 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1304 format->fmt.pix.bytesperline = width * 2;
1305 format->fmt.pix.sizeimage = width * 2 * height;
1306 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1307 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
1309 em2820_videodbg("%s: returned %dx%d (%d, %d)",
1311 VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
1312 "VIDIOC_S_FMT", format->fmt.pix.width,
1313 format->fmt.pix.height, hscale, vscale);
1315 if (cmd == VIDIOC_TRY_FMT)
1318 for (i = 0; i < dev->num_frames; i++)
1319 if (dev->frame[i].vma_use_count) {
1320 em2820_videodbg("VIDIOC_S_FMT failed. "
1321 "Unmap the buffers first.");
1325 /* stop io in case it is already in progress */
1326 if (dev->stream == STREAM_ON) {
1327 em2820_videodbg("VIDIOC_SET_FMT: interupting stream");
1328 if ((ret = em2820_stream_interrupt(dev)))
1332 em2820_release_buffers(dev);
1335 /* set new image size */
1337 dev->height = height;
1338 dev->frame_size = dev->width * dev->height * 2;
1339 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
1340 dev->bytesperline = dev->width * 2;
1341 dev->hscale = hscale;
1342 dev->vscale = vscale;
1343 /* dev->both_fileds = both_fileds; */
1344 em2820_uninit_isoc(dev);
1345 em2820_set_alternate(dev);
1346 em2820_capture_start(dev, 1);
1347 em2820_resolution_set(dev);
1348 em2820_init_isoc(dev);
1353 /* --- streaming capture ------------------------------------- */
1354 case VIDIOC_REQBUFS:
1356 struct v4l2_requestbuffers *rb = arg;
1360 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1361 rb->memory != V4L2_MEMORY_MMAP)
1364 if (dev->io == IO_READ) {
1365 em2820_videodbg ("method is set to read;"
1366 " close and open the device again to"
1367 " choose the mmap I/O method");
1371 for (i = 0; i < dev->num_frames; i++)
1372 if (dev->frame[i].vma_use_count) {
1373 em2820_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped");
1377 if (dev->stream == STREAM_ON) {
1378 em2820_videodbg("VIDIOC_REQBUFS: interrupting stream");
1379 if ((ret = em2820_stream_interrupt(dev)))
1383 em2820_empty_framequeues(dev);
1385 em2820_release_buffers(dev);
1388 em2820_request_buffers(dev, rb->count);
1390 dev->frame_current = NULL;
1392 em2820_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i",
1394 dev->io = rb->count ? IO_MMAP : IO_NONE;
1398 case VIDIOC_QUERYBUF:
1400 struct v4l2_buffer *b = arg;
1402 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1403 b->index >= dev->num_frames || dev->io != IO_MMAP)
1406 memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
1408 if (dev->frame[b->index].vma_use_count) {
1409 b->flags |= V4L2_BUF_FLAG_MAPPED;
1411 if (dev->frame[b->index].state == F_DONE)
1412 b->flags |= V4L2_BUF_FLAG_DONE;
1413 else if (dev->frame[b->index].state != F_UNUSED)
1414 b->flags |= V4L2_BUF_FLAG_QUEUED;
1419 struct v4l2_buffer *b = arg;
1420 unsigned long lock_flags;
1422 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1423 b->index >= dev->num_frames || dev->io != IO_MMAP) {
1427 if (dev->frame[b->index].state != F_UNUSED) {
1430 dev->frame[b->index].state = F_QUEUED;
1432 /* add frame to fifo */
1433 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1434 list_add_tail(&dev->frame[b->index].frame,
1436 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1442 struct v4l2_buffer *b = arg;
1443 struct em2820_frame_t *f;
1444 unsigned long lock_flags;
1447 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1448 || dev->io != IO_MMAP)
1451 if (list_empty(&dev->outqueue)) {
1452 if (dev->stream == STREAM_OFF)
1454 if (filp->f_flags & O_NONBLOCK)
1456 ret = wait_event_interruptible
1458 (!list_empty(&dev->outqueue)) ||
1459 (dev->state & DEV_DISCONNECTED));
1462 if (dev->state & DEV_DISCONNECTED)
1466 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1467 f = list_entry(dev->outqueue.next,
1468 struct em2820_frame_t, frame);
1469 list_del(dev->outqueue.next);
1470 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1472 f->state = F_UNUSED;
1473 memcpy(b, &f->buf, sizeof(*b));
1475 if (f->vma_use_count)
1476 b->flags |= V4L2_BUF_FLAG_MAPPED;
1481 return em2820_do_ioctl(inode, filp, dev, cmd, arg,
1482 em2820_video_do_ioctl);
1488 * em2820_v4l2_ioctl()
1489 * handle v4l2 ioctl the main action happens in em2820_v4l2_do_ioctl()
1491 static int em2820_v4l2_ioctl(struct inode *inode, struct file *filp,
1492 unsigned int cmd, unsigned long arg)
1494 struct em2820 *dev = video_get_drvdata(video_devdata(filp));
1497 if (down_interruptible(&dev->fileop_lock))
1498 return -ERESTARTSYS;
1500 if (dev->state & DEV_DISCONNECTED) {
1501 em2820_errdev("v4l2 ioctl: device not present\n");
1502 up(&dev->fileop_lock);
1506 if (dev->state & DEV_MISCONFIGURED) {
1508 ("v4l2 ioctl: device is misconfigured; close and open it again\n");
1509 up(&dev->fileop_lock);
1513 ret = video_usercopy(inode, filp, cmd, arg, em2820_video_do_ioctl);
1515 up(&dev->fileop_lock);
1520 static struct file_operations em2820_v4l_fops = {
1521 .owner = THIS_MODULE,
1522 .open = em2820_v4l2_open,
1523 .release = em2820_v4l2_close,
1524 .ioctl = em2820_v4l2_ioctl,
1525 .read = em2820_v4l2_read,
1526 .poll = em2820_v4l2_poll,
1527 .mmap = em2820_v4l2_mmap,
1528 .llseek = no_llseek,
1531 /******************************** usb interface *****************************************/
1535 * allocates and inits the device structs, registers i2c bus and v4l device
1537 static int em2820_init_dev(struct em2820 **devhandle, struct usb_device *udev,
1538 int minor, int model)
1540 struct em2820 *dev = *devhandle;
1541 int retval = -ENOMEM;
1543 unsigned int maxh, maxw;
1544 struct usb_interface *uif;
1548 init_MUTEX(&dev->lock);
1549 init_waitqueue_head(&dev->open);
1551 dev->em2820_write_regs = em2820_write_regs;
1552 dev->em2820_read_reg = em2820_read_reg;
1553 dev->em2820_read_reg_req_len = em2820_read_reg_req_len;
1554 dev->em2820_write_regs_req = em2820_write_regs_req;
1555 dev->em2820_read_reg_req = em2820_read_reg_req;
1556 dev->is_em2800 = em2820_boards[model].is_em2800;
1557 dev->has_tuner = em2820_boards[model].has_tuner;
1558 dev->has_msp34xx = em2820_boards[model].has_msp34xx;
1559 dev->tda9887_conf = em2820_boards[model].tda9887_conf;
1560 dev->decoder = em2820_boards[model].decoder;
1563 dev->tuner_type = tuner;
1565 dev->tuner_type = em2820_boards[model].tuner_type;
1567 dev->video_inputs = em2820_boards[model].vchannels;
1569 for (i = 0; i < TVNORMS; i++)
1570 if (em2820_boards[model].norm == tvnorms[i].mode)
1575 dev->tvnorm = &tvnorms[i]; /* set default norm */
1577 em2820_videodbg("tvnorm=%s\n", dev->tvnorm->name);
1579 maxw = norm_maxw(dev);
1580 maxh = norm_maxh(dev);
1582 /* set default image size */
1585 dev->interlaced = EM2820_INTERLACED_DEFAULT;
1586 dev->field_size = dev->width * dev->height;
1588 dev->interlaced ? dev->field_size << 1 : dev->field_size;
1589 dev->bytesperline = dev->width * 2;
1594 /* setup video picture settings for saa7113h */
1595 memset(&dev->vpic, 0, sizeof(dev->vpic));
1596 dev->vpic.colour = 128 << 8;
1597 dev->vpic.hue = 128 << 8;
1598 dev->vpic.brightness = 128 << 8;
1599 dev->vpic.contrast = 192 << 8;
1600 dev->vpic.whiteness = 128 << 8; /* This one isn't used */
1601 dev->vpic.depth = 16;
1602 dev->vpic.palette = VIDEO_PALETTE_YUV422;
1604 /* compute alternate max packet sizes */
1605 uif = dev->udev->actconfig->interface[0];
1606 dev->alt_max_pkt_size[0] = 0;
1607 for (i = 1; i <= EM2820_MAX_ALT && i < uif->num_altsetting ; i++) {
1609 le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
1611 dev->alt_max_pkt_size[i] =
1612 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1615 #ifdef CONFIG_MODULES
1616 /* request some modules */
1617 if (dev->decoder == EM2820_SAA7113)
1618 request_module("saa7113");
1619 if (dev->decoder == EM2820_SAA7114)
1620 request_module("saa7114");
1621 if (dev->decoder == EM2820_TVP5150)
1622 request_module("tvp5150");
1624 request_module("tuner");
1625 if (dev->tda9887_conf)
1626 request_module("tda9887");
1628 errCode = em2820_config(dev);
1630 em2820_errdev("error configuring device\n");
1636 /* register i2c bus */
1637 em2820_i2c_register(dev);
1639 /* Do board specific init and eeprom reading */
1640 em2820_card_setup(dev);
1642 /* configure the device */
1643 em2820_config_i2c(dev);
1647 errCode = em2820_config(dev);
1649 #ifdef CONFIG_MODULES
1650 if (dev->has_msp34xx)
1651 request_module("msp3400");
1653 /* allocate and fill v4l2 device struct */
1654 dev->vdev = video_device_alloc();
1655 if (NULL == dev->vdev) {
1656 em2820_errdev("cannot allocate video_device.\n");
1661 dev->vdev->owner = THIS_MODULE;
1662 dev->vdev->type = VID_TYPE_CAPTURE;
1664 dev->vdev->type |= VID_TYPE_TUNER;
1665 dev->vdev->hardware = 0;
1666 dev->vdev->fops = &em2820_v4l_fops;
1667 dev->vdev->minor = -1;
1668 dev->vdev->dev = &dev->udev->dev;
1669 dev->vdev->release = video_device_release;
1670 snprintf(dev->vdev->name, sizeof(dev->vdev->name), "%s",
1672 video_set_drvdata(dev->vdev, dev);
1674 /* register v4l2 device */
1676 if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1))) {
1677 em2820_errdev("unable to register video device (error=%i).\n",
1680 video_set_drvdata(dev->vdev, NULL);
1681 video_device_release(dev->vdev);
1685 if (dev->has_msp34xx) {
1686 /* Send a reset to other chips via gpio */
1687 em2820_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
1689 em2820_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
1697 em2820_info("V4L2 device registered as /dev/video%d\n",
1704 * em2820_usb_probe()
1705 * checks for supported devices
1707 static int em2820_usb_probe(struct usb_interface *interface,
1708 const struct usb_device_id *id)
1710 const struct usb_endpoint_descriptor *endpoint;
1711 struct usb_device *udev;
1712 struct em2820 *dev = NULL;
1713 int retval = -ENODEV;
1714 int model,i,nr,ifnum;
1716 udev = usb_get_dev(interface_to_usbdev(interface));
1717 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1719 em2820_err(DRIVER_NAME " new device (%04x:%04x): interface %i, class %i\n",
1720 udev->descriptor.idVendor,udev->descriptor.idProduct,
1722 interface->altsetting[0].desc.bInterfaceClass);
1724 /* Don't register audio interfaces */
1725 if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO)
1728 endpoint = &interface->cur_altsetting->endpoint[1].desc;
1730 /* check if the the device has the iso in endpoint at the correct place */
1731 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1732 USB_ENDPOINT_XFER_ISOC) {
1733 em2820_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n");
1736 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
1737 em2820_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n");
1741 model=id->driver_info;
1742 nr=interface->minor;
1744 if (nr>EM2820_MAXBOARDS) {
1745 printk ("em2820: Supports only %i em28xx boards.\n",EM2820_MAXBOARDS);
1749 /* allocate memory for our device state and initialize it */
1750 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
1752 em2820_err(DRIVER_NAME ": out of memory!\n");
1755 memset(dev, 0, sizeof(*dev));
1757 snprintf(dev->name, 29, "em2820 #%d", nr);
1759 if ((card[nr]>=0)&&(card[nr]<em2820_bcount))
1762 if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) {
1763 printk( "%s: Your board has no eeprom inside it and thus can't\n"
1764 "%s: be autodetected. Please pass card=<n> insmod option to\n"
1765 "%s: workaround that. Redirect complaints to the vendor of\n"
1766 "%s: the TV card. Best regards,\n"
1768 dev->name,dev->name,dev->name,dev->name,dev->name);
1769 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
1771 for (i = 0; i < em2820_bcount; i++) {
1772 printk("%s: card=%d -> %s\n",
1773 dev->name, i, em2820_boards[i].name);
1777 /* allocate device struct */
1778 retval = em2820_init_dev(&dev, udev, nr, model);
1782 em2820_info("Found %s\n", em2820_boards[model].name);
1784 /* save our data pointer in this interface device */
1785 usb_set_intfdata(interface, dev);
1790 * em2820_usb_disconnect()
1791 * called when the device gets diconencted
1792 * video device will be unregistered on v4l2_close in case it is still open
1794 static void em2820_usb_disconnect(struct usb_interface *interface)
1796 struct em2820 *dev = usb_get_intfdata(interface);
1797 usb_set_intfdata(interface, NULL);
1802 down_write(&em2820_disconnect);
1806 em2820_info("disconnecting %s\n", dev->vdev->name);
1808 wake_up_interruptible_all(&dev->open);
1812 ("device /dev/video%d is open! Deregistration and memory "
1813 "deallocation are deferred on close.\n", dev->vdev->minor);
1814 dev->state |= DEV_MISCONFIGURED;
1815 em2820_uninit_isoc(dev);
1816 dev->state |= DEV_DISCONNECTED;
1817 wake_up_interruptible(&dev->wait_frame);
1818 wake_up_interruptible(&dev->wait_stream);
1820 dev->state |= DEV_DISCONNECTED;
1821 em2820_release_resources(dev);
1829 up_write(&em2820_disconnect);
1833 static struct usb_driver em2820_usb_driver = {
1834 .owner = THIS_MODULE,
1836 .probe = em2820_usb_probe,
1837 .disconnect = em2820_usb_disconnect,
1838 .id_table = em2820_id_table,
1841 static int __init em2820_module_init(void)
1845 printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n",
1846 (EM2820_VERSION_CODE >> 16) & 0xff,
1847 (EM2820_VERSION_CODE >> 8) & 0xff, EM2820_VERSION_CODE & 0xff);
1849 printk(KERN_INFO DRIVER_NAME " snapshot date %04d-%02d-%02d\n",
1850 SNAPSHOT / 10000, (SNAPSHOT / 100) % 100, SNAPSHOT % 100);
1853 /* register this driver with the USB subsystem */
1854 result = usb_register(&em2820_usb_driver);
1856 em2820_err(DRIVER_NAME
1857 " usb_register failed. Error number %d.\n", result);
1862 static void __exit em2820_module_exit(void)
1864 /* deregister this driver with the USB subsystem */
1865 usb_deregister(&em2820_usb_driver);
1868 module_init(em2820_module_init);
1869 module_exit(em2820_module_exit);