diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2013-04-13 09:00:52 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-04-16 17:06:35 -0400 |
commit | 2efe2cc4305ad9a8ea4db5881808c4db1c451091 (patch) | |
tree | 66b3337700b6c114568a590cdb8cb6e40b8235bf /drivers/media | |
parent | 11f095aa4154d27bdb15909b12a9d3922ab55cde (diff) |
[media] cx25821: move vidq from cx25821_fh to cx25821_channel
This is not a per-filehandle object, it's a per-channel object.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/pci/cx25821/cx25821-video.c | 235 | ||||
-rw-r--r-- | drivers/media/pci/cx25821/cx25821.h | 8 |
2 files changed, 115 insertions, 128 deletions
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c index 2aba24f2a3d8..d88316c5f5de 100644 --- a/drivers/media/pci/cx25821/cx25821-video.c +++ b/drivers/media/pci/cx25821/cx25821-video.c | |||
@@ -288,7 +288,7 @@ static void cx25821_vid_timeout(unsigned long data) | |||
288 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; | 288 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; |
289 | struct cx25821_dev *dev = timeout_data->dev; | 289 | struct cx25821_dev *dev = timeout_data->dev; |
290 | const struct sram_channel *channel = timeout_data->channel; | 290 | const struct sram_channel *channel = timeout_data->channel; |
291 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq; | 291 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq; |
292 | struct cx25821_buffer *buf; | 292 | struct cx25821_buffer *buf; |
293 | unsigned long flags; | 293 | unsigned long flags; |
294 | 294 | ||
@@ -334,7 +334,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) | |||
334 | if (status & FLD_VID_DST_RISC1) { | 334 | if (status & FLD_VID_DST_RISC1) { |
335 | spin_lock(&dev->slock); | 335 | spin_lock(&dev->slock); |
336 | count = cx_read(channel->gpcnt); | 336 | count = cx_read(channel->gpcnt); |
337 | cx25821_video_wakeup(dev, &dev->channels[channel->i].vidq, | 337 | cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq, |
338 | count); | 338 | count); |
339 | spin_unlock(&dev->slock); | 339 | spin_unlock(&dev->slock); |
340 | handled++; | 340 | handled++; |
@@ -345,7 +345,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) | |||
345 | dprintk(2, "stopper video\n"); | 345 | dprintk(2, "stopper video\n"); |
346 | spin_lock(&dev->slock); | 346 | spin_lock(&dev->slock); |
347 | cx25821_restart_video_queue(dev, | 347 | cx25821_restart_video_queue(dev, |
348 | &dev->channels[channel->i].vidq, channel); | 348 | &dev->channels[channel->i].dma_vidq, channel); |
349 | spin_unlock(&dev->slock); | 349 | spin_unlock(&dev->slock); |
350 | handled++; | 350 | handled++; |
351 | } | 351 | } |
@@ -355,9 +355,9 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) | |||
355 | static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, | 355 | static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, |
356 | unsigned int *size) | 356 | unsigned int *size) |
357 | { | 357 | { |
358 | struct cx25821_fh *fh = q->priv_data; | 358 | struct cx25821_channel *chan = q->priv_data; |
359 | 359 | ||
360 | *size = fh->fmt->depth * fh->width * fh->height >> 3; | 360 | *size = chan->fmt->depth * chan->width * chan->height >> 3; |
361 | 361 | ||
362 | if (0 == *count) | 362 | if (0 == *count) |
363 | *count = 32; | 363 | *count = 32; |
@@ -371,32 +371,32 @@ static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, | |||
371 | static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, | 371 | static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
372 | enum v4l2_field field) | 372 | enum v4l2_field field) |
373 | { | 373 | { |
374 | struct cx25821_fh *fh = q->priv_data; | 374 | struct cx25821_channel *chan = q->priv_data; |
375 | struct cx25821_dev *dev = fh->dev; | 375 | struct cx25821_dev *dev = chan->dev; |
376 | struct cx25821_buffer *buf = | 376 | struct cx25821_buffer *buf = |
377 | container_of(vb, struct cx25821_buffer, vb); | 377 | container_of(vb, struct cx25821_buffer, vb); |
378 | int rc, init_buffer = 0; | 378 | int rc, init_buffer = 0; |
379 | u32 line0_offset; | 379 | u32 line0_offset; |
380 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); | 380 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
381 | int bpl_local = LINE_SIZE_D1; | 381 | int bpl_local = LINE_SIZE_D1; |
382 | int channel_opened = fh->channel_id; | 382 | int channel_opened = chan->id; |
383 | 383 | ||
384 | BUG_ON(NULL == fh->fmt); | 384 | BUG_ON(NULL == chan->fmt); |
385 | if (fh->width < 48 || fh->width > 720 || | 385 | if (chan->width < 48 || chan->width > 720 || |
386 | fh->height < 32 || fh->height > 576) | 386 | chan->height < 32 || chan->height > 576) |
387 | return -EINVAL; | 387 | return -EINVAL; |
388 | 388 | ||
389 | buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; | 389 | buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3; |
390 | 390 | ||
391 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) | 391 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
392 | return -EINVAL; | 392 | return -EINVAL; |
393 | 393 | ||
394 | if (buf->fmt != fh->fmt || | 394 | if (buf->fmt != chan->fmt || |
395 | buf->vb.width != fh->width || | 395 | buf->vb.width != chan->width || |
396 | buf->vb.height != fh->height || buf->vb.field != field) { | 396 | buf->vb.height != chan->height || buf->vb.field != field) { |
397 | buf->fmt = fh->fmt; | 397 | buf->fmt = chan->fmt; |
398 | buf->vb.width = fh->width; | 398 | buf->vb.width = chan->width; |
399 | buf->vb.height = fh->height; | 399 | buf->vb.height = chan->height; |
400 | buf->vb.field = field; | 400 | buf->vb.field = field; |
401 | init_buffer = 1; | 401 | init_buffer = 1; |
402 | } | 402 | } |
@@ -413,7 +413,6 @@ static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buff | |||
413 | dprintk(1, "init_buffer=%d\n", init_buffer); | 413 | dprintk(1, "init_buffer=%d\n", init_buffer); |
414 | 414 | ||
415 | if (init_buffer) { | 415 | if (init_buffer) { |
416 | |||
417 | channel_opened = dev->channel_opened; | 416 | channel_opened = dev->channel_opened; |
418 | if (channel_opened < 0 || channel_opened > 7) | 417 | if (channel_opened < 0 || channel_opened > 7) |
419 | channel_opened = 7; | 418 | channel_opened = 7; |
@@ -483,8 +482,8 @@ static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buff | |||
483 | } | 482 | } |
484 | 483 | ||
485 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", | 484 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
486 | buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, | 485 | buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth, |
487 | fh->fmt->name, (unsigned long)buf->risc.dma); | 486 | chan->fmt->name, (unsigned long)buf->risc.dma); |
488 | 487 | ||
489 | buf->vb.state = VIDEOBUF_PREPARED; | 488 | buf->vb.state = VIDEOBUF_PREPARED; |
490 | 489 | ||
@@ -504,11 +503,6 @@ static void cx25821_buffer_release(struct videobuf_queue *q, | |||
504 | cx25821_free_buffer(q, buf); | 503 | cx25821_free_buffer(q, buf); |
505 | } | 504 | } |
506 | 505 | ||
507 | static struct videobuf_queue *get_queue(struct cx25821_fh *fh) | ||
508 | { | ||
509 | return &fh->vidq; | ||
510 | } | ||
511 | |||
512 | static int cx25821_get_resource(struct cx25821_fh *fh, int resource) | 506 | static int cx25821_get_resource(struct cx25821_fh *fh, int resource) |
513 | { | 507 | { |
514 | return resource; | 508 | return resource; |
@@ -516,9 +510,9 @@ static int cx25821_get_resource(struct cx25821_fh *fh, int resource) | |||
516 | 510 | ||
517 | static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma) | 511 | static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma) |
518 | { | 512 | { |
519 | struct cx25821_fh *fh = file->private_data; | 513 | struct cx25821_channel *chan = video_drvdata(file); |
520 | 514 | ||
521 | return videobuf_mmap_mapper(get_queue(fh), vma); | 515 | return videobuf_mmap_mapper(&chan->vidq, vma); |
522 | } | 516 | } |
523 | 517 | ||
524 | 518 | ||
@@ -527,9 +521,9 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |||
527 | struct cx25821_buffer *buf = | 521 | struct cx25821_buffer *buf = |
528 | container_of(vb, struct cx25821_buffer, vb); | 522 | container_of(vb, struct cx25821_buffer, vb); |
529 | struct cx25821_buffer *prev; | 523 | struct cx25821_buffer *prev; |
530 | struct cx25821_fh *fh = vq->priv_data; | 524 | struct cx25821_channel *chan = vq->priv_data; |
531 | struct cx25821_dev *dev = fh->dev; | 525 | struct cx25821_dev *dev = chan->dev; |
532 | struct cx25821_dmaqueue *q = &dev->channels[fh->channel_id].vidq; | 526 | struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; |
533 | 527 | ||
534 | /* add jump to stopper */ | 528 | /* add jump to stopper */ |
535 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); | 529 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
@@ -546,8 +540,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |||
546 | 540 | ||
547 | } else if (list_empty(&q->active)) { | 541 | } else if (list_empty(&q->active)) { |
548 | list_add_tail(&buf->vb.queue, &q->active); | 542 | list_add_tail(&buf->vb.queue, &q->active); |
549 | cx25821_start_video_dma(dev, q, buf, | 543 | cx25821_start_video_dma(dev, q, buf, chan->sram_channels); |
550 | dev->channels[fh->channel_id].sram_channels); | ||
551 | buf->vb.state = VIDEOBUF_ACTIVE; | 544 | buf->vb.state = VIDEOBUF_ACTIVE; |
552 | buf->count = q->count++; | 545 | buf->count = q->count++; |
553 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); | 546 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
@@ -590,19 +583,9 @@ static struct videobuf_queue_ops cx25821_video_qops = { | |||
590 | 583 | ||
591 | static int video_open(struct file *file) | 584 | static int video_open(struct file *file) |
592 | { | 585 | { |
593 | struct video_device *vdev = video_devdata(file); | 586 | struct cx25821_channel *chan = video_drvdata(file); |
594 | struct cx25821_dev *dev = video_drvdata(file); | 587 | struct cx25821_dev *dev = chan->dev; |
595 | struct cx25821_fh *fh; | 588 | struct cx25821_fh *fh; |
596 | u32 pix_format; | ||
597 | int ch_id; | ||
598 | |||
599 | for (ch_id = 0; ch_id < MAX_VID_CHANNEL_NUM - 1; ch_id++) | ||
600 | if (&dev->channels[ch_id].vdev == vdev) | ||
601 | break; | ||
602 | |||
603 | /* Can't happen */ | ||
604 | if (ch_id >= MAX_VID_CHANNEL_NUM - 1) | ||
605 | return -ENODEV; | ||
606 | 589 | ||
607 | /* allocate + initialize per filehandle data */ | 590 | /* allocate + initialize per filehandle data */ |
608 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); | 591 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
@@ -611,27 +594,11 @@ static int video_open(struct file *file) | |||
611 | 594 | ||
612 | file->private_data = fh; | 595 | file->private_data = fh; |
613 | fh->dev = dev; | 596 | fh->dev = dev; |
614 | fh->width = 720; | 597 | fh->channel_id = chan->id; |
615 | fh->channel_id = ch_id; | ||
616 | |||
617 | if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) | ||
618 | fh->height = 576; | ||
619 | else | ||
620 | fh->height = 480; | ||
621 | 598 | ||
622 | dev->channel_opened = fh->channel_id; | 599 | dev->channel_opened = fh->channel_id; |
623 | if (dev->channels[ch_id].pixel_formats == PIXEL_FRMT_411) | ||
624 | pix_format = V4L2_PIX_FMT_Y41P; | ||
625 | else | ||
626 | pix_format = V4L2_PIX_FMT_YUYV; | ||
627 | fh->fmt = cx25821_format_by_fourcc(pix_format); | ||
628 | |||
629 | v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio); | ||
630 | 600 | ||
631 | videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, &dev->pci->dev, | 601 | v4l2_prio_open(&chan->prio, &fh->prio); |
632 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, | ||
633 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), | ||
634 | fh, &dev->lock); | ||
635 | 602 | ||
636 | dprintk(1, "post videobuf_queue_init()\n"); | 603 | dprintk(1, "post videobuf_queue_init()\n"); |
637 | 604 | ||
@@ -642,6 +609,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count, | |||
642 | loff_t *ppos) | 609 | loff_t *ppos) |
643 | { | 610 | { |
644 | struct cx25821_fh *fh = file->private_data; | 611 | struct cx25821_fh *fh = file->private_data; |
612 | struct cx25821_channel *chan = video_drvdata(file); | ||
645 | struct cx25821_dev *dev = fh->dev; | 613 | struct cx25821_dev *dev = fh->dev; |
646 | int err; | 614 | int err; |
647 | 615 | ||
@@ -650,7 +618,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count, | |||
650 | if (cx25821_res_locked(fh, RESOURCE_VIDEO0)) | 618 | if (cx25821_res_locked(fh, RESOURCE_VIDEO0)) |
651 | err = -EBUSY; | 619 | err = -EBUSY; |
652 | else | 620 | else |
653 | err = videobuf_read_one(&fh->vidq, data, count, ppos, | 621 | err = videobuf_read_one(&chan->vidq, data, count, ppos, |
654 | file->f_flags & O_NONBLOCK); | 622 | file->f_flags & O_NONBLOCK); |
655 | mutex_unlock(&dev->lock); | 623 | mutex_unlock(&dev->lock); |
656 | return err; | 624 | return err; |
@@ -660,17 +628,18 @@ static unsigned int video_poll(struct file *file, | |||
660 | struct poll_table_struct *wait) | 628 | struct poll_table_struct *wait) |
661 | { | 629 | { |
662 | struct cx25821_fh *fh = file->private_data; | 630 | struct cx25821_fh *fh = file->private_data; |
631 | struct cx25821_channel *chan = video_drvdata(file); | ||
663 | struct cx25821_buffer *buf; | 632 | struct cx25821_buffer *buf; |
664 | 633 | ||
665 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { | 634 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
666 | /* streaming capture */ | 635 | /* streaming capture */ |
667 | if (list_empty(&fh->vidq.stream)) | 636 | if (list_empty(&chan->vidq.stream)) |
668 | return POLLERR; | 637 | return POLLERR; |
669 | buf = list_entry(fh->vidq.stream.next, | 638 | buf = list_entry(chan->vidq.stream.next, |
670 | struct cx25821_buffer, vb.stream); | 639 | struct cx25821_buffer, vb.stream); |
671 | } else { | 640 | } else { |
672 | /* read() capture */ | 641 | /* read() capture */ |
673 | buf = (struct cx25821_buffer *)fh->vidq.read_buf; | 642 | buf = (struct cx25821_buffer *)chan->vidq.read_buf; |
674 | if (NULL == buf) | 643 | if (NULL == buf) |
675 | return POLLERR; | 644 | return POLLERR; |
676 | } | 645 | } |
@@ -680,12 +649,11 @@ static unsigned int video_poll(struct file *file, | |||
680 | if (buf->vb.state == VIDEOBUF_DONE) { | 649 | if (buf->vb.state == VIDEOBUF_DONE) { |
681 | struct cx25821_dev *dev = fh->dev; | 650 | struct cx25821_dev *dev = fh->dev; |
682 | 651 | ||
683 | if (dev && dev->channels[fh->channel_id] | 652 | if (dev && chan->use_cif_resolution) { |
684 | .use_cif_resolution) { | ||
685 | u8 cam_id = *((char *)buf->vb.baddr + 3); | 653 | u8 cam_id = *((char *)buf->vb.baddr + 3); |
686 | memcpy((char *)buf->vb.baddr, | 654 | memcpy((char *)buf->vb.baddr, |
687 | (char *)buf->vb.baddr + (fh->width * 2), | 655 | (char *)buf->vb.baddr + (chan->width * 2), |
688 | (fh->width * 2)); | 656 | (chan->width * 2)); |
689 | *((char *)buf->vb.baddr + 3) = cam_id; | 657 | *((char *)buf->vb.baddr + 3) = cam_id; |
690 | } | 658 | } |
691 | } | 659 | } |
@@ -698,8 +666,9 @@ static unsigned int video_poll(struct file *file, | |||
698 | 666 | ||
699 | static int video_release(struct file *file) | 667 | static int video_release(struct file *file) |
700 | { | 668 | { |
669 | struct cx25821_channel *chan = video_drvdata(file); | ||
701 | struct cx25821_fh *fh = file->private_data; | 670 | struct cx25821_fh *fh = file->private_data; |
702 | struct cx25821_dev *dev = fh->dev; | 671 | struct cx25821_dev *dev = chan->dev; |
703 | const struct sram_channel *sram_ch = | 672 | const struct sram_channel *sram_ch = |
704 | dev->channels[0].sram_channels; | 673 | dev->channels[0].sram_channels; |
705 | 674 | ||
@@ -709,19 +678,19 @@ static int video_release(struct file *file) | |||
709 | 678 | ||
710 | /* stop video capture */ | 679 | /* stop video capture */ |
711 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { | 680 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
712 | videobuf_queue_cancel(&fh->vidq); | 681 | videobuf_queue_cancel(&chan->vidq); |
713 | cx25821_res_free(dev, fh, RESOURCE_VIDEO0); | 682 | cx25821_res_free(dev, fh, RESOURCE_VIDEO0); |
714 | } | 683 | } |
715 | mutex_unlock(&dev->lock); | 684 | mutex_unlock(&dev->lock); |
716 | 685 | ||
717 | if (fh->vidq.read_buf) { | 686 | if (chan->vidq.read_buf) { |
718 | cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf); | 687 | cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf); |
719 | kfree(fh->vidq.read_buf); | 688 | kfree(chan->vidq.read_buf); |
720 | } | 689 | } |
721 | 690 | ||
722 | videobuf_mmap_free(&fh->vidq); | 691 | videobuf_mmap_free(&chan->vidq); |
723 | 692 | ||
724 | v4l2_prio_close(&dev->channels[fh->channel_id].prio, fh->prio); | 693 | v4l2_prio_close(&chan->prio, fh->prio); |
725 | file->private_data = NULL; | 694 | file->private_data = NULL; |
726 | kfree(fh); | 695 | kfree(fh); |
727 | 696 | ||
@@ -732,13 +701,13 @@ static int video_release(struct file *file) | |||
732 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, | 701 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
733 | struct v4l2_format *f) | 702 | struct v4l2_format *f) |
734 | { | 703 | { |
735 | struct cx25821_fh *fh = priv; | 704 | struct cx25821_channel *chan = video_drvdata(file); |
736 | 705 | ||
737 | f->fmt.pix.width = fh->width; | 706 | f->fmt.pix.width = chan->width; |
738 | f->fmt.pix.height = fh->height; | 707 | f->fmt.pix.height = chan->height; |
739 | f->fmt.pix.field = fh->vidq.field; | 708 | f->fmt.pix.field = chan->vidq.field; |
740 | f->fmt.pix.pixelformat = fh->fmt->fourcc; | 709 | f->fmt.pix.pixelformat = chan->fmt->fourcc; |
741 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fh->fmt->depth) >> 3; | 710 | f->fmt.pix.bytesperline = (f->fmt.pix.width * chan->fmt->depth) >> 3; |
742 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; | 711 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
743 | 712 | ||
744 | return 0; | 713 | return 0; |
@@ -794,6 +763,7 @@ static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, | |||
794 | } | 763 | } |
795 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | 764 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
796 | { | 765 | { |
766 | struct cx25821_channel *chan = video_drvdata(file); | ||
797 | struct cx25821_fh *fh = priv; | 767 | struct cx25821_fh *fh = priv; |
798 | struct cx25821_dev *dev = fh->dev; | 768 | struct cx25821_dev *dev = fh->dev; |
799 | 769 | ||
@@ -804,11 +774,12 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | |||
804 | cx25821_get_resource(fh, RESOURCE_VIDEO0))) | 774 | cx25821_get_resource(fh, RESOURCE_VIDEO0))) |
805 | return -EBUSY; | 775 | return -EBUSY; |
806 | 776 | ||
807 | return videobuf_streamon(get_queue(fh)); | 777 | return videobuf_streamon(&chan->vidq); |
808 | } | 778 | } |
809 | 779 | ||
810 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) | 780 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
811 | { | 781 | { |
782 | struct cx25821_channel *chan = video_drvdata(file); | ||
812 | struct cx25821_fh *fh = priv; | 783 | struct cx25821_fh *fh = priv; |
813 | struct cx25821_dev *dev = fh->dev; | 784 | struct cx25821_dev *dev = fh->dev; |
814 | int err, res; | 785 | int err, res; |
@@ -817,7 +788,7 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) | |||
817 | return -EINVAL; | 788 | return -EINVAL; |
818 | 789 | ||
819 | res = cx25821_get_resource(fh, RESOURCE_VIDEO0); | 790 | res = cx25821_get_resource(fh, RESOURCE_VIDEO0); |
820 | err = videobuf_streamoff(get_queue(fh)); | 791 | err = videobuf_streamoff(&chan->vidq); |
821 | if (err < 0) | 792 | if (err < 0) |
822 | return err; | 793 | return err; |
823 | cx25821_res_free(dev, fh, res); | 794 | cx25821_res_free(dev, fh, res); |
@@ -865,6 +836,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
865 | struct v4l2_format *f) | 836 | struct v4l2_format *f) |
866 | { | 837 | { |
867 | struct cx25821_fh *fh = priv; | 838 | struct cx25821_fh *fh = priv; |
839 | struct cx25821_channel *chan = video_drvdata(file); | ||
868 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; | 840 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
869 | struct v4l2_mbus_framefmt mbus_fmt; | 841 | struct v4l2_mbus_framefmt mbus_fmt; |
870 | int err; | 842 | int err; |
@@ -882,15 +854,15 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
882 | if (0 != err) | 854 | if (0 != err) |
883 | return err; | 855 | return err; |
884 | 856 | ||
885 | fh->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); | 857 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
886 | fh->vidq.field = f->fmt.pix.field; | 858 | chan->vidq.field = f->fmt.pix.field; |
887 | 859 | ||
888 | /* check if width and height is valid based on set standard */ | 860 | /* check if width and height is valid based on set standard */ |
889 | if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) | 861 | if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) |
890 | fh->width = f->fmt.pix.width; | 862 | chan->width = f->fmt.pix.width; |
891 | 863 | ||
892 | if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) | 864 | if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) |
893 | fh->height = f->fmt.pix.height; | 865 | chan->height = f->fmt.pix.height; |
894 | 866 | ||
895 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) | 867 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
896 | pix_format = PIXEL_FRMT_411; | 868 | pix_format = PIXEL_FRMT_411; |
@@ -902,13 +874,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
902 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); | 874 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
903 | 875 | ||
904 | /* check if cif resolution */ | 876 | /* check if cif resolution */ |
905 | if (fh->width == 320 || fh->width == 352) | 877 | if (chan->width == 320 || chan->width == 352) |
906 | dev->channels[fh->channel_id].use_cif_resolution = 1; | 878 | chan->use_cif_resolution = 1; |
907 | else | 879 | else |
908 | dev->channels[fh->channel_id].use_cif_resolution = 0; | 880 | chan->use_cif_resolution = 0; |
909 | 881 | ||
910 | dev->channels[fh->channel_id].cif_width = fh->width; | 882 | chan->cif_width = chan->width; |
911 | medusa_set_resolution(dev, fh->width, SRAM_CH00); | 883 | medusa_set_resolution(dev, chan->width, SRAM_CH00); |
912 | 884 | ||
913 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); | 885 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
914 | cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); | 886 | cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
@@ -919,12 +891,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
919 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) | 891 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
920 | { | 892 | { |
921 | int ret_val = 0; | 893 | int ret_val = 0; |
922 | struct cx25821_fh *fh = priv; | 894 | struct cx25821_channel *chan = video_drvdata(file); |
923 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; | ||
924 | 895 | ||
925 | ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); | 896 | ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK); |
926 | 897 | p->sequence = chan->dma_vidq.count; | |
927 | p->sequence = dev->channels[fh->channel_id].vidq.count; | ||
928 | 898 | ||
929 | return ret_val; | 899 | return ret_val; |
930 | } | 900 | } |
@@ -980,21 +950,24 @@ static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, | |||
980 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, | 950 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
981 | struct v4l2_requestbuffers *p) | 951 | struct v4l2_requestbuffers *p) |
982 | { | 952 | { |
983 | struct cx25821_fh *fh = priv; | 953 | struct cx25821_channel *chan = video_drvdata(file); |
984 | return videobuf_reqbufs(get_queue(fh), p); | 954 | |
955 | return videobuf_reqbufs(&chan->vidq, p); | ||
985 | } | 956 | } |
986 | 957 | ||
987 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, | 958 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
988 | struct v4l2_buffer *p) | 959 | struct v4l2_buffer *p) |
989 | { | 960 | { |
990 | struct cx25821_fh *fh = priv; | 961 | struct cx25821_channel *chan = video_drvdata(file); |
991 | return videobuf_querybuf(get_queue(fh), p); | 962 | |
963 | return videobuf_querybuf(&chan->vidq, p); | ||
992 | } | 964 | } |
993 | 965 | ||
994 | static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) | 966 | static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
995 | { | 967 | { |
996 | struct cx25821_fh *fh = priv; | 968 | struct cx25821_channel *chan = video_drvdata(file); |
997 | return videobuf_qbuf(get_queue(fh), p); | 969 | |
970 | return videobuf_qbuf(&chan->vidq, p); | ||
998 | } | 971 | } |
999 | 972 | ||
1000 | static int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) | 973 | static int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) |
@@ -1466,7 +1439,7 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) | |||
1466 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); | 1439 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
1467 | 1440 | ||
1468 | btcx_riscmem_free(dev->pci, | 1441 | btcx_riscmem_free(dev->pci, |
1469 | &dev->channels[chan_num].vidq.stopper); | 1442 | &dev->channels[chan_num].dma_vidq.stopper); |
1470 | } | 1443 | } |
1471 | } | 1444 | } |
1472 | 1445 | ||
@@ -1482,8 +1455,9 @@ int cx25821_video_register(struct cx25821_dev *dev) | |||
1482 | spin_lock_init(&dev->slock); | 1455 | spin_lock_init(&dev->slock); |
1483 | 1456 | ||
1484 | for (i = 0; i < VID_CHANNEL_NUM; ++i) { | 1457 | for (i = 0; i < VID_CHANNEL_NUM; ++i) { |
1485 | struct video_device *vdev = &dev->channels[i].vdev; | 1458 | struct cx25821_channel *chan = &dev->channels[i]; |
1486 | struct v4l2_ctrl_handler *hdl = &dev->channels[i].hdl; | 1459 | struct video_device *vdev = &chan->vdev; |
1460 | struct v4l2_ctrl_handler *hdl = &chan->hdl; | ||
1487 | 1461 | ||
1488 | if (i == SRAM_CH08) /* audio channel */ | 1462 | if (i == SRAM_CH08) /* audio channel */ |
1489 | continue; | 1463 | continue; |
@@ -1505,24 +1479,37 @@ int cx25821_video_register(struct cx25821_dev *dev) | |||
1505 | if (err) | 1479 | if (err) |
1506 | goto fail_unreg; | 1480 | goto fail_unreg; |
1507 | 1481 | ||
1508 | cx25821_risc_stopper(dev->pci, &dev->channels[i].vidq.stopper, | 1482 | cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper, |
1509 | dev->channels[i].sram_channels->dma_ctl, 0x11, 0); | 1483 | chan->sram_channels->dma_ctl, 0x11, 0); |
1510 | 1484 | ||
1511 | dev->channels[i].sram_channels = &cx25821_sram_channels[i]; | 1485 | chan->sram_channels = &cx25821_sram_channels[i]; |
1512 | dev->channels[i].resources = 0; | 1486 | chan->resources = 0; |
1487 | chan->width = 720; | ||
1488 | if (dev->tvnorm & V4L2_STD_625_50) | ||
1489 | chan->height = 576; | ||
1490 | else | ||
1491 | chan->height = 480; | ||
1513 | 1492 | ||
1514 | cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff); | 1493 | if (chan->pixel_formats == PIXEL_FRMT_411) |
1494 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); | ||
1495 | else | ||
1496 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); | ||
1515 | 1497 | ||
1516 | INIT_LIST_HEAD(&dev->channels[i].vidq.active); | 1498 | cx_write(chan->sram_channels->int_stat, 0xffffffff); |
1517 | INIT_LIST_HEAD(&dev->channels[i].vidq.queued); | ||
1518 | 1499 | ||
1519 | dev->channels[i].timeout_data.dev = dev; | 1500 | INIT_LIST_HEAD(&chan->dma_vidq.active); |
1520 | dev->channels[i].timeout_data.channel = | 1501 | INIT_LIST_HEAD(&chan->dma_vidq.queued); |
1521 | &cx25821_sram_channels[i]; | 1502 | |
1522 | dev->channels[i].vidq.timeout.function = cx25821_vid_timeout; | 1503 | chan->timeout_data.dev = dev; |
1523 | dev->channels[i].vidq.timeout.data = | 1504 | chan->timeout_data.channel = &cx25821_sram_channels[i]; |
1524 | (unsigned long)&dev->channels[i].timeout_data; | 1505 | chan->dma_vidq.timeout.function = cx25821_vid_timeout; |
1525 | init_timer(&dev->channels[i].vidq.timeout); | 1506 | chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data; |
1507 | init_timer(&chan->dma_vidq.timeout); | ||
1508 | |||
1509 | videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev, | ||
1510 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, | ||
1511 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), | ||
1512 | chan, &dev->lock); | ||
1526 | 1513 | ||
1527 | /* register v4l devices */ | 1514 | /* register v4l devices */ |
1528 | *vdev = cx25821_video_device; | 1515 | *vdev = cx25821_video_device; |
@@ -1530,7 +1517,7 @@ int cx25821_video_register(struct cx25821_dev *dev) | |||
1530 | vdev->ctrl_handler = hdl; | 1517 | vdev->ctrl_handler = hdl; |
1531 | vdev->lock = &dev->lock; | 1518 | vdev->lock = &dev->lock; |
1532 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); | 1519 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
1533 | video_set_drvdata(vdev, dev); | 1520 | video_set_drvdata(vdev, chan); |
1534 | 1521 | ||
1535 | err = video_register_device(vdev, VFL_TYPE_GRABBER, | 1522 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
1536 | video_nr[dev->nr]); | 1523 | video_nr[dev->nr]); |
diff --git a/drivers/media/pci/cx25821/cx25821.h b/drivers/media/pci/cx25821/cx25821.h index d1c91c9e911a..06dadb5d9e56 100644 --- a/drivers/media/pci/cx25821/cx25821.h +++ b/drivers/media/pci/cx25821/cx25821.h | |||
@@ -123,10 +123,7 @@ struct cx25821_fh { | |||
123 | enum v4l2_priority prio; | 123 | enum v4l2_priority prio; |
124 | 124 | ||
125 | /* video capture */ | 125 | /* video capture */ |
126 | const struct cx25821_fmt *fmt; | ||
127 | unsigned int width, height; | ||
128 | int channel_id; | 126 | int channel_id; |
129 | struct videobuf_queue vidq; | ||
130 | }; | 127 | }; |
131 | 128 | ||
132 | enum cx25821_itype { | 129 | enum cx25821_itype { |
@@ -217,12 +214,15 @@ struct cx25821_channel { | |||
217 | struct cx25821_data timeout_data; | 214 | struct cx25821_data timeout_data; |
218 | 215 | ||
219 | struct video_device vdev; | 216 | struct video_device vdev; |
220 | struct cx25821_dmaqueue vidq; | 217 | struct cx25821_dmaqueue dma_vidq; |
218 | struct videobuf_queue vidq; | ||
221 | 219 | ||
222 | const struct sram_channel *sram_channels; | 220 | const struct sram_channel *sram_channels; |
223 | 221 | ||
224 | int resources; | 222 | int resources; |
225 | 223 | ||
224 | const struct cx25821_fmt *fmt; | ||
225 | unsigned int width, height; | ||
226 | int pixel_formats; | 226 | int pixel_formats; |
227 | int use_cif_resolution; | 227 | int use_cif_resolution; |
228 | int cif_width; | 228 | int cif_width; |