Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

2015-01-12 Thread Hans Verkuil
Hi Shuah,

Looks good! I do have a few small comments, see below.

On 12/18/2014 05:20 PM, Shuah Khan wrote:
 Convert au0828 to use videobuf2. Tested with NTSC.
 Tested video and vbi devices with xawtv, tvtime,
 and vlc. Ran v4l2-compliance to ensure there are
 no new regressions in video and vbi now has 3 fewer
 failures.
 
 video before:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 Video after:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 vbi before:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
 test VIDIOC_EXPBUF: FAIL
 test USERPTR: FAIL
 Total: 72, Succeeded: 66, Failed: 6, Warnings: 0
 
 vbi after:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
 test VIDIOC_EXPBUF: OK (Not Supported)
 test USERPTR: OK
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 Signed-off-by: Shuah Khan shua...@osg.samsung.com
 ---
  drivers/media/usb/au0828/Kconfig|   2 +-
  drivers/media/usb/au0828/au0828-cards.c |   2 +-
  drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
  drivers/media/usb/au0828/au0828-video.c | 949 
 +---
  drivers/media/usb/au0828/au0828.h   |  61 +-
  5 files changed, 444 insertions(+), 692 deletions(-)
 
 diff --git a/drivers/media/usb/au0828/au0828-video.c 
 b/drivers/media/usb/au0828/au0828-video.c
 index 5f337b1..3011ca8 100644
 --- a/drivers/media/usb/au0828/au0828-video.c
 +++ b/drivers/media/usb/au0828/au0828-video.c
 +void au0828_analog_unregister(struct au0828_dev *dev)
  {
 - switch (fh-type) {
 - case V4L2_BUF_TYPE_VIDEO_CAPTURE:
 - return AU0828_RESOURCE_VIDEO;
 - case V4L2_BUF_TYPE_VBI_CAPTURE:
 - return AU0828_RESOURCE_VBI;
 - default:
 - BUG();
 - return 0;
 - }
 + dprintk(1, au0828_analog_unregister called\n);
 + mutex_lock(au0828_sysfs_lock);
 +
 + if (dev-vdev)
 + video_unregister_device(dev-vdev);
 + if (dev-vbi_dev)
 + video_unregister_device(dev-vbi_dev);
 +
 + mutex_unlock(au0828_sysfs_lock);
  }
  
  /* This function ensures that video frames continue to be delivered even if
 @@ -951,8 +932,8 @@ static void au0828_vid_buffer_timeout(unsigned long data)
  
   buf = dev-isoc_ctl.buf;
   if (buf != NULL) {
 - vid_data = videobuf_to_vmalloc(buf-vb);
 - memset(vid_data, 0x00, buf-vb.size); /* Blank green frame */
 + vid_data = vb2_plane_vaddr(buf-vb, 0);
 + memset(vid_data, 0x00, buf-length); /* Blank green frame */
   buffer_filled(dev, dma_q, buf);
   }
   get_next_buf(dma_q, buf);
 @@ -975,8 +956,8 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
  
   buf = dev-isoc_ctl.vbi_buf;
   if (buf != NULL) {
 - vbi_data = videobuf_to_vmalloc(buf-vb);
 - memset(vbi_data, 0x00, buf-vb.size);
 + vbi_data = vb2_plane_vaddr(buf-vb, 0);
 + memset(vbi_data, 0x00, buf-length);
   vbi_buffer_filled(dev, dma_q, buf);
   }
   vbi_get_next_buf(dma_q, buf);
 @@ -986,14 +967,12 @@ static void au0828_vbi_buffer_timeout(unsigned long 
 data)
   spin_unlock_irqrestore(dev-slock, flags);
  }
  
 -
  static int au0828_v4l2_open(struct file *filp)
  {
 - int ret = 0;
   struct video_device *vdev = video_devdata(filp);
   struct au0828_dev *dev = video_drvdata(filp);
 - struct au0828_fh *fh;
   int type;
 + int ret = 0;
  
   switch (vdev-vfl_type) {
   case VFL_TYPE_GRABBER:

This switch can be removed.

 @@ -1957,17 +1693,23 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
   .vidioc_g_audio = vidioc_g_audio,
   .vidioc_s_audio = vidioc_s_audio,
   .vidioc_cropcap = vidioc_cropcap,
 - .vidioc_reqbufs = vidioc_reqbufs,
 - .vidioc_querybuf= vidioc_querybuf,
 - .vidioc_qbuf= vidioc_qbuf,
 - .vidioc_dqbuf   = vidioc_dqbuf,
 +
 + .vidioc_reqbufs = vb2_ioctl_reqbufs,
 + .vidioc_create_bufs = vb2_ioctl_create_bufs,
 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
 + .vidioc_querybuf= vb2_ioctl_querybuf,
 + .vidioc_qbuf= vb2_ioctl_qbuf,
 + .vidioc_dqbuf   = vb2_ioctl_dqbuf,

Add vidioc_expbuf as well. That is now supported by videobuf2-vmalloc.

 +
   .vidioc_s_std   = vidioc_s_std,
   .vidioc_g_std   = vidioc_g_std,
   .vidioc_enum_input  = vidioc_enum_input,
   .vidioc_g_input = vidioc_g_input,
   .vidioc_s_input = vidioc_s_input,
 - .vidioc_streamon= vidioc_streamon,
 - .vidioc_streamoff   = vidioc_streamoff,
 +
 + .vidioc_streamon= vb2_ioctl_streamon,
 + .vidioc_streamoff   = vb2_ioctl_streamoff,
 +
   .vidioc_g_tuner   

Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

2015-01-12 Thread Hans Verkuil
On 12/18/2014 05:20 PM, Shuah Khan wrote:
 Convert au0828 to use videobuf2. Tested with NTSC.
 Tested video and vbi devices with xawtv, tvtime,
 and vlc. Ran v4l2-compliance to ensure there are
 no new regressions in video and vbi now has 3 fewer
 failures.
 
 video before:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 Video after:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 vbi before:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
 test VIDIOC_EXPBUF: FAIL
 test USERPTR: FAIL
 Total: 72, Succeeded: 66, Failed: 6, Warnings: 0
 
 vbi after:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
 test VIDIOC_EXPBUF: OK (Not Supported)
 test USERPTR: OK
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0
 
 Signed-off-by: Shuah Khan shua...@osg.samsung.com
 ---
  drivers/media/usb/au0828/Kconfig|   2 +-
  drivers/media/usb/au0828/au0828-cards.c |   2 +-
  drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
  drivers/media/usb/au0828/au0828-video.c | 949 
 +---
  drivers/media/usb/au0828/au0828.h   |  61 +-
  5 files changed, 444 insertions(+), 692 deletions(-)
 
 diff --git a/drivers/media/usb/au0828/Kconfig 
 b/drivers/media/usb/au0828/Kconfig
 index 1d410ac..78b797e 100644
 --- a/drivers/media/usb/au0828/Kconfig
 +++ b/drivers/media/usb/au0828/Kconfig
 @@ -4,7 +4,7 @@ config VIDEO_AU0828
   depends on I2C  INPUT  DVB_CORE  USB
   select I2C_ALGOBIT
   select VIDEO_TVEEPROM
 - select VIDEOBUF_VMALLOC
 + select VIDEOBUF2_VMALLOC
   select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
   select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
   select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
 diff --git a/drivers/media/usb/au0828/au0828-cards.c 
 b/drivers/media/usb/au0828/au0828-cards.c
 index 9eb77ac..ae2e563 100644
 --- a/drivers/media/usb/au0828/au0828-cards.c
 +++ b/drivers/media/usb/au0828/au0828-cards.c
 @@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
  struct au0828_board au0828_boards[] = {
   [AU0828_BOARD_UNKNOWN] = {
   .name   = Unknown board,
 - .tuner_type = UNSET,
 + .tuner_type = -1U,
   .tuner_addr = ADDR_UNSET,
   },
   [AU0828_BOARD_HAUPPAUGE_HVR850] = {

I would split off this au0828-cards.c change into a separate patch. It has 
nothing to
do with the vb2 conversion.

Regards,

Hans

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

2015-01-12 Thread Shuah Khan
On 01/12/2015 07:19 AM, Hans Verkuil wrote:
 On 12/18/2014 05:20 PM, Shuah Khan wrote:
 Convert au0828 to use videobuf2. Tested with NTSC.
 Tested video and vbi devices with xawtv, tvtime,
 and vlc. Ran v4l2-compliance to ensure there are
 no new regressions in video and vbi now has 3 fewer
 failures.

 video before:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

 Video after:
 test VIDIOC_G_FMT: FAIL 3 failures
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

 vbi before:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
 test VIDIOC_EXPBUF: FAIL
 test USERPTR: FAIL
 Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

 vbi after:
 test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
 test VIDIOC_EXPBUF: OK (Not Supported)
 test USERPTR: OK
 Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

 Signed-off-by: Shuah Khan shua...@osg.samsung.com
 ---
  drivers/media/usb/au0828/Kconfig|   2 +-
  drivers/media/usb/au0828/au0828-cards.c |   2 +-
  drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
  drivers/media/usb/au0828/au0828-video.c | 949 
 +---
  drivers/media/usb/au0828/au0828.h   |  61 +-
  5 files changed, 444 insertions(+), 692 deletions(-)

 diff --git a/drivers/media/usb/au0828/Kconfig 
 b/drivers/media/usb/au0828/Kconfig
 index 1d410ac..78b797e 100644
 --- a/drivers/media/usb/au0828/Kconfig
 +++ b/drivers/media/usb/au0828/Kconfig
 @@ -4,7 +4,7 @@ config VIDEO_AU0828
  depends on I2C  INPUT  DVB_CORE  USB
  select I2C_ALGOBIT
  select VIDEO_TVEEPROM
 -select VIDEOBUF_VMALLOC
 +select VIDEOBUF2_VMALLOC
  select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
  select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
  select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
 diff --git a/drivers/media/usb/au0828/au0828-cards.c 
 b/drivers/media/usb/au0828/au0828-cards.c
 index 9eb77ac..ae2e563 100644
 --- a/drivers/media/usb/au0828/au0828-cards.c
 +++ b/drivers/media/usb/au0828/au0828-cards.c
 @@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
  struct au0828_board au0828_boards[] = {
  [AU0828_BOARD_UNKNOWN] = {
  .name   = Unknown board,
 -.tuner_type = UNSET,
 +.tuner_type = -1U,
  .tuner_addr = ADDR_UNSET,
  },
  [AU0828_BOARD_HAUPPAUGE_HVR850] = {
 
 I would split off this au0828-cards.c change into a separate patch. It has 
 nothing to
 do with the vb2 conversion.
 

I will split this patch and add it to the series.

-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shua...@osg.samsung.com | (970) 217-8978
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/3] media: au0828 - convert to use videobuf2

2014-12-18 Thread Shuah Khan
Convert au0828 to use videobuf2. Tested with NTSC.
Tested video and vbi devices with xawtv, tvtime,
and vlc. Ran v4l2-compliance to ensure there are
no new regressions in video and vbi now has 3 fewer
failures.

video before:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Video after:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

vbi before:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
test VIDIOC_EXPBUF: FAIL
test USERPTR: FAIL
Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

vbi after:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test USERPTR: OK
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Signed-off-by: Shuah Khan shua...@osg.samsung.com
---
 drivers/media/usb/au0828/Kconfig|   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 949 +---
 drivers/media/usb/au0828/au0828.h   |  61 +-
 5 files changed, 444 insertions(+), 692 deletions(-)

diff --git a/drivers/media/usb/au0828/Kconfig b/drivers/media/usb/au0828/Kconfig
index 1d410ac..78b797e 100644
--- a/drivers/media/usb/au0828/Kconfig
+++ b/drivers/media/usb/au0828/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_AU0828
depends on I2C  INPUT  DVB_CORE  USB
select I2C_ALGOBIT
select VIDEO_TVEEPROM
-   select VIDEOBUF_VMALLOC
+   select VIDEOBUF2_VMALLOC
select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/usb/au0828/au0828-cards.c 
b/drivers/media/usb/au0828/au0828-cards.c
index 9eb77ac..ae2e563 100644
--- a/drivers/media/usb/au0828/au0828-cards.c
+++ b/drivers/media/usb/au0828/au0828-cards.c
@@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
 struct au0828_board au0828_boards[] = {
[AU0828_BOARD_UNKNOWN] = {
.name   = Unknown board,
-   .tuner_type = UNSET,
+   .tuner_type = -1U,
.tuner_addr = ADDR_UNSET,
},
[AU0828_BOARD_HAUPPAUGE_HVR850] = {
diff --git a/drivers/media/usb/au0828/au0828-vbi.c 
b/drivers/media/usb/au0828/au0828-vbi.c
index 932d24f..f67247c 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -28,111 +28,67 @@
 #include linux/init.h
 #include linux/slab.h
 
-static unsigned int vbibufs = 5;
-module_param(vbibufs, int, 0644);
-MODULE_PARM_DESC(vbibufs, number of vbi buffers, range 2-32);
-
 /* -- */
 
-static void
-free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf)
+static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+  unsigned int *nbuffers, unsigned int *nplanes,
+  unsigned int sizes[], void *alloc_ctxs[])
 {
-   struct au0828_fh *fh  = vq-priv_data;
-   struct au0828_dev*dev = fh-dev;
-   unsigned long flags = 0;
-   if (in_interrupt())
-   BUG();
-
-   /* We used to wait for the buffer to finish here, but this didn't work
-  because, as we were keeping the state as VIDEOBUF_QUEUED,
-  videobuf_queue_cancel marked it as finished for us.
-  (Also, it could wedge forever if the hardware was misconfigured.)
-
-  This should be safe; by the time we get here, the buffer isn't
-  queued anymore. If we ever start marking the buffers as
-  VIDEOBUF_ACTIVE, it won't be, though.
-   */
-   spin_lock_irqsave(dev-slock, flags);
-   if (dev-isoc_ctl.vbi_buf == buf)
-   dev-isoc_ctl.vbi_buf = NULL;
-   spin_unlock_irqrestore(dev-slock, flags);
+   struct au0828_dev *dev = vb2_get_drv_priv(vq);
+   unsigned long img_size = dev-vbi_width * dev-vbi_height * 2;
+   unsigned long size;
 
-   videobuf_vmalloc_free(buf-vb);
-   buf-vb.state = VIDEOBUF_NEEDS_INIT;
-}
-
-static int
-vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
-{
-   struct au0828_fh *fh  = q-priv_data;
-   struct au0828_dev*dev = fh-dev;
+   size = fmt ? (fmt-fmt.vbi.samples_per_line *
+   (fmt-fmt.vbi.count[0] + fmt-fmt.vbi.count[1])) : img_size;
+   if (size  img_size)
+   return -EINVAL;
 
-   *size = dev-vbi_width * dev-vbi_height * 2;
+   *nplanes = 1;
+   sizes[0] = size;
 
-   if (0 == *count)
-   *count = vbibufs;
-   if (*count  2)
-   *count = 2;
-   if (*count  32)
-   *count = 32;
return 0;
 }
 
-static int
-vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
-   enum v4l2_field field)
+static int vbi_buffer_prepare(struct vb2_buffer *vb)
 {
-