Re: [PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-31 Thread Maciej S. Szmigiero
Hi Hans,

On 21.08.2017 15:23, Hans Verkuil wrote:
> Hi Maciej,
> 
> On 08/10/2017 11:53 PM, Maciej S. Szmigiero wrote:
>> This patch adds support for analog part of Medion 95700 in the cxusb
>> driver.
>>
>> What works:
>> * Video capture at various sizes with sequential fields,
>> * Input switching (TV Tuner, Composite, S-Video),
>> * TV and radio tuning,
>> * Video standard switching and auto detection,
>> * Radio mode switching (stereo / mono),
>> * Unplugging while capturing,
>> * DVB / analog coexistence,
>> * Raw BT.656 stream support.
> 
> Another scary patch :-)

Although this isn't a single-liner, most of the code in cxusb-analog.c are
simple implementations of v4l2 and videobuf2 callbacks - only the buffer
management code is a bit more complicated.

> A high-level question first: is any of the code in cxusb-analog medion
> specific? There are a lot of cxusb_medion_ prefixes, but I wonder if that
> shouldn't be cxusb_analog_.

>From all the devices cxusb driver supports it looks like only Medion 95700
and FusionHDTV5 USB have an analog part.

However, FusionHDTV5 USB has a different tuner and a different digital
frontend, doesn't support power off command, has a different USB interface
number for digital mode than Medion and requires upload of a firmware upon
plugging in (while Medion doesn't), so it's unlikely the current code for
Medion would work for it without significant changes.

> There are some obvious code cleanups that need to take place first, such
> as the huge functions with too many indentations. I would also split off
> cxusb-analog.c as a separate patch.

For example like splitting this part into two:
1) one that adds required analog support to cxusb with functions that are
provided by cxusb-analog.c (analog init, register, unregister) replaced
with stubs,

2) the second one that actually provides correct implementations via
cxusb-analog.c?

> 
> Regards,
> 
>   Hans

Best regards,
Maciej


Re: [PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-21 Thread Hans Verkuil
Hi Maciej,

On 08/10/2017 11:53 PM, Maciej S. Szmigiero wrote:
> This patch adds support for analog part of Medion 95700 in the cxusb
> driver.
> 
> What works:
> * Video capture at various sizes with sequential fields,
> * Input switching (TV Tuner, Composite, S-Video),
> * TV and radio tuning,
> * Video standard switching and auto detection,
> * Radio mode switching (stereo / mono),
> * Unplugging while capturing,
> * DVB / analog coexistence,
> * Raw BT.656 stream support.

Another scary patch :-)

A high-level question first: is any of the code in cxusb-analog medion
specific? There are a lot of cxusb_medion_ prefixes, but I wonder if that
shouldn't be cxusb_analog_.

There are some obvious code cleanups that need to take place first, such
as the huge functions with too many indentations. I would also split off
cxusb-analog.c as a separate patch.

Regards,

Hans

> What does not work yet:
> * Audio,
> * VBI,
> * Picture controls.
> 
> Signed-off-by: Maciej S. Szmigiero 
> ---
>  drivers/media/usb/dvb-usb/Kconfig|8 +-
>  drivers/media/usb/dvb-usb/Makefile   |2 +-
>  drivers/media/usb/dvb-usb/cxusb-analog.c | 1867 
> ++
>  drivers/media/usb/dvb-usb/cxusb.c|  453 +++-
>  drivers/media/usb/dvb-usb/cxusb.h|  137 +++
>  drivers/media/usb/dvb-usb/dvb-usb-dvb.c  |   20 +-
>  drivers/media/usb/dvb-usb/dvb-usb-init.c |   13 +
>  drivers/media/usb/dvb-usb/dvb-usb.h  |8 +
>  8 files changed, 2449 insertions(+), 59 deletions(-)
>  create mode 100644 drivers/media/usb/dvb-usb/cxusb-analog.c
> 
> diff --git a/drivers/media/usb/dvb-usb/Kconfig 
> b/drivers/media/usb/dvb-usb/Kconfig
> index 959fa09dfd92..ba941069ae3b 100644
> --- a/drivers/media/usb/dvb-usb/Kconfig
> +++ b/drivers/media/usb/dvb-usb/Kconfig
> @@ -118,7 +118,9 @@ config DVB_USB_UMT_010
>  
>  config DVB_USB_CXUSB
>   tristate "Conexant USB2.0 hybrid reference design support"
> - depends on DVB_USB
> + depends on DVB_USB && VIDEO_V4L2
> + select VIDEO_CX25840
> + select VIDEOBUF2_VMALLOC
>   select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT
>   select DVB_CX22702 if MEDIA_SUBDRV_AUTOSELECT
>   select DVB_LGDT330X if MEDIA_SUBDRV_AUTOSELECT
> @@ -136,8 +138,8 @@ config DVB_USB_CXUSB
>   select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
>   help
> Say Y here to support the Conexant USB2.0 hybrid reference design.
> -   Currently, only DVB and ATSC modes are supported, analog mode
> -   shall be added in the future. Devices that require this module:
> +   DVB and ATSC modes are supported, with basic analog mode support
> +   for Medion MD95700. Devices that require this module:
>  
> Medion MD95700 hybrid USB2.0 device.
> DViCO FusionHDTV (Bluebird) USB2.0 devices
> diff --git a/drivers/media/usb/dvb-usb/Makefile 
> b/drivers/media/usb/dvb-usb/Makefile
> index 3b3f32b426d1..24d222e9acc7 100644
> --- a/drivers/media/usb/dvb-usb/Makefile
> +++ b/drivers/media/usb/dvb-usb/Makefile
> @@ -40,7 +40,7 @@ obj-$(CONFIG_DVB_USB_M920X) += dvb-usb-m920x.o
>  dvb-usb-digitv-objs := digitv.o
>  obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
>  
> -dvb-usb-cxusb-objs := cxusb.o
> +dvb-usb-cxusb-objs := cxusb.o cxusb-analog.o
>  obj-$(CONFIG_DVB_USB_CXUSB) += dvb-usb-cxusb.o
>  
>  dvb-usb-ttusb2-objs := ttusb2.o
> diff --git a/drivers/media/usb/dvb-usb/cxusb-analog.c 
> b/drivers/media/usb/dvb-usb/cxusb-analog.c
> new file mode 100644
> index ..473d3f06145f
> --- /dev/null
> +++ b/drivers/media/usb/dvb-usb/cxusb-analog.c
> @@ -0,0 +1,1867 @@
> +/* DVB USB compliant linux driver for Conexant USB reference design -
> + * (analog part).
> + *
> + * Copyright (C) 2011, 2017 Maciej S. Szmigiero (m...@maciej.szmigiero.name)
> + *
> + * TODO:
> + *  * audio support,
> + *  * finish radio support (requires audio of course),
> + *  * VBI support,
> + *  * controls support
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "cxusb.h"
> +
> +static int cxusb_medion_v_queue_setup(struct vb2_queue *q,
> +   unsigned int *num_buffers,
> +   unsigned int *num_planes,
> +   unsigned int sizes[],
> +   struct device *alloc_devs[])
> +{
> + struct dvb_usb_device *dvbdev = vb2_get_drv_priv(q);
> + struct cxusb_medion_dev *cxdev = dvbdev->priv;
> + unsigned int size = cxdev->raw_mode ?
> + CXUSB_VIDEO_MAX_FRAME_SIZE :
> + 

Re: [PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-12 Thread kbuild test robot
Hi Maciej,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.13-rc4 next-20170811]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Maciej-S-Szmigiero/Add-analog-mode-support-for-Medion-MD95700/20170813-041742
base:   git://linuxtv.org/media_tree.git master
config: tile-allyesconfig (attached as .config)
compiler: tilegx-linux-gcc (GCC) 4.6.2
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=tile 

All warnings (new ones prefixed by >>):

   drivers/media//usb/dvb-usb/cxusb-analog.c: In function 
'cxusb_medion_copy_field':
>> drivers/media//usb/dvb-usb/cxusb-analog.c:359:27: warning: comparison of 
>> distinct pointer types lacks a cast [enabled by default]
>> drivers/media//usb/dvb-usb/cxusb-analog.c:359:27: warning: comparison of 
>> distinct pointer types lacks a cast [enabled by default]

vim +359 drivers/media//usb/dvb-usb/cxusb-analog.c

   198  
   199  static bool cxusb_medion_copy_field(struct dvb_usb_device *dvbdev,
   200  struct cxusb_medion_auxbuf *auxbuf,
   201  struct cxusb_bt656_params *bt656,
   202  bool firstfield,
   203  unsigned int maxlines,
   204  unsigned int maxlinesamples)
   205  {
   206  while (bt656->line < maxlines &&
   207 !cxusb_auxbuf_isend(auxbuf, bt656->pos)) {
   208  
   209  unsigned char val;
   210  
   211  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos, , 1))
   212  return false;
   213  
   214  if ((char)val == CXUSB_BT656_COMMON[0]) {
   215  char buf[3];
   216  
   217  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos + 1,
   218 buf, 3))
   219  return false;
   220  
   221  if (buf[0] != (CXUSB_BT656_COMMON)[1] ||
   222  buf[1] != (CXUSB_BT656_COMMON)[2])
   223  goto normal_sample;
   224  
   225  if (bt656->line != 0 && (!!firstfield !=
   226   ((buf[2] & 
CXUSB_FIELD_MASK)
   227== CXUSB_FIELD_1))) {
   228  if (bt656->fmode == LINE_SAMPLES) {
   229  cxusb_vprintk(dvbdev, BT656,
   230"field %c after 
line %u field change\n",
   231firstfield ? '1' 
: '2',
   232bt656->line);
   233  
   234  if (bt656->buf != NULL &&
   235  maxlinesamples -
   236  bt656->linesamples > 0) 
{
   237  
   238  memset(bt656->buf, 0,
   239  maxlinesamples -
   240  
bt656->linesamples);
   241  
   242  bt656->buf +=
   243  maxlinesamples -
   244  
bt656->linesamples;
   245  
   246  cxusb_vprintk(dvbdev, 
BT656,
   247"field %c 
line %u %u samples still remaining (of %u)\n",
   248
firstfield ?
   249'1' : '2',
   250
bt656->line,
   251
maxlinesamples -
   252bt656->
   253
linesamples,
   254
maxlinesamples);
   255  }
   256  
   257  bt656->line++;
   258  }
   259  
   260  if (maxlines - bt656->line > 0 &&
   261  bt656->buf != NULL) {
   

Re: [PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-12 Thread kbuild test robot
Hi Maciej,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.13-rc4 next-20170811]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Maciej-S-Szmigiero/Add-analog-mode-support-for-Medion-MD95700/20170813-041742
base:   git://linuxtv.org/media_tree.git master
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)


vim +359 drivers/media/usb/dvb-usb/cxusb-analog.c

   198  
   199  static bool cxusb_medion_copy_field(struct dvb_usb_device *dvbdev,
   200  struct cxusb_medion_auxbuf *auxbuf,
   201  struct cxusb_bt656_params *bt656,
   202  bool firstfield,
   203  unsigned int maxlines,
   204  unsigned int maxlinesamples)
   205  {
   206  while (bt656->line < maxlines &&
   207 !cxusb_auxbuf_isend(auxbuf, bt656->pos)) {
   208  
   209  unsigned char val;
   210  
   211  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos, , 1))
   212  return false;
   213  
   214  if ((char)val == CXUSB_BT656_COMMON[0]) {
   215  char buf[3];
   216  
   217  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos + 1,
   218 buf, 3))
   219  return false;
   220  
   221  if (buf[0] != (CXUSB_BT656_COMMON)[1] ||
   222  buf[1] != (CXUSB_BT656_COMMON)[2])
   223  goto normal_sample;
   224  
   225  if (bt656->line != 0 && (!!firstfield !=
   226   ((buf[2] & 
CXUSB_FIELD_MASK)
   227== CXUSB_FIELD_1))) {
   228  if (bt656->fmode == LINE_SAMPLES) {
   229  cxusb_vprintk(dvbdev, BT656,
   230"field %c after 
line %u field change\n",
   231firstfield ? '1' 
: '2',
   232bt656->line);
   233  
   234  if (bt656->buf != NULL &&
   235  maxlinesamples -
   236  bt656->linesamples > 0) 
{
   237  
   238  memset(bt656->buf, 0,
   239  maxlinesamples -
   240  
bt656->linesamples);
   241  
   242  bt656->buf +=
   243  maxlinesamples -
   244  
bt656->linesamples;
   245  
   246  cxusb_vprintk(dvbdev, 
BT656,
   247"field %c 
line %u %u samples still remaining (of %u)\n",
   248
firstfield ?
   249'1' : '2',
   250
bt656->line,
   251
maxlinesamples -
   252bt656->
   253
linesamples,
   254
maxlinesamples);
   255  }
   256  
   257  bt656->line++;
   258  }
   259  
   260  if (maxlines - bt656->line > 0 &&
   261  bt656->buf != NULL) {
   262  memset(bt656->buf, 0,
   263  (maxlines - bt656->line)
   264  * maxlinesamples);
   265  
   266  bt656->buf +=
   267  (maxlines - bt656->line)
   268  * maxlinesamples;
   269  
   270  cxusb_vprintk(dvbdev, BT656,
   271   

Re: [PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-12 Thread kbuild test robot
Hi Maciej,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.13-rc4 next-20170811]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Maciej-S-Szmigiero/Add-analog-mode-support-for-Medion-MD95700/20170813-041742
base:   git://linuxtv.org/media_tree.git master
config: ia64-allyesconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64 

All warnings (new ones prefixed by >>):

   In file included from include/linux/list.h:8:0,
from include/linux/kobject.h:20,
from include/linux/device.h:17,
from drivers/media//usb/dvb-usb/cxusb-analog.c:19:
   drivers/media//usb/dvb-usb/cxusb-analog.c: In function 
'cxusb_medion_copy_field':
   include/linux/kernel.h:772:16: warning: comparison of distinct pointer types 
lacks a cast
 (void) ( == );   \
   ^
   include/linux/kernel.h:761:2: note: in definition of macro '__min'
 t2 min2 = (y); \
 ^~
>> drivers/media//usb/dvb-usb/cxusb-analog.c:359:27: note: in expansion of 
>> macro 'min'
   unsigned int tocheck = min(sizeof(buf),
  ^~~
   include/linux/kernel.h:775:2: note: in expansion of macro '__max'
 __max(typeof(x), typeof(y),   \
 ^
>> drivers/media//usb/dvb-usb/cxusb-analog.c:360:10: note: in expansion of 
>> macro 'max'
 max(sizeof(buf),
 ^~~
   include/linux/kernel.h:772:16: warning: comparison of distinct pointer types 
lacks a cast
 (void) ( == );   \
   ^
   include/linux/kernel.h:761:13: note: in definition of macro '__min'
 t2 min2 = (y); \
^
>> drivers/media//usb/dvb-usb/cxusb-analog.c:359:27: note: in expansion of 
>> macro 'min'
   unsigned int tocheck = min(sizeof(buf),
  ^~~
   include/linux/kernel.h:775:2: note: in expansion of macro '__max'
 __max(typeof(x), typeof(y),   \
 ^
>> drivers/media//usb/dvb-usb/cxusb-analog.c:360:10: note: in expansion of 
>> macro 'max'
 max(sizeof(buf),
 ^~~

vim +/min +359 drivers/media//usb/dvb-usb/cxusb-analog.c

   198  
   199  static bool cxusb_medion_copy_field(struct dvb_usb_device *dvbdev,
   200  struct cxusb_medion_auxbuf *auxbuf,
   201  struct cxusb_bt656_params *bt656,
   202  bool firstfield,
   203  unsigned int maxlines,
   204  unsigned int maxlinesamples)
   205  {
   206  while (bt656->line < maxlines &&
   207 !cxusb_auxbuf_isend(auxbuf, bt656->pos)) {
   208  
   209  unsigned char val;
   210  
   211  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos, , 1))
   212  return false;
   213  
   214  if ((char)val == CXUSB_BT656_COMMON[0]) {
   215  char buf[3];
   216  
   217  if (!cxusb_auxbuf_copy(auxbuf, bt656->pos + 1,
   218 buf, 3))
   219  return false;
   220  
   221  if (buf[0] != (CXUSB_BT656_COMMON)[1] ||
   222  buf[1] != (CXUSB_BT656_COMMON)[2])
   223  goto normal_sample;
   224  
   225  if (bt656->line != 0 && (!!firstfield !=
   226   ((buf[2] & 
CXUSB_FIELD_MASK)
   227== CXUSB_FIELD_1))) {
   228  if (bt656->fmode == LINE_SAMPLES) {
   229  cxusb_vprintk(dvbdev, BT656,
   230"field %c after 
line %u field change\n",
   231firstfield ? '1' 
: '2',
   232bt656->line);
   233  
   234  if (bt656->buf != NULL &&
   235  maxlinesamples -
   236  bt656->linesamples > 0) 
{
   237  
   238  memset(bt656->buf, 0,
   239  maxlinesamples -
   240  
bt656->linesamples);
   241  
   242  

[PATCH 5/5] [media] cxusb: add analog mode support for Medion MD95700

2017-08-10 Thread Maciej S. Szmigiero
This patch adds support for analog part of Medion 95700 in the cxusb
driver.

What works:
* Video capture at various sizes with sequential fields,
* Input switching (TV Tuner, Composite, S-Video),
* TV and radio tuning,
* Video standard switching and auto detection,
* Radio mode switching (stereo / mono),
* Unplugging while capturing,
* DVB / analog coexistence,
* Raw BT.656 stream support.

What does not work yet:
* Audio,
* VBI,
* Picture controls.

Signed-off-by: Maciej S. Szmigiero 
---
 drivers/media/usb/dvb-usb/Kconfig|8 +-
 drivers/media/usb/dvb-usb/Makefile   |2 +-
 drivers/media/usb/dvb-usb/cxusb-analog.c | 1867 ++
 drivers/media/usb/dvb-usb/cxusb.c|  453 +++-
 drivers/media/usb/dvb-usb/cxusb.h|  137 +++
 drivers/media/usb/dvb-usb/dvb-usb-dvb.c  |   20 +-
 drivers/media/usb/dvb-usb/dvb-usb-init.c |   13 +
 drivers/media/usb/dvb-usb/dvb-usb.h  |8 +
 8 files changed, 2449 insertions(+), 59 deletions(-)
 create mode 100644 drivers/media/usb/dvb-usb/cxusb-analog.c

diff --git a/drivers/media/usb/dvb-usb/Kconfig 
b/drivers/media/usb/dvb-usb/Kconfig
index 959fa09dfd92..ba941069ae3b 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -118,7 +118,9 @@ config DVB_USB_UMT_010
 
 config DVB_USB_CXUSB
tristate "Conexant USB2.0 hybrid reference design support"
-   depends on DVB_USB
+   depends on DVB_USB && VIDEO_V4L2
+   select VIDEO_CX25840
+   select VIDEOBUF2_VMALLOC
select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT
select DVB_CX22702 if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGDT330X if MEDIA_SUBDRV_AUTOSELECT
@@ -136,8 +138,8 @@ config DVB_USB_CXUSB
select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
help
  Say Y here to support the Conexant USB2.0 hybrid reference design.
- Currently, only DVB and ATSC modes are supported, analog mode
- shall be added in the future. Devices that require this module:
+ DVB and ATSC modes are supported, with basic analog mode support
+ for Medion MD95700. Devices that require this module:
 
  Medion MD95700 hybrid USB2.0 device.
  DViCO FusionHDTV (Bluebird) USB2.0 devices
diff --git a/drivers/media/usb/dvb-usb/Makefile 
b/drivers/media/usb/dvb-usb/Makefile
index 3b3f32b426d1..24d222e9acc7 100644
--- a/drivers/media/usb/dvb-usb/Makefile
+++ b/drivers/media/usb/dvb-usb/Makefile
@@ -40,7 +40,7 @@ obj-$(CONFIG_DVB_USB_M920X) += dvb-usb-m920x.o
 dvb-usb-digitv-objs := digitv.o
 obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
 
-dvb-usb-cxusb-objs := cxusb.o
+dvb-usb-cxusb-objs := cxusb.o cxusb-analog.o
 obj-$(CONFIG_DVB_USB_CXUSB) += dvb-usb-cxusb.o
 
 dvb-usb-ttusb2-objs := ttusb2.o
diff --git a/drivers/media/usb/dvb-usb/cxusb-analog.c 
b/drivers/media/usb/dvb-usb/cxusb-analog.c
new file mode 100644
index ..473d3f06145f
--- /dev/null
+++ b/drivers/media/usb/dvb-usb/cxusb-analog.c
@@ -0,0 +1,1867 @@
+/* DVB USB compliant linux driver for Conexant USB reference design -
+ * (analog part).
+ *
+ * Copyright (C) 2011, 2017 Maciej S. Szmigiero (m...@maciej.szmigiero.name)
+ *
+ * TODO:
+ *  * audio support,
+ *  * finish radio support (requires audio of course),
+ *  * VBI support,
+ *  * controls support
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "cxusb.h"
+
+static int cxusb_medion_v_queue_setup(struct vb2_queue *q,
+ unsigned int *num_buffers,
+ unsigned int *num_planes,
+ unsigned int sizes[],
+ struct device *alloc_devs[])
+{
+   struct dvb_usb_device *dvbdev = vb2_get_drv_priv(q);
+   struct cxusb_medion_dev *cxdev = dvbdev->priv;
+   unsigned int size = cxdev->raw_mode ?
+   CXUSB_VIDEO_MAX_FRAME_SIZE :
+   cxdev->width * cxdev->height * 2;
+
+   if (*num_planes > 0) {
+   if (*num_planes != 1)
+   return -EINVAL;
+
+   if (sizes[0] < size)
+   return -EINVAL;
+   } else {
+   *num_planes = 1;
+   sizes[0] = size;
+   }
+
+   if (q->num_buffers + *num_buffers < 6)
+   *num_buffers = 6 - q->num_buffers;
+
+   return 0;
+}
+
+static int cxusb_medion_v_buf_init(struct vb2_buffer *vb)
+{
+   struct dvb_usb_device *dvbdev = vb2_get_drv_priv(vb->vb2_queue);
+   struct cxusb_medion_dev *cxdev = dvbdev->priv;
+
+   cxusb_vprintk(dvbdev, OPS,