Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-06 Thread Federico Vaga
Hi Hans,

thank you very much for your review and your patience.

> OK, I'm going to give this my Acked-by, but I really wish you would
> have split this up into smaller changes. It's hard to review since
> you have made so many changes in this one patch. Even though I'm
> giving my ack, Mauro might decide against it, so if you have time
> to spread out the changes in multiple patches, then please do so.

I tried to do smaller patch but there is always some incoherent part 
and the driver cannot work without all the patches. I should write 
some "fake" patches to make a coherent series.
I reduce the size of the patch since v4/5; I leaved 
unchanged some code/comments to simplify the patch.

> So, given the fact that this changes just a single driver not
> commonly used in existing deployments, assuming that you have
> tested the changes (you did that, right? Just checking...), that
> these are really useful improvements, and that I reviewed the code
> (as well as I could) and didn't see any problems, I'm giving my ack
> anyway:

Tested every time I sent a patch

> Acked-by: Hans Verkuil 

Thank you again

-- 
Federico Vaga
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-06 Thread Hans Verkuil
Hi Federico,

OK, I'm going to give this my Acked-by, but I really wish you would have split
this up into smaller changes. It's hard to review since you have made so many
changes in this one patch. Even though I'm giving my ack, Mauro might decide
against it, so if you have time to spread out the changes in multiple patches,
then please do so.

So, given the fact that this changes just a single driver not commonly used in
existing deployments, assuming that you have tested the changes (you did that,
right? Just checking...), that these are really useful improvements, and that
I reviewed the code (as well as I could) and didn't see any problems, I'm
giving my ack anyway:

Acked-by: Hans Verkuil 

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-06 Thread Hans Verkuil
Hi Federico,

OK, I'm going to give this my Acked-by, but I really wish you would have split
this up into smaller changes. It's hard to review since you have made so many
changes in this one patch. Even though I'm giving my ack, Mauro might decide
against it, so if you have time to spread out the changes in multiple patches,
then please do so.

So, given the fact that this changes just a single driver not commonly used in
existing deployments, assuming that you have tested the changes (you did that,
right? Just checking...), that these are really useful improvements, and that
I reviewed the code (as well as I could) and didn't see any problems, I'm
giving my ack anyway:

Acked-by: Hans Verkuil hans.verk...@cisco.com

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-06 Thread Federico Vaga
Hi Hans,

thank you very much for your review and your patience.

 OK, I'm going to give this my Acked-by, but I really wish you would
 have split this up into smaller changes. It's hard to review since
 you have made so many changes in this one patch. Even though I'm
 giving my ack, Mauro might decide against it, so if you have time
 to spread out the changes in multiple patches, then please do so.

I tried to do smaller patch but there is always some incoherent part 
and the driver cannot work without all the patches. I should write 
some fake patches to make a coherent series.
I reduce the size of the patch since v4/5; I leaved 
unchanged some code/comments to simplify the patch.

 So, given the fact that this changes just a single driver not
 commonly used in existing deployments, assuming that you have
 tested the changes (you did that, right? Just checking...), that
 these are really useful improvements, and that I reviewed the code
 (as well as I could) and didn't see any problems, I'm giving my ack
 anyway:

Tested every time I sent a patch

 Acked-by: Hans Verkuil hans.verk...@cisco.com

Thank you again

-- 
Federico Vaga
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-05 Thread Federico Vaga
This patch re-write the driver and use the videobuf2
interface instead of the old videobuf. Moreover, it uses also
the control framework which allows the driver to inherit
controls from its subdevice (ADV7180). Finally the driver does not
implement custom file operation but it uses the generic ones from
videobuf2 and v4l2_fh

Signed-off-by: Federico Vaga 
Acked-by: Giancarlo Asnaghi 
---
 drivers/media/pci/sta2x11/Kconfig   |2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c | 1073 +--
 2 file modificati, 434 inserzioni(+), 641 rimozioni(-)

diff --git a/drivers/media/pci/sta2x11/Kconfig 
b/drivers/media/pci/sta2x11/Kconfig
index 6749f67..a94ccad 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
tristate "STA2X11 VIP Video For Linux"
depends on STA2X11
select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
-   select VIDEOBUF_DMA_CONTIG
+   select VIDEOBUF2_DMA_CONTIG
depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS
help
  Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index ed1337a..b4521b5 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
 /*
  * This is the driver for the STA2x11 Video Input Port.
  *
+ * Copyright (C) 2012   ST Microelectronics
+ * author: Federico Vaga 
  * Copyright (C) 2010   WindRiver Systems, Inc.
+ * authors: Andreas Kies 
+ *  Vlad Lungu   
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
  * The full GNU General Public License is included in this distribution in
  * the file called "COPYING".
  *
- * Author: Andreas Kies 
- * Vlad Lungu 
- *
  */
 
 #include 
 #include 
 #include 
 #include 
-#include 
-
 #include 
-
 #include 
-
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
-#include 
+#include 
+#include 
+#include 
 
 #include "sta2x11_vip.h"
 
-#define DRV_NAME "sta2x11_vip"
 #define DRV_VERSION "1.3"
 
 #ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
 #define DVP_TFS0x08
 #define DVP_BFO0x0C
 #define DVP_BFS0x10
-#define DVP_VTP 0x14
-#define DVP_VBP 0x18
+#define DVP_VTP0x14
+#define DVP_VBP0x18
 #define DVP_VMP0x1C
 #define DVP_ITM0x98
 #define DVP_ITS0x9C
@@ -84,13 +82,21 @@
 
 #define DVP_HLFLN_SD   0x0001
 
-#define REG_WRITE(vip, reg, value) iowrite32((value), (vip->iomem)+(reg))
-#define REG_READ(vip, reg) ioread32((vip->iomem)+(reg))
-
 #define SAVE_COUNT 8
 #define AUX_COUNT 3
 #define IRQ_COUNT 1
 
+
+struct vip_buffer {
+   struct vb2_buffer   vb;
+   struct list_headlist;
+   dma_addr_t  dma;
+};
+static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
+{
+   return container_of(vb2, struct vip_buffer, vb);
+}
+
 /**
  * struct sta2x11_vip - All internal data for one instance of device
  * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
  * @adapter: contains I2C adapter information
  * @register_save_area: All relevant register are saved here during suspend
  * @decoder: contains information about video DAC
+ * @ctrl_hdl: handler for control framework
  * @format: pixel format, fixed UYVY
  * @std: video standard (e.g. PAL/NTSC)
  * @input: input line for video signal ( 0 or 1 )
- * @users: Number of open of device ( max. 1 )
  * @disabled: Device is in power down state
- * @mutex: ensures exclusive opening of device
  * @slock: for excluse acces of registers
- * @vb_vidq: queue maintained by videobuf layer
- * @capture: linked list of capture buffer
- * @active: struct videobuf_buffer currently beingg filled
- * @started: device is ready to capture frame
- * @closing: device will be shut down
+ * @alloc_ctx: context for videobuf2
+ * @vb_vidq: queue maintained by videobuf2 layer
+ * @buffer_list: list of buffer in use
+ * @sequence: sequence number of acquired buffer
+ * @active: current active buffer
+ * @lock: used in videobuf2 callback
  * @tcount: Number of top frames
  * @bcount: Number of bottom frames
  * @overflow: Number of FIFO overflows
- * @mem_spare: small buffer of unused frame
- * @dma_spare: dma addres of mem_spare
  * @iomem: hardware base address
  * @config: I2C and gpio config from platform
  *
  * All non-local data is accessed via this structure.
  */
-
 struct sta2x11_vip {
struct v4l2_device v4l2_dev;
struct video_device *video_dev;
@@ -129,21 +132,27 @@ struct sta2x11_vip {
struct i2c_adapter *adapter;
unsigned int 

[PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-05 Thread Federico Vaga
This patch re-write the driver and use the videobuf2
interface instead of the old videobuf. Moreover, it uses also
the control framework which allows the driver to inherit
controls from its subdevice (ADV7180). Finally the driver does not
implement custom file operation but it uses the generic ones from
videobuf2 and v4l2_fh

Signed-off-by: Federico Vaga federico.v...@gmail.com
Acked-by: Giancarlo Asnaghi giancarlo.asna...@st.com
---
 drivers/media/pci/sta2x11/Kconfig   |2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c | 1073 +--
 2 file modificati, 434 inserzioni(+), 641 rimozioni(-)

diff --git a/drivers/media/pci/sta2x11/Kconfig 
b/drivers/media/pci/sta2x11/Kconfig
index 6749f67..a94ccad 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
tristate STA2X11 VIP Video For Linux
depends on STA2X11
select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
-   select VIDEOBUF_DMA_CONTIG
+   select VIDEOBUF2_DMA_CONTIG
depends on PCI  VIDEO_V4L2  VIRT_TO_BUS
help
  Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index ed1337a..b4521b5 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
 /*
  * This is the driver for the STA2x11 Video Input Port.
  *
+ * Copyright (C) 2012   ST Microelectronics
+ * author: Federico Vaga federico.v...@gmail.com
  * Copyright (C) 2010   WindRiver Systems, Inc.
+ * authors: Andreas Kies andreas.k...@windriver.com
+ *  Vlad Lungu   vlad.lu...@windriver.com
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
  * The full GNU General Public License is included in this distribution in
  * the file called COPYING.
  *
- * Author: Andreas Kies andreas.k...@windriver.com
- * Vlad Lungu vlad.lu...@windriver.com
- *
  */
 
 #include linux/types.h
 #include linux/kernel.h
 #include linux/module.h
 #include linux/init.h
-#include linux/vmalloc.h
-
 #include linux/videodev2.h
-
 #include linux/kmod.h
-
 #include linux/pci.h
 #include linux/interrupt.h
-#include linux/mutex.h
 #include linux/io.h
 #include linux/gpio.h
 #include linux/i2c.h
 #include linux/delay.h
 #include media/v4l2-common.h
 #include media/v4l2-device.h
+#include media/v4l2-ctrls.h
 #include media/v4l2-ioctl.h
-#include media/videobuf-dma-contig.h
+#include media/v4l2-fh.h
+#include media/v4l2-event.h
+#include media/videobuf2-dma-contig.h
 
 #include sta2x11_vip.h
 
-#define DRV_NAME sta2x11_vip
 #define DRV_VERSION 1.3
 
 #ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
 #define DVP_TFS0x08
 #define DVP_BFO0x0C
 #define DVP_BFS0x10
-#define DVP_VTP 0x14
-#define DVP_VBP 0x18
+#define DVP_VTP0x14
+#define DVP_VBP0x18
 #define DVP_VMP0x1C
 #define DVP_ITM0x98
 #define DVP_ITS0x9C
@@ -84,13 +82,21 @@
 
 #define DVP_HLFLN_SD   0x0001
 
-#define REG_WRITE(vip, reg, value) iowrite32((value), (vip-iomem)+(reg))
-#define REG_READ(vip, reg) ioread32((vip-iomem)+(reg))
-
 #define SAVE_COUNT 8
 #define AUX_COUNT 3
 #define IRQ_COUNT 1
 
+
+struct vip_buffer {
+   struct vb2_buffer   vb;
+   struct list_headlist;
+   dma_addr_t  dma;
+};
+static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
+{
+   return container_of(vb2, struct vip_buffer, vb);
+}
+
 /**
  * struct sta2x11_vip - All internal data for one instance of device
  * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
  * @adapter: contains I2C adapter information
  * @register_save_area: All relevant register are saved here during suspend
  * @decoder: contains information about video DAC
+ * @ctrl_hdl: handler for control framework
  * @format: pixel format, fixed UYVY
  * @std: video standard (e.g. PAL/NTSC)
  * @input: input line for video signal ( 0 or 1 )
- * @users: Number of open of device ( max. 1 )
  * @disabled: Device is in power down state
- * @mutex: ensures exclusive opening of device
  * @slock: for excluse acces of registers
- * @vb_vidq: queue maintained by videobuf layer
- * @capture: linked list of capture buffer
- * @active: struct videobuf_buffer currently beingg filled
- * @started: device is ready to capture frame
- * @closing: device will be shut down
+ * @alloc_ctx: context for videobuf2
+ * @vb_vidq: queue maintained by videobuf2 layer
+ * @buffer_list: list of buffer in use
+ * @sequence: sequence number of acquired buffer
+ * @active: current active buffer
+ * @lock: used in videobuf2 callback
  * @tcount: Number of top frames
  * @bcount: Number of bottom 

Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-04 Thread Hans Verkuil
On Wed January 23 2013 15:07:06 Federico Vaga wrote:
> This patch re-write the driver and use the videobuf2
> interface instead of the old videobuf. Moreover, it uses also
> the control framework which allows the driver to inherit
> controls from its subdevice (ADV7180). Finally the driver does not
> implement custom file operation but it uses the generic ones from
> videobuf2 and v4l2_fh
> 
> Signed-off-by: Federico Vaga 
> Acked-by: Giancarlo Asnaghi 
> ---
>  drivers/media/pci/sta2x11/Kconfig   |2 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c | 1071 
> +--
>  2 file modificati, 432 inserzioni(+), 641 rimozioni(-)
> 
> @@ -797,12 +601,11 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, 
> void *priv,
>  static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
> struct v4l2_format *f)
>  {
> - struct video_device *dev = priv;
> - struct sta2x11_vip *vip = video_get_drvdata(dev);
> + struct sta2x11_vip *vip = video_drvdata(file);
>   int interlace_lim;
>  
>   if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat)
> - return -EINVAL;
> + v4l2_warn(>v4l2_dev, "Invalid format, only UYVY 
> supported\n");

As mentioned in my v4 review, keep the return -EINVAL here. As long as it is
uncertain what try_fmt should do with unsupported pixelformats we shouldn't
change this behavior.

Regards,

Hans

>  
>   if (V4L2_STD_525_60 & vip->std)
>   interlace_lim = 240;
> @@ -810,6 +613,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void 
> *priv,
>   interlace_lim = 288;
>  
>   switch (f->fmt.pix.field) {
> + default:
>   case V4L2_FIELD_ANY:
>   if (interlace_lim < f->fmt.pix.height)
>   f->fmt.pix.field = V4L2_FIELD_INTERLACED;
> @@ -823,10 +627,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, 
> void *priv,
>   break;
>   case V4L2_FIELD_INTERLACED:
>   break;
> - default:
> - return -EINVAL;
>   }
>  
> + /* It is the only supported format */
> + f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
>   f->fmt.pix.height &= ~1;
>   if (2 * interlace_lim < f->fmt.pix.height)
>   f->fmt.pix.height = 2 * interlace_lim;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-02-04 Thread Hans Verkuil
On Wed January 23 2013 15:07:06 Federico Vaga wrote:
 This patch re-write the driver and use the videobuf2
 interface instead of the old videobuf. Moreover, it uses also
 the control framework which allows the driver to inherit
 controls from its subdevice (ADV7180). Finally the driver does not
 implement custom file operation but it uses the generic ones from
 videobuf2 and v4l2_fh
 
 Signed-off-by: Federico Vaga federico.v...@gmail.com
 Acked-by: Giancarlo Asnaghi giancarlo.asna...@st.com
 ---
  drivers/media/pci/sta2x11/Kconfig   |2 +-
  drivers/media/pci/sta2x11/sta2x11_vip.c | 1071 
 +--
  2 file modificati, 432 inserzioni(+), 641 rimozioni(-)
 
 @@ -797,12 +601,11 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, 
 void *priv,
  static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 struct v4l2_format *f)
  {
 - struct video_device *dev = priv;
 - struct sta2x11_vip *vip = video_get_drvdata(dev);
 + struct sta2x11_vip *vip = video_drvdata(file);
   int interlace_lim;
  
   if (V4L2_PIX_FMT_UYVY != f-fmt.pix.pixelformat)
 - return -EINVAL;
 + v4l2_warn(vip-v4l2_dev, Invalid format, only UYVY 
 supported\n);

As mentioned in my v4 review, keep the return -EINVAL here. As long as it is
uncertain what try_fmt should do with unsupported pixelformats we shouldn't
change this behavior.

Regards,

Hans

  
   if (V4L2_STD_525_60  vip-std)
   interlace_lim = 240;
 @@ -810,6 +613,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void 
 *priv,
   interlace_lim = 288;
  
   switch (f-fmt.pix.field) {
 + default:
   case V4L2_FIELD_ANY:
   if (interlace_lim  f-fmt.pix.height)
   f-fmt.pix.field = V4L2_FIELD_INTERLACED;
 @@ -823,10 +627,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, 
 void *priv,
   break;
   case V4L2_FIELD_INTERLACED:
   break;
 - default:
 - return -EINVAL;
   }
  
 + /* It is the only supported format */
 + f-fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
   f-fmt.pix.height = ~1;
   if (2 * interlace_lim  f-fmt.pix.height)
   f-fmt.pix.height = 2 * interlace_lim;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-01-23 Thread Federico Vaga
This patch re-write the driver and use the videobuf2
interface instead of the old videobuf. Moreover, it uses also
the control framework which allows the driver to inherit
controls from its subdevice (ADV7180). Finally the driver does not
implement custom file operation but it uses the generic ones from
videobuf2 and v4l2_fh

Signed-off-by: Federico Vaga 
Acked-by: Giancarlo Asnaghi 
---
 drivers/media/pci/sta2x11/Kconfig   |2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c | 1071 +--
 2 file modificati, 432 inserzioni(+), 641 rimozioni(-)

diff --git a/drivers/media/pci/sta2x11/Kconfig 
b/drivers/media/pci/sta2x11/Kconfig
index 6749f67..a94ccad 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
tristate "STA2X11 VIP Video For Linux"
depends on STA2X11
select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
-   select VIDEOBUF_DMA_CONTIG
+   select VIDEOBUF2_DMA_CONTIG
depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS
help
  Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index ed1337a..834ac55 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
 /*
  * This is the driver for the STA2x11 Video Input Port.
  *
+ * Copyright (C) 2012   ST Microelectronics
+ * author: Federico Vaga 
  * Copyright (C) 2010   WindRiver Systems, Inc.
+ * authors: Andreas Kies 
+ *  Vlad Lungu   
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
  * The full GNU General Public License is included in this distribution in
  * the file called "COPYING".
  *
- * Author: Andreas Kies 
- * Vlad Lungu 
- *
  */
 
 #include 
 #include 
 #include 
 #include 
-#include 
-
 #include 
-
 #include 
-
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
-#include 
+#include 
+#include 
+#include 
 
 #include "sta2x11_vip.h"
 
-#define DRV_NAME "sta2x11_vip"
 #define DRV_VERSION "1.3"
 
 #ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
 #define DVP_TFS0x08
 #define DVP_BFO0x0C
 #define DVP_BFS0x10
-#define DVP_VTP 0x14
-#define DVP_VBP 0x18
+#define DVP_VTP0x14
+#define DVP_VBP0x18
 #define DVP_VMP0x1C
 #define DVP_ITM0x98
 #define DVP_ITS0x9C
@@ -84,13 +82,21 @@
 
 #define DVP_HLFLN_SD   0x0001
 
-#define REG_WRITE(vip, reg, value) iowrite32((value), (vip->iomem)+(reg))
-#define REG_READ(vip, reg) ioread32((vip->iomem)+(reg))
-
 #define SAVE_COUNT 8
 #define AUX_COUNT 3
 #define IRQ_COUNT 1
 
+
+struct vip_buffer {
+   struct vb2_buffer   vb;
+   struct list_headlist;
+   dma_addr_t  dma;
+};
+static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
+{
+   return container_of(vb2, struct vip_buffer, vb);
+}
+
 /**
  * struct sta2x11_vip - All internal data for one instance of device
  * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
  * @adapter: contains I2C adapter information
  * @register_save_area: All relevant register are saved here during suspend
  * @decoder: contains information about video DAC
+ * @ctrl_hdl: handler for control framework
  * @format: pixel format, fixed UYVY
  * @std: video standard (e.g. PAL/NTSC)
  * @input: input line for video signal ( 0 or 1 )
- * @users: Number of open of device ( max. 1 )
  * @disabled: Device is in power down state
- * @mutex: ensures exclusive opening of device
  * @slock: for excluse acces of registers
- * @vb_vidq: queue maintained by videobuf layer
- * @capture: linked list of capture buffer
- * @active: struct videobuf_buffer currently beingg filled
- * @started: device is ready to capture frame
- * @closing: device will be shut down
+ * @alloc_ctx: context for videobuf2
+ * @vb_vidq: queue maintained by videobuf2 layer
+ * @buffer_list: list of buffer in use
+ * @sequence: sequence number of acquired buffer
+ * @active: current active buffer
+ * @lock: used in videobuf2 callback
  * @tcount: Number of top frames
  * @bcount: Number of bottom frames
  * @overflow: Number of FIFO overflows
- * @mem_spare: small buffer of unused frame
- * @dma_spare: dma addres of mem_spare
  * @iomem: hardware base address
  * @config: I2C and gpio config from platform
  *
  * All non-local data is accessed via this structure.
  */
-
 struct sta2x11_vip {
struct v4l2_device v4l2_dev;
struct video_device *video_dev;
@@ -129,21 +132,27 @@ struct sta2x11_vip {
struct i2c_adapter *adapter;
unsigned int 

[PATCH v6 1/2] sta2x11_vip: convert to videobuf2, control framework, file handler

2013-01-23 Thread Federico Vaga
This patch re-write the driver and use the videobuf2
interface instead of the old videobuf. Moreover, it uses also
the control framework which allows the driver to inherit
controls from its subdevice (ADV7180). Finally the driver does not
implement custom file operation but it uses the generic ones from
videobuf2 and v4l2_fh

Signed-off-by: Federico Vaga federico.v...@gmail.com
Acked-by: Giancarlo Asnaghi giancarlo.asna...@st.com
---
 drivers/media/pci/sta2x11/Kconfig   |2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c | 1071 +--
 2 file modificati, 432 inserzioni(+), 641 rimozioni(-)

diff --git a/drivers/media/pci/sta2x11/Kconfig 
b/drivers/media/pci/sta2x11/Kconfig
index 6749f67..a94ccad 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
tristate STA2X11 VIP Video For Linux
depends on STA2X11
select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
-   select VIDEOBUF_DMA_CONTIG
+   select VIDEOBUF2_DMA_CONTIG
depends on PCI  VIDEO_V4L2  VIRT_TO_BUS
help
  Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index ed1337a..834ac55 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
 /*
  * This is the driver for the STA2x11 Video Input Port.
  *
+ * Copyright (C) 2012   ST Microelectronics
+ * author: Federico Vaga federico.v...@gmail.com
  * Copyright (C) 2010   WindRiver Systems, Inc.
+ * authors: Andreas Kies andreas.k...@windriver.com
+ *  Vlad Lungu   vlad.lu...@windriver.com
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
  * The full GNU General Public License is included in this distribution in
  * the file called COPYING.
  *
- * Author: Andreas Kies andreas.k...@windriver.com
- * Vlad Lungu vlad.lu...@windriver.com
- *
  */
 
 #include linux/types.h
 #include linux/kernel.h
 #include linux/module.h
 #include linux/init.h
-#include linux/vmalloc.h
-
 #include linux/videodev2.h
-
 #include linux/kmod.h
-
 #include linux/pci.h
 #include linux/interrupt.h
-#include linux/mutex.h
 #include linux/io.h
 #include linux/gpio.h
 #include linux/i2c.h
 #include linux/delay.h
 #include media/v4l2-common.h
 #include media/v4l2-device.h
+#include media/v4l2-ctrls.h
 #include media/v4l2-ioctl.h
-#include media/videobuf-dma-contig.h
+#include media/v4l2-fh.h
+#include media/v4l2-event.h
+#include media/videobuf2-dma-contig.h
 
 #include sta2x11_vip.h
 
-#define DRV_NAME sta2x11_vip
 #define DRV_VERSION 1.3
 
 #ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
 #define DVP_TFS0x08
 #define DVP_BFO0x0C
 #define DVP_BFS0x10
-#define DVP_VTP 0x14
-#define DVP_VBP 0x18
+#define DVP_VTP0x14
+#define DVP_VBP0x18
 #define DVP_VMP0x1C
 #define DVP_ITM0x98
 #define DVP_ITS0x9C
@@ -84,13 +82,21 @@
 
 #define DVP_HLFLN_SD   0x0001
 
-#define REG_WRITE(vip, reg, value) iowrite32((value), (vip-iomem)+(reg))
-#define REG_READ(vip, reg) ioread32((vip-iomem)+(reg))
-
 #define SAVE_COUNT 8
 #define AUX_COUNT 3
 #define IRQ_COUNT 1
 
+
+struct vip_buffer {
+   struct vb2_buffer   vb;
+   struct list_headlist;
+   dma_addr_t  dma;
+};
+static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
+{
+   return container_of(vb2, struct vip_buffer, vb);
+}
+
 /**
  * struct sta2x11_vip - All internal data for one instance of device
  * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
  * @adapter: contains I2C adapter information
  * @register_save_area: All relevant register are saved here during suspend
  * @decoder: contains information about video DAC
+ * @ctrl_hdl: handler for control framework
  * @format: pixel format, fixed UYVY
  * @std: video standard (e.g. PAL/NTSC)
  * @input: input line for video signal ( 0 or 1 )
- * @users: Number of open of device ( max. 1 )
  * @disabled: Device is in power down state
- * @mutex: ensures exclusive opening of device
  * @slock: for excluse acces of registers
- * @vb_vidq: queue maintained by videobuf layer
- * @capture: linked list of capture buffer
- * @active: struct videobuf_buffer currently beingg filled
- * @started: device is ready to capture frame
- * @closing: device will be shut down
+ * @alloc_ctx: context for videobuf2
+ * @vb_vidq: queue maintained by videobuf2 layer
+ * @buffer_list: list of buffer in use
+ * @sequence: sequence number of acquired buffer
+ * @active: current active buffer
+ * @lock: used in videobuf2 callback
  * @tcount: Number of top frames
  * @bcount: Number of bottom