aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/pci
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2014-09-20 08:23:44 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-11-03 05:32:36 -0500
commitccd6f1d488e7e49ca90d4255cb3f8a2f61951e55 (patch)
tree7bca7160649dd812de9579ad383c66e694e76774 /drivers/media/pci
parentd386259f8ee95d260ecb99aad3afc434819491ec (diff)
[media] cx88: move width, height and field to core struct
The width, height and field values are core fields since both vbi, video and blackbird use the same video input. Move those fields to the correct struct. Also fix the field checks in the try_fmt functions: add V4L2_FIELD_SEQ_BT/TB support and map incorrect field values to a correct field value instead of returning an error. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/pci')
-rw-r--r--drivers/media/pci/cx88/cx88-blackbird.c85
-rw-r--r--drivers/media/pci/cx88/cx88-cards.c5
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c2
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c4
-rw-r--r--drivers/media/pci/cx88/cx88-video.c75
-rw-r--r--drivers/media/pci/cx88/cx88.h9
6 files changed, 98 insertions, 82 deletions
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index 32fb9355c9f6..58e5254e154a 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -515,12 +515,14 @@ DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | M
515 515
516static void blackbird_codec_settings(struct cx8802_dev *dev) 516static void blackbird_codec_settings(struct cx8802_dev *dev)
517{ 517{
518 struct cx88_core *core = dev->core;
519
518 /* assign frame size */ 520 /* assign frame size */
519 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 521 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
520 dev->height, dev->width); 522 core->height, core->width);
521 523
522 dev->cxhdl.width = dev->width; 524 dev->cxhdl.width = core->width;
523 dev->cxhdl.height = dev->height; 525 dev->cxhdl.height = core->height;
524 cx2341x_handler_set_50hz(&dev->cxhdl, dev->core->tvnorm & V4L2_STD_625_50); 526 cx2341x_handler_set_50hz(&dev->cxhdl, dev->core->tvnorm & V4L2_STD_625_50);
525 cx2341x_handler_setup(&dev->cxhdl); 527 cx2341x_handler_setup(&dev->cxhdl);
526} 528}
@@ -658,7 +660,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
658 struct cx8802_dev *dev = vb->vb2_queue->drv_priv; 660 struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
659 struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); 661 struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
660 662
661 return cx8802_buf_prepare(vb->vb2_queue, dev, buf, dev->field); 663 return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
662} 664}
663 665
664static void buffer_finish(struct vb2_buffer *vb) 666static void buffer_finish(struct vb2_buffer *vb)
@@ -796,55 +798,75 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
796 return 0; 798 return 0;
797} 799}
798 800
799static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, 801static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
800 struct v4l2_format *f) 802 struct v4l2_format *f)
801{ 803{
802 struct cx8802_dev *dev = video_drvdata(file); 804 struct cx8802_dev *dev = video_drvdata(file);
805 struct cx88_core *core = dev->core;
803 806
804 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 807 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
805 f->fmt.pix.bytesperline = 0; 808 f->fmt.pix.bytesperline = 0;
806 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; 809 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count;
807 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 810 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
808 f->fmt.pix.width = dev->width; 811 f->fmt.pix.width = core->width;
809 f->fmt.pix.height = dev->height; 812 f->fmt.pix.height = core->height;
810 f->fmt.pix.field = dev->field; 813 f->fmt.pix.field = core->field;
811 dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
812 dev->width, dev->height, dev->field);
813 return 0; 814 return 0;
814} 815}
815 816
816static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, 817static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
817 struct v4l2_format *f) 818 struct v4l2_format *f)
818{ 819{
819 struct cx8802_dev *dev = video_drvdata(file); 820 struct cx8802_dev *dev = video_drvdata(file);
821 struct cx88_core *core = dev->core;
822 unsigned maxw, maxh;
823 enum v4l2_field field;
820 824
821 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 825 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
822 f->fmt.pix.bytesperline = 0; 826 f->fmt.pix.bytesperline = 0;
823 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; 827 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count;
824 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 828 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
825 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n", 829
826 dev->width, dev->height, dev->field); 830 maxw = norm_maxw(core->tvnorm);
831 maxh = norm_maxh(core->tvnorm);
832
833 field = f->fmt.pix.field;
834
835 switch (field) {
836 case V4L2_FIELD_TOP:
837 case V4L2_FIELD_BOTTOM:
838 case V4L2_FIELD_INTERLACED:
839 case V4L2_FIELD_SEQ_BT:
840 case V4L2_FIELD_SEQ_TB:
841 break;
842 default:
843 field = (f->fmt.pix.height > maxh / 2)
844 ? V4L2_FIELD_INTERLACED
845 : V4L2_FIELD_BOTTOM;
846 break;
847 }
848 if (V4L2_FIELD_HAS_T_OR_B(field))
849 maxh /= 2;
850
851 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
852 &f->fmt.pix.height, 32, maxh, 0, 0);
853 f->fmt.pix.field = field;
827 return 0; 854 return 0;
828} 855}
829 856
830static int vidioc_s_fmt_vid_cap (struct file *file, void *priv, 857static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
831 struct v4l2_format *f) 858 struct v4l2_format *f)
832{ 859{
833 struct cx8802_dev *dev = video_drvdata(file); 860 struct cx8802_dev *dev = video_drvdata(file);
834 struct cx88_core *core = dev->core; 861 struct cx88_core *core = dev->core;
835 862
836 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 863 vidioc_try_fmt_vid_cap(file, priv, f);
837 f->fmt.pix.bytesperline = 0; 864 core->width = f->fmt.pix.width;
838 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; 865 core->height = f->fmt.pix.height;
839 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 866 core->field = f->fmt.pix.field;
840 dev->width = f->fmt.pix.width;
841 dev->height = f->fmt.pix.height;
842 dev->field = f->fmt.pix.field;
843 cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); 867 cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
844 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 868 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
845 f->fmt.pix.height, f->fmt.pix.width); 869 f->fmt.pix.height, f->fmt.pix.width);
846 dprintk(1, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
847 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
848 return 0; 870 return 0;
849} 871}
850 872
@@ -863,8 +885,8 @@ static int vidioc_s_frequency (struct file *file, void *priv,
863 885
864 cx88_set_freq (core,f); 886 cx88_set_freq (core,f);
865 blackbird_initialize_codec(dev); 887 blackbird_initialize_codec(dev);
866 cx88_set_scale(dev->core, dev->width, dev->height, 888 cx88_set_scale(core, core->width, core->height,
867 dev->field); 889 core->field);
868 return 0; 890 return 0;
869} 891}
870 892
@@ -1128,16 +1150,9 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1128 if (!(core->board.mpeg & CX88_MPEG_BLACKBIRD)) 1150 if (!(core->board.mpeg & CX88_MPEG_BLACKBIRD))
1129 goto fail_core; 1151 goto fail_core;
1130 1152
1131 dev->width = 720;
1132 if (core->tvnorm & V4L2_STD_525_60) {
1133 dev->height = 480;
1134 } else {
1135 dev->height = 576;
1136 }
1137 dev->field = V4L2_FIELD_INTERLACED;
1138 dev->cxhdl.port = CX2341X_PORT_STREAMING; 1153 dev->cxhdl.port = CX2341X_PORT_STREAMING;
1139 dev->cxhdl.width = dev->width; 1154 dev->cxhdl.width = core->width;
1140 dev->cxhdl.height = dev->height; 1155 dev->cxhdl.height = core->height;
1141 dev->cxhdl.func = blackbird_mbox_func; 1156 dev->cxhdl.func = blackbird_mbox_func;
1142 dev->cxhdl.priv = dev; 1157 dev->cxhdl.priv = dev;
1143 err = cx2341x_handler_init(&dev->cxhdl, 36); 1158 err = cx2341x_handler_init(&dev->cxhdl, 36);
@@ -1156,7 +1171,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1156// init_controls(core); 1171// init_controls(core);
1157 cx88_set_tvnorm(core,core->tvnorm); 1172 cx88_set_tvnorm(core,core->tvnorm);
1158 cx88_video_mux(core,0); 1173 cx88_video_mux(core,0);
1159 cx2341x_handler_set_50hz(&dev->cxhdl, dev->height == 576); 1174 cx2341x_handler_set_50hz(&dev->cxhdl, core->height == 576);
1160 cx2341x_handler_setup(&dev->cxhdl); 1175 cx2341x_handler_setup(&dev->cxhdl);
1161 1176
1162 q = &dev->vb2_mpegq; 1177 q = &dev->vb2_mpegq;
diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c
index 851754bf1291..6db654990263 100644
--- a/drivers/media/pci/cx88/cx88-cards.c
+++ b/drivers/media/pci/cx88/cx88-cards.c
@@ -3691,6 +3691,11 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3691 core->nr = nr; 3691 core->nr = nr;
3692 sprintf(core->name, "cx88[%d]", core->nr); 3692 sprintf(core->name, "cx88[%d]", core->nr);
3693 3693
3694 core->tvnorm = V4L2_STD_NTSC_M;
3695 core->width = 320;
3696 core->height = 240;
3697 core->field = V4L2_FIELD_INTERLACED;
3698
3694 strcpy(core->v4l2_dev.name, core->name); 3699 strcpy(core->v4l2_dev.name, core->name);
3695 if (v4l2_device_register(NULL, &core->v4l2_dev)) { 3700 if (v4l2_device_register(NULL, &core->v4l2_dev)) {
3696 kfree(core); 3701 kfree(core);
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index dd0deb1c87ce..c344bfd0b896 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -101,7 +101,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
101 struct cx8802_dev *dev = vb->vb2_queue->drv_priv; 101 struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
102 struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); 102 struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
103 103
104 return cx8802_buf_prepare(vb->vb2_queue, dev, buf, dev->field); 104 return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
105} 105}
106 106
107static void buffer_finish(struct vb2_buffer *vb) 107static void buffer_finish(struct vb2_buffer *vb)
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index 746c0ea13035..f181a3a10389 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -93,7 +93,7 @@ int cx8802_start_dma(struct cx8802_dev *dev,
93 struct cx88_core *core = dev->core; 93 struct cx88_core *core = dev->core;
94 94
95 dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n", 95 dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n",
96 dev->width, dev->height, dev->field); 96 core->width, core->height, core->field);
97 97
98 /* setup fifo + format */ 98 /* setup fifo + format */
99 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], 99 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
@@ -224,7 +224,7 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
224/* ------------------------------------------------------------------ */ 224/* ------------------------------------------------------------------ */
225 225
226int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, 226int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
227 struct cx88_buffer *buf, enum v4l2_field field) 227 struct cx88_buffer *buf)
228{ 228{
229 int size = dev->ts_packet_size * dev->ts_packet_count; 229 int size = dev->ts_packet_size * dev->ts_packet_count;
230 struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0); 230 struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0);
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index 85c3d0c4df97..eadceebfed8e 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -365,7 +365,7 @@ static int start_video_dma(struct cx8800_dev *dev,
365 /* setup fifo + format */ 365 /* setup fifo + format */
366 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], 366 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
367 buf->bpl, buf->risc.dma); 367 buf->bpl, buf->risc.dma);
368 cx88_set_scale(core, dev->width, dev->height, dev->field); 368 cx88_set_scale(core, core->width, core->height, core->field);
369 cx_write(MO_COLOR_CTRL, dev->fmt->cxformat | ColorFormatGamma); 369 cx_write(MO_COLOR_CTRL, dev->fmt->cxformat | ColorFormatGamma);
370 370
371 /* reset counter */ 371 /* reset counter */
@@ -436,9 +436,10 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
436 unsigned int sizes[], void *alloc_ctxs[]) 436 unsigned int sizes[], void *alloc_ctxs[])
437{ 437{
438 struct cx8800_dev *dev = q->drv_priv; 438 struct cx8800_dev *dev = q->drv_priv;
439 struct cx88_core *core = dev->core;
439 440
440 *num_planes = 1; 441 *num_planes = 1;
441 sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; 442 sizes[0] = (dev->fmt->depth * core->width * core->height) >> 3;
442 return 0; 443 return 0;
443} 444}
444 445
@@ -450,52 +451,52 @@ static int buffer_prepare(struct vb2_buffer *vb)
450 struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); 451 struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
451 int rc; 452 int rc;
452 453
453 buf->bpl = dev->width * dev->fmt->depth >> 3; 454 buf->bpl = core->width * dev->fmt->depth >> 3;
454 455
455 if (vb2_plane_size(vb, 0) < dev->height * buf->bpl) 456 if (vb2_plane_size(vb, 0) < core->height * buf->bpl)
456 return -EINVAL; 457 return -EINVAL;
457 vb2_set_plane_payload(vb, 0, dev->height * buf->bpl); 458 vb2_set_plane_payload(vb, 0, core->height * buf->bpl);
458 459
459 rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); 460 rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE);
460 if (!rc) 461 if (!rc)
461 return -EIO; 462 return -EIO;
462 463
463 switch (dev->field) { 464 switch (core->field) {
464 case V4L2_FIELD_TOP: 465 case V4L2_FIELD_TOP:
465 cx88_risc_buffer(dev->pci, &buf->risc, 466 cx88_risc_buffer(dev->pci, &buf->risc,
466 sgt->sgl, 0, UNSET, 467 sgt->sgl, 0, UNSET,
467 buf->bpl, 0, dev->height); 468 buf->bpl, 0, core->height);
468 break; 469 break;
469 case V4L2_FIELD_BOTTOM: 470 case V4L2_FIELD_BOTTOM:
470 cx88_risc_buffer(dev->pci, &buf->risc, 471 cx88_risc_buffer(dev->pci, &buf->risc,
471 sgt->sgl, UNSET, 0, 472 sgt->sgl, UNSET, 0,
472 buf->bpl, 0, dev->height); 473 buf->bpl, 0, core->height);
473 break; 474 break;
474 case V4L2_FIELD_SEQ_TB: 475 case V4L2_FIELD_SEQ_TB:
475 cx88_risc_buffer(dev->pci, &buf->risc, 476 cx88_risc_buffer(dev->pci, &buf->risc,
476 sgt->sgl, 477 sgt->sgl,
477 0, buf->bpl * (dev->height >> 1), 478 0, buf->bpl * (core->height >> 1),
478 buf->bpl, 0, 479 buf->bpl, 0,
479 dev->height >> 1); 480 core->height >> 1);
480 break; 481 break;
481 case V4L2_FIELD_SEQ_BT: 482 case V4L2_FIELD_SEQ_BT:
482 cx88_risc_buffer(dev->pci, &buf->risc, 483 cx88_risc_buffer(dev->pci, &buf->risc,
483 sgt->sgl, 484 sgt->sgl,
484 buf->bpl * (dev->height >> 1), 0, 485 buf->bpl * (core->height >> 1), 0,
485 buf->bpl, 0, 486 buf->bpl, 0,
486 dev->height >> 1); 487 core->height >> 1);
487 break; 488 break;
488 case V4L2_FIELD_INTERLACED: 489 case V4L2_FIELD_INTERLACED:
489 default: 490 default:
490 cx88_risc_buffer(dev->pci, &buf->risc, 491 cx88_risc_buffer(dev->pci, &buf->risc,
491 sgt->sgl, 0, buf->bpl, 492 sgt->sgl, 0, buf->bpl,
492 buf->bpl, buf->bpl, 493 buf->bpl, buf->bpl,
493 dev->height >> 1); 494 core->height >> 1);
494 break; 495 break;
495 } 496 }
496 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", 497 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
497 buf, buf->vb.v4l2_buf.index, 498 buf, buf->vb.v4l2_buf.index,
498 dev->width, dev->height, dev->fmt->depth, dev->fmt->name, 499 core->width, core->height, dev->fmt->depth, dev->fmt->name,
499 (unsigned long)buf->risc.dma); 500 (unsigned long)buf->risc.dma);
500 return 0; 501 return 0;
501} 502}
@@ -723,10 +724,11 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
723 struct v4l2_format *f) 724 struct v4l2_format *f)
724{ 725{
725 struct cx8800_dev *dev = video_drvdata(file); 726 struct cx8800_dev *dev = video_drvdata(file);
727 struct cx88_core *core = dev->core;
726 728
727 f->fmt.pix.width = dev->width; 729 f->fmt.pix.width = core->width;
728 f->fmt.pix.height = dev->height; 730 f->fmt.pix.height = core->height;
729 f->fmt.pix.field = dev->field; 731 f->fmt.pix.field = core->field;
730 f->fmt.pix.pixelformat = dev->fmt->fourcc; 732 f->fmt.pix.pixelformat = dev->fmt->fourcc;
731 f->fmt.pix.bytesperline = 733 f->fmt.pix.bytesperline =
732 (f->fmt.pix.width * dev->fmt->depth) >> 3; 734 (f->fmt.pix.width * dev->fmt->depth) >> 3;
@@ -749,30 +751,30 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
749 if (NULL == fmt) 751 if (NULL == fmt)
750 return -EINVAL; 752 return -EINVAL;
751 753
752 field = f->fmt.pix.field; 754 maxw = norm_maxw(core->tvnorm);
753 maxw = norm_maxw(core->tvnorm); 755 maxh = norm_maxh(core->tvnorm);
754 maxh = norm_maxh(core->tvnorm);
755 756
756 if (V4L2_FIELD_ANY == field) { 757 field = f->fmt.pix.field;
757 field = (f->fmt.pix.height > maxh/2)
758 ? V4L2_FIELD_INTERLACED
759 : V4L2_FIELD_BOTTOM;
760 }
761 758
762 switch (field) { 759 switch (field) {
763 case V4L2_FIELD_TOP: 760 case V4L2_FIELD_TOP:
764 case V4L2_FIELD_BOTTOM: 761 case V4L2_FIELD_BOTTOM:
765 maxh = maxh / 2;
766 break;
767 case V4L2_FIELD_INTERLACED: 762 case V4L2_FIELD_INTERLACED:
763 case V4L2_FIELD_SEQ_BT:
764 case V4L2_FIELD_SEQ_TB:
768 break; 765 break;
769 default: 766 default:
770 return -EINVAL; 767 field = (f->fmt.pix.height > maxh / 2)
768 ? V4L2_FIELD_INTERLACED
769 : V4L2_FIELD_BOTTOM;
770 break;
771 } 771 }
772 if (V4L2_FIELD_HAS_T_OR_B(field))
773 maxh /= 2;
772 774
773 f->fmt.pix.field = field;
774 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, 775 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
775 &f->fmt.pix.height, 32, maxh, 0, 0); 776 &f->fmt.pix.height, 32, maxh, 0, 0);
777 f->fmt.pix.field = field;
776 f->fmt.pix.bytesperline = 778 f->fmt.pix.bytesperline =
777 (f->fmt.pix.width * fmt->depth) >> 3; 779 (f->fmt.pix.width * fmt->depth) >> 3;
778 f->fmt.pix.sizeimage = 780 f->fmt.pix.sizeimage =
@@ -785,14 +787,15 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
785 struct v4l2_format *f) 787 struct v4l2_format *f)
786{ 788{
787 struct cx8800_dev *dev = video_drvdata(file); 789 struct cx8800_dev *dev = video_drvdata(file);
790 struct cx88_core *core = dev->core;
788 int err = vidioc_try_fmt_vid_cap (file,priv,f); 791 int err = vidioc_try_fmt_vid_cap (file,priv,f);
789 792
790 if (0 != err) 793 if (0 != err)
791 return err; 794 return err;
792 dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 795 dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
793 dev->width = f->fmt.pix.width; 796 core->width = f->fmt.pix.width;
794 dev->height = f->fmt.pix.height; 797 core->height = f->fmt.pix.height;
795 dev->field = f->fmt.pix.field; 798 core->field = f->fmt.pix.field;
796 return 0; 799 return 0;
797} 800}
798 801
@@ -1343,7 +1346,6 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1343 1346
1344 /* initialize driver struct */ 1347 /* initialize driver struct */
1345 spin_lock_init(&dev->slock); 1348 spin_lock_init(&dev->slock);
1346 core->tvnorm = V4L2_STD_NTSC_M;
1347 1349
1348 /* init video dma queues */ 1350 /* init video dma queues */
1349 INIT_LIST_HEAD(&dev->vidq.active); 1351 INIT_LIST_HEAD(&dev->vidq.active);
@@ -1438,10 +1440,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1438 /* Sets device info at pci_dev */ 1440 /* Sets device info at pci_dev */
1439 pci_set_drvdata(pci_dev, dev); 1441 pci_set_drvdata(pci_dev, dev);
1440 1442
1441 dev->width = 320; 1443 dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
1442 dev->height = 240;
1443 dev->field = V4L2_FIELD_INTERLACED;
1444 dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
1445 1444
1446 /* initial device configuration */ 1445 /* initial device configuration */
1447 mutex_lock(&core->lock); 1446 mutex_lock(&core->lock);
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index dd50177cea1e..862c60938663 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -379,6 +379,8 @@ struct cx88_core {
379 /* state info */ 379 /* state info */
380 struct task_struct *kthread; 380 struct task_struct *kthread;
381 v4l2_std_id tvnorm; 381 v4l2_std_id tvnorm;
382 unsigned width, height;
383 unsigned field;
382 enum cx88_tvaudio tvaudio; 384 enum cx88_tvaudio tvaudio;
383 u32 audiomode_manual; 385 u32 audiomode_manual;
384 u32 audiomode_current; 386 u32 audiomode_current;
@@ -479,8 +481,6 @@ struct cx8800_dev {
479 unsigned char pci_rev,pci_lat; 481 unsigned char pci_rev,pci_lat;
480 482
481 const struct cx8800_fmt *fmt; 483 const struct cx8800_fmt *fmt;
482 unsigned int width, height;
483 unsigned field;
484 484
485 /* capture queues */ 485 /* capture queues */
486 struct cx88_dmaqueue vidq; 486 struct cx88_dmaqueue vidq;
@@ -557,9 +557,6 @@ struct cx8802_dev {
557#if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD) 557#if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD)
558 struct video_device *mpeg_dev; 558 struct video_device *mpeg_dev;
559 u32 mailbox; 559 u32 mailbox;
560 int width;
561 int height;
562 unsigned field;
563 unsigned char mpeg_active; /* nonzero if mpeg encoder is active */ 560 unsigned char mpeg_active; /* nonzero if mpeg encoder is active */
564 561
565 /* mpeg params */ 562 /* mpeg params */
@@ -721,7 +718,7 @@ extern void cx88_i2c_init_ir(struct cx88_core *core);
721/* cx88-mpeg.c */ 718/* cx88-mpeg.c */
722 719
723int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, 720int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
724 struct cx88_buffer *buf, enum v4l2_field field); 721 struct cx88_buffer *buf);
725void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); 722void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
726void cx8802_cancel_buffers(struct cx8802_dev *dev); 723void cx8802_cancel_buffers(struct cx8802_dev *dev);
727int cx8802_start_dma(struct cx8802_dev *dev, 724int cx8802_start_dma(struct cx8802_dev *dev,