Lines Matching +full:de +full:- +full:interlacing
1 // SPDX-License-Identifier: GPL-2.0+
3 // em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
9 // Sascha Sommer <saschasommer@freenet.de>
28 #include "em28xx-v4l.h"
29 #include <media/v4l2-common.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/v4l2-event.h>
32 #include <media/drv-intf/msp3400.h>
38 "Sascha Sommer <saschasommer@freenet.de>"
54 dev_printk(KERN_DEBUG, &dev->intf->dev, \
60 dev_printk(KERN_DEBUG, &dev->intf->dev, \
65 MODULE_DESCRIPTION(DRIVER_DESC " - v4l2 interface");
77 static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
78 static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
79 static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
128 struct em28xx_v4l2 *v4l2 = dev->v4l2; in norm_maxw()
130 if (dev->is_webcam) in norm_maxw()
131 return v4l2->sensor_xres; in norm_maxw()
133 if (dev->board.max_range_640_480) in norm_maxw()
141 struct em28xx_v4l2 *v4l2 = dev->v4l2; in norm_maxh()
143 if (dev->is_webcam) in norm_maxh()
144 return v4l2->sensor_yres; in norm_maxh()
146 if (dev->board.max_range_640_480) in norm_maxh()
149 return (v4l2->norm & V4L2_STD_625_50) ? 576 : 480; in norm_maxh()
158 if (dev->is_webcam) in em28xx_vbi_supported()
163 if (dev->chip_id == CHIP_ID_EM2860 || in em28xx_vbi_supported()
164 dev->chip_id == CHIP_ID_EM2883) in em28xx_vbi_supported()
177 struct v4l2_device *v4l2_dev = &dev->v4l2->v4l2_dev; in em28xx_wake_i2c()
181 INPUT(dev->ctl_input)->vmux, 0, 0); in em28xx_wake_i2c()
206 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_set_outfmt()
208 fmt = v4l2->format->reg; in em28xx_set_outfmt()
209 if (!dev->is_em25xx) in em28xx_set_outfmt()
224 ret = em28xx_write_reg(dev, EM28XX_R10_VINMODE, v4l2->vinmode); in em28xx_set_outfmt()
228 vinctrl = v4l2->vinctl; in em28xx_set_outfmt()
233 v4l2->vbi_width / 4); in em28xx_set_outfmt()
234 em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, v4l2->vbi_height); in em28xx_set_outfmt()
235 if (v4l2->norm & V4L2_STD_525_60) { in em28xx_set_outfmt()
238 } else if (v4l2->norm & V4L2_STD_625_50) { in em28xx_set_outfmt()
250 em28xx_videodbg("em28xx Scale: (%d,%d)-(%d,%d)\n", in em28xx_accumulator_set()
280 if (dev->is_em25xx) { in em28xx_capture_area_set()
291 if (dev->board.is_em2800) { in em28xx_scaler_set()
315 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_resolution_set()
320 v4l2->vbi_width = 720; in em28xx_resolution_set()
321 if (v4l2->norm & V4L2_STD_525_60) in em28xx_resolution_set()
322 v4l2->vbi_height = 12; in em28xx_resolution_set()
324 v4l2->vbi_height = 18; in em28xx_resolution_set()
328 em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2); in em28xx_resolution_set()
332 * with line 20/21 being YUYV encoded instead of being in 8-bit in em28xx_resolution_set()
344 return em28xx_scaler_set(dev, v4l2->hscale, v4l2->vscale); in em28xx_resolution_set()
350 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_set_alternate()
351 struct usb_device *udev = interface_to_usbdev(dev->intf); in em28xx_set_alternate()
354 unsigned int min_pkt_size = v4l2->width * 2 + 4; in em28xx_set_alternate()
360 dev->alt = 0; in em28xx_set_alternate()
361 if (alt > 0 && alt < dev->num_alt) { in em28xx_set_alternate()
362 em28xx_videodbg("alternate forced to %d\n", dev->alt); in em28xx_set_alternate()
363 dev->alt = alt; in em28xx_set_alternate()
366 if (dev->analog_xfer_bulk) in em28xx_set_alternate()
374 if (v4l2->width * 2 * v4l2->height > 720 * 240 * 2) in em28xx_set_alternate()
377 for (i = 0; i < dev->num_alt; i++) { in em28xx_set_alternate()
379 if (dev->alt_max_pkt_size_isoc[i] >= min_pkt_size) { in em28xx_set_alternate()
380 dev->alt = i; in em28xx_set_alternate()
387 } else if (dev->alt_max_pkt_size_isoc[i] > in em28xx_set_alternate()
388 dev->alt_max_pkt_size_isoc[dev->alt]) in em28xx_set_alternate()
389 dev->alt = i; in em28xx_set_alternate()
396 * fails with all urbs having status = -EOVERFLOW ! in em28xx_set_alternate()
398 if (dev->analog_xfer_bulk) { in em28xx_set_alternate()
399 dev->max_pkt_size = 512; /* USB 2.0 spec */ in em28xx_set_alternate()
400 dev->packet_multiplier = EM28XX_BULK_PACKET_MULTIPLIER; in em28xx_set_alternate()
403 min_pkt_size, dev->alt); in em28xx_set_alternate()
404 dev->max_pkt_size = in em28xx_set_alternate()
405 dev->alt_max_pkt_size_isoc[dev->alt]; in em28xx_set_alternate()
406 dev->packet_multiplier = EM28XX_NUM_ISOC_PACKETS; in em28xx_set_alternate()
409 dev->alt, dev->max_pkt_size); in em28xx_set_alternate()
410 err = usb_set_interface(udev, dev->ifnum, dev->alt); in em28xx_set_alternate()
412 dev_err(&dev->intf->dev, in em28xx_set_alternate()
414 dev->alt, err); in em28xx_set_alternate()
430 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field); in finish_buffer()
432 buf->vb.sequence = dev->v4l2->field_count++; in finish_buffer()
433 if (dev->v4l2->progressive) in finish_buffer()
434 buf->vb.field = V4L2_FIELD_NONE; in finish_buffer()
436 buf->vb.field = V4L2_FIELD_INTERLACED; in finish_buffer()
437 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in finish_buffer()
439 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in finish_buffer()
450 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_copy_video()
453 int bytesperline = v4l2->width << 1; in em28xx_copy_video()
455 if (buf->pos + len > buf->length) in em28xx_copy_video()
456 len = buf->length - buf->pos; in em28xx_copy_video()
461 if (v4l2->progressive || buf->top_field) in em28xx_copy_video()
462 fieldstart = buf->vb_buf; in em28xx_copy_video()
464 fieldstart = buf->vb_buf + bytesperline; in em28xx_copy_video()
466 linesdone = buf->pos / bytesperline; in em28xx_copy_video()
467 currlinedone = buf->pos % bytesperline; in em28xx_copy_video()
469 if (v4l2->progressive) in em28xx_copy_video()
475 lencopy = bytesperline - currlinedone; in em28xx_copy_video()
478 if ((char *)startwrite + lencopy > (char *)buf->vb_buf + buf->length) { in em28xx_copy_video()
480 ((char *)startwrite + lencopy) - in em28xx_copy_video()
481 ((char *)buf->vb_buf + buf->length)); in em28xx_copy_video()
482 remain = (char *)buf->vb_buf + buf->length - in em28xx_copy_video()
490 remain -= lencopy; in em28xx_copy_video()
493 if (v4l2->progressive) in em28xx_copy_video()
503 if ((char *)startwrite + lencopy > (char *)buf->vb_buf + in em28xx_copy_video()
504 buf->length) { in em28xx_copy_video()
506 ((char *)startwrite + lencopy) - in em28xx_copy_video()
507 ((char *)buf->vb_buf + buf->length)); in em28xx_copy_video()
508 remain = (char *)buf->vb_buf + buf->length - in em28xx_copy_video()
517 remain -= lencopy; in em28xx_copy_video()
520 buf->pos += len; in em28xx_copy_video()
533 if (buf->pos + len > buf->length) in em28xx_copy_vbi()
534 len = buf->length - buf->pos; in em28xx_copy_vbi()
536 offset = buf->pos; in em28xx_copy_vbi()
538 if (buf->top_field == 0) in em28xx_copy_vbi()
539 offset += dev->v4l2->vbi_width * dev->v4l2->vbi_height; in em28xx_copy_vbi()
541 memcpy(buf->vb_buf + offset, usb_buf, len); in em28xx_copy_vbi()
542 buf->pos += len; in em28xx_copy_vbi()
551 case -ENOENT: in print_err_status()
554 case -ECONNRESET: in print_err_status()
557 case -ENOSR: in print_err_status()
560 case -EPIPE: in print_err_status()
563 case -EOVERFLOW: in print_err_status()
566 case -EPROTO: in print_err_status()
567 errmsg = "Bit-stuff error (bad cable?)"; in print_err_status()
569 case -EILSEQ: in print_err_status()
572 case -ETIME: in print_err_status()
592 if (list_empty(&dma_q->active)) { in get_next_buf()
598 buf = list_entry(dma_q->active.next, struct em28xx_buffer, list); in get_next_buf()
599 /* Cleans up buffer - Useful for testing for frame/URB loss */ in get_next_buf()
600 list_del(&buf->list); in get_next_buf()
601 buf->pos = 0; in get_next_buf()
602 buf->vb_buf = buf->mem; in get_next_buf()
615 struct em28xx_v4l2 *v4l2 = dev->v4l2; in finish_field_prepare_next()
617 if (v4l2->progressive || v4l2->top_field) { /* Brand new frame */ in finish_field_prepare_next()
623 buf->top_field = v4l2->top_field; in finish_field_prepare_next()
624 buf->pos = 0; in finish_field_prepare_next()
637 struct em28xx_v4l2 *v4l2 = dev->v4l2; in process_frame_data_em28xx()
638 struct em28xx_buffer *buf = dev->usb_ctl.vid_buf; in process_frame_data_em28xx()
639 struct em28xx_buffer *vbi_buf = dev->usb_ctl.vbi_buf; in process_frame_data_em28xx()
640 struct em28xx_dmaqueue *dma_q = &dev->vidq; in process_frame_data_em28xx()
641 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; in process_frame_data_em28xx()
658 data_len -= 4; in process_frame_data_em28xx()
661 v4l2->capture_type = 0; in process_frame_data_em28xx()
662 v4l2->vbi_read = 0; in process_frame_data_em28xx()
664 v4l2->top_field = !(data_pkt[2] & 1); in process_frame_data_em28xx()
666 data_len -= 4; in process_frame_data_em28xx()
669 v4l2->capture_type = 2; in process_frame_data_em28xx()
671 v4l2->top_field = !(data_pkt[2] & 1); in process_frame_data_em28xx()
673 data_len -= 4; in process_frame_data_em28xx()
681 if (v4l2->capture_type == 0) { in process_frame_data_em28xx()
683 dev->usb_ctl.vbi_buf = vbi_buf; in process_frame_data_em28xx()
684 v4l2->capture_type = 1; in process_frame_data_em28xx()
687 if (v4l2->capture_type == 1) { in process_frame_data_em28xx()
688 int vbi_size = v4l2->vbi_width * v4l2->vbi_height; in process_frame_data_em28xx()
689 int vbi_data_len = ((v4l2->vbi_read + data_len) > vbi_size) ? in process_frame_data_em28xx()
690 (vbi_size - v4l2->vbi_read) : data_len; in process_frame_data_em28xx()
695 v4l2->vbi_read += vbi_data_len; in process_frame_data_em28xx()
699 v4l2->capture_type = 2; in process_frame_data_em28xx()
701 data_len -= vbi_data_len; in process_frame_data_em28xx()
705 if (v4l2->capture_type == 2) { in process_frame_data_em28xx()
707 dev->usb_ctl.vid_buf = buf; in process_frame_data_em28xx()
708 v4l2->capture_type = 3; in process_frame_data_em28xx()
711 if (v4l2->capture_type == 3 && buf && data_len > 0) in process_frame_data_em28xx()
722 struct em28xx_buffer *buf = dev->usb_ctl.vid_buf; in process_frame_data_em25xx()
723 struct em28xx_dmaqueue *dmaq = &dev->vidq; in process_frame_data_em25xx()
724 struct em28xx_v4l2 *v4l2 = dev->v4l2; in process_frame_data_em25xx()
735 v4l2->top_field = !(data_pkt[1] & in process_frame_data_em25xx()
740 data_len -= 2; in process_frame_data_em25xx()
744 if (dev->analog_xfer_bulk && frame_end) { in process_frame_data_em25xx()
746 dev->usb_ctl.vid_buf = buf; in process_frame_data_em25xx()
760 if (!dev->analog_xfer_bulk && frame_end) { in process_frame_data_em25xx()
762 dev->usb_ctl.vid_buf = buf; in process_frame_data_em25xx()
788 if (dev->disconnected) in em28xx_urb_data_copy()
791 if (urb->status < 0) in em28xx_urb_data_copy()
792 print_err_status(dev, -1, urb->status); in em28xx_urb_data_copy()
794 xfer_bulk = usb_pipebulk(urb->pipe); in em28xx_urb_data_copy()
799 num_packets = urb->number_of_packets; in em28xx_urb_data_copy()
803 usb_data_len = urb->actual_length; in em28xx_urb_data_copy()
805 usb_data_pkt = urb->transfer_buffer; in em28xx_urb_data_copy()
807 if (urb->iso_frame_desc[i].status < 0) { in em28xx_urb_data_copy()
809 urb->iso_frame_desc[i].status); in em28xx_urb_data_copy()
810 if (urb->iso_frame_desc[i].status != -EPROTO) in em28xx_urb_data_copy()
814 usb_data_len = urb->iso_frame_desc[i].actual_length; in em28xx_urb_data_copy()
815 if (usb_data_len > dev->max_pkt_size) { in em28xx_urb_data_copy()
820 usb_data_pkt = urb->transfer_buffer + in em28xx_urb_data_copy()
821 urb->iso_frame_desc[i].offset; in em28xx_urb_data_copy()
826 /* em28xx_usbdbg("packet %d is empty",i); - spammy */ in em28xx_urb_data_copy()
830 if (dev->is_em25xx) in em28xx_urb_data_copy()
849 return -1; /* Indicate that device is busy */ in get_resource()
859 if (dev->resources & res_type) { in res_get()
861 return -EBUSY; in res_get()
865 dev->resources |= res_type; in res_get()
874 dev->resources &= ~res_type; in res_free()
884 if (!INPUT(i)->type) in em28xx_v4l2_media_release()
886 media_device_unregister_entity(&dev->input_ent[i]); in em28xx_v4l2_media_release()
898 struct media_device *mdev = dev->media_dev; in em28xx_enable_analog_tuner()
899 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_enable_analog_tuner()
904 if (!mdev || !v4l2->decoder) in em28xx_enable_analog_tuner()
914 list_for_each_entry(link, &v4l2->decoder->links, list) { in em28xx_enable_analog_tuner()
915 if (link->sink->entity == v4l2->decoder) { in em28xx_enable_analog_tuner()
917 if (link->flags & MEDIA_LNK_FL_ENABLED) in em28xx_enable_analog_tuner()
926 source = found_link->source->entity; in em28xx_enable_analog_tuner()
927 list_for_each_entry(link, &source->links, list) { in em28xx_enable_analog_tuner()
931 sink = link->sink->entity; in em28xx_enable_analog_tuner()
933 if (sink == v4l2->decoder) in em28xx_enable_analog_tuner()
938 dev_err(&dev->intf->dev, in em28xx_enable_analog_tuner()
939 "Couldn't change link %s->%s to %s. Error %d\n", in em28xx_enable_analog_tuner()
940 source->name, sink->name, in em28xx_enable_analog_tuner()
946 em28xx_videodbg("link %s->%s was %s\n", in em28xx_enable_analog_tuner()
947 source->name, sink->name, in em28xx_enable_analog_tuner()
956 [EM28XX_VMUX_SVIDEO] = "S-Video",
964 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_v4l2_create_entities()
968 v4l2->video_pad.flags = MEDIA_PAD_FL_SINK; in em28xx_v4l2_create_entities()
969 ret = media_entity_pads_init(&v4l2->vdev.entity, 1, &v4l2->video_pad); in em28xx_v4l2_create_entities()
971 dev_err(&dev->intf->dev, in em28xx_v4l2_create_entities()
975 v4l2->vbi_pad.flags = MEDIA_PAD_FL_SINK; in em28xx_v4l2_create_entities()
976 ret = media_entity_pads_init(&v4l2->vbi_dev.entity, 1, in em28xx_v4l2_create_entities()
977 &v4l2->vbi_pad); in em28xx_v4l2_create_entities()
979 dev_err(&dev->intf->dev, in em28xx_v4l2_create_entities()
984 if (dev->is_webcam) in em28xx_v4l2_create_entities()
989 struct media_entity *ent = &dev->input_ent[i]; in em28xx_v4l2_create_entities()
991 if (!INPUT(i)->type) in em28xx_v4l2_create_entities()
994 ent->name = iname[INPUT(i)->type]; in em28xx_v4l2_create_entities()
995 ent->flags = MEDIA_ENT_FL_CONNECTOR; in em28xx_v4l2_create_entities()
996 dev->input_pad[i].flags = MEDIA_PAD_FL_SOURCE; in em28xx_v4l2_create_entities()
998 switch (INPUT(i)->type) { in em28xx_v4l2_create_entities()
1000 ent->function = MEDIA_ENT_F_CONN_COMPOSITE; in em28xx_v4l2_create_entities()
1003 ent->function = MEDIA_ENT_F_CONN_SVIDEO; in em28xx_v4l2_create_entities()
1006 if (dev->tuner_type != TUNER_ABSENT) in em28xx_v4l2_create_entities()
1007 ent->function = MEDIA_ENT_F_CONN_RF; in em28xx_v4l2_create_entities()
1011 ret = media_entity_pads_init(ent, 1, &dev->input_pad[i]); in em28xx_v4l2_create_entities()
1013 dev_err(&dev->intf->dev, in em28xx_v4l2_create_entities()
1016 ret = media_device_register_entity(dev->media_dev, ent); in em28xx_v4l2_create_entities()
1018 dev_err(&dev->intf->dev, in em28xx_v4l2_create_entities()
1033 struct em28xx_v4l2 *v4l2 = dev->v4l2; in queue_setup()
1035 (v4l2->width * v4l2->height * v4l2->format->depth + 7) >> 3; in queue_setup()
1038 return sizes[0] < size ? -EINVAL : 0; in queue_setup()
1051 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare()
1052 struct em28xx_v4l2 *v4l2 = dev->v4l2; in buffer_prepare()
1055 em28xx_videodbg("%s, field=%d\n", __func__, vbuf->field); in buffer_prepare()
1057 size = (v4l2->width * v4l2->height * v4l2->format->depth + 7) >> 3; in buffer_prepare()
1062 return -EINVAL; in buffer_prepare()
1072 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_start_analog_streaming()
1079 dev->v4l2->field_count = 0; in em28xx_start_analog_streaming()
1085 rc = res_get(dev, vq->type); in em28xx_start_analog_streaming()
1089 if (v4l2->streaming_users == 0) { in em28xx_start_analog_streaming()
1101 v4l2->capture_type = -1; in em28xx_start_analog_streaming()
1103 dev->analog_xfer_bulk, in em28xx_start_analog_streaming()
1105 dev->max_pkt_size, in em28xx_start_analog_streaming()
1106 dev->packet_multiplier, in em28xx_start_analog_streaming()
1119 f.frequency = v4l2->frequency; in em28xx_start_analog_streaming()
1120 owner = (struct v4l2_fh *)vq->owner; in em28xx_start_analog_streaming()
1121 if (owner && owner->vdev->vfl_type == VFL_TYPE_RADIO) in em28xx_start_analog_streaming()
1125 v4l2_device_call_all(&v4l2->v4l2_dev, in em28xx_start_analog_streaming()
1129 v4l2_device_call_all(&v4l2->v4l2_dev, 0, video, s_stream, 1); in em28xx_start_analog_streaming()
1132 v4l2->streaming_users++; in em28xx_start_analog_streaming()
1140 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_stop_streaming()
1141 struct em28xx_dmaqueue *vidq = &dev->vidq; in em28xx_stop_streaming()
1146 res_free(dev, vq->type); in em28xx_stop_streaming()
1148 if (v4l2->streaming_users-- == 1) { in em28xx_stop_streaming()
1150 v4l2_device_call_all(&v4l2->v4l2_dev, 0, video, s_stream, 0); in em28xx_stop_streaming()
1156 spin_lock_irqsave(&dev->slock, flags); in em28xx_stop_streaming()
1157 if (dev->usb_ctl.vid_buf) { in em28xx_stop_streaming()
1158 vb2_buffer_done(&dev->usb_ctl.vid_buf->vb.vb2_buf, in em28xx_stop_streaming()
1160 dev->usb_ctl.vid_buf = NULL; in em28xx_stop_streaming()
1162 while (!list_empty(&vidq->active)) { in em28xx_stop_streaming()
1165 buf = list_entry(vidq->active.next, struct em28xx_buffer, list); in em28xx_stop_streaming()
1166 list_del(&buf->list); in em28xx_stop_streaming()
1167 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in em28xx_stop_streaming()
1169 spin_unlock_irqrestore(&dev->slock, flags); in em28xx_stop_streaming()
1175 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_stop_vbi_streaming()
1176 struct em28xx_dmaqueue *vbiq = &dev->vbiq; in em28xx_stop_vbi_streaming()
1181 res_free(dev, vq->type); in em28xx_stop_vbi_streaming()
1183 if (v4l2->streaming_users-- == 1) { in em28xx_stop_vbi_streaming()
1185 v4l2_device_call_all(&v4l2->v4l2_dev, 0, video, s_stream, 0); in em28xx_stop_vbi_streaming()
1191 spin_lock_irqsave(&dev->slock, flags); in em28xx_stop_vbi_streaming()
1192 if (dev->usb_ctl.vbi_buf) { in em28xx_stop_vbi_streaming()
1193 vb2_buffer_done(&dev->usb_ctl.vbi_buf->vb.vb2_buf, in em28xx_stop_vbi_streaming()
1195 dev->usb_ctl.vbi_buf = NULL; in em28xx_stop_vbi_streaming()
1197 while (!list_empty(&vbiq->active)) { in em28xx_stop_vbi_streaming()
1200 buf = list_entry(vbiq->active.next, struct em28xx_buffer, list); in em28xx_stop_vbi_streaming()
1201 list_del(&buf->list); in em28xx_stop_vbi_streaming()
1202 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in em28xx_stop_vbi_streaming()
1204 spin_unlock_irqrestore(&dev->slock, flags); in em28xx_stop_vbi_streaming()
1211 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue()
1214 struct em28xx_dmaqueue *vidq = &dev->vidq; in buffer_queue()
1218 buf->mem = vb2_plane_vaddr(vb, 0); in buffer_queue()
1219 buf->length = vb2_plane_size(vb, 0); in buffer_queue()
1221 spin_lock_irqsave(&dev->slock, flags); in buffer_queue()
1222 list_add_tail(&buf->list, &vidq->active); in buffer_queue()
1223 spin_unlock_irqrestore(&dev->slock, flags); in buffer_queue()
1240 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_vb2_setup()
1243 q = &v4l2->vb_vidq; in em28xx_vb2_setup()
1244 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in em28xx_vb2_setup()
1245 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in em28xx_vb2_setup()
1246 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in em28xx_vb2_setup()
1247 q->drv_priv = dev; in em28xx_vb2_setup()
1248 q->buf_struct_size = sizeof(struct em28xx_buffer); in em28xx_vb2_setup()
1249 q->ops = &em28xx_video_qops; in em28xx_vb2_setup()
1250 q->mem_ops = &vb2_vmalloc_memops; in em28xx_vb2_setup()
1257 q = &v4l2->vb_vbiq; in em28xx_vb2_setup()
1258 q->type = V4L2_BUF_TYPE_VBI_CAPTURE; in em28xx_vb2_setup()
1259 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR; in em28xx_vb2_setup()
1260 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in em28xx_vb2_setup()
1261 q->drv_priv = dev; in em28xx_vb2_setup()
1262 q->buf_struct_size = sizeof(struct em28xx_buffer); in em28xx_vb2_setup()
1263 q->ops = &em28xx_vbi_qops; in em28xx_vb2_setup()
1264 q->mem_ops = &vb2_vmalloc_memops; in em28xx_vb2_setup()
1279 struct v4l2_device *v4l2_dev = &dev->v4l2->v4l2_dev; in video_mux()
1281 dev->ctl_input = index; in video_mux()
1282 dev->ctl_ainput = INPUT(index)->amux; in video_mux()
1283 dev->ctl_aoutput = INPUT(index)->aout; in video_mux()
1285 if (!dev->ctl_aoutput) in video_mux()
1286 dev->ctl_aoutput = EM28XX_AOUT_MASTER; in video_mux()
1289 INPUT(index)->vmux, 0, 0); in video_mux()
1291 if (dev->has_msp34xx) { in video_mux()
1292 if (dev->i2s_speed) { in video_mux()
1294 s_i2s_clock_freq, dev->i2s_speed); in video_mux()
1298 dev->ctl_ainput, in video_mux()
1302 if (dev->board.adecoder != EM28XX_NOADECODER) { in video_mux()
1304 dev->ctl_ainput, dev->ctl_aoutput, 0); in video_mux()
1315 * In the case of non-AC97 volume controls, we still need in em28xx_ctrl_notify()
1320 switch (ctrl->id) { in em28xx_ctrl_notify()
1322 dev->mute = ctrl->val; in em28xx_ctrl_notify()
1326 dev->volume = ctrl->val; in em28xx_ctrl_notify()
1335 container_of(ctrl->handler, struct em28xx_v4l2, ctrl_handler); in em28xx_s_ctrl()
1336 struct em28xx *dev = v4l2->dev; in em28xx_s_ctrl()
1337 int ret = -EINVAL; in em28xx_s_ctrl()
1339 switch (ctrl->id) { in em28xx_s_ctrl()
1341 dev->mute = ctrl->val; in em28xx_s_ctrl()
1345 dev->volume = ctrl->val; in em28xx_s_ctrl()
1349 ret = em28xx_write_reg(dev, EM28XX_R20_YGAIN, ctrl->val); in em28xx_s_ctrl()
1352 ret = em28xx_write_reg(dev, EM28XX_R21_YOFFSET, ctrl->val); in em28xx_s_ctrl()
1355 ret = em28xx_write_reg(dev, EM28XX_R22_UVGAIN, ctrl->val); in em28xx_s_ctrl()
1358 ret = em28xx_write_reg(dev, EM28XX_R23_UOFFSET, ctrl->val); in em28xx_s_ctrl()
1361 ret = em28xx_write_reg(dev, EM28XX_R24_VOFFSET, ctrl->val); in em28xx_s_ctrl()
1364 ret = em28xx_write_reg(dev, EM28XX_R25_SHARPNESS, ctrl->val); in em28xx_s_ctrl()
1382 *hscale = (((unsigned long)maxw) << 12) / width - 4096L; in size_to_scale()
1386 *vscale = (((unsigned long)maxh) << 12) / height - 4096L; in size_to_scale()
1416 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_g_fmt_vid_cap()
1418 f->fmt.pix.width = v4l2->width; in vidioc_g_fmt_vid_cap()
1419 f->fmt.pix.height = v4l2->height; in vidioc_g_fmt_vid_cap()
1420 f->fmt.pix.pixelformat = v4l2->format->fourcc; in vidioc_g_fmt_vid_cap()
1421 f->fmt.pix.bytesperline = (v4l2->width * v4l2->format->depth + 7) >> 3; in vidioc_g_fmt_vid_cap()
1422 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * v4l2->height; in vidioc_g_fmt_vid_cap()
1423 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in vidioc_g_fmt_vid_cap()
1426 if (v4l2->progressive) in vidioc_g_fmt_vid_cap()
1427 f->fmt.pix.field = V4L2_FIELD_NONE; in vidioc_g_fmt_vid_cap()
1429 f->fmt.pix.field = v4l2->interlaced_fieldmode ? in vidioc_g_fmt_vid_cap()
1449 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_try_fmt_vid_cap()
1450 unsigned int width = f->fmt.pix.width; in vidioc_try_fmt_vid_cap()
1451 unsigned int height = f->fmt.pix.height; in vidioc_try_fmt_vid_cap()
1457 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_try_fmt_vid_cap()
1461 f->fmt.pix.pixelformat, fmt->fourcc); in vidioc_try_fmt_vid_cap()
1464 if (dev->board.is_em2800) { in vidioc_try_fmt_vid_cap()
1478 * height must be even because of interlacing in vidioc_try_fmt_vid_cap()
1492 f->fmt.pix.width = width; in vidioc_try_fmt_vid_cap()
1493 f->fmt.pix.height = height; in vidioc_try_fmt_vid_cap()
1494 f->fmt.pix.pixelformat = fmt->fourcc; in vidioc_try_fmt_vid_cap()
1495 f->fmt.pix.bytesperline = (width * fmt->depth + 7) >> 3; in vidioc_try_fmt_vid_cap()
1496 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; in vidioc_try_fmt_vid_cap()
1497 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in vidioc_try_fmt_vid_cap()
1498 if (v4l2->progressive) in vidioc_try_fmt_vid_cap()
1499 f->fmt.pix.field = V4L2_FIELD_NONE; in vidioc_try_fmt_vid_cap()
1501 f->fmt.pix.field = v4l2->interlaced_fieldmode ? in vidioc_try_fmt_vid_cap()
1511 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_set_video_format()
1515 return -EINVAL; in em28xx_set_video_format()
1517 v4l2->format = fmt; in em28xx_set_video_format()
1518 v4l2->width = width; in em28xx_set_video_format()
1519 v4l2->height = height; in em28xx_set_video_format()
1522 size_to_scale(dev, v4l2->width, v4l2->height, in em28xx_set_video_format()
1523 &v4l2->hscale, &v4l2->vscale); in em28xx_set_video_format()
1534 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_s_fmt_vid_cap()
1536 if (vb2_is_busy(&v4l2->vb_vidq)) in vidioc_s_fmt_vid_cap()
1537 return -EBUSY; in vidioc_s_fmt_vid_cap()
1541 return em28xx_set_video_format(dev, f->fmt.pix.pixelformat, in vidioc_s_fmt_vid_cap()
1542 f->fmt.pix.width, f->fmt.pix.height); in vidioc_s_fmt_vid_cap()
1549 *norm = dev->v4l2->norm; in vidioc_g_std()
1558 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, video, querystd, norm); in vidioc_querystd()
1566 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_s_std()
1569 if (norm == v4l2->norm) in vidioc_s_std()
1572 if (v4l2->streaming_users > 0) in vidioc_s_std()
1573 return -EBUSY; in vidioc_s_std()
1575 v4l2->norm = norm; in vidioc_s_std()
1583 v4l2->width = f.fmt.pix.width; in vidioc_s_std()
1584 v4l2->height = f.fmt.pix.height; in vidioc_s_std()
1585 size_to_scale(dev, v4l2->width, v4l2->height, in vidioc_s_std()
1586 &v4l2->hscale, &v4l2->vscale); in vidioc_s_std()
1589 v4l2_device_call_all(&v4l2->v4l2_dev, 0, video, s_std, v4l2->norm); in vidioc_s_std()
1599 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_g_parm()
1602 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in vidioc_g_parm()
1603 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in vidioc_g_parm()
1604 return -EINVAL; in vidioc_g_parm()
1606 p->parm.capture.readbuffers = EM28XX_MIN_BUF; in vidioc_g_parm()
1607 p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_g_parm()
1608 if (dev->is_webcam) { in vidioc_g_parm()
1609 rc = v4l2_device_call_until_err(&v4l2->v4l2_dev, 0, in vidioc_g_parm()
1613 p->parm.capture.timeperframe = ival.interval; in vidioc_g_parm()
1615 v4l2_video_std_frame_period(v4l2->norm, in vidioc_g_parm()
1616 &p->parm.capture.timeperframe); in vidioc_g_parm()
1628 p->parm.capture.timeperframe in vidioc_s_parm()
1632 if (!dev->is_webcam) in vidioc_s_parm()
1633 return -ENOTTY; in vidioc_s_parm()
1635 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in vidioc_s_parm()
1636 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in vidioc_s_parm()
1637 return -EINVAL; in vidioc_s_parm()
1639 memset(&p->parm, 0, sizeof(p->parm)); in vidioc_s_parm()
1640 p->parm.capture.readbuffers = EM28XX_MIN_BUF; in vidioc_s_parm()
1641 p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_s_parm()
1642 rc = v4l2_device_call_until_err(&dev->v4l2->v4l2_dev, 0, in vidioc_s_parm()
1646 p->parm.capture.timeperframe = ival.interval; in vidioc_s_parm()
1657 n = i->index; in vidioc_enum_input()
1659 return -EINVAL; in vidioc_enum_input()
1660 if (!INPUT(n)->type) in vidioc_enum_input()
1661 return -EINVAL; in vidioc_enum_input()
1663 i->type = V4L2_INPUT_TYPE_CAMERA; in vidioc_enum_input()
1665 strscpy(i->name, iname[INPUT(n)->type], sizeof(i->name)); in vidioc_enum_input()
1667 if (INPUT(n)->type == EM28XX_VMUX_TELEVISION) in vidioc_enum_input()
1668 i->type = V4L2_INPUT_TYPE_TUNER; in vidioc_enum_input()
1670 i->std = dev->v4l2->vdev.tvnorms; in vidioc_enum_input()
1672 if (dev->is_webcam) in vidioc_enum_input()
1673 i->capabilities = 0; in vidioc_enum_input()
1676 i->audioset = 0; in vidioc_enum_input()
1678 if (dev->amux_map[j] != EM28XX_AMUX_UNUSED) in vidioc_enum_input()
1679 i->audioset |= 1 << j; in vidioc_enum_input()
1688 *i = dev->ctl_input; in vidioc_g_input()
1698 return -EINVAL; in vidioc_s_input()
1699 if (!INPUT(i)->type) in vidioc_s_input()
1700 return -EINVAL; in vidioc_s_input()
1711 unsigned int idx = dev->amux_map[index]; in em28xx_fill_audio_input()
1720 if (dev->has_msp34xx && idx != EM28XX_AMUX_UNUSED) in em28xx_fill_audio_input()
1725 strscpy(a->name, "Television", sizeof(a->name)); in em28xx_fill_audio_input()
1728 strscpy(a->name, "Line In", sizeof(a->name)); in em28xx_fill_audio_input()
1731 strscpy(a->name, "Television alt", sizeof(a->name)); in em28xx_fill_audio_input()
1734 strscpy(a->name, "Phone", sizeof(a->name)); in em28xx_fill_audio_input()
1737 strscpy(a->name, "Mic", sizeof(a->name)); in em28xx_fill_audio_input()
1740 strscpy(a->name, "CD", sizeof(a->name)); in em28xx_fill_audio_input()
1743 strscpy(a->name, "Aux", sizeof(a->name)); in em28xx_fill_audio_input()
1746 strscpy(a->name, "PCM", sizeof(a->name)); in em28xx_fill_audio_input()
1750 return -EINVAL; in em28xx_fill_audio_input()
1752 a->index = index; in em28xx_fill_audio_input()
1753 a->capability = V4L2_AUDCAP_STEREO; in em28xx_fill_audio_input()
1756 s, a->index, a->name); in em28xx_fill_audio_input()
1765 if (a->index >= MAX_EM28XX_INPUT) in vidioc_enumaudio()
1766 return -EINVAL; in vidioc_enumaudio()
1768 return em28xx_fill_audio_input(dev, __func__, a, a->index); in vidioc_enumaudio()
1777 if (dev->ctl_ainput == dev->amux_map[i]) in vidioc_g_audio()
1781 return -EINVAL; in vidioc_g_audio()
1790 if (a->index >= MAX_EM28XX_INPUT) in vidioc_s_audio()
1791 return -EINVAL; in vidioc_s_audio()
1793 idx = dev->amux_map[a->index]; in vidioc_s_audio()
1796 return -EINVAL; in vidioc_s_audio()
1798 dev->ctl_ainput = idx; in vidioc_s_audio()
1808 if (idx == dev->amux_map[i]) in vidioc_s_audio()
1811 return -EINVAL; in vidioc_s_audio()
1813 dev->ctl_aoutput = INPUT(i)->aout; in vidioc_s_audio()
1815 if (!dev->ctl_aoutput) in vidioc_s_audio()
1816 dev->ctl_aoutput = EM28XX_AOUT_MASTER; in vidioc_s_audio()
1819 dev->ctl_ainput); in vidioc_s_audio()
1829 if (t->index != 0) in vidioc_g_tuner()
1830 return -EINVAL; in vidioc_g_tuner()
1832 strscpy(t->name, "Tuner", sizeof(t->name)); in vidioc_g_tuner()
1834 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, g_tuner, t); in vidioc_g_tuner()
1843 if (t->index != 0) in vidioc_s_tuner()
1844 return -EINVAL; in vidioc_s_tuner()
1846 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t); in vidioc_s_tuner()
1854 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_g_frequency()
1856 if (f->tuner != 0) in vidioc_g_frequency()
1857 return -EINVAL; in vidioc_g_frequency()
1859 f->frequency = v4l2->frequency; in vidioc_g_frequency()
1868 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_s_frequency()
1870 if (f->tuner != 0) in vidioc_s_frequency()
1871 return -EINVAL; in vidioc_s_frequency()
1873 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, s_frequency, f); in vidioc_s_frequency()
1874 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, g_frequency, &new_freq); in vidioc_s_frequency()
1875 v4l2->frequency = new_freq.frequency; in vidioc_s_frequency()
1886 if (chip->match.addr > 1) in vidioc_g_chip_info()
1887 return -EINVAL; in vidioc_g_chip_info()
1888 if (chip->match.addr == 1) in vidioc_g_chip_info()
1889 strscpy(chip->name, "ac97", sizeof(chip->name)); in vidioc_g_chip_info()
1891 strscpy(chip->name, in vidioc_g_chip_info()
1892 dev->v4l2->v4l2_dev.name, sizeof(chip->name)); in vidioc_g_chip_info()
1914 if (reg->match.addr > 1) in vidioc_g_register()
1915 return -EINVAL; in vidioc_g_register()
1916 if (reg->match.addr) { in vidioc_g_register()
1917 ret = em28xx_read_ac97(dev, reg->reg); in vidioc_g_register()
1921 reg->val = ret; in vidioc_g_register()
1922 reg->size = 1; in vidioc_g_register()
1927 reg->size = em28xx_reg_len(reg->reg); in vidioc_g_register()
1928 if (reg->size == 1) { in vidioc_g_register()
1929 ret = em28xx_read_reg(dev, reg->reg); in vidioc_g_register()
1934 reg->val = ret; in vidioc_g_register()
1938 ret = dev->em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS, in vidioc_g_register()
1939 reg->reg, (char *)&val, 2); in vidioc_g_register()
1943 reg->val = le16_to_cpu(val); in vidioc_g_register()
1955 if (reg->match.addr > 1) in vidioc_s_register()
1956 return -EINVAL; in vidioc_s_register()
1957 if (reg->match.addr) in vidioc_s_register()
1958 return em28xx_write_ac97(dev, reg->reg, reg->val); in vidioc_s_register()
1961 buf = cpu_to_le16(reg->val); in vidioc_s_register()
1963 return em28xx_write_regs(dev, reg->reg, (char *)&buf, in vidioc_s_register()
1964 em28xx_reg_len(reg->reg)); in vidioc_s_register()
1972 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_querycap()
1973 struct usb_device *udev = interface_to_usbdev(dev->intf); in vidioc_querycap()
1975 strscpy(cap->driver, "em28xx", sizeof(cap->driver)); in vidioc_querycap()
1976 strscpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); in vidioc_querycap()
1977 usb_make_path(udev, cap->bus_info, sizeof(cap->bus_info)); in vidioc_querycap()
1979 cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_READWRITE | in vidioc_querycap()
1981 if (dev->int_audio_type != EM28XX_INT_AUDIO_NONE) in vidioc_querycap()
1982 cap->capabilities |= V4L2_CAP_AUDIO; in vidioc_querycap()
1983 if (dev->tuner_type != TUNER_ABSENT) in vidioc_querycap()
1984 cap->capabilities |= V4L2_CAP_TUNER; in vidioc_querycap()
1985 if (video_is_registered(&v4l2->vbi_dev)) in vidioc_querycap()
1986 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; in vidioc_querycap()
1987 if (video_is_registered(&v4l2->radio_dev)) in vidioc_querycap()
1988 cap->capabilities |= V4L2_CAP_RADIO; in vidioc_querycap()
1995 if (unlikely(f->index >= ARRAY_SIZE(format))) in vidioc_enum_fmt_vid_cap()
1996 return -EINVAL; in vidioc_enum_fmt_vid_cap()
1998 f->pixelformat = format[f->index].fourcc; in vidioc_enum_fmt_vid_cap()
2011 fmt = format_by_fourcc(fsize->pixel_format); in vidioc_enum_framesizes()
2014 fsize->pixel_format); in vidioc_enum_framesizes()
2015 return -EINVAL; in vidioc_enum_framesizes()
2018 if (dev->board.is_em2800) { in vidioc_enum_framesizes()
2019 if (fsize->index > 1) in vidioc_enum_framesizes()
2020 return -EINVAL; in vidioc_enum_framesizes()
2021 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; in vidioc_enum_framesizes()
2022 fsize->discrete.width = maxw / (1 + fsize->index); in vidioc_enum_framesizes()
2023 fsize->discrete.height = maxh / (1 + fsize->index); in vidioc_enum_framesizes()
2027 if (fsize->index != 0) in vidioc_enum_framesizes()
2028 return -EINVAL; in vidioc_enum_framesizes()
2031 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in vidioc_enum_framesizes()
2033 &fsize->stepwise.min_width, &fsize->stepwise.min_height); in vidioc_enum_framesizes()
2034 if (fsize->stepwise.min_width < 48) in vidioc_enum_framesizes()
2035 fsize->stepwise.min_width = 48; in vidioc_enum_framesizes()
2036 if (fsize->stepwise.min_height < 38) in vidioc_enum_framesizes()
2037 fsize->stepwise.min_height = 38; in vidioc_enum_framesizes()
2038 fsize->stepwise.max_width = maxw; in vidioc_enum_framesizes()
2039 fsize->stepwise.max_height = maxh; in vidioc_enum_framesizes()
2040 fsize->stepwise.step_width = 1; in vidioc_enum_framesizes()
2041 fsize->stepwise.step_height = 1; in vidioc_enum_framesizes()
2051 struct em28xx_v4l2 *v4l2 = dev->v4l2; in vidioc_g_fmt_vbi_cap()
2053 format->fmt.vbi.samples_per_line = v4l2->vbi_width; in vidioc_g_fmt_vbi_cap()
2054 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; in vidioc_g_fmt_vbi_cap()
2055 format->fmt.vbi.offset = 0; in vidioc_g_fmt_vbi_cap()
2056 format->fmt.vbi.flags = 0; in vidioc_g_fmt_vbi_cap()
2057 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; in vidioc_g_fmt_vbi_cap()
2058 format->fmt.vbi.count[0] = v4l2->vbi_height; in vidioc_g_fmt_vbi_cap()
2059 format->fmt.vbi.count[1] = v4l2->vbi_height; in vidioc_g_fmt_vbi_cap()
2060 memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved)); in vidioc_g_fmt_vbi_cap()
2063 if (v4l2->norm & V4L2_STD_525_60) { in vidioc_g_fmt_vbi_cap()
2065 format->fmt.vbi.start[0] = 10; in vidioc_g_fmt_vbi_cap()
2066 format->fmt.vbi.start[1] = 273; in vidioc_g_fmt_vbi_cap()
2067 } else if (v4l2->norm & V4L2_STD_625_50) { in vidioc_g_fmt_vbi_cap()
2069 format->fmt.vbi.start[0] = 6; in vidioc_g_fmt_vbi_cap()
2070 format->fmt.vbi.start[1] = 318; in vidioc_g_fmt_vbi_cap()
2085 if (unlikely(t->index > 0)) in radio_g_tuner()
2086 return -EINVAL; in radio_g_tuner()
2088 strscpy(t->name, "Radio", sizeof(t->name)); in radio_g_tuner()
2090 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, g_tuner, t); in radio_g_tuner()
2100 if (t->index != 0) in radio_s_tuner()
2101 return -EINVAL; in radio_s_tuner()
2103 v4l2_device_call_all(&dev->v4l2->v4l2_dev, 0, tuner, s_tuner, t); in radio_s_tuner()
2109 * em28xx_free_v4l2() - Free struct em28xx_v4l2
2119 v4l2->dev->v4l2 = NULL; in em28xx_free_v4l2()
2131 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_v4l2_open()
2135 switch (vdev->vfl_type) { in em28xx_v4l2_open()
2145 return -EINVAL; in em28xx_v4l2_open()
2150 v4l2->users); in em28xx_v4l2_open()
2152 if (mutex_lock_interruptible(&dev->lock)) in em28xx_v4l2_open()
2153 return -ERESTARTSYS; in em28xx_v4l2_open()
2157 dev_err(&dev->intf->dev, in em28xx_v4l2_open()
2160 mutex_unlock(&dev->lock); in em28xx_v4l2_open()
2164 if (v4l2->users == 0) { in em28xx_v4l2_open()
2167 if (vdev->vfl_type != VFL_TYPE_RADIO) in em28xx_v4l2_open()
2177 if (vdev->vfl_type == VFL_TYPE_RADIO) { in em28xx_v4l2_open()
2179 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, s_radio); in em28xx_v4l2_open()
2182 kref_get(&dev->ref); in em28xx_v4l2_open()
2183 kref_get(&v4l2->ref); in em28xx_v4l2_open()
2184 v4l2->users++; in em28xx_v4l2_open()
2186 mutex_unlock(&dev->lock); in em28xx_v4l2_open()
2198 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_v4l2_fini()
2200 if (dev->is_audio_only) { in em28xx_v4l2_fini()
2205 if (!dev->has_video) { in em28xx_v4l2_fini()
2213 dev_info(&dev->intf->dev, "Closing video extension\n"); in em28xx_v4l2_fini()
2215 mutex_lock(&dev->lock); in em28xx_v4l2_fini()
2217 v4l2_device_disconnect(&v4l2->v4l2_dev); in em28xx_v4l2_fini()
2223 if (video_is_registered(&v4l2->radio_dev)) { in em28xx_v4l2_fini()
2224 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", in em28xx_v4l2_fini()
2225 video_device_node_name(&v4l2->radio_dev)); in em28xx_v4l2_fini()
2226 video_unregister_device(&v4l2->radio_dev); in em28xx_v4l2_fini()
2228 if (video_is_registered(&v4l2->vbi_dev)) { in em28xx_v4l2_fini()
2229 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", in em28xx_v4l2_fini()
2230 video_device_node_name(&v4l2->vbi_dev)); in em28xx_v4l2_fini()
2231 video_unregister_device(&v4l2->vbi_dev); in em28xx_v4l2_fini()
2233 if (video_is_registered(&v4l2->vdev)) { in em28xx_v4l2_fini()
2234 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", in em28xx_v4l2_fini()
2235 video_device_node_name(&v4l2->vdev)); in em28xx_v4l2_fini()
2236 video_unregister_device(&v4l2->vdev); in em28xx_v4l2_fini()
2239 v4l2_ctrl_handler_free(&v4l2->ctrl_handler); in em28xx_v4l2_fini()
2240 v4l2_device_unregister(&v4l2->v4l2_dev); in em28xx_v4l2_fini()
2242 kref_put(&v4l2->ref, em28xx_free_v4l2); in em28xx_v4l2_fini()
2244 mutex_unlock(&dev->lock); in em28xx_v4l2_fini()
2246 kref_put(&dev->ref, em28xx_free_device); in em28xx_v4l2_fini()
2253 if (dev->is_audio_only) in em28xx_v4l2_suspend()
2256 if (!dev->has_video) in em28xx_v4l2_suspend()
2259 dev_info(&dev->intf->dev, "Suspending video extension\n"); in em28xx_v4l2_suspend()
2266 if (dev->is_audio_only) in em28xx_v4l2_resume()
2269 if (!dev->has_video) in em28xx_v4l2_resume()
2272 dev_info(&dev->intf->dev, "Resuming video extension\n"); in em28xx_v4l2_resume()
2285 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_v4l2_close()
2286 struct usb_device *udev = interface_to_usbdev(dev->intf); in em28xx_v4l2_close()
2289 em28xx_videodbg("users=%d\n", v4l2->users); in em28xx_v4l2_close()
2292 mutex_lock(&dev->lock); in em28xx_v4l2_close()
2294 if (v4l2->users == 1) { in em28xx_v4l2_close()
2296 if (dev->disconnected) in em28xx_v4l2_close()
2300 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, standby); in em28xx_v4l2_close()
2306 dev->alt = 0; in em28xx_v4l2_close()
2310 dev_err(&dev->intf->dev, in em28xx_v4l2_close()
2317 v4l2->users--; in em28xx_v4l2_close()
2318 kref_put(&v4l2->ref, em28xx_free_v4l2); in em28xx_v4l2_close()
2319 mutex_unlock(&dev->lock); in em28xx_v4l2_close()
2320 kref_put(&dev->ref, em28xx_free_device); in em28xx_v4l2_close()
2440 vfd->v4l2_dev = &dev->v4l2->v4l2_dev; in em28xx_vdev_init()
2441 vfd->lock = &dev->lock; in em28xx_vdev_init()
2442 if (dev->is_webcam) in em28xx_vdev_init()
2443 vfd->tvnorms = 0; in em28xx_vdev_init()
2445 snprintf(vfd->name, sizeof(vfd->name), "%s %s", in em28xx_vdev_init()
2446 dev_name(&dev->intf->dev), type_name); in em28xx_vdev_init()
2453 struct em28xx_v4l2 *v4l2 = dev->v4l2; in em28xx_tuner_setup()
2454 struct v4l2_device *v4l2_dev = &v4l2->v4l2_dev; in em28xx_tuner_setup()
2463 if (dev->board.radio.type) { in em28xx_tuner_setup()
2464 tun_setup.type = dev->board.radio.type; in em28xx_tuner_setup()
2465 tun_setup.addr = dev->board.radio_addr; in em28xx_tuner_setup()
2471 if (dev->tuner_type != TUNER_ABSENT && dev->tuner_type) { in em28xx_tuner_setup()
2472 tun_setup.type = dev->tuner_type; in em28xx_tuner_setup()
2479 if (dev->board.tda9887_conf) { in em28xx_tuner_setup()
2483 tda9887_cfg.priv = &dev->board.tda9887_conf; in em28xx_tuner_setup()
2489 if (dev->tuner_type == TUNER_XC2028) { in em28xx_tuner_setup()
2508 v4l2->frequency = f.frequency; in em28xx_tuner_setup()
2520 if (dev->is_audio_only) { in em28xx_v4l2_init()
2525 if (!dev->has_video) { in em28xx_v4l2_init()
2530 dev_info(&dev->intf->dev, "Registering V4L2 extension\n"); in em28xx_v4l2_init()
2532 mutex_lock(&dev->lock); in em28xx_v4l2_init()
2536 mutex_unlock(&dev->lock); in em28xx_v4l2_init()
2537 return -ENOMEM; in em28xx_v4l2_init()
2539 kref_init(&v4l2->ref); in em28xx_v4l2_init()
2540 v4l2->dev = dev; in em28xx_v4l2_init()
2541 dev->v4l2 = v4l2; in em28xx_v4l2_init()
2544 v4l2->v4l2_dev.mdev = dev->media_dev; in em28xx_v4l2_init()
2546 ret = v4l2_device_register(&dev->intf->dev, &v4l2->v4l2_dev); in em28xx_v4l2_init()
2548 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2553 hdl = &v4l2->ctrl_handler; in em28xx_v4l2_init()
2555 v4l2->v4l2_dev.ctrl_handler = hdl; in em28xx_v4l2_init()
2557 if (dev->is_webcam) in em28xx_v4l2_init()
2558 v4l2->progressive = true; in em28xx_v4l2_init()
2563 v4l2->vinmode = EM28XX_VINMODE_YUV422_CbYCrY; in em28xx_v4l2_init()
2564 v4l2->vinctl = EM28XX_VINCTRL_INTERLACED | in em28xx_v4l2_init()
2569 if (dev->has_msp34xx) in em28xx_v4l2_init()
2570 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2571 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2574 if (dev->board.decoder == EM28XX_SAA711X) in em28xx_v4l2_init()
2575 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2576 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2579 if (dev->board.decoder == EM28XX_TVP5150) in em28xx_v4l2_init()
2580 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2581 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2584 if (dev->board.adecoder == EM28XX_TVAUDIO) in em28xx_v4l2_init()
2585 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2586 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2587 "tvaudio", dev->board.tvaudio_addr, NULL); in em28xx_v4l2_init()
2591 if (dev->board.tuner_type != TUNER_ABSENT) { in em28xx_v4l2_init()
2592 unsigned short tuner_addr = dev->board.tuner_addr; in em28xx_v4l2_init()
2593 int has_demod = (dev->board.tda9887_conf & TDA9887_PRESENT); in em28xx_v4l2_init()
2595 if (dev->board.radio.type) in em28xx_v4l2_init()
2596 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2597 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2598 "tuner", dev->board.radio_addr, in em28xx_v4l2_init()
2602 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2603 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2611 sd = v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2612 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2619 v4l2_i2c_new_subdev(&v4l2->v4l2_dev, in em28xx_v4l2_init()
2620 &dev->i2c_adap[dev->def_i2c_bus], in em28xx_v4l2_init()
2627 if (dev->em28xx_sensor != EM28XX_NOSENSOR) in em28xx_v4l2_init()
2633 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2634 "%s: Error while setting audio - error [%d]!\n", in em28xx_v4l2_init()
2638 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) { in em28xx_v4l2_init()
2655 INIT_LIST_HEAD(&dev->vidq.active); in em28xx_v4l2_init()
2656 INIT_LIST_HEAD(&dev->vbiq.active); in em28xx_v4l2_init()
2658 if (dev->has_msp34xx) { in em28xx_v4l2_init()
2662 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2663 "%s: em28xx_write_reg - msp34xx(1) failed! error [%d]\n", in em28xx_v4l2_init()
2671 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2672 "%s: em28xx_write_reg - msp34xx(2) failed! error [%d]\n", in em28xx_v4l2_init()
2680 v4l2->norm = V4L2_STD_PAL; in em28xx_v4l2_init()
2681 v4l2_device_call_all(&v4l2->v4l2_dev, 0, video, s_std, v4l2->norm); in em28xx_v4l2_init()
2682 v4l2->interlaced_fieldmode = EM28XX_INTERLACED_DEFAULT; in em28xx_v4l2_init()
2685 v4l2->format = &format[0]; in em28xx_v4l2_init()
2692 if (dev->board.is_em2800) in em28xx_v4l2_init()
2701 dev->mute = 1; in em28xx_v4l2_init()
2702 dev->volume = 0x1f; in em28xx_v4l2_init()
2725 -0x80, 0x7f, 1, BRIGHTNESS_DEFAULT); in em28xx_v4l2_init()
2733 -0x30, 0x30, 1, BLUE_BALANCE_DEFAULT); in em28xx_v4l2_init()
2737 -0x30, 0x30, 1, RED_BALANCE_DEFAULT); in em28xx_v4l2_init()
2746 ret = hdl->error; in em28xx_v4l2_init()
2751 em28xx_vdev_init(dev, &v4l2->vdev, &em28xx_video_template, "video"); in em28xx_v4l2_init()
2752 mutex_init(&v4l2->vb_queue_lock); in em28xx_v4l2_init()
2753 mutex_init(&v4l2->vb_vbi_queue_lock); in em28xx_v4l2_init()
2754 v4l2->vdev.queue = &v4l2->vb_vidq; in em28xx_v4l2_init()
2755 v4l2->vdev.queue->lock = &v4l2->vb_queue_lock; in em28xx_v4l2_init()
2756 v4l2->vdev.device_caps = V4L2_CAP_READWRITE | V4L2_CAP_VIDEO_CAPTURE | in em28xx_v4l2_init()
2758 if (dev->int_audio_type != EM28XX_INT_AUDIO_NONE) in em28xx_v4l2_init()
2759 v4l2->vdev.device_caps |= V4L2_CAP_AUDIO; in em28xx_v4l2_init()
2760 if (dev->tuner_type != TUNER_ABSENT) in em28xx_v4l2_init()
2761 v4l2->vdev.device_caps |= V4L2_CAP_TUNER; in em28xx_v4l2_init()
2765 if (dev->is_webcam) { in em28xx_v4l2_init()
2766 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_QUERYSTD); in em28xx_v4l2_init()
2767 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_STD); in em28xx_v4l2_init()
2768 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_STD); in em28xx_v4l2_init()
2770 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_PARM); in em28xx_v4l2_init()
2772 if (dev->tuner_type == TUNER_ABSENT) { in em28xx_v4l2_init()
2773 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_TUNER); in em28xx_v4l2_init()
2774 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_TUNER); in em28xx_v4l2_init()
2775 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_FREQUENCY); in em28xx_v4l2_init()
2776 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_FREQUENCY); in em28xx_v4l2_init()
2778 if (dev->int_audio_type == EM28XX_INT_AUDIO_NONE) { in em28xx_v4l2_init()
2779 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_G_AUDIO); in em28xx_v4l2_init()
2780 v4l2_disable_ioctl(&v4l2->vdev, VIDIOC_S_AUDIO); in em28xx_v4l2_init()
2784 ret = video_register_device(&v4l2->vdev, VFL_TYPE_VIDEO, in em28xx_v4l2_init()
2785 video_nr[dev->devno]); in em28xx_v4l2_init()
2787 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2794 em28xx_vdev_init(dev, &v4l2->vbi_dev, &em28xx_video_template, in em28xx_v4l2_init()
2797 v4l2->vbi_dev.queue = &v4l2->vb_vbiq; in em28xx_v4l2_init()
2798 v4l2->vbi_dev.queue->lock = &v4l2->vb_vbi_queue_lock; in em28xx_v4l2_init()
2799 v4l2->vbi_dev.device_caps = V4L2_CAP_STREAMING | in em28xx_v4l2_init()
2801 if (dev->tuner_type != TUNER_ABSENT) in em28xx_v4l2_init()
2802 v4l2->vbi_dev.device_caps |= V4L2_CAP_TUNER; in em28xx_v4l2_init()
2805 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_S_PARM); in em28xx_v4l2_init()
2806 if (dev->tuner_type == TUNER_ABSENT) { in em28xx_v4l2_init()
2807 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_G_TUNER); in em28xx_v4l2_init()
2808 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_S_TUNER); in em28xx_v4l2_init()
2809 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_G_FREQUENCY); in em28xx_v4l2_init()
2810 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_S_FREQUENCY); in em28xx_v4l2_init()
2812 if (dev->int_audio_type == EM28XX_INT_AUDIO_NONE) { in em28xx_v4l2_init()
2813 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_G_AUDIO); in em28xx_v4l2_init()
2814 v4l2_disable_ioctl(&v4l2->vbi_dev, VIDIOC_S_AUDIO); in em28xx_v4l2_init()
2818 ret = video_register_device(&v4l2->vbi_dev, VFL_TYPE_VBI, in em28xx_v4l2_init()
2819 vbi_nr[dev->devno]); in em28xx_v4l2_init()
2821 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2827 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { in em28xx_v4l2_init()
2828 em28xx_vdev_init(dev, &v4l2->radio_dev, &em28xx_radio_template, in em28xx_v4l2_init()
2830 v4l2->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; in em28xx_v4l2_init()
2831 ret = video_register_device(&v4l2->radio_dev, VFL_TYPE_RADIO, in em28xx_v4l2_init()
2832 radio_nr[dev->devno]); in em28xx_v4l2_init()
2834 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2838 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2840 video_device_node_name(&v4l2->radio_dev)); in em28xx_v4l2_init()
2847 ret = v4l2_mc_create_media_graph(dev->media_dev); in em28xx_v4l2_init()
2849 dev_err(&dev->intf->dev, in em28xx_v4l2_init()
2856 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2858 video_device_node_name(&v4l2->vdev)); in em28xx_v4l2_init()
2860 if (video_is_registered(&v4l2->vbi_dev)) in em28xx_v4l2_init()
2861 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2863 video_device_node_name(&v4l2->vbi_dev)); in em28xx_v4l2_init()
2866 v4l2_device_call_all(&v4l2->v4l2_dev, 0, tuner, standby); in em28xx_v4l2_init()
2871 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2874 kref_get(&dev->ref); in em28xx_v4l2_init()
2876 mutex_unlock(&dev->lock); in em28xx_v4l2_init()
2880 if (video_is_registered(&v4l2->radio_dev)) { in em28xx_v4l2_init()
2881 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2883 video_device_node_name(&v4l2->radio_dev)); in em28xx_v4l2_init()
2884 video_unregister_device(&v4l2->radio_dev); in em28xx_v4l2_init()
2886 if (video_is_registered(&v4l2->vbi_dev)) { in em28xx_v4l2_init()
2887 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2889 video_device_node_name(&v4l2->vbi_dev)); in em28xx_v4l2_init()
2890 video_unregister_device(&v4l2->vbi_dev); in em28xx_v4l2_init()
2892 if (video_is_registered(&v4l2->vdev)) { in em28xx_v4l2_init()
2893 dev_info(&dev->intf->dev, in em28xx_v4l2_init()
2895 video_device_node_name(&v4l2->vdev)); in em28xx_v4l2_init()
2896 video_unregister_device(&v4l2->vdev); in em28xx_v4l2_init()
2899 v4l2_ctrl_handler_free(&v4l2->ctrl_handler); in em28xx_v4l2_init()
2900 v4l2_device_unregister(&v4l2->v4l2_dev); in em28xx_v4l2_init()
2902 dev->v4l2 = NULL; in em28xx_v4l2_init()
2903 kref_put(&v4l2->ref, em28xx_free_v4l2); in em28xx_v4l2_init()
2904 mutex_unlock(&dev->lock); in em28xx_v4l2_init()