Re: [PATCH v3 2/2] v4l: vsp1: Provide a writeback video device

2017-05-17 Thread Kieran Bingham
Hi Geert,

On 16/05/17 16:30, Geert Uytterhoeven wrote:
> Hi Kieran,
> 
> On Tue, May 9, 2017 at 6:39 PM, Kieran Bingham
>  wrote:
>> When the VSP1 is used in an active display pipeline, the output of the
>> WPF can supply the LIF entity directly and simultaneously write to
>> memory.
>>
>> Support this functionality in the VSP1 driver, by extending the WPF
>> source pads, and establishing a V4L2 video device node connected to the
>> new source.
>>
>> The source will be able to perform pixel format conversion, but not
>> rescaling, and as such the output from the memory node will always be
>> of the same dimensions as the display output.
>>
>> Signed-off-by: Kieran Bingham 
> 
>> --- a/drivers/media/platform/vsp1/vsp1_video.c
>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> 
>> @@ -900,6 +901,147 @@ static const struct vb2_ops vsp1_video_queue_qops = {
>> .stop_streaming = vsp1_video_stop_streaming,
>>  };
>>
>> +
>> +/* 
>> -
>> + * videobuf2 queue operations for writeback nodes
>> + */
>> +
>> +static void vsp1_video_wb_process_buffer(struct vsp1_video *video)
>> +{
>> +   struct vsp1_vb2_buffer *buf;
>> +   unsigned long flags;
>> +
>> +   /*
>> +* Writeback uses a running stream, unlike the M2M interface which
>> +* controls a pipeline process manually though the use of
>> +* vsp1_pipeline_run().
>> +*
>> +* Instead writeback will commence at the next frame interval, and 
>> can
>> +* be marked complete at the interval following that. To handle this 
>> we
>> +* store the configured buffer as pending until the next callback.
>> +*
>> +* |||||
>> +*  A   |<-->|
>> +*   B   |<-->|
>> +*C   |<-->| : Only at interrupt C can A be marked done
>> +*/
>> +
>> +   spin_lock_irqsave(&video->irqlock, flags);
>> +
>> +   /* Move the pending image to the active hw queue */
>> +   if (video->pending) {
>> +   list_add_tail(&video->pending->queue, &video->irqqueue);
>> +   video->pending = NULL;
>> +   }
>> +
>> +   buf = list_first_entry_or_null(&video->wbqueue, struct 
>> vsp1_vb2_buffer,
>> +   queue);
>> +
>> +   if (buf) {
>> +   video->rwpf->mem = buf->mem;
>> +
>> +   /*
>> +* Store this buffer as pending. It will commence at the next
>> +* frame start interrupt
>> +*/
>> +   video->pending = buf;
>> +   list_del(&buf->queue);
>> +   } else {
>> +   /* Disable writeback with no buffer */
>> +   video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
> 
> With gcc 4.9.0:
> 
> drivers/media/platform/vsp1/vsp1_video.c: In function
> 'vsp1_video_wb_process_buffer':
> drivers/media/platform/vsp1/vsp1_video.c:942:30: warning: missing
> braces around initializer [-Wmissing-braces]
>video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
> 
> -   video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
> +   video->rwpf->mem = (struct vsp1_rwpf_memory) { { 0, } };
> 

I've updated these to use a memset(&mem, 0, sizeof(mem)) instead.



>> +static void vsp1_video_wb_stop_streaming(struct vb2_queue *vq)
>> +{
>> +   struct vsp1_video *video = vb2_get_drv_priv(vq);
>> +   struct vsp1_rwpf *rwpf = video->rwpf;
>> +   struct vsp1_pipeline *pipe = rwpf->pipe;
>> +   struct vsp1_vb2_buffer *buffer;
>> +   unsigned long flags;
>> +
>> +   /*
>> +* Disable the completion interrupts, and clear the WPF memory to
>> +* prevent writing out frames
>> +*/
>> +   spin_lock_irqsave(&video->irqlock, flags);
>> +   video->frame_end = NULL;
>> +   rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
> 
> Likewise:
> 
> -   rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
> +   rwpf->mem = (struct vsp1_rwpf_memory) { { 0, } };
> 

Now memset...

> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds
> 


Re: [PATCH v3 2/2] v4l: vsp1: Provide a writeback video device

2017-05-16 Thread Geert Uytterhoeven
Hi Kieran,

On Tue, May 9, 2017 at 6:39 PM, Kieran Bingham
 wrote:
> When the VSP1 is used in an active display pipeline, the output of the
> WPF can supply the LIF entity directly and simultaneously write to
> memory.
>
> Support this functionality in the VSP1 driver, by extending the WPF
> source pads, and establishing a V4L2 video device node connected to the
> new source.
>
> The source will be able to perform pixel format conversion, but not
> rescaling, and as such the output from the memory node will always be
> of the same dimensions as the display output.
>
> Signed-off-by: Kieran Bingham 

> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c

> @@ -900,6 +901,147 @@ static const struct vb2_ops vsp1_video_queue_qops = {
> .stop_streaming = vsp1_video_stop_streaming,
>  };
>
> +
> +/* 
> -
> + * videobuf2 queue operations for writeback nodes
> + */
> +
> +static void vsp1_video_wb_process_buffer(struct vsp1_video *video)
> +{
> +   struct vsp1_vb2_buffer *buf;
> +   unsigned long flags;
> +
> +   /*
> +* Writeback uses a running stream, unlike the M2M interface which
> +* controls a pipeline process manually though the use of
> +* vsp1_pipeline_run().
> +*
> +* Instead writeback will commence at the next frame interval, and can
> +* be marked complete at the interval following that. To handle this 
> we
> +* store the configured buffer as pending until the next callback.
> +*
> +* |||||
> +*  A   |<-->|
> +*   B   |<-->|
> +*C   |<-->| : Only at interrupt C can A be marked done
> +*/
> +
> +   spin_lock_irqsave(&video->irqlock, flags);
> +
> +   /* Move the pending image to the active hw queue */
> +   if (video->pending) {
> +   list_add_tail(&video->pending->queue, &video->irqqueue);
> +   video->pending = NULL;
> +   }
> +
> +   buf = list_first_entry_or_null(&video->wbqueue, struct 
> vsp1_vb2_buffer,
> +   queue);
> +
> +   if (buf) {
> +   video->rwpf->mem = buf->mem;
> +
> +   /*
> +* Store this buffer as pending. It will commence at the next
> +* frame start interrupt
> +*/
> +   video->pending = buf;
> +   list_del(&buf->queue);
> +   } else {
> +   /* Disable writeback with no buffer */
> +   video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };

With gcc 4.9.0:

drivers/media/platform/vsp1/vsp1_video.c: In function
'vsp1_video_wb_process_buffer':
drivers/media/platform/vsp1/vsp1_video.c:942:30: warning: missing
braces around initializer [-Wmissing-braces]
   video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };

-   video->rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
+   video->rwpf->mem = (struct vsp1_rwpf_memory) { { 0, } };

> +static void vsp1_video_wb_stop_streaming(struct vb2_queue *vq)
> +{
> +   struct vsp1_video *video = vb2_get_drv_priv(vq);
> +   struct vsp1_rwpf *rwpf = video->rwpf;
> +   struct vsp1_pipeline *pipe = rwpf->pipe;
> +   struct vsp1_vb2_buffer *buffer;
> +   unsigned long flags;
> +
> +   /*
> +* Disable the completion interrupts, and clear the WPF memory to
> +* prevent writing out frames
> +*/
> +   spin_lock_irqsave(&video->irqlock, flags);
> +   video->frame_end = NULL;
> +   rwpf->mem = (struct vsp1_rwpf_memory) { 0 };

Likewise:

-   rwpf->mem = (struct vsp1_rwpf_memory) { 0 };
+   rwpf->mem = (struct vsp1_rwpf_memory) { { 0, } };

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH v3 2/2] v4l: vsp1: Provide a writeback video device

2017-05-09 Thread Kieran Bingham
When the VSP1 is used in an active display pipeline, the output of the
WPF can supply the LIF entity directly and simultaneously write to
memory.

Support this functionality in the VSP1 driver, by extending the WPF
source pads, and establishing a V4L2 video device node connected to the
new source.

The source will be able to perform pixel format conversion, but not
rescaling, and as such the output from the memory node will always be
of the same dimensions as the display output.

Signed-off-by: Kieran Bingham 

---
Changes since RFC
 - Fix checkpatch.pl warnings
 - Adapt to use a single source pad for the Writeback and LIF
 - Use WPF properties to determine when to create links instead of VSP
 - Remove incorrect vsp1_video_verify_format() changes
 - Spelling and grammar fixes

 - Rebased to v4.12-rc1
---
 drivers/media/platform/vsp1/vsp1.h   |   1 +-
 drivers/media/platform/vsp1/vsp1_drm.c   |  18 +++-
 drivers/media/platform/vsp1/vsp1_drv.c   |   5 +-
 drivers/media/platform/vsp1/vsp1_rwpf.h  |   1 +-
 drivers/media/platform/vsp1/vsp1_video.c | 150 +++-
 drivers/media/platform/vsp1/vsp1_video.h |   5 +-
 drivers/media/platform/vsp1/vsp1_wpf.c   |  19 ++-
 7 files changed, 192 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index 85387a64179a..a2d462264312 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -54,6 +54,7 @@ struct vsp1_uds;
 #define VSP1_HAS_WPF_HFLIP (1 << 6)
 #define VSP1_HAS_HGO   (1 << 7)
 #define VSP1_HAS_HGT   (1 << 8)
+#define VSP1_HAS_WPF_WRITEBACK (1 << 9)
 
 struct vsp1_device_info {
u32 version;
diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
b/drivers/media/platform/vsp1/vsp1_drm.c
index 9d235e830f5a..539890b27864 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -25,6 +25,7 @@
 #include "vsp1_lif.h"
 #include "vsp1_pipe.h"
 #include "vsp1_rwpf.h"
+#include "vsp1_video.h"
 
 
 /* 
-
@@ -483,6 +484,13 @@ void vsp1_du_atomic_flush(struct device *dev)
__func__, rpf->entity.index);
}
 
+   /*
+* If we have a writeback node attached, we use this opportunity to
+* update the video buffers.
+*/
+   if (pipe->output->video && pipe->output->video->frame_end)
+   pipe->output->video->frame_end(pipe);
+
/* Configure all entities in the pipeline. */
list_for_each_entry(entity, &pipe->entities, list_pipe) {
/* Disconnect unused RPFs from the pipeline. */
@@ -572,6 +580,16 @@ int vsp1_drm_create_links(struct vsp1_device *vsp1)
if (ret < 0)
return ret;
 
+   if (vsp1->wpf[0]->has_writeback) {
+   /* Connect the video device to the WPF for Writeback support */
+   ret = media_create_pad_link(&vsp1->wpf[0]->entity.subdev.entity,
+   RWPF_PAD_SOURCE,
+   &vsp1->wpf[0]->video->video.entity,
+   0, flags);
+   if (ret < 0)
+   return ret;
+   }
+
return 0;
 }
 
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index 048446af5ae7..240045e82cc2 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -411,7 +411,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
vsp1->wpf[i] = wpf;
list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
 
-   if (vsp1->info->uapi) {
+   if (vsp1->info->uapi || wpf->has_writeback) {
struct vsp1_video *video = vsp1_video_create(vsp1, wpf);
 
if (IS_ERR(video)) {
@@ -709,7 +709,8 @@ static const struct vsp1_device_info vsp1_device_infos[] = {
.version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
.model = "VSP2-D",
.gen = 3,
-   .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_WPF_VFLIP,
+   .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_WPF_VFLIP
+ | VSP1_HAS_WPF_WRITEBACK,
.rpf_count = 5,
.wpf_count = 2,
.num_bru_inputs = 5,
diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.h 
b/drivers/media/platform/vsp1/vsp1_rwpf.h
index 58215a7ab631..d26a92cd5c7d 100644
--- a/drivers/media/platform/vsp1/vsp1_rwpf.h
+++ b/drivers/media/platform/vsp1/vsp1_rwpf.h
@@ -53,6 +53,7 @@ struct vsp1_rwpf {
 
u32 mult_alpha;
u32 outfmt;
+   bool has_writeback;
 
struct {
spinlock_t lock;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c 
b/drivers/media/platform/vsp1/vsp1_video.c
index 47b5c24043d7..91def2609882 100644
---