Re: [PATCH 24/29] drivers: convert iblock_req.pending from atomic_t to refcount_t

2017-03-07 Thread Nicholas A. Bellinger
Hi Elena,

On Mon, 2017-03-06 at 16:21 +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 
> ---
>  drivers/target/target_core_iblock.c | 12 ++--
>  drivers/target/target_core_iblock.h |  3 ++-
>  2 files changed, 8 insertions(+), 7 deletions(-)

For the target_core_iblock part:

Acked-by: Nicholas Bellinger 



Re: [bug report] [media] atmel-isc: add the isc pipeline function

2017-03-07 Thread Wu, Songjun

Hi Dan,

I understand now, thank you very much.

On 3/8/2017 12:38, Dan Carpenter wrote:

No.  Imagine the v4l2_subdev_call() loop exits with "fmt" set to NULL.
It will cause a crash.

Please re-read my original email because I think you may have meant to
reset fmt after that loop.

regards,
dan carpenter



Re: [bug report] [media] atmel-isc: add the isc pipeline function

2017-03-07 Thread Dan Carpenter
No.  Imagine the v4l2_subdev_call() loop exits with "fmt" set to NULL.
It will cause a crash.

Please re-read my original email because I think you may have meant to
reset fmt after that loop.

regards,
dan carpenter



cron job: media_tree daily build: ERRORS

2017-03-07 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Wed Mar  8 05:00:17 CET 2017
media-tree git hash:700ea5e0e0dd70420a04e703ff264cc133834cba
media_build git hash:   9d6cebc34b27fea784dec19085970d9b4df9783e
v4l-utils git hash: 098aa386ea6cf08cacb44e0982431c5e837e63d0
gcc version:i686-linux-gcc (GCC) 6.2.0
sparse version: v0.5.0-3553-g78b2ea6
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.9.0-164

linux-git-arm-at91: ERRORS
linux-git-arm-davinci: ERRORS
linux-git-arm-multi: ERRORS
linux-git-arm-pxa: ERRORS
linux-git-blackfin-bf561: ERRORS
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: ERRORS
linux-git-powerpc64: OK
linux-git-sh: ERRORS
linux-git-x86_64: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.2.37-i686: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.8-i686: ERRORS
linux-3.9.2-i686: ERRORS
linux-3.10.1-i686: ERRORS
linux-3.11.1-i686: ERRORS
linux-3.12.67-i686: ERRORS
linux-3.13.11-i686: ERRORS
linux-3.14.9-i686: ERRORS
linux-3.15.2-i686: ERRORS
linux-3.16.7-i686: ERRORS
linux-3.17.8-i686: ERRORS
linux-3.18.7-i686: ERRORS
linux-3.19-i686: ERRORS
linux-4.0.9-i686: ERRORS
linux-4.1.33-i686: ERRORS
linux-4.2.8-i686: ERRORS
linux-4.3.6-i686: ERRORS
linux-4.4.22-i686: ERRORS
linux-4.5.7-i686: ERRORS
linux-4.6.7-i686: ERRORS
linux-4.7.5-i686: ERRORS
linux-4.8-i686: ERRORS
linux-4.9-i686: ERRORS
linux-4.10-rc3-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-x86_64: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.37-x86_64: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-x86_64: ERRORS
linux-3.10.1-x86_64: ERRORS
linux-3.11.1-x86_64: ERRORS
linux-3.12.67-x86_64: ERRORS
linux-3.13.11-x86_64: ERRORS
linux-3.14.9-x86_64: ERRORS
linux-3.15.2-x86_64: ERRORS
linux-3.16.7-x86_64: ERRORS
linux-3.17.8-x86_64: ERRORS
linux-3.18.7-x86_64: ERRORS
linux-3.19-x86_64: ERRORS
linux-4.0.9-x86_64: ERRORS
linux-4.1.33-x86_64: ERRORS
linux-4.2.8-x86_64: ERRORS
linux-4.3.6-x86_64: ERRORS
linux-4.4.22-x86_64: ERRORS
linux-4.5.7-x86_64: ERRORS
linux-4.6.7-x86_64: ERRORS
linux-4.7.5-x86_64: ERRORS
linux-4.8-x86_64: ERRORS
linux-4.9-x86_64: ERRORS
linux-4.10-rc3-x86_64: ERRORS
apps: WARNINGS
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Wednesday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Wednesday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


Re: [PATCH v3 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread Tiffany Lin
On Wed, 2017-03-08 at 11:40 +0800, Wu-Cheng Li wrote:
> From: Wu-Cheng Li 
> 
> VPU firmware has a bug and may return invalid buffer index for
> some vp9 videos. Check the buffer indexes before accessing the
> buffer.
> 

Acked-by: Tiffany Lin 

> Signed-off-by: Wu-Cheng Li 
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 33 
> +-
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
>  .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 +
>  drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
>  4 files changed, 56 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> index 502877a4b1df..a60b538686ea 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> @@ -420,6 +420,11 @@ static void mtk_vdec_worker(struct work_struct *work)
>   dst_buf->index,
>   ret, res_chg);
>   src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
> + if (ret == -EIO) {
> + mutex_lock(>lock);
> + src_buf_info->error = true;
> + mutex_unlock(>lock);
> + }
>   v4l2_m2m_buf_done(_buf_info->vb, VB2_BUF_STATE_ERROR);
>   } else if (res_chg == false) {
>   /*
> @@ -1170,8 +1175,16 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer 
> *vb)
>*/
>  
>   src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
> - v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
> - VB2_BUF_STATE_DONE);
> + if (ret == -EIO) {
> + mtk_v4l2_err("[%d] Unrecoverable error in 
> vdec_if_decode.",
> + ctx->id);
> + ctx->state = MTK_STATE_ABORT;
> + v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
> + VB2_BUF_STATE_ERROR);
> + } else {
> + v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
> + VB2_BUF_STATE_DONE);
> + }
>   mtk_v4l2_debug(ret ? 0 : 1,
>  "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
> fail=%d, res_chg=%d",
>  ctx->id, src_buf->index,
> @@ -1216,16 +1229,22 @@ static void vb2ops_vdec_buf_finish(struct vb2_buffer 
> *vb)
>   struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
>   struct vb2_v4l2_buffer *vb2_v4l2;
>   struct mtk_video_dec_buf *buf;
> -
> - if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> - return;
> + bool buf_error;
>  
>   vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
>   buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
>   mutex_lock(>lock);
> - buf->queued_in_v4l2 = false;
> - buf->queued_in_vb2 = false;
> + if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
> + buf->queued_in_v4l2 = false;
> + buf->queued_in_vb2 = false;
> + }
> + buf_error = buf->error;
>   mutex_unlock(>lock);
> +
> + if (buf_error) {
> + mtk_v4l2_err("Unrecoverable error on buffer.");
> + ctx->state = MTK_STATE_ABORT;
> + }
>  }
>  
>  static int vb2ops_vdec_buf_init(struct vb2_buffer *vb)
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> index 362f5a85762e..dc4fc1df63c5 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> @@ -50,6 +50,7 @@ struct vdec_fb {
>   * @queued_in_v4l2:  Capture buffer is in v4l2 driver, but not in vb2
>   *   queue yet
>   * @lastframe:   Intput buffer is last buffer - EOS
> + * @error:   An unrecoverable error occurs on this buffer.
>   * @frame_buffer:Decode status, and buffer information of Capture buffer
>   *
>   * Note : These status information help us track and debug buffer state
> @@ -63,6 +64,7 @@ struct mtk_video_dec_buf {
>   boolqueued_in_vb2;
>   boolqueued_in_v4l2;
>   boollastframe;
> + boolerror;
>   struct vdec_fb  frame_buffer;
>  };
>  
> diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
> b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> index e91a3b425b0c..5539b1853f16 100644
> --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> @@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, 
> struct vdec_fb **out_fb)
>   *out_fb = fb;
>  }
>  
> +static int 

[PATCH v3 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread Wu-Cheng Li
From: Wu-Cheng Li 

VPU firmware has a bug and may return invalid buffer index for
some vp9 videos. Check the buffer indexes before accessing the
buffer.

Signed-off-by: Wu-Cheng Li 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 33 +-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
 .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 +
 drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
 4 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index 502877a4b1df..a60b538686ea 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -420,6 +420,11 @@ static void mtk_vdec_worker(struct work_struct *work)
dst_buf->index,
ret, res_chg);
src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+   if (ret == -EIO) {
+   mutex_lock(>lock);
+   src_buf_info->error = true;
+   mutex_unlock(>lock);
+   }
v4l2_m2m_buf_done(_buf_info->vb, VB2_BUF_STATE_ERROR);
} else if (res_chg == false) {
/*
@@ -1170,8 +1175,16 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb)
 */
 
src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
-   v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
-   VB2_BUF_STATE_DONE);
+   if (ret == -EIO) {
+   mtk_v4l2_err("[%d] Unrecoverable error in 
vdec_if_decode.",
+   ctx->id);
+   ctx->state = MTK_STATE_ABORT;
+   v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
+   VB2_BUF_STATE_ERROR);
+   } else {
+   v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
+   VB2_BUF_STATE_DONE);
+   }
mtk_v4l2_debug(ret ? 0 : 1,
   "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
fail=%d, res_chg=%d",
   ctx->id, src_buf->index,
@@ -1216,16 +1229,22 @@ static void vb2ops_vdec_buf_finish(struct vb2_buffer 
*vb)
struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vb2_v4l2;
struct mtk_video_dec_buf *buf;
-
-   if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-   return;
+   bool buf_error;
 
vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
mutex_lock(>lock);
-   buf->queued_in_v4l2 = false;
-   buf->queued_in_vb2 = false;
+   if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+   buf->queued_in_v4l2 = false;
+   buf->queued_in_vb2 = false;
+   }
+   buf_error = buf->error;
mutex_unlock(>lock);
+
+   if (buf_error) {
+   mtk_v4l2_err("Unrecoverable error on buffer.");
+   ctx->state = MTK_STATE_ABORT;
+   }
 }
 
 static int vb2ops_vdec_buf_init(struct vb2_buffer *vb)
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
index 362f5a85762e..dc4fc1df63c5 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
@@ -50,6 +50,7 @@ struct vdec_fb {
  * @queued_in_v4l2:Capture buffer is in v4l2 driver, but not in vb2
  * queue yet
  * @lastframe: Intput buffer is last buffer - EOS
+ * @error: An unrecoverable error occurs on this buffer.
  * @frame_buffer:  Decode status, and buffer information of Capture buffer
  *
  * Note : These status information help us track and debug buffer state
@@ -63,6 +64,7 @@ struct mtk_video_dec_buf {
boolqueued_in_vb2;
boolqueued_in_v4l2;
boollastframe;
+   boolerror;
struct vdec_fb  frame_buffer;
 };
 
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
index e91a3b425b0c..5539b1853f16 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
@@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, struct 
vdec_fb **out_fb)
*out_fb = fb;
 }
 
+static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
+   struct vdec_vp9_vsi *vsi) {
+   if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
+   mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.",
+  

[PATCH v3 0/1] mtk-vcodec: check the vp9 decoder buffer index from VPU

2017-03-07 Thread Wu-Cheng Li
From: Wu-Cheng Li 

v2: also check the result of vdec_if_decode in mtk_vdec_worker.
v3: set buffer status to VB2_BUF_STATE_ERROR. Move printk out of lock.

Wu-Cheng Li (1):
  mtk-vcodec: check the vp9 decoder buffer index from VPU.

 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 33 +-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
 .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 +
 drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
 4 files changed, 56 insertions(+), 7 deletions(-)

-- 
2.12.0.246.ga2ecc84866-goog



Re: [PATCH v2 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread Tiffany Lin
On Tue, 2017-03-07 at 22:42 +0800, Wu-Cheng Li wrote:
> From: Wu-Cheng Li 
> 
> VPU firmware has a bug and may return invalid buffer index for
> some vp9 videos. Check the buffer indexes before accessing the
> buffer.
> 
> Signed-off-by: Wu-Cheng Li 
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 23 ++-
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
>  .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 
> ++
>  drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
>  4 files changed, 48 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> index 502877a4b1df..8a9285a84d47 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> @@ -420,6 +420,11 @@ static void mtk_vdec_worker(struct work_struct *work)
>   dst_buf->index,
>   ret, res_chg);
>   src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
> + if (ret == -EIO) {
> + mutex_lock(>lock);
> + src_buf_info->error = true;
> + mutex_unlock(>lock);
> + }
>   v4l2_m2m_buf_done(_buf_info->vb, VB2_BUF_STATE_ERROR);
>   } else if (res_chg == false) {
>   /*
> @@ -1176,6 +1181,11 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer 
> *vb)
>  "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
> fail=%d, res_chg=%d",
>  ctx->id, src_buf->index,
>  src_mem.size, ret, res_chg);
> + if (ret == -EIO) {
> + mtk_v4l2_err("[%d] Unrecoverable error in 
> vdec_if_decode.",
> + ctx->id);
> + ctx->state = MTK_STATE_ABORT;
> + }
Should we set buf status to VB2_BUF_STATE_ERROR in this case?

>   return;
>   }
>  
> @@ -1217,14 +1227,17 @@ static void vb2ops_vdec_buf_finish(struct vb2_buffer 
> *vb)
>   struct vb2_v4l2_buffer *vb2_v4l2;
>   struct mtk_video_dec_buf *buf;
>  
> - if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> - return;
> -
>   vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
>   buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
>   mutex_lock(>lock);
> - buf->queued_in_v4l2 = false;
> - buf->queued_in_vb2 = false;
> + if (buf->error) {
> + mtk_v4l2_err("Unrecoverable error on buffer.");
Remove mtk_v4l2_err out of mutex_lock/mutex_unlock?


best regards,
Tiffany
> + ctx->state = MTK_STATE_ABORT;
> + }
> + if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
> + buf->queued_in_v4l2 = false;
> + buf->queued_in_vb2 = false;
> + }
>   mutex_unlock(>lock);
>  }
>  
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> index 362f5a85762e..dc4fc1df63c5 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
> @@ -50,6 +50,7 @@ struct vdec_fb {
>   * @queued_in_v4l2:  Capture buffer is in v4l2 driver, but not in vb2
>   *   queue yet
>   * @lastframe:   Intput buffer is last buffer - EOS
> + * @error:   An unrecoverable error occurs on this buffer.
>   * @frame_buffer:Decode status, and buffer information of Capture buffer
>   *
>   * Note : These status information help us track and debug buffer state
> @@ -63,6 +64,7 @@ struct mtk_video_dec_buf {
>   boolqueued_in_vb2;
>   boolqueued_in_v4l2;
>   boollastframe;
> + boolerror;
>   struct vdec_fb  frame_buffer;
>  };
>  
> diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
> b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> index e91a3b425b0c..5539b1853f16 100644
> --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> @@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, 
> struct vdec_fb **out_fb)
>   *out_fb = fb;
>  }
>  
> +static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
> + struct vdec_vp9_vsi *vsi) {
> + if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
> + mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.",
> + vsi->sf_frm_idx);
> + return -EIO;
> + }
> + if (vsi->frm_to_show_idx >= VP9_MAX_FRM_BUF_NUM) {
> + mtk_vcodec_err(inst, "Invalid vsi->frm_to_show_idx=%u.",
> + vsi->frm_to_show_idx);
> + return -EIO;
> + }
> + if (vsi->new_fb_idx 

Re: [bug report] [media] atmel-isc: add the isc pipeline function

2017-03-07 Thread Wu, Songjun

Hi Dan,

Thank you very much for your bug report.
Then I have question about 'error: we previously assumed 'fmt' could be 
null (see line 1480)'

Do you mean that the code should be written like 'if (fmt == NULL)'?

On 3/7/2017 08:17, Dan Carpenter wrote:

  1476  while (!v4l2_subdev_call(subdev, pad, enum_mbus_code,
  1477 NULL, _code)) {
  1478  mbus_code.index++;
  1479  fmt = find_format_by_code(mbus_code.code, );
  1480  if (!fmt)
 ^^^
Check for NULL.


Re: [PATCH] [media] atmel-isc: fix off-by-one comparison and out of bounds read issue

2017-03-07 Thread Wu, Songjun

Hi Colin,

Thank you for your comment.
It is a bug, will be fixed in the next patch.

On 3/7/2017 22:30, Colin King wrote:

From: Colin Ian King 

The are only HIST_ENTRIES worth of entries in  hist_entry however the
for-loop is iterating one too many times leasing to a read access off
the end off the array ctrls->hist_entry.  Fix this by iterating by
the correct number of times.

Detected by CoverityScan, CID#1415279 ("Out-of-bounds read")

Signed-off-by: Colin Ian King 
---
 drivers/media/platform/atmel/atmel-isc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index b380a7d..7dacf8c 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -1298,7 +1298,7 @@ static void isc_hist_count(struct isc_device *isc)
regmap_bulk_read(regmap, ISC_HIS_ENTRY, hist_entry, HIST_ENTRIES);

*hist_count = 0;
-   for (i = 0; i <= HIST_ENTRIES; i++)
+   for (i = 0; i < HIST_ENTRIES; i++)
*hist_count += i * (*hist_entry++);
 }




[PATCH 01/13] [media] dvb-frontends/stv0367: add flag to make i2c_gatectrl optional

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

There can be use cases (bridges, namely ddbridge) which will care about
gate control in a way that involves mutex_locks and remapped i2c_gatectrl
FE ops. If the demod driver (additionally) performs it's own gate control
and there's something else that already took the lock, locking again will
lead to kernel deadlocks, so add and check a conditional before triggering
gate_ctrl.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index fd49c43..fc80934 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -89,6 +89,8 @@ struct stv0367_state {
struct stv0367cab_state *cab_state;
/* DVB-T */
struct stv0367ter_state *ter_state;
+   /* flags for operation control */
+   u8 use_i2c_gatectrl;
 };
 
 struct st_register {
@@ -1827,10 +1829,10 @@ static int stv0367ter_set_frontend(struct dvb_frontend 
*fe)
stv0367ter_init(fe);
 
if (fe->ops.tuner_ops.set_params) {
-   if (fe->ops.i2c_gate_ctrl)
+   if (state->use_i2c_gatectrl && fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);
fe->ops.tuner_ops.set_params(fe);
-   if (fe->ops.i2c_gate_ctrl)
+   if (state->use_i2c_gatectrl && fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);
}
 
@@ -2321,6 +2323,9 @@ struct dvb_frontend *stv0367ter_attach(const struct 
stv0367_config *config,
state->fe.demodulator_priv = state;
state->chip_id = stv0367_readreg(state, 0xf000);
 
+   /* demod operation options */
+   state->use_i2c_gatectrl = 1;
+
dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
 
/* check if the demod is there */
@@ -3120,10 +3125,10 @@ static int stv0367cab_set_frontend(struct dvb_frontend 
*fe)
 
/* Tuner Frequency Setting */
if (fe->ops.tuner_ops.set_params) {
-   if (fe->ops.i2c_gate_ctrl)
+   if (state->use_i2c_gatectrl && fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);
fe->ops.tuner_ops.set_params(fe);
-   if (fe->ops.i2c_gate_ctrl)
+   if (state->use_i2c_gatectrl && fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);
}
 
@@ -3437,6 +3442,9 @@ struct dvb_frontend *stv0367cab_attach(const struct 
stv0367_config *config,
state->fe.demodulator_priv = state;
state->chip_id = stv0367_readreg(state, 0xf000);
 
+   /* demod operation options */
+   state->use_i2c_gatectrl = 1;
+
dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
 
/* check if the demod is there */
-- 
2.10.2



[PATCH 11/13] [media] dvb-frontends/stv0367: add Digital Devices compatibility

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

This - in conjunction with the previous changes - makes it possible to use
the STV0367 DVB-C/T demodulator driver with Digital Devices hardware having
this demodulator soldered on them (namely CineCTv6 bridges and some earlier
DuoFlex CT addon modules).

The changes do the following:

- add a third *_attach function which will make use of a third frontend_ops
  struct which announces both -C and -T support (the same as with DD's own
  driver stv0367dd). This is necessary to support both delivery systems
  on one FE without having to do large conversions to VB2 or the need to
  select either -C or -T mode via modparams and the like. Additionally,
  the frontend_ops point to new "glue" functions which will then call into
  the existing functionality depending on the active delivery system/demod
  state (all used functionality works almost OOTB).
- Demod initialisation has been ported from stv0367dd. DD's driver always
  does a full init of both OFDM and QAM cores, with some additional things.
  The active delivery system is remembered and upon switch, the Demod will
  be reconfigured to work in OFDM or QAM mode (that's what the ddb_setup_XX
  functions are used for). Note that in QAM mode, the DD demods work with
  an IC speed of 58Mhz. It's not very good to perform full reinits upon
  Demod mode changes since in very rare occasions this can lead to the I2C
  interface or the whole Demod to crash, requiring a powercycle, thus the
  flag to perform full reinit is set to disabled.
- A little enum is added for named identifiers of the current Demod state.

Initialisation code/register writes originate from stv0367dd. Permission
to reuse was formally granted by Ralph Metzler .

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 323 ++
 drivers/media/dvb-frontends/stv0367.h |  10 ++
 2 files changed, 333 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index ffc046a..db55063 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -46,6 +46,8 @@ module_param_named(i2c_debug, i2cdebug, int, 0644);
} while (0)
/* DVB-C */
 
+enum active_demod_state { demod_none, demod_ter, demod_cab };
+
 struct stv0367cab_state {
enum stv0367_cab_signal_typestate;
u32 mclk;
@@ -96,6 +98,7 @@ struct stv0367_state {
u8 deftabs;
u8 reinit_on_setfrontend;
u8 auto_if_khz;
+   enum active_demod_state activedemod;
 };
 
 #define RF_LOOKUP_TABLE_SIZE  31
@@ -2880,6 +2883,326 @@ struct dvb_frontend *stv0367cab_attach(const struct 
stv0367_config *config,
 }
 EXPORT_SYMBOL(stv0367cab_attach);
 
+/*
+ * Functions for operation on Digital Devices hardware
+ */
+
+static void stv0367ddb_setup_ter(struct stv0367_state *state)
+{
+   stv0367_writereg(state, R367TER_DEBUG_LT4, 0x00);
+   stv0367_writereg(state, R367TER_DEBUG_LT5, 0x00);
+   stv0367_writereg(state, R367TER_DEBUG_LT6, 0x00); /* R367CAB_CTRL_1 */
+   stv0367_writereg(state, R367TER_DEBUG_LT7, 0x00); /* R367CAB_CTRL_2 */
+   stv0367_writereg(state, R367TER_DEBUG_LT8, 0x00);
+   stv0367_writereg(state, R367TER_DEBUG_LT9, 0x00);
+
+   /* Tuner Setup */
+   /* Buffer Q disabled, I Enabled, unsigned ADC */
+   stv0367_writereg(state, R367TER_ANADIGCTRL, 0x89);
+   stv0367_writereg(state, R367TER_DUAL_AD12, 0x04); /* ADCQ disabled */
+
+   /* Clock setup */
+   /* PLL bypassed and disabled */
+   stv0367_writereg(state, R367TER_ANACTRL, 0x0D);
+   stv0367_writereg(state, R367TER_TOPCTRL, 0x00); /* Set OFDM */
+
+   /* IC runs at 54 MHz with a 27 MHz crystal */
+   stv0367_pll_setup(state, STV0367_ICSPEED_53125, state->config->xtal);
+
+   msleep(50);
+   /* PLL enabled and used */
+   stv0367_writereg(state, R367TER_ANACTRL, 0x00);
+
+   state->activedemod = demod_ter;
+}
+
+static void stv0367ddb_setup_cab(struct stv0367_state *state)
+{
+   stv0367_writereg(state, R367TER_DEBUG_LT4, 0x00);
+   stv0367_writereg(state, R367TER_DEBUG_LT5, 0x01);
+   stv0367_writereg(state, R367TER_DEBUG_LT6, 0x06); /* R367CAB_CTRL_1 */
+   stv0367_writereg(state, R367TER_DEBUG_LT7, 0x03); /* R367CAB_CTRL_2 */
+   stv0367_writereg(state, R367TER_DEBUG_LT8, 0x00);
+   stv0367_writereg(state, R367TER_DEBUG_LT9, 0x00);
+
+   /* Tuner Setup */
+   /* Buffer Q disabled, I Enabled, signed ADC */
+   stv0367_writereg(state, R367TER_ANADIGCTRL, 0x8B);
+   /* ADCQ disabled */
+   stv0367_writereg(state, R367TER_DUAL_AD12, 0x04);
+
+   /* Clock setup */
+   /* PLL bypassed and disabled */
+   stv0367_writereg(state, R367TER_ANACTRL, 0x0D);
+   /* Set QAM */
+   stv0367_writereg(state, R367TER_TOPCTRL, 0x10);
+
+   /* IC runs at 58 MHz with a 27 MHz crystal */
+   

[PATCH v3 3/6] documentation: media: Add documentation for new RGB and YUV bus formats

2017-03-07 Thread Neil Armstrong
Add documentation for added Bus Formats to describe RGB and YUS formats used
as input to the Synopsys DesignWare HDMI TX Controller.

Signed-off-by: Neil Armstrong 
---
 Documentation/media/uapi/v4l/subdev-formats.rst | 4992 ++-
 1 file changed, 3963 insertions(+), 1029 deletions(-)

diff --git a/Documentation/media/uapi/v4l/subdev-formats.rst 
b/Documentation/media/uapi/v4l/subdev-formats.rst
index d6152c9..feb55b5 100644
--- a/Documentation/media/uapi/v4l/subdev-formats.rst
+++ b/Documentation/media/uapi/v4l/subdev-formats.rst
@@ -114,7 +114,7 @@ The following tables list existing packed RGB formats.
 .. it switches to long table, and there's no way to override it.
 
 
-.. tabularcolumns:: 
|p{4.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|
+.. tabularcolumns:: 
|p{4.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|
 
 .. _v4l2-mbus-pixelcode-rgb:
 
@@ -127,7 +127,7 @@ The following tables list existing packed RGB formats.
 .. flat-table:: RGB formats
 :header-rows:  2
 :stub-columns: 0
-:widths: 36 7 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
2 2 2
+:widths: 36 7 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
 
 * - Identifier
   - Code
@@ -136,6 +136,22 @@ The following tables list existing packed RGB formats.
 * -
   -
   - Bit
+  - 47
+  - 46
+  - 45
+  - 44
+  - 43
+  - 42
+  - 41
+  - 40
+  - 39
+  - 38
+  - 37
+  - 36
+  - 35
+  - 34
+  - 33
+  - 32
   - 31
   - 30
   - 29
@@ -193,6 +209,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - r\ :sub:`3`
   - r\ :sub:`2`
   - r\ :sub:`1`
@@ -234,6 +266,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - 0
   - 0
   - 0
@@ -269,6 +317,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - g\ :sub:`3`
   - g\ :sub:`2`
   - g\ :sub:`1`
@@ -306,6 +370,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - g\ :sub:`3`
   - g\ :sub:`2`
   - g\ :sub:`1`
@@ -341,6 +421,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - 0
   - 0
   - 0
@@ -378,6 +474,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - 0
   - r\ :sub:`4`
   - r\ :sub:`3`
@@ -413,6 +525,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - g\ :sub:`2`
   - g\ :sub:`1`
   - g\ :sub:`0`
@@ -450,6 +578,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
   - g\ :sub:`2`
   - g\ :sub:`1`
   - g\ :sub:`0`
@@ -485,6 +629,22 @@ The following tables list existing packed RGB formats.
   -
   -
   -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -

[PATCH v3 6/6] drm: bridge: dw-hdmi: Move HPD handling to PHY operations

2017-03-07 Thread Neil Armstrong
The HDMI TX controller support HPD and RXSENSE signaling from the PHY
via it's STAT0 PHY interface, but some vendor PHYs can manage these
signals independently from the controller, thus these STAT0 handling
should be moved to PHY specific operations and become optional.

The existing STAT0 HPD and RXSENSE handling code is refactored into
a supplementaty set of default PHY operations that are used automatically
when the platform glue doesn't provide its own operations.

Signed-off-by: Neil Armstrong 
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 135 ++
 include/drm/bridge/dw_hdmi.h  |   5 ++
 2 files changed, 86 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 348311c..1c6cb46 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -1215,10 +1215,46 @@ static enum drm_connector_status 
dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi,
connector_status_connected : connector_status_disconnected;
 }
 
+static void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data,
+  bool force, bool disabled, bool rxsense)
+{
+   u8 old_mask = hdmi->phy_mask;
+
+   if (force || disabled || !rxsense)
+   hdmi->phy_mask |= HDMI_PHY_RX_SENSE;
+   else
+   hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE;
+
+   if (old_mask != hdmi->phy_mask)
+   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
+}
+
+static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data)
+{
+   /*
+* Configure the PHY RX SENSE and HPD interrupts polarities and clear
+* any pending interrupt.
+*/
+   hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
+   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
+   HDMI_IH_PHY_STAT0);
+
+   /* Enable cable hot plug irq. */
+   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
+
+   /* Clear and unmute interrupts. */
+   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
+   HDMI_IH_PHY_STAT0);
+   hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
+   HDMI_IH_MUTE_PHY_STAT0);
+}
+
 static const struct dw_hdmi_phy_ops dw_hdmi_synopsys_phy_ops = {
.init = dw_hdmi_phy_init,
.disable = dw_hdmi_phy_disable,
.read_hpd = dw_hdmi_phy_read_hpd,
+   .update_hpd = dw_hdmi_phy_update_hpd,
+   .setup_hpd = dw_hdmi_phy_setup_hpd,
 };
 
 /* 
-
@@ -1742,35 +1778,10 @@ static void dw_hdmi_update_power(struct dw_hdmi *hdmi)
  */
 static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi)
 {
-   u8 old_mask = hdmi->phy_mask;
-
-   if (hdmi->force || hdmi->disabled || !hdmi->rxsense)
-   hdmi->phy_mask |= HDMI_PHY_RX_SENSE;
-   else
-   hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE;
-
-   if (old_mask != hdmi->phy_mask)
-   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
-}
-
-static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi)
-{
-   /*
-* Configure the PHY RX SENSE and HPD interrupts polarities and clear
-* any pending interrupt.
-*/
-   hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
-   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
-   HDMI_IH_PHY_STAT0);
-
-   /* Enable cable hot plug irq. */
-   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
-
-   /* Clear and unmute interrupts. */
-   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
-   HDMI_IH_PHY_STAT0);
-   hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
-   HDMI_IH_MUTE_PHY_STAT0);
+   if (hdmi->phy.ops->update_hpd)
+   hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data,
+ hdmi->force, hdmi->disabled,
+ hdmi->rxsense);
 }
 
 static enum drm_connector_status
@@ -1962,6 +1973,41 @@ static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id)
return ret;
 }
 
+void __dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense)
+{
+   mutex_lock(>mutex);
+
+   if (!hdmi->disabled && !hdmi->force) {
+   /*
+* If the RX sense status indicates we're disconnected,
+* clear the software rxsense status.
+*/
+   if (!rx_sense)
+   hdmi->rxsense = false;
+
+   /*
+* Only set the software rxsense status when both
+* rxsense and hpd indicates we're connected.
+* This avoids what seems to be bad 

[PATCH 12/13] [media] tuners/tda18212: add flag for retrying tuner init on failure

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Taken from tda18212dd, first read after cold reset sometimes fails on some
cards, trying twice shall do the trick. This is the case with the STV0367
demods soldered on the CineCTv6 bridge boards and older DuoFlex CT modules.

All other users (configs) of the tda18212 are updated as well to be sure
they won't be affected at all by this change.

Signed-off-by: Daniel Scheller 
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c | 1 +
 drivers/media/tuners/tda18212.c  | 5 +
 drivers/media/tuners/tda18212.h  | 7 +++
 drivers/media/usb/dvb-usb-v2/anysee.c| 2 ++
 drivers/media/usb/em28xx/em28xx-dvb.c| 1 +
 5 files changed, 16 insertions(+)

diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c 
b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
index 2c0015b..03688ee 100644
--- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
+++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
@@ -111,6 +111,7 @@ static struct tda18212_config tda18212_conf = {
.if_dvbt_7 = 4150,
.if_dvbt_8 = 4500,
.if_dvbc = 5000,
+   .init_flags = 0,
 };
 
 int c8sectpfe_frontend_attach(struct dvb_frontend **fe,
diff --git a/drivers/media/tuners/tda18212.c b/drivers/media/tuners/tda18212.c
index 7b80683..2488537 100644
--- a/drivers/media/tuners/tda18212.c
+++ b/drivers/media/tuners/tda18212.c
@@ -220,6 +220,11 @@ static int tda18212_probe(struct i2c_client *client,
fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
 
ret = regmap_read(dev->regmap, 0x00, _id);
+
+   /* retry probe if desired */
+   if (ret && (cfg->init_flags & TDA18212_INIT_RETRY))
+   ret = regmap_read(dev->regmap, 0x00, _id);
+
dev_dbg(>client->dev, "chip_id=%02x\n", chip_id);
 
if (fe->ops.i2c_gate_ctrl)
diff --git a/drivers/media/tuners/tda18212.h b/drivers/media/tuners/tda18212.h
index 6391daf..717aa2c 100644
--- a/drivers/media/tuners/tda18212.h
+++ b/drivers/media/tuners/tda18212.h
@@ -23,6 +23,8 @@
 
 #include "dvb_frontend.h"
 
+#define TDA18212_INIT_RETRY(1 << 0)
+
 struct tda18212_config {
u16 if_dvbt_6;
u16 if_dvbt_7;
@@ -36,6 +38,11 @@ struct tda18212_config {
u16 if_atsc_qam;
 
/*
+* flags for tuner init control
+*/
+   u32 init_flags;
+
+   /*
 * pointer to DVB frontend
 */
struct dvb_frontend *fe;
diff --git a/drivers/media/usb/dvb-usb-v2/anysee.c 
b/drivers/media/usb/dvb-usb-v2/anysee.c
index 6795c0c..c35b66e 100644
--- a/drivers/media/usb/dvb-usb-v2/anysee.c
+++ b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -332,6 +332,7 @@ static struct tda18212_config anysee_tda18212_config = {
.if_dvbt_7 = 4150,
.if_dvbt_8 = 4150,
.if_dvbc = 5000,
+   .init_flags = 0,
 };
 
 static struct tda18212_config anysee_tda18212_config2 = {
@@ -342,6 +343,7 @@ static struct tda18212_config anysee_tda18212_config2 = {
.if_dvbt2_7 = 4000,
.if_dvbt2_8 = 4000,
.if_dvbc = 5000,
+   .init_flags = 0,
 };
 
 static struct cx24116_config anysee_cx24116_config = {
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index 82edd37..143efb0 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -380,6 +380,7 @@ static struct tda18271_config kworld_ub435q_v2_config = {
 static struct tda18212_config kworld_ub435q_v3_config = {
.if_atsc_vsb= 3600,
.if_atsc_qam= 3600,
+   .init_flags = 0,
 };
 
 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
-- 
2.10.2



[PATCH 10/13] [media] dvb-frontends/stv0367: add defaults for use w/DD-branded devices

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Digital Devices uses defaults tables in their stv0367dd demod driver
variant which differ in a few registers, at least enough that no stable
operation can be provided with the tables already present in the driver
(init succeeds and DVB reception works but at least when the driver is
reloaded using rmmod/modprobe, the demod goes into a crashed state in a
way it doesn't react on any I2C command anymore, while even more
side-effects may occur), so there's a good reason to better have another
set of defaults.

Defaults originating from the stv0367dd driver. Permission to reuse them
was formally granted by Ralph Metzler .

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367_defs.h | 610 -
 1 file changed, 609 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stv0367_defs.h 
b/drivers/media/dvb-frontends/stv0367_defs.h
index 53faad6..277d297 100644
--- a/drivers/media/dvb-frontends/stv0367_defs.h
+++ b/drivers/media/dvb-frontends/stv0367_defs.h
@@ -25,7 +25,8 @@
 #include "stv0367_regs.h"
 
 #define STV0367_DEFTAB_GENERIC 0
-#define STV0367_DEFTAB_MAX 1
+#define STV0367_DEFTAB_DDB 1
+#define STV0367_DEFTAB_MAX 2
 
 #define STV0367_TAB_TER0
 #define STV0367_TAB_CAB1
@@ -680,6 +681,611 @@ static const struct st_register def0367cab[] = {
{0x,0x00},
 };
 
+/**
+ *
+ * Defaults / Tables for Digital Devices C/T Cine/Flex devices
+ *
+ **/
+
+static const struct st_register def0367dd_ofdm[] = {
+   {R367TER_AGC2MAX,0xff},
+   {R367TER_AGC2MIN,0x00},
+   {R367TER_AGC1MAX,0xff},
+   {R367TER_AGC1MIN,0x00},
+   {R367TER_AGCR,   0xbc},
+   {R367TER_AGC2TH, 0x00},
+   {R367TER_AGCCTRL1,   0x85},
+   {R367TER_AGCCTRL2,   0x1f},
+   {R367TER_AGC1VAL1,   0x00},
+   {R367TER_AGC1VAL2,   0x00},
+   {R367TER_AGC2VAL1,   0x6f},
+   {R367TER_AGC2VAL2,   0x05},
+   {R367TER_AGC2PGA,0x00},
+   {R367TER_OVF_RATE1,  0x00},
+   {R367TER_OVF_RATE2,  0x00},
+   {R367TER_GAIN_SRC1,  0x2b},
+   {R367TER_GAIN_SRC2,  0x04},
+   {R367TER_INC_DEROT1, 0x55},
+   {R367TER_INC_DEROT2, 0x55},
+   {R367TER_PPM_CPAMP_DIR,  0x2c},
+   {R367TER_PPM_CPAMP_INV,  0x00},
+   {R367TER_FREESTFE_1, 0x00},
+   {R367TER_FREESTFE_2, 0x1c},
+   {R367TER_DCOFFSET,   0x00},
+   {R367TER_EN_PROCESS, 0x05},
+   {R367TER_SDI_SMOOTHER,   0x80},
+   {R367TER_FE_LOOP_OPEN,   0x1c},
+   {R367TER_FREQOFF1,   0x00},
+   {R367TER_FREQOFF2,   0x00},
+   {R367TER_FREQOFF3,   0x00},
+   {R367TER_TIMOFF1,0x00},
+   {R367TER_TIMOFF2,0x00},
+   {R367TER_EPQ,0x02},
+   {R367TER_EPQAUTO,0x01},
+   {R367TER_SYR_UPDATE, 0xf5},
+   {R367TER_CHPFREE,0x00},
+   {R367TER_PPM_STATE_MAC,  0x23},
+   {R367TER_INR_THRESHOLD,  0xff},
+   {R367TER_EPQ_TPS_ID_CELL,0xf9},
+   {R367TER_EPQ_CFG,0x00},
+   {R367TER_EPQ_STATUS, 0x01},
+   {R367TER_AUTORELOCK, 0x81},
+   {R367TER_BER_THR_VMSB,   0x00},
+   {R367TER_BER_THR_MSB,0x00},
+   {R367TER_BER_THR_LSB,0x00},
+   {R367TER_CCD,0x83},
+   {R367TER_SPECTR_CFG, 0x00},
+   {R367TER_CHC_DUMMY,  0x18},
+   {R367TER_INC_CTL,0x88},
+   {R367TER_INCTHRES_COR1,  0xb4},
+   {R367TER_INCTHRES_COR2,  0x96},
+   {R367TER_INCTHRES_DET1,  0x0e},
+   {R367TER_INCTHRES_DET2,  0x11},
+   {R367TER_IIR_CELLNB, 0x8d},
+   {R367TER_IIRCX_COEFF1_MSB,   0x00},
+   {R367TER_IIRCX_COEFF1_LSB,   0x00},
+   {R367TER_IIRCX_COEFF2_MSB,   0x09},
+   {R367TER_IIRCX_COEFF2_LSB,   0x18},
+   {R367TER_IIRCX_COEFF3_MSB,   0x14},
+   {R367TER_IIRCX_COEFF3_LSB,   0x9c},
+   {R367TER_IIRCX_COEFF4_MSB,   0x00},
+   {R367TER_IIRCX_COEFF4_LSB,   0x00},
+   {R367TER_IIRCX_COEFF5_MSB,   0x36},
+   {R367TER_IIRCX_COEFF5_LSB,   0x42},
+   {R367TER_FEPATH_CFG, 0x00},
+   {R367TER_PMC1_FUNC,  0x65},
+   {R367TER_PMC1_FOR,   0x00},
+   {R367TER_PMC2_FUNC,  0x00},
+   {R367TER_STATUS_ERR_DA,  0xe0},
+   {R367TER_DIG_AGC_R,

[PATCH v4] media: platform: Renesas IMR driver

2017-03-07 Thread Sergei Shtylyov
From: Konstantin Kozhevnikov 

The image renderer, or the distortion correction engine, is a drawing
processor with a simple instruction system capable of referencing video
capture data or data in an external memory as the 2D texture data and
performing texture mapping and drawing with respect to any shape that is
split into triangular objects.

This V4L2 memory-to-memory device driver only supports image renderer light
extended 4 (IMR-LX4) found in the R-Car gen3 SoCs; the R-Car gen2 support
can be added later...

[Sergei: merged 2 original patches, added the patch description, removed
unrelated parts,  added the binding document, ported the driver to the
modern kernel, renamed the UAPI header file and the  guard macros to match
the driver name, extended the copyrights, fixed up Kconfig prompt/depends/
help, made use of the BIT/GENMASK() macros, sorted #include's, removed
leading  dots and fixed grammar in the comments, fixed up indentation to
use tabs where possible, renamed DLSR, CMRCR.DY1{0|2}, and ICR bits to
match the manual, changed the prefixes of the CMRCR[2]/TRI{M|C}R bits/
fields to match the manual, removed non-existent TRIMR.D{Y|U}D{X|V}M bits,
added/used the IMR/{UV|CP}DPOR/SUSR bits/fields/shifts, separated the
register offset/bit #define's, sorted the instruction macros by opcode,
removed unsupported LINE instruction, masked the register address in
WTL[2]/WTS instruction macros, avoided setting reserved bits when writing
to CMRCCR[2]/TRIMCR, used the SR bits instead of a bare number, removed
*inline* from .c file, fixed lines over 80 columns, removed useless parens,
operators, casts, braces, variables, #include's, statements, and even 1
function, inserted empty line after declaration, removed extra empty lines,
reordered some local variable desclarations, removed calls to 4l2_err() on
kmalloc() failure, replaced '*' with 'x' in some format strings for
v4l2_dbg(), fixed the error returned by imr_default(), avoided code
duplication in the IRQ handler, used '__packed' for the UAPI structures,
enclosed the macro parameters in parens, exchanged the values of
IMR_MAP_AUTO{S|D}G macros.]

Signed-off-by: Konstantin Kozhevnikov 

Signed-off-by: Sergei Shtylyov 

---
This patch is against the 'media_tree.git' repo's 'master' branch.

Changes in version 4:
- added/used SUSR fields/shifts.

Changes in version 3:
- added/used the {UV|CP}DPOR fields/shifts;
- removed unsupported LINE instruction;
- replaced '*' with 'x' in the string passed to v4l2_dbg() in
  imr_dl_program_setup();
- switched to prepending the SoC model to "imr-lx4" in the "compatible" prop
  strings.

Changes in version 2:
- renamed the ICR bits to match the manual;
- added/used the IMR bits;
- changed the prefixes of the CMRCR[2]/TRI{M|C}R bits/fields to match the
  manual;
- renamed the CMRCR.DY1{0|2} bits to match the manual;
- removed non-existent TRIMR.D{Y|U}D{X|V}M bits;
- used the SR bits instead of a bare number;
- sorted the instruction macros by opcode, removing redundant parens;
- masked the register address in WTL[2]/WTS instruction macros;
- avoided setting reserved bits when writing to CMRCCR[2]/TRIMCR;
- mentioned the video capture data as a texture source in the binding and the
  patch description;
- documented the SoC specific "compatible" values;
- clarified the "interrupts" and "clocks" property text;
- updated the patch description.

 Documentation/devicetree/bindings/media/rcar_imr.txt |   27 
 drivers/media/platform/Kconfig   |   13 
 drivers/media/platform/Makefile  |1 
 drivers/media/platform/rcar_imr.c| 1944 +++
 include/uapi/linux/rcar_imr.h|   94 
 5 files changed, 2079 insertions(+)

Index: media_tree/Documentation/devicetree/bindings/media/rcar_imr.txt
===
--- /dev/null
+++ media_tree/Documentation/devicetree/bindings/media/rcar_imr.txt
@@ -0,0 +1,27 @@
+Renesas R-Car Image Renderer (Distortion Correction Engine)
+---
+
+The image renderer, or the distortion correction engine, is a drawing processor
+with a simple instruction system capable of referencing video capture data or
+data in an external memory as 2D texture data and performing texture mapping
+and drawing with respect to any shape that is split into triangular objects.
+
+Required properties:
+
+- compatible: "renesas,-imr-lx4", "renesas,imr-lx4" as a fallback for
+  the image renderer light extended 4 (IMR-LX4) found in the R-Car gen3 SoCs,
+  where the examples with  are:
+  - "renesas,r8a7795-imr-lx4" for R-Car H3,
+  - "renesas,r8a7796-imr-lx4" for R-Car M3-W.
+- reg: offset and length of the register block;
+- interrupts: single interrupt specifier;
+- clocks: single clock phandle/specifier pair.
+

[PATCH 09/13] [media] dvb-frontends/stv0367: fix symbol rate conditions in cab_SetQamSize()

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

The values used for comparing symbol rates and the resulting conditional
reg writes seem wrong (rates multiplied by ten), so fix those values.
While this doesn't seem to influence operation, it should be fixed anyway.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index fb41c7b..ffc046a 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -1838,11 +1838,11 @@ static enum stv0367cab_mod stv0367cab_SetQamSize(struct 
stv0367_state *state,
case FE_CAB_MOD_QAM64:
stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x82);
stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x5a);
-   if (SymbolRate > 4500) {
+   if (SymbolRate > 450) {
stv0367_writereg(state, R367CAB_FSM_STATE, 0xb0);
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa5);
-   } else if (SymbolRate > 2500) {
+   } else if (SymbolRate > 250) {
stv0367_writereg(state, R367CAB_FSM_STATE, 0xa0);
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa6);
@@ -1860,9 +1860,9 @@ static enum stv0367cab_mod stv0367cab_SetQamSize(struct 
stv0367_state *state,
stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x76);
stv0367_writereg(state, R367CAB_FSM_STATE, 0x90);
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xb1);
-   if (SymbolRate > 4500)
+   if (SymbolRate > 450)
stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa7);
-   else if (SymbolRate > 2500)
+   else if (SymbolRate > 250)
stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa6);
else
stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0x97);
@@ -1875,9 +1875,9 @@ static enum stv0367cab_mod stv0367cab_SetQamSize(struct 
stv0367_state *state,
stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x94);
stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x5a);
stv0367_writereg(state, R367CAB_FSM_STATE, 0xa0);
-   if (SymbolRate > 4500)
+   if (SymbolRate > 450)
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
-   else if (SymbolRate > 2500)
+   else if (SymbolRate > 250)
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
else
stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xd1);
-- 
2.10.2



[PATCH 03/13] [media] dvb-frontends/stv0367: refactor defaults table handling

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Change defaults table writing so tables can be of dynamic length without
having to keep track of their lengths by adding and evaluating an end
marker (reg 0x), also move table writing to a dedicated function to
remove code duplication. Additionally mark st_register tables const since
they're used read-only.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c  | 30 --
 drivers/media/dvb-frontends/stv0367_regs.h |  4 
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index 0064d9d..5ed52ec 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -99,7 +99,7 @@ struct st_register {
 };
 
 /* values for STV4100 XTAL=30M int clk=53.125M*/
-static struct st_register def0367ter[STV0367TER_NBREGS] = {
+static const struct st_register def0367ter[] = {
{R367TER_ID,0x60},
{R367TER_I2CRPT,0xa0},
/* {R367TER_I2CRPT, 0x22},*/
@@ -546,6 +546,7 @@ static struct st_register def0367ter[STV0367TER_NBREGS] = {
{R367TER_DEBUG_LT7, 0x00},
{R367TER_DEBUG_LT8, 0x00},
{R367TER_DEBUG_LT9, 0x00},
+   {0x,0x00},
 };
 
 #define RF_LOOKUP_TABLE_SIZE  31
@@ -573,7 +574,7 @@ static const s32 
stv0367cab_RF_LookUp2[RF_LOOKUP_TABLE2_SIZE][RF_LOOKUP_TABLE2_S
}
 };
 
-static struct st_register def0367cab[STV0367CAB_NBREGS] = {
+static const struct st_register def0367cab[] = {
{R367CAB_ID,0x60},
{R367CAB_I2CRPT,0xa0},
/*{R367CAB_I2CRPT,  0x22},*/
@@ -762,6 +763,7 @@ static struct st_register def0367cab[STV0367CAB_NBREGS] = {
{R367CAB_T_O_ID_1,  0x00},
{R367CAB_T_O_ID_2,  0x00},
{R367CAB_T_O_ID_3,  0x00},
+   {0x,0x00},
 };
 
 static
@@ -901,6 +903,20 @@ static u8 stv0367_getbits(u8 reg, u32 label)
return (reg & mask) >> pos;
 }
 #endif
+
+static void stv0367_write_table(struct stv0367_state *state,
+   const struct st_register *deftab)
+{
+   int i = 0;
+
+   while (1) {
+   if (!deftab[i].addr)
+   break;
+   stv0367_writereg(state, deftab[i].addr, deftab[i].value);
+   i++;
+   }
+}
+
 static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
struct stv0367_state *state = fe->demodulator_priv;
@@ -1540,15 +1556,12 @@ static int stv0367ter_init(struct dvb_frontend *fe)
 {
struct stv0367_state *state = fe->demodulator_priv;
struct stv0367ter_state *ter_state = state->ter_state;
-   int i;
 
dprintk("%s:\n", __func__);
 
ter_state->pBER = 0;
 
-   for (i = 0; i < STV0367TER_NBREGS; i++)
-   stv0367_writereg(state, def0367ter[i].addr,
-   def0367ter[i].value);
+   stv0367_write_table(state, def0367ter);
 
switch (state->config->xtal) {
/*set internal freq to 53.125MHz */
@@ -2782,13 +2795,10 @@ static int stv0367cab_init(struct dvb_frontend *fe)
 {
struct stv0367_state *state = fe->demodulator_priv;
struct stv0367cab_state *cab_state = state->cab_state;
-   int i;
 
dprintk("%s:\n", __func__);
 
-   for (i = 0; i < STV0367CAB_NBREGS; i++)
-   stv0367_writereg(state, def0367cab[i].addr,
-   def0367cab[i].value);
+   stv0367_write_table(state, def0367cab);
 
switch (state->config->ts_mode) {
case STV0367_DVBCI_CLOCK:
diff --git a/drivers/media/dvb-frontends/stv0367_regs.h 
b/drivers/media/dvb-frontends/stv0367_regs.h
index 1d15862..cc66d93 100644
--- a/drivers/media/dvb-frontends/stv0367_regs.h
+++ b/drivers/media/dvb-frontends/stv0367_regs.h
@@ -2639,8 +2639,6 @@
 #defineR367TER_DEBUG_LT9   0xf405
 #defineF367TER_F_DEBUG_LT9 0xf40500ff
 
-#define STV0367TER_NBREGS  445
-
 /* ID */
 #defineR367CAB_ID  0xf000
 #defineF367CAB_IDENTIFICATIONREGISTER  0xf0ff
@@ -3605,6 +3603,4 @@
 #defineR367CAB_T_O_ID_30xf4d3
 #defineF367CAB_TS_ID_I_H   0xf4d300ff
 
-#define STV0367CAB_NBREGS  187
-
 #endif
-- 
2.10.2



[PATCH 13/13] [media] ddbridge: support STV0367-based cards and modules

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

This adds detection and activation for STV0367-based tuner hardware (namely
CineCTv6 bridge cards and older DuoFlex CT addon modules). Utilises the
extended stv0367 demod driver, and needs the init_retry when attaching the
TDA18212 tuner.

TDA18212 i2c_client/regmap-api code was originally implemented by
Antti Palosaari  in a variant to update the ddbridge code
from the vendor dddvb package (formal ack for these parts received).
Original patch at [1].

Signed-off-by: Daniel Scheller 

[1] https://patchwork.linuxtv.org/patch/25146/
---
 drivers/media/pci/ddbridge/Kconfig |   3 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 127 +
 drivers/media/pci/ddbridge/ddbridge.h  |   1 +
 3 files changed, 131 insertions(+)

diff --git a/drivers/media/pci/ddbridge/Kconfig 
b/drivers/media/pci/ddbridge/Kconfig
index 44e5dc1..16ede23 100644
--- a/drivers/media/pci/ddbridge/Kconfig
+++ b/drivers/media/pci/ddbridge/Kconfig
@@ -6,6 +6,8 @@ config DVB_DDBRIDGE
select DVB_STV090x if MEDIA_SUBDRV_AUTOSELECT
select DVB_DRXK if MEDIA_SUBDRV_AUTOSELECT
select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
---help---
  Support for cards with the Digital Devices PCI express bridge:
  - Octopus PCIe Bridge
@@ -14,5 +16,6 @@ config DVB_DDBRIDGE
  - DuoFlex S2 Octopus
  - DuoFlex CT Octopus
  - cineS2(v6)
+ - CineCTv6 and DuoFlex CT (STV0367-based)
 
  Say Y if you own such a card and want to use it.
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 340cff0..5082340 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -39,6 +39,9 @@
 #include "stv090x.h"
 #include "lnbh24.h"
 #include "drxk.h"
+#include "stv0367.h"
+#include "stv0367_priv.h"
+#include "tda18212.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
@@ -609,6 +612,92 @@ static int tuner_attach_tda18271(struct ddb_input *input)
 
/**/
 
/**/
 
+static struct stv0367_config ddb_stv0367_config[] = {
+   {
+   .demod_address = 0x1f,
+   .xtal = 2700,
+   .if_khz = 0,
+   .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
+   .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
+   .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
+   }, {
+   .demod_address = 0x1e,
+   .xtal = 2700,
+   .if_khz = 0,
+   .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
+   .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
+   .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
+   },
+};
+
+static int demod_attach_stv0367(struct ddb_input *input)
+{
+   struct i2c_adapter *i2c = >port->i2c->adap;
+
+   /* attach frontend */
+   input->fe = dvb_attach(stv0367ddb_attach,
+   _stv0367_config[(input->nr & 1)], i2c);
+
+   if (!input->fe) {
+   printk(KERN_ERR "stv0367ddb_attach failed (not found?)\n");
+   return -ENODEV;
+   }
+
+   input->fe->sec_priv = input;
+   input->gate_ctrl = input->fe->ops.i2c_gate_ctrl;
+   input->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
+
+   return 0;
+}
+
+static int tuner_attach_tda18212(struct ddb_input *input)
+{
+   struct i2c_adapter *adapter = >port->i2c->adap;
+   struct i2c_client *client;
+   struct tda18212_config config = {
+   .fe = input->fe,
+   .if_dvbt_6 = 3550,
+   .if_dvbt_7 = 3700,
+   .if_dvbt_8 = 4150,
+   .if_dvbt2_6 = 3250,
+   .if_dvbt2_7 = 4000,
+   .if_dvbt2_8 = 4000,
+   .if_dvbc = 5000,
+   .init_flags = TDA18212_INIT_RETRY,
+   };
+   struct i2c_board_info board_info = {
+   .type = "tda18212",
+   .platform_data = ,
+   };
+
+   if (input->nr & 1)
+   board_info.addr = 0x63;
+   else
+   board_info.addr = 0x60;
+
+   request_module(board_info.type);
+
+   client = i2c_new_device(adapter, _info);
+   if (client == NULL || client->dev.driver == NULL)
+   goto err;
+
+   if (!try_module_get(client->dev.driver->owner)) {
+   i2c_unregister_device(client);
+   goto err;
+   }
+
+   input->i2c_client[0] = client;
+
+   return 0;
+err:
+   printk(KERN_INFO "TDA18212 tuner not found. Device is not fully 
operational.\n");
+   return -ENODEV;
+}
+
+/**/

[PATCH v3 2/6] media: uapi: Add RGB and YUV bus formats for Synopsys HDMI TX Controller

2017-03-07 Thread Neil Armstrong
In order to describe the RGB and YUB bus formats used to feed the
Synopsys DesignWare HDMI TX Controller, add missing formats to the
list of Bus Formats.

Documentation for these formats is added in a separate patch.

Signed-off-by: Neil Armstrong 
---
 include/uapi/linux/media-bus-format.h | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/media-bus-format.h 
b/include/uapi/linux/media-bus-format.h
index 2168759..7cc820b 100644
--- a/include/uapi/linux/media-bus-format.h
+++ b/include/uapi/linux/media-bus-format.h
@@ -33,7 +33,7 @@
 
 #define MEDIA_BUS_FMT_FIXED0x0001
 
-/* RGB - next is   0x1018 */
+/* RGB - next is   0x101b */
 #define MEDIA_BUS_FMT_RGB444_1X12  0x1016
 #define MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE  0x1001
 #define MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE  0x1002
@@ -57,8 +57,11 @@
 #define MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA   0x1012
 #define MEDIA_BUS_FMT_ARGB_1X320x100d
 #define MEDIA_BUS_FMT_RGB888_1X32_PADHI0x100f
+#define MEDIA_BUS_FMT_RGB101010_1X30   0x1018
+#define MEDIA_BUS_FMT_RGB121212_1X36   0x1019
+#define MEDIA_BUS_FMT_RGB161616_1X48   0x101a
 
-/* YUV (including grey) - next is  0x2026 */
+/* YUV (including grey) - next is  0x202c */
 #define MEDIA_BUS_FMT_Y8_1X8   0x2001
 #define MEDIA_BUS_FMT_UV8_1X8  0x2015
 #define MEDIA_BUS_FMT_UYVY8_1_5X8  0x2002
@@ -90,12 +93,18 @@
 #define MEDIA_BUS_FMT_YVYU10_1X20  0x200e
 #define MEDIA_BUS_FMT_VUY8_1X240x2024
 #define MEDIA_BUS_FMT_YUV8_1X240x2025
+#define MEDIA_BUS_FMT_UYVY8_1_1X24 0x2026
 #define MEDIA_BUS_FMT_UYVY12_1X24  0x2020
 #define MEDIA_BUS_FMT_VYUY12_1X24  0x2021
 #define MEDIA_BUS_FMT_YUYV12_1X24  0x2022
 #define MEDIA_BUS_FMT_YVYU12_1X24  0x2023
 #define MEDIA_BUS_FMT_YUV10_1X30   0x2016
+#define MEDIA_BUS_FMT_UYVY10_1_1X300x2027
 #define MEDIA_BUS_FMT_AYUV8_1X32   0x2017
+#define MEDIA_BUS_FMT_UYVY12_1_1X360x2028
+#define MEDIA_BUS_FMT_YUV12_1X36   0x2029
+#define MEDIA_BUS_FMT_YUV16_1X48   0x202a
+#define MEDIA_BUS_FMT_UYVY16_1_1X480x202b
 
 /* Bayer - next is 0x3021 */
 #define MEDIA_BUS_FMT_SBGGR8_1X8   0x3001
-- 
1.9.1



[PATCH 05/13] [media] dvb-frontends/stv0367: make PLLSETUP a function, add 58MHz IC speed

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

This moves the PLL SETUP code from stv0367ter_init() into a dedicated
function, and also make it possible to configure 58Mhz IC speed at
27MHz Xtal (used on STV0367-based DDB cards/modules in QAM mode).

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 73 +++
 drivers/media/dvb-frontends/stv0367.h |  3 ++
 2 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index 5b52673..da10d9a 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -271,6 +271,53 @@ static void stv0367_write_table(struct stv0367_state 
*state,
}
 }
 
+static void stv0367_pll_setup(struct stv0367_state *state,
+   u32 icspeed, u32 xtal)
+{
+   /* note on regs: R367TER_* and R367CAB_* defines each point to
+* 0xf0d8, so just use R367TER_ for both cases
+*/
+
+   switch (icspeed) {
+   case STV0367_ICSPEED_58000:
+   switch (xtal) {
+   default:
+   case 2700:
+   dprintk("STV0367 SetCLKgen for 58MHz IC and 27Mhz 
crystal\n");
+   /* PLLMDIV: 27, PLLNDIV: 232 */
+   stv0367_writereg(state, R367TER_PLLMDIV, 0x1b);
+   stv0367_writereg(state, R367TER_PLLNDIV, 0xe8);
+   break;
+   }
+   break;
+   default:
+   case STV0367_ICSPEED_53125:
+   switch (xtal) {
+   /* set internal freq to 53.125MHz */
+   case 1600:
+   stv0367_writereg(state, R367TER_PLLMDIV, 0x2);
+   stv0367_writereg(state, R367TER_PLLNDIV, 0x1b);
+   break;
+   case 2500:
+   stv0367_writereg(state, R367TER_PLLMDIV, 0xa);
+   stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
+   break;
+   default:
+   case 2700:
+   dprintk("FE_STV0367TER_SetCLKgen for 27Mhz\n");
+   stv0367_writereg(state, R367TER_PLLMDIV, 0x1);
+   stv0367_writereg(state, R367TER_PLLNDIV, 0x8);
+   break;
+   case 3000:
+   stv0367_writereg(state, R367TER_PLLMDIV, 0xc);
+   stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
+   break;
+   }
+   }
+
+   stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
+}
+
 static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
struct stv0367_state *state = fe->demodulator_priv;
@@ -918,31 +965,7 @@ static int stv0367ter_init(struct dvb_frontend *fe)
stv0367_write_table(state,
stv0367_deftabs[state->deftabs][STV0367_TAB_TER]);
 
-   switch (state->config->xtal) {
-   /*set internal freq to 53.125MHz */
-   case 1600:
-   stv0367_writereg(state, R367TER_PLLMDIV, 0x2);
-   stv0367_writereg(state, R367TER_PLLNDIV, 0x1b);
-   stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
-   break;
-   case 2500:
-   stv0367_writereg(state, R367TER_PLLMDIV, 0xa);
-   stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
-   stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
-   break;
-   default:
-   case 2700:
-   dprintk("FE_STV0367TER_SetCLKgen for 27Mhz\n");
-   stv0367_writereg(state, R367TER_PLLMDIV, 0x1);
-   stv0367_writereg(state, R367TER_PLLNDIV, 0x8);
-   stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
-   break;
-   case 3000:
-   stv0367_writereg(state, R367TER_PLLMDIV, 0xc);
-   stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
-   stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
-   break;
-   }
+   stv0367_pll_setup(state, STV0367_ICSPEED_53125, state->config->xtal);
 
stv0367_writereg(state, R367TER_I2CRPT, 0xa0);
stv0367_writereg(state, R367TER_ANACTRL, 0x00);
diff --git a/drivers/media/dvb-frontends/stv0367.h 
b/drivers/media/dvb-frontends/stv0367.h
index 26c38a0..aaa0236 100644
--- a/drivers/media/dvb-frontends/stv0367.h
+++ b/drivers/media/dvb-frontends/stv0367.h
@@ -25,6 +25,9 @@
 #include 
 #include "dvb_frontend.h"
 
+#define STV0367_ICSPEED_53125  53125000
+#define STV0367_ICSPEED_58000  5800
+
 struct stv0367_config {
u8 demod_address;
u32 xtal;
-- 
2.10.2



[PATCH 06/13] [media] dvb-frontends/stv0367: make full reinit on set_frontend() optional

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Every time dvb_frontend_ops.set_frontend() is called, an almost full reinit
of the demodulator will be performed. While this might cause a slight delay
when switching channels due to all involved tables being rewritten, it can
even be dangerous in certain causes in that the demod may lock up and
requires to be powercycled (this can happen on Digital Devices hardware).
So this adds a flag if it should be done, and to not change behaviour with
existing card support, it'll be enabled in all cases.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index da10d9a..9370afa 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -93,6 +93,7 @@ struct stv0367_state {
/* flags for operation control */
u8 use_i2c_gatectrl;
u8 deftabs;
+   u8 reinit_on_setfrontend;
 };
 
 #define RF_LOOKUP_TABLE_SIZE  31
@@ -1217,7 +1218,8 @@ static int stv0367ter_set_frontend(struct dvb_frontend 
*fe)
s8 num_trials, index;
u8 SenseTrials[] = { INVERSION_ON, INVERSION_OFF };
 
-   stv0367ter_init(fe);
+   if (state->reinit_on_setfrontend)
+   stv0367ter_init(fe);
 
if (fe->ops.tuner_ops.set_params) {
if (state->use_i2c_gatectrl && fe->ops.i2c_gate_ctrl)
@@ -1717,6 +1719,7 @@ struct dvb_frontend *stv0367ter_attach(const struct 
stv0367_config *config,
/* demod operation options */
state->use_i2c_gatectrl = 1;
state->deftabs = STV0367_DEFTAB_GENERIC;
+   state->reinit_on_setfrontend = 1;
 
dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
 
@@ -2511,7 +2514,8 @@ static int stv0367cab_set_frontend(struct dvb_frontend 
*fe)
break;
}
 
-   stv0367cab_init(fe);
+   if (state->reinit_on_setfrontend)
+   stv0367cab_init(fe);
 
/* Tuner Frequency Setting */
if (fe->ops.tuner_ops.set_params) {
@@ -2835,6 +2839,7 @@ struct dvb_frontend *stv0367cab_attach(const struct 
stv0367_config *config,
/* demod operation options */
state->use_i2c_gatectrl = 1;
state->deftabs = STV0367_DEFTAB_GENERIC;
+   state->reinit_on_setfrontend = 1;
 
dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
 
-- 
2.10.2



[PATCH 07/13] [media] dvb-frontends/stv0367: support reading if_khz from tuner config

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Currently, if_khz is set and provided using the configuration var in
struct stv0367_config. However, in some constellations, the value might be
different for differing channel bandwidths or even -T and -C operation.
When e.g. used in conjunction with TDA18212 tuners, the tuner frontend
might be aware of the different freqs. This factors if_khz retrieval in a
function, which checks a new flag if an automatic retrieval attempt should
be made, and if the tuner provides it, use it whenever needed.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 45 +--
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index 9370afa..74fee3f 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -94,6 +94,7 @@ struct stv0367_state {
u8 use_i2c_gatectrl;
u8 deftabs;
u8 reinit_on_setfrontend;
+   u8 auto_if_khz;
 };
 
 #define RF_LOOKUP_TABLE_SIZE  31
@@ -319,6 +320,17 @@ static void stv0367_pll_setup(struct stv0367_state *state,
stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
 }
 
+static int stv0367_get_if_khz(struct stv0367_state *state, u32 *ifkhz)
+{
+   if (state->auto_if_khz && state->fe.ops.tuner_ops.get_if_frequency) {
+   state->fe.ops.tuner_ops.get_if_frequency(>fe, ifkhz);
+   *ifkhz = *ifkhz / 1000; /* hz -> khz */
+   } else
+   *ifkhz = state->config->if_khz;
+
+   return 0;
+}
+
 static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
struct stv0367_state *state = fe->demodulator_priv;
@@ -992,10 +1004,12 @@ static int stv0367ter_algo(struct dvb_frontend *fe)
u8 /*constell,*/ counter;
s8 step;
s32 timing_offset = 0;
-   u32 trl_nomrate = 0, InternalFreq = 0, temp = 0;
+   u32 trl_nomrate = 0, InternalFreq = 0, temp = 0, ifkhz = 0;
 
dprintk("%s:\n", __func__);
 
+   stv0367_get_if_khz(state, );
+
ter_state->frequency = p->frequency;
ter_state->force = FE_TER_FORCENONE
+ stv0367_readbits(state, F367TER_FORCE) * 2;
@@ -1098,8 +1112,7 @@ static int stv0367ter_algo(struct dvb_frontend *fe)
stv0367_readbits(state, F367TER_GAIN_SRC_LO);
 
temp = (int)
-   ((InternalFreq - state->config->if_khz) * (1 << 16)
-   / (InternalFreq));
+   ((InternalFreq - ifkhz) * (1 << 16) / (InternalFreq));
 
dprintk("DEROT temp=0x%x\n", temp);
stv0367_writebits(state, F367TER_INC_DEROT_HI, temp / 256);
@@ -1720,6 +1733,7 @@ struct dvb_frontend *stv0367ter_attach(const struct 
stv0367_config *config,
state->use_i2c_gatectrl = 1;
state->deftabs = STV0367_DEFTAB_GENERIC;
state->reinit_on_setfrontend = 1;
+   state->auto_if_khz = 0;
 
dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
 
@@ -2229,7 +2243,7 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct 
stv0367_state *state,
 {
struct stv0367cab_state *cab_state = state->cab_state;
enum stv0367_cab_signal_type signalType = FE_CAB_NOAGC;
-   u32 QAMFEC_Lock, QAM_Lock, u32_tmp,
+   u32 QAMFEC_Lock, QAM_Lock, u32_tmp, ifkhz,
LockTime, TRLTimeOut, AGCTimeOut, CRLSymbols,
CRLTimeOut, EQLTimeOut, DemodTimeOut, FECTimeOut;
u8  TrackAGCAccum;
@@ -2237,6 +2251,8 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct 
stv0367_state *state,
 
dprintk("%s:\n", __func__);
 
+   stv0367_get_if_khz(state, );
+
/* Timeouts calculation */
/* A max lock time of 25 ms is allowed for delayed AGC */
AGCTimeOut = 25;
@@ -2315,7 +2331,7 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct 
stv0367_state *state,
/* The sweep function is never used, Sweep rate must be set to 0 */
/* Set the derotator frequency in Hz */
stv0367cab_set_derot_freq(state, cab_state->adc_clk,
-   (1000 * (s32)state->config->if_khz + cab_state->derot_offset));
+   (1000 * (s32)ifkhz + cab_state->derot_offset));
/* Disable the Allpass Filter when the symbol rate is out of range */
if ((p->symbol_rate > 1080) | (p->symbol_rate < 180)) {
stv0367_writebits(state, F367CAB_ADJ_EN, 0);
@@ -2405,17 +2421,17 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct 
stv0367_state *state,
F367CAB_QUAD_INV);
 #if 0
 /* not clear for me */
-   if (state->config->if_khz != 0) {
-   if (state->config->if_khz > cab_state->adc_clk / 1000) {
+   if (ifkhz != 0) {
+   if (ifkhz > cab_state->adc_clk / 1000) {
   

[PATCH 08/13] [media] dvb-frontends/stv0367: selectable QAM FEC Lock status register

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

In some configurations (due to different PIN config, wiring or so), the
QAM FECLock might be signalled using a different register than
F367CAB_QAMFEC_LOCK (e.g. F367CAB_DESCR_SYNCSTATE on Digital Devices hw),
so make that register selectable.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index 74fee3f..fb41c7b 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -57,6 +57,7 @@ struct stv0367cab_state {
u32 freq_khz;   /* found frequency (in kHz) */
u32 symbol_rate;/* found symbol rate (in Bds)   */
enum fe_spectral_inversion spect_inv; /* Spectrum Inversion */
+   u32 qamfec_status_reg;  /* status reg to poll for FEC Lock */
 };
 
 struct stv0367ter_state {
@@ -2145,7 +2146,8 @@ static int stv0367cab_read_status(struct dvb_frontend *fe,
 
*status = 0;
 
-   if (stv0367_readbits(state, F367CAB_QAMFEC_LOCK)) {
+   if (stv0367_readbits(state, (state->cab_state->qamfec_status_reg ?
+   state->cab_state->qamfec_status_reg : F367CAB_QAMFEC_LOCK))) {
*status |= FE_HAS_LOCK;
dprintk("%s: stv0367 has locked\n", __func__);
}
@@ -2410,7 +2412,9 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct 
stv0367_state *state,
usleep_range(5000, 7000);
LockTime += 5;
QAMFEC_Lock = stv0367_readbits(state,
-   F367CAB_QAMFEC_LOCK);
+   (state->cab_state->qamfec_status_reg ?
+   state->cab_state->qamfec_status_reg :
+   F367CAB_QAMFEC_LOCK));
} while (!QAMFEC_Lock && (LockTime < FECTimeOut));
} else
QAMFEC_Lock = 0;
@@ -2849,6 +2853,7 @@ struct dvb_frontend *stv0367cab_attach(const struct 
stv0367_config *config,
state->i2c = i2c;
state->config = config;
cab_state->search_range = 28;
+   cab_state->qamfec_status_reg = F367CAB_QAMFEC_LOCK;
state->cab_state = cab_state;
state->fe.ops = stv0367cab_ops;
state->fe.demodulator_priv = state;
-- 
2.10.2



[PATCH 00/13] stv0367/ddbridge: support CTv6/FlexCT hardware

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

These patches enhance the functionality of dvb-frontends/stv0367 to work
with Digital Devices hardware driven by the ST STV0367 demodulator chip
and adds probe & attach bits to ddbridge to make use of them, effectively
enabling full support for CineCTv6 PCIe bridges and (older) DuoFlex CT
addon modules.

While the stv0367 code basically works with the DD hardware (e.g. setup
of demodulation works for both -C and -T delivery systems), some bits
(mostly initialisation) have to be done differently. Also, the static
if_khz configuration is not sufficient as the TDA18212 tuner works at
different IF speeds depending on the delivery system and carrier
bandwidth, so functionality is added to read that speed from the tuner.

The most important part is the addition of register default tabs for
the DD boards, the DD demod initialisation code and the automated
operation mode switch (OFDM vs. QAM) to be able to provide both systems
in one DVB frontend. Everything else is provided by the existing code
or the existing code is enhanced where it didn't suffice. So instead
of duplicating the driver, the existing one is reused. Patches are
laid out in a way to add each enhancement in small increments so they
should be fairly easy to review.

A note on the i2c_gatectrl flag: The exact reason why this is neccessary
isn't known, but all C/T demods supported by the official vendorprovided
driver does the mutex_lock thing, so I'd prefer to not diverge from that
behaviour.

Checkpatch complains about some minor style issues, however the patches
were cleaned up beforehand and - where it still complains - match the
rest of the code style throughout the respective files.

In patches where code parts have been picked from other places, proper
credits to the original author is given and permissions where granted
beforehand.

Resulting STV0367/DD support was successfully tested with TVHeadend
and VDR setups by some users, with -C and -T combinations and two+four
port tuner setups (CTv6 with and without attached CT modules).

Apologizes if anything regarding the patch submission is/went wrong,
as this is my first time contribution to OSS via patch emails.

Daniel Scheller (13):
  [media] dvb-frontends/stv0367: add flag to make i2c_gatectrl optional
  [media] dvb-frontends/stv0367: print CPAMP status only if stv_debug is
enabled
  [media] dvb-frontends/stv0367: refactor defaults table handling
  [media] dvb-frontends/stv0367: move out tables, support multiple tab
variants
  [media] dvb-frontends/stv0367: make PLLSETUP a function, add 58MHz IC
speed
  [media] dvb-frontends/stv0367: make full reinit on set_frontend()
optional
  [media] dvb-frontends/stv0367: support reading if_khz from tuner
config
  [media] dvb-frontends/stv0367: selectable QAM FEC Lock status register
  [media] dvb-frontends/stv0367: fix symbol rate conditions in
cab_SetQamSize()
  [media] dvb-frontends/stv0367: add defaults for use w/DD-branded
devices
  [media] dvb-frontends/stv0367: add Digital Devices compatibility
  [media] tuners/tda18212: add flag for retrying tuner init on failure
  [media] ddbridge: support STV0367-based cards and modules

 drivers/media/dvb-frontends/stv0367.c  | 1167 +++---
 drivers/media/dvb-frontends/stv0367.h  |   13 +
 drivers/media/dvb-frontends/stv0367_defs.h | 1301 
 drivers/media/dvb-frontends/stv0367_regs.h |4 -
 drivers/media/pci/ddbridge/Kconfig |3 +
 drivers/media/pci/ddbridge/ddbridge-core.c |  127 ++
 drivers/media/pci/ddbridge/ddbridge.h  |1 +
 .../media/platform/sti/c8sectpfe/c8sectpfe-dvb.c   |1 +
 drivers/media/tuners/tda18212.c|5 +
 drivers/media/tuners/tda18212.h|7 +
 drivers/media/usb/dvb-usb-v2/anysee.c  |2 +
 drivers/media/usb/em28xx/em28xx-dvb.c  |1 +
 12 files changed, 1920 insertions(+), 712 deletions(-)
 create mode 100644 drivers/media/dvb-frontends/stv0367_defs.h

-- 
2.10.2



[PATCH 04/13] [media] dvb-frontends/stv0367: move out tables, support multiple tab variants

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

Move the *ter and *cab st_register tables into a separate header file and
additionally organize them via a multidimensional array, allowing to add
more tables with differing init values, and also prepare for a base init
table which should contain general setup values. Also add a state var to
store the table triplet to be used.

Also fixes three minor style problems reported by checkpatch.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c  | 658 +--
 drivers/media/dvb-frontends/stv0367_defs.h | 693 +
 2 files changed, 701 insertions(+), 650 deletions(-)
 create mode 100644 drivers/media/dvb-frontends/stv0367_defs.h

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index 5ed52ec..5b52673 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -26,6 +26,7 @@
 #include 
 
 #include "stv0367.h"
+#include "stv0367_defs.h"
 #include "stv0367_regs.h"
 #include "stv0367_priv.h"
 
@@ -91,462 +92,7 @@ struct stv0367_state {
struct stv0367ter_state *ter_state;
/* flags for operation control */
u8 use_i2c_gatectrl;
-};
-
-struct st_register {
-   u16 addr;
-   u8  value;
-};
-
-/* values for STV4100 XTAL=30M int clk=53.125M*/
-static const struct st_register def0367ter[] = {
-   {R367TER_ID,0x60},
-   {R367TER_I2CRPT,0xa0},
-   /* {R367TER_I2CRPT, 0x22},*/
-   {R367TER_TOPCTRL,   0x00},/* for xc5000; was 0x02 */
-   {R367TER_IOCFG0,0x40},
-   {R367TER_DAC0R, 0x00},
-   {R367TER_IOCFG1,0x00},
-   {R367TER_DAC1R, 0x00},
-   {R367TER_IOCFG2,0x62},
-   {R367TER_SDFR,  0x00},
-   {R367TER_STATUS,0xf8},
-   {R367TER_AUX_CLK,   0x0a},
-   {R367TER_FREESYS1,  0x00},
-   {R367TER_FREESYS2,  0x00},
-   {R367TER_FREESYS3,  0x00},
-   {R367TER_GPIO_CFG,  0x55},
-   {R367TER_GPIO_CMD,  0x00},
-   {R367TER_AGC2MAX,   0xff},
-   {R367TER_AGC2MIN,   0x00},
-   {R367TER_AGC1MAX,   0xff},
-   {R367TER_AGC1MIN,   0x00},
-   {R367TER_AGCR,  0xbc},
-   {R367TER_AGC2TH,0x00},
-   {R367TER_AGC12C,0x00},
-   {R367TER_AGCCTRL1,  0x85},
-   {R367TER_AGCCTRL2,  0x1f},
-   {R367TER_AGC1VAL1,  0x00},
-   {R367TER_AGC1VAL2,  0x00},
-   {R367TER_AGC2VAL1,  0x6f},
-   {R367TER_AGC2VAL2,  0x05},
-   {R367TER_AGC2PGA,   0x00},
-   {R367TER_OVF_RATE1, 0x00},
-   {R367TER_OVF_RATE2, 0x00},
-   {R367TER_GAIN_SRC1, 0xaa},/* for xc5000; was 0x2b */
-   {R367TER_GAIN_SRC2, 0xd6},/* for xc5000; was 0x04 */
-   {R367TER_INC_DEROT1,0x55},
-   {R367TER_INC_DEROT2,0x55},
-   {R367TER_PPM_CPAMP_DIR, 0x2c},
-   {R367TER_PPM_CPAMP_INV, 0x00},
-   {R367TER_FREESTFE_1,0x00},
-   {R367TER_FREESTFE_2,0x1c},
-   {R367TER_DCOFFSET,  0x00},
-   {R367TER_EN_PROCESS,0x05},
-   {R367TER_SDI_SMOOTHER,  0x80},
-   {R367TER_FE_LOOP_OPEN,  0x1c},
-   {R367TER_FREQOFF1,  0x00},
-   {R367TER_FREQOFF2,  0x00},
-   {R367TER_FREQOFF3,  0x00},
-   {R367TER_TIMOFF1,   0x00},
-   {R367TER_TIMOFF2,   0x00},
-   {R367TER_EPQ,   0x02},
-   {R367TER_EPQAUTO,   0x01},
-   {R367TER_SYR_UPDATE,0xf5},
-   {R367TER_CHPFREE,   0x00},
-   {R367TER_PPM_STATE_MAC, 0x23},
-   {R367TER_INR_THRESHOLD, 0xff},
-   {R367TER_EPQ_TPS_ID_CELL, 0xf9},
-   {R367TER_EPQ_CFG,   0x00},
-   {R367TER_EPQ_STATUS,0x01},
-   {R367TER_AUTORELOCK,0x81},
-   {R367TER_BER_THR_VMSB,  0x00},
-   {R367TER_BER_THR_MSB,   0x00},
-   {R367TER_BER_THR_LSB,   0x00},
-   {R367TER_CCD,   0x83},
-   {R367TER_SPECTR_CFG,0x00},
-   {R367TER_CHC_DUMMY, 0x18},
-   {R367TER_INC_CTL,   0x88},
-   {R367TER_INCTHRES_COR1, 0xb4},
-   {R367TER_INCTHRES_COR2, 0x96},
-   {R367TER_INCTHRES_DET1, 0x0e},
-   {R367TER_INCTHRES_DET2, 0x11},
-   {R367TER_IIR_CELLNB,0x8d},
-   {R367TER_IIRCX_COEFF1_MSB, 0x00},
-   {R367TER_IIRCX_COEFF1_LSB, 0x00},
-   {R367TER_IIRCX_COEFF2_MSB, 0x09},
-   {R367TER_IIRCX_COEFF2_LSB, 0x18},
-   {R367TER_IIRCX_COEFF3_MSB, 0x14},
-   {R367TER_IIRCX_COEFF3_LSB, 0x9c},
-   {R367TER_IIRCX_COEFF4_MSB, 0x00},
-   {R367TER_IIRCX_COEFF4_LSB, 0x00},
-   {R367TER_IIRCX_COEFF5_MSB, 0x36},
-   {R367TER_IIRCX_COEFF5_LSB, 0x42},
-   {R367TER_FEPATH_CFG,0x00},
-   {R367TER_PMC1_FUNC, 0x65},
-   {R367TER_PMC1_FOR,  0x00},
-   {R367TER_PMC2_FUNC, 0x00},
-   {R367TER_STATUS_ERR_DA, 0xe0},
-   {R367TER_DIG_AGC_R, 0xfe},
-  

Re: [PATCH 10/29] drivers, md: convert stripe_head.count from atomic_t to refcount_t

2017-03-07 Thread Shaohua Li
On Mon, Mar 06, 2017 at 04:20:57PM +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 
> ---
>  drivers/md/raid5-cache.c |  8 +++---
>  drivers/md/raid5.c   | 66 
> 
>  drivers/md/raid5.h   |  3 ++-
>  3 files changed, 39 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
> index 3f307be..6c05e12 100644
> --- a/drivers/md/raid5-cache.c
> +++ b/drivers/md/raid5-cache.c

snip
>  sh->check_state, sh->reconstruct_state);
>  
>   analyse_stripe(sh, );
> @@ -4924,7 +4924,7 @@ static void activate_bit_delay(struct r5conf *conf,
>   struct stripe_head *sh = list_entry(head.next, struct 
> stripe_head, lru);
>   int hash;
>   list_del_init(>lru);
> - atomic_inc(>count);
> + refcount_inc(>count);
>   hash = sh->hash_lock_index;
>   __release_stripe(conf, sh, _inactive_list[hash]);
>   }
> @@ -5240,7 +5240,7 @@ static struct stripe_head *__get_priority_stripe(struct 
> r5conf *conf, int group)
>   sh->group = NULL;
>   }
>   list_del_init(>lru);
> - BUG_ON(atomic_inc_return(>count) != 1);
> + BUG_ON(refcount_inc_not_zero(>count));

This changes the behavior. refcount_inc_not_zero doesn't inc if original value 
is 0

Thanks,
Shaohua


Re: [PATCH 08/29] drivers, md: convert mddev.active from atomic_t to refcount_t

2017-03-07 Thread Shaohua Li
On Mon, Mar 06, 2017 at 04:20:55PM +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.

Looks good. Let me know how do you want to route the patch to upstream.
 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 
> ---
>  drivers/md/md.c | 6 +++---
>  drivers/md/md.h | 3 ++-
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 985374f..94c8ebf 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -449,7 +449,7 @@ EXPORT_SYMBOL(md_unplug);
>  
>  static inline struct mddev *mddev_get(struct mddev *mddev)
>  {
> - atomic_inc(>active);
> + refcount_inc(>active);
>   return mddev;
>  }
>  
> @@ -459,7 +459,7 @@ static void mddev_put(struct mddev *mddev)
>  {
>   struct bio_set *bs = NULL;
>  
> - if (!atomic_dec_and_lock(>active, _mddevs_lock))
> + if (!refcount_dec_and_lock(>active, _mddevs_lock))
>   return;
>   if (!mddev->raid_disks && list_empty(>disks) &&
>   mddev->ctime == 0 && !mddev->hold_active) {
> @@ -495,7 +495,7 @@ void mddev_init(struct mddev *mddev)
>   INIT_LIST_HEAD(>all_mddevs);
>   setup_timer(>safemode_timer, md_safemode_timeout,
>   (unsigned long) mddev);
> - atomic_set(>active, 1);
> + refcount_set(>active, 1);
>   atomic_set(>openers, 0);
>   atomic_set(>active_io, 0);
>   spin_lock_init(>lock);
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index b8859cb..4811663 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -22,6 +22,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -360,7 +361,7 @@ struct mddev {
>*/
>   struct mutexopen_mutex;
>   struct mutexreconfig_mutex;
> - atomic_tactive; /* general refcount */
> + refcount_t  active; /* general refcount */
>   atomic_topeners;/* number of active 
> opens */
>  
>   int changed;/* True if we might 
> need to
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/13] [media] dvb-frontends/stv0367: print CPAMP status only if stv_debug is enabled

2017-03-07 Thread Daniel Scheller
From: Daniel Scheller 

The CPAMP log lines generated in stv0367_ter_check_cpamp() are printed
everytime tuning succeeds or fails, quite cluttering the normal kernel log.
Use dprintk() instead of printk(KERN_ERR...) so that if the information is
needed, it'll be printed when the stv_debug modparam is enabled.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0367.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c 
b/drivers/media/dvb-frontends/stv0367.c
index fc80934..0064d9d 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -1262,9 +1262,9 @@ stv0367_ter_signal_type stv0367ter_check_cpamp(struct 
stv0367_state *state,
dprintk("**last CPAMPvalue= %d at wd=%d\n", CPAMPvalue, wd);
if (CPAMPvalue < CPAMPMin) {
CPAMPStatus = FE_TER_NOCPAMP;
-   printk(KERN_ERR "CPAMP failed\n");
+   dprintk("%s: CPAMP failed\n", __func__);
} else {
-   printk(KERN_ERR "CPAMP OK !\n");
+   dprintk("%s: CPAMP OK !\n", __func__);
CPAMPStatus = FE_TER_CPAMPOK;
}
 
-- 
2.10.2



[PATCH v3 0/6] drm: bridge: dw-hdmi: Add support for Custom PHYs

2017-03-07 Thread Neil Armstrong
The Amlogic GX SoCs implements a Synopsys DesignWare HDMI TX Controller
in combination with a very custom PHY.

Thanks to Laurent Pinchart's changes, the HW report the following :
 Detected HDMI TX controller v2.01a with HDCP (Vendor PHY)

The following differs from common PHY integration as managed in the current
driver :
 - Amlogic PHY is not configured through the internal I2C link
 - Amlogic PHY do not use the ENTMDS, SVSRET, PDDQ, ... signals from the 
controller
 - Amlogic PHY do not export HPD ands RxSense signals to the controller

And finally, concerning the controller integration :
 - the Controller registers are not flat memory-mapped, and uses an
addr+read/write register pair to write all registers.
 - Inputs only YUV444 pixel data

Most of these uses case are implemented in Laurent Pinchart v5.1 patchset at 
[3] :
 - Conversion to regmap for register access
 - Add more callbacks ops to handle Custom PHYs
 - Fixes a bug that considers the input to be always RBG and sends bad pixel
   format to a DVI sink by disabling CSC

This is why the following patchset implements :
 - Configure the Input format from the plat_data
 - Add PHY callback to handle HPD and RxSense out of the dw-hdmi driver

To implement the input format handling, the Synopsys HDMIT TX Controller input
V4L bus formats are used and missing formats + documentation are added.

This patchset makes the Amlogic GX SoCs HDMI output successfully work, and is
also tested on the RK3288 ACT8846 EVB Board.

Changes since v2 at [4] :
 - Rebase on laurent patch "Extract PHY interrupt setup to a function"
 - Reduce phy operations
 - Switch the V4L bus formats and encodings instead of custom enum

Changes since v1 at [2] :
 - Drop patches submitted by laurent

Changes since RFC at [1] :
 - Regmap fixup for 4bytes register access, tested on RK3288 SoC
 - Move phy callbacks to phy_ops and move Synopsys PHY calls into default ops
 - Move HDMI link data into shared header
 - Move Pixel Encoding enum to shared header

[1] 
http://lkml.kernel.org/r/1484656294-6140-1-git-send-email-narmstr...@baylibre.com
[2] 
http://lkml.kernel.org/r/1485774318-21916-1-git-send-email-narmstr...@baylibre.com
[3] 
http://lkml.kernel.org/r/20170303172007.26541-1-laurent.pinchart+rene...@ideasonboard.com
[4] 
http://lkml.kernel.org/r/1488468572-31971-1-git-send-email-narmstr...@baylibre.com

Laurent Pinchart (1):
  drm: bridge: dw-hdmi: Extract PHY interrupt setup to a function

Neil Armstrong (5):
  media: uapi: Add RGB and YUV bus formats for Synopsys HDMI TX
Controller
  documentation: media: Add documentation for new RGB and YUV bus
formats
  drm: bridge: dw-hdmi: Switch to V4L bus format and encodings
  drm: bridge: dw-hdmi: Add Documentation on supported input formats
  drm: bridge: dw-hdmi: Move HPD handling to PHY operations

 Documentation/gpu/dw-hdmi.rst   |   15 +
 Documentation/gpu/index.rst |1 +
 Documentation/media/uapi/v4l/subdev-formats.rst | 4992 ++-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c   |  465 ++-
 include/drm/bridge/dw_hdmi.h|   68 +
 include/uapi/linux/media-bus-format.h   |   13 +-
 6 files changed, 4368 insertions(+), 1186 deletions(-)
 create mode 100644 Documentation/gpu/dw-hdmi.rst

-- 
1.9.1



Re: [PATCH v3 6/6] drm: bridge: dw-hdmi: Move HPD handling to PHY operations

2017-03-07 Thread Jose Abreu
Hi Neil,


On 07-03-2017 16:42, Neil Armstrong wrote:
> The HDMI TX controller support HPD and RXSENSE signaling from the PHY
> via it's STAT0 PHY interface, but some vendor PHYs can manage these
> signals independently from the controller, thus these STAT0 handling
> should be moved to PHY specific operations and become optional.
>
> The existing STAT0 HPD and RXSENSE handling code is refactored into
> a supplementaty set of default PHY operations that are used automatically
> when the platform glue doesn't provide its own operations.
>
> Signed-off-by: Neil Armstrong 

Looks nice!

Reviewed-by: Jose Abreu 

Best regards,
Jose Miguel Abreu

> ---
>  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 135 
> ++
>  include/drm/bridge/dw_hdmi.h  |   5 ++
>  2 files changed, 86 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
> b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 348311c..1c6cb46 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> @@ -1215,10 +1215,46 @@ static enum drm_connector_status 
> dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi,
>   connector_status_connected : connector_status_disconnected;
>  }
>  
> +static void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data,
> +bool force, bool disabled, bool rxsense)
> +{
> + u8 old_mask = hdmi->phy_mask;
> +
> + if (force || disabled || !rxsense)
> + hdmi->phy_mask |= HDMI_PHY_RX_SENSE;
> + else
> + hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE;
> +
> + if (old_mask != hdmi->phy_mask)
> + hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> +}
> +
> +static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data)
> +{
> + /*
> +  * Configure the PHY RX SENSE and HPD interrupts polarities and clear
> +  * any pending interrupt.
> +  */
> + hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
> + hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> + HDMI_IH_PHY_STAT0);
> +
> + /* Enable cable hot plug irq. */
> + hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> +
> + /* Clear and unmute interrupts. */
> + hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> + HDMI_IH_PHY_STAT0);
> + hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
> + HDMI_IH_MUTE_PHY_STAT0);
> +}
> +
>  static const struct dw_hdmi_phy_ops dw_hdmi_synopsys_phy_ops = {
>   .init = dw_hdmi_phy_init,
>   .disable = dw_hdmi_phy_disable,
>   .read_hpd = dw_hdmi_phy_read_hpd,
> + .update_hpd = dw_hdmi_phy_update_hpd,
> + .setup_hpd = dw_hdmi_phy_setup_hpd,
>  };
>  
>  /* 
> -
> @@ -1742,35 +1778,10 @@ static void dw_hdmi_update_power(struct dw_hdmi *hdmi)
>   */
>  static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi)
>  {
> - u8 old_mask = hdmi->phy_mask;
> -
> - if (hdmi->force || hdmi->disabled || !hdmi->rxsense)
> - hdmi->phy_mask |= HDMI_PHY_RX_SENSE;
> - else
> - hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE;
> -
> - if (old_mask != hdmi->phy_mask)
> - hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> -}
> -
> -static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi)
> -{
> - /*
> -  * Configure the PHY RX SENSE and HPD interrupts polarities and clear
> -  * any pending interrupt.
> -  */
> - hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
> - hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> - HDMI_IH_PHY_STAT0);
> -
> - /* Enable cable hot plug irq. */
> - hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> -
> - /* Clear and unmute interrupts. */
> - hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> - HDMI_IH_PHY_STAT0);
> - hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
> - HDMI_IH_MUTE_PHY_STAT0);
> + if (hdmi->phy.ops->update_hpd)
> + hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data,
> +   hdmi->force, hdmi->disabled,
> +   hdmi->rxsense);
>  }
>  
>  static enum drm_connector_status
> @@ -1962,6 +1973,41 @@ static irqreturn_t dw_hdmi_hardirq(int irq, void 
> *dev_id)
>   return ret;
>  }
>  
> +void __dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense)
> +{
> + mutex_lock(>mutex);
> +
> + if (!hdmi->disabled && !hdmi->force) {
> + /*
> +  * If the RX sense status indicates we're disconnected,
> +  * clear the software rxsense status.
> +  */
> +

[PATCH v3 4/6] drm: bridge: dw-hdmi: Switch to V4L bus format and encodings

2017-03-07 Thread Neil Armstrong
Some display pipelines can only provide non-RBG input pixels to the HDMI TX
Controller, this patch takes the pixel format from the plat_data if provided.

Signed-off-by: Neil Armstrong 
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 322 +-
 include/drm/bridge/dw_hdmi.h  |  63 ++
 2 files changed, 290 insertions(+), 95 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 1ed8bc1..348311c 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -30,17 +30,14 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include "dw-hdmi.h"
 #include "dw-hdmi-audio.h"
 
 #define HDMI_EDID_LEN  512
 
-#define RGB0
-#define YCBCR444   1
-#define YCBCR422_16BITS2
-#define YCBCR422_8BITS 3
-#define XVYCC444   4
-
 enum hdmi_datamap {
RGB444_8B = 0x01,
RGB444_10B = 0x03,
@@ -94,10 +91,10 @@ struct hdmi_vmode {
 };
 
 struct hdmi_data_info {
-   unsigned int enc_in_format;
-   unsigned int enc_out_format;
-   unsigned int enc_color_depth;
-   unsigned int colorimetry;
+   unsigned int enc_in_bus_format;
+   unsigned int enc_out_bus_format;
+   unsigned int enc_in_encoding;
+   unsigned int enc_out_encoding;
unsigned int pix_repet_factor;
unsigned int hdcp_enable;
struct hdmi_vmode video_mode;
@@ -557,6 +554,92 @@ void dw_hdmi_audio_disable(struct dw_hdmi *hdmi)
 }
 EXPORT_SYMBOL_GPL(dw_hdmi_audio_disable);
 
+static bool hdmi_bus_fmt_is_rgb(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   case MEDIA_BUS_FMT_RGB101010_1X30:
+   case MEDIA_BUS_FMT_RGB121212_1X36:
+   case MEDIA_BUS_FMT_RGB161616_1X48:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static bool hdmi_bus_fmt_is_yuv444(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_YUV8_1X24:
+   case MEDIA_BUS_FMT_YUV10_1X30:
+   case MEDIA_BUS_FMT_YUV12_1X36:
+   case MEDIA_BUS_FMT_YUV16_1X48:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static bool hdmi_bus_fmt_is_yuv422(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_UYVY10_1X20:
+   case MEDIA_BUS_FMT_UYVY12_1X24:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static bool hdmi_bus_fmt_is_yuv420(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_UYVY8_1_1X24:
+   case MEDIA_BUS_FMT_UYVY10_1_1X30:
+   case MEDIA_BUS_FMT_UYVY12_1_1X36:
+   case MEDIA_BUS_FMT_UYVY16_1_1X48:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static int hdmi_bus_fmt_color_depth(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   case MEDIA_BUS_FMT_YUV8_1X24:
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_1_1X24:
+   return 8;
+
+   case MEDIA_BUS_FMT_RGB101010_1X30:
+   case MEDIA_BUS_FMT_YUV10_1X30:
+   case MEDIA_BUS_FMT_UYVY10_1X20:
+   case MEDIA_BUS_FMT_UYVY10_1_1X30:
+   return 10;
+
+   case MEDIA_BUS_FMT_RGB121212_1X36:
+   case MEDIA_BUS_FMT_YUV12_1X36:
+   case MEDIA_BUS_FMT_UYVY12_1X24:
+   case MEDIA_BUS_FMT_UYVY12_1_1X36:
+   return 12;
+
+   case MEDIA_BUS_FMT_RGB161616_1X48:
+   case MEDIA_BUS_FMT_YUV16_1X48:
+   case MEDIA_BUS_FMT_UYVY16_1_1X48:
+   return 16;
+
+   default:
+   return 0;
+   }
+}
+
 /*
  * this submodule is responsible for the video data synchronization.
  * for example, for RGB 4:4:4 input, the data map is defined as
@@ -569,37 +652,45 @@ static void hdmi_video_sample(struct dw_hdmi *hdmi)
int color_format = 0;
u8 val;
 
-   if (hdmi->hdmi_data.enc_in_format == RGB) {
-   if (hdmi->hdmi_data.enc_color_depth == 8)
-   color_format = 0x01;
-   else if (hdmi->hdmi_data.enc_color_depth == 10)
-   color_format = 0x03;
-   else if (hdmi->hdmi_data.enc_color_depth == 12)
-   color_format = 0x05;
-   else if (hdmi->hdmi_data.enc_color_depth == 16)
-   color_format = 0x07;
-   else
-   return;
-   } else if (hdmi->hdmi_data.enc_in_format == YCBCR444) {
-   if (hdmi->hdmi_data.enc_color_depth == 8)
-   color_format = 0x09;
-   else if (hdmi->hdmi_data.enc_color_depth == 10)
-   color_format = 0x0B;
-   else if 

[PATCH] [media] mceusb: fix NULL-deref at probe

2017-03-07 Thread Johan Hovold
Make sure to check for the required out endpoint to avoid dereferencing
a NULL-pointer in mce_request_packet should a malicious device lack such
an endpoint. Note that this path it hit during probe.

Fixes: 66e89522aff7 ("V4L/DVB: IR: add mceusb IR receiver driver")
Cc: stable  # 2.6.36
Signed-off-by: Johan Hovold 
---

Found through inspection, compile tested only.

Johan


 drivers/media/rc/mceusb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 238d8eaf7d94..93b16fe3ab38 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -1288,8 +1288,8 @@ static int mceusb_dev_probe(struct usb_interface *intf,
}
}
}
-   if (ep_in == NULL) {
-   dev_dbg(>dev, "inbound and/or endpoint not found");
+   if (!ep_in || !ep_out) {
+   dev_dbg(>dev, "required endpoints not found\n");
return -ENODEV;
}
 
-- 
2.12.0



Re: [PATCH v3 4/6] drm: bridge: dw-hdmi: Switch to V4L bus format and encodings

2017-03-07 Thread Jose Abreu
Hi Neil,


On 07-03-2017 16:42, Neil Armstrong wrote:
> Some display pipelines can only provide non-RBG input pixels to the HDMI TX
> Controller, this patch takes the pixel format from the plat_data if provided.
>
> Signed-off-by: Neil Armstrong 
> ---
>  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 322 
> +-
>  include/drm/bridge/dw_hdmi.h  |  63 ++
>  2 files changed, 290 insertions(+), 95 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
> b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 1ed8bc1..348311c 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> @@ -30,17 +30,14 @@
>  #include 
>  #include 
>  
> +#include 
> +#include 
> +
>  #include "dw-hdmi.h"
>  #include "dw-hdmi-audio.h"
>  
>  #define HDMI_EDID_LEN512
>  
> -#define RGB  0
> -#define YCBCR444 1
> -#define YCBCR422_16BITS  2
> -#define YCBCR422_8BITS   3
> -#define XVYCC444 4
> -
>  enum hdmi_datamap {
>   RGB444_8B = 0x01,
>   RGB444_10B = 0x03,
> @@ -94,10 +91,10 @@ struct hdmi_vmode {
>  };
>  
>  struct hdmi_data_info {
> - unsigned int enc_in_format;
> - unsigned int enc_out_format;
> - unsigned int enc_color_depth;
> - unsigned int colorimetry;
> + unsigned int enc_in_bus_format;
> + unsigned int enc_out_bus_format;
> + unsigned int enc_in_encoding;
> + unsigned int enc_out_encoding;
>   unsigned int pix_repet_factor;
>   unsigned int hdcp_enable;
>   struct hdmi_vmode video_mode;
> @@ -557,6 +554,92 @@ void dw_hdmi_audio_disable(struct dw_hdmi *hdmi)
>  }
>  EXPORT_SYMBOL_GPL(dw_hdmi_audio_disable);
>  
> +static bool hdmi_bus_fmt_is_rgb(unsigned int bus_format)
> +{
> + switch (bus_format) {
> + case MEDIA_BUS_FMT_RGB888_1X24:
> + case MEDIA_BUS_FMT_RGB101010_1X30:
> + case MEDIA_BUS_FMT_RGB121212_1X36:
> + case MEDIA_BUS_FMT_RGB161616_1X48:
> + return true;
> +
> + default:
> + return false;
> + }
> +}
> +
> +static bool hdmi_bus_fmt_is_yuv444(unsigned int bus_format)
> +{
> + switch (bus_format) {
> + case MEDIA_BUS_FMT_YUV8_1X24:
> + case MEDIA_BUS_FMT_YUV10_1X30:
> + case MEDIA_BUS_FMT_YUV12_1X36:
> + case MEDIA_BUS_FMT_YUV16_1X48:
> + return true;
> +
> + default:
> + return false;
> + }
> +}
> +
> +static bool hdmi_bus_fmt_is_yuv422(unsigned int bus_format)
> +{
> + switch (bus_format) {
> + case MEDIA_BUS_FMT_UYVY8_1X16:
> + case MEDIA_BUS_FMT_UYVY10_1X20:
> + case MEDIA_BUS_FMT_UYVY12_1X24:
> + return true;
> +
> + default:
> + return false;
> + }
> +}
> +
> +static bool hdmi_bus_fmt_is_yuv420(unsigned int bus_format)
> +{
> + switch (bus_format) {
> + case MEDIA_BUS_FMT_UYVY8_1_1X24:
> + case MEDIA_BUS_FMT_UYVY10_1_1X30:
> + case MEDIA_BUS_FMT_UYVY12_1_1X36:
> + case MEDIA_BUS_FMT_UYVY16_1_1X48:
> + return true;
> +
> + default:
> + return false;
> + }
> +}
> +
> +static int hdmi_bus_fmt_color_depth(unsigned int bus_format)
> +{
> + switch (bus_format) {
> + case MEDIA_BUS_FMT_RGB888_1X24:
> + case MEDIA_BUS_FMT_YUV8_1X24:
> + case MEDIA_BUS_FMT_UYVY8_1X16:
> + case MEDIA_BUS_FMT_UYVY8_1_1X24:
> + return 8;
> +
> + case MEDIA_BUS_FMT_RGB101010_1X30:
> + case MEDIA_BUS_FMT_YUV10_1X30:
> + case MEDIA_BUS_FMT_UYVY10_1X20:
> + case MEDIA_BUS_FMT_UYVY10_1_1X30:
> + return 10;
> +
> + case MEDIA_BUS_FMT_RGB121212_1X36:
> + case MEDIA_BUS_FMT_YUV12_1X36:
> + case MEDIA_BUS_FMT_UYVY12_1X24:
> + case MEDIA_BUS_FMT_UYVY12_1_1X36:
> + return 12;
> +
> + case MEDIA_BUS_FMT_RGB161616_1X48:
> + case MEDIA_BUS_FMT_YUV16_1X48:
> + case MEDIA_BUS_FMT_UYVY16_1_1X48:
> + return 16;
> +
> + default:
> + return 0;

Maybe fallback to 8bpp in case of error as this is the most
common supported.

> + }
> +}
> +
>  /*
>   * this submodule is responsible for the video data synchronization.
>   * for example, for RGB 4:4:4 input, the data map is defined as
> @@ -569,37 +652,45 @@ static void hdmi_video_sample(struct dw_hdmi *hdmi)
>   int color_format = 0;
>   u8 val;
>  
> - if (hdmi->hdmi_data.enc_in_format == RGB) {
> - if (hdmi->hdmi_data.enc_color_depth == 8)
> - color_format = 0x01;
> - else if (hdmi->hdmi_data.enc_color_depth == 10)
> - color_format = 0x03;
> - else if (hdmi->hdmi_data.enc_color_depth == 12)
> - color_format = 0x05;
> - else if (hdmi->hdmi_data.enc_color_depth == 16)
> - color_format = 0x07;
> - else
> - return;
> - } else if 

[PATCH v3 5/6] drm: bridge: dw-hdmi: Add Documentation on supported input formats

2017-03-07 Thread Neil Armstrong
This patch adds a new DRM documentation entry and links to the input
format table added in the dw_hdmi header.

Signed-off-by: Neil Armstrong 
---
 Documentation/gpu/dw-hdmi.rst | 15 +++
 Documentation/gpu/index.rst   |  1 +
 2 files changed, 16 insertions(+)
 create mode 100644 Documentation/gpu/dw-hdmi.rst

diff --git a/Documentation/gpu/dw-hdmi.rst b/Documentation/gpu/dw-hdmi.rst
new file mode 100644
index 000..486faad
--- /dev/null
+++ b/Documentation/gpu/dw-hdmi.rst
@@ -0,0 +1,15 @@
+===
+ drm/bridge/dw-hdmi Synopsys DesignWare HDMI Controller
+===
+
+Synopsys DesignWare HDMI Controller
+===
+
+This section covers everything related to the Synopsys DesignWare HDMI
+Controller implemented as a DRM bridge.
+
+Supported Input Formats and Encodings
+-
+
+.. kernel-doc:: include/drm/bridge/dw_hdmi.h
+   :doc: Supported input formats and encodings
diff --git a/Documentation/gpu/index.rst b/Documentation/gpu/index.rst
index e998ee0..0725449 100644
--- a/Documentation/gpu/index.rst
+++ b/Documentation/gpu/index.rst
@@ -10,6 +10,7 @@ Linux GPU Driver Developer's Guide
drm-kms
drm-kms-helpers
drm-uapi
+   dw-hdmi
i915
tinydrm
vc4
-- 
1.9.1



Re: [PATCH] media: vpif: use a configurable i2c_adapter_id for vpif display

2017-03-07 Thread Lad, Prabhakar
Hi Bartosz,

Thanks for the patch.

On Thu, Feb 16, 2017 at 6:08 PM, Bartosz Golaszewski
 wrote:
>
> The vpif display driver uses a static i2c adapter ID of 1 but on the
> da850-evm board in DT boot mode the i2c adapter ID is actually 0.
>
> Make the adapter ID configurable like it already is for vpif capture.
>
> Signed-off-by: Bartosz Golaszewski 
> Acked-by: Kevin Hilman 
> ---
>  arch/arm/mach-davinci/board-da850-evm.c   | 1 +
>  drivers/media/platform/davinci/vpif_display.c | 2 +-
>  include/media/davinci/vpif_types.h| 1 +
>  3 files changed, 3 insertions(+), 1 deletion(-)
>

Acked-by: Lad, Prabhakar 

Cheers,
--Prabhakar Lad


Re: [PATCH v3 1/6] drm: bridge: dw-hdmi: Extract PHY interrupt setup to a function

2017-03-07 Thread Jose Abreu
Hi Neil,


On 07-03-2017 16:42, Neil Armstrong wrote:
> From: Laurent Pinchart 
>
> In preparation for adding PHY operations to handle RX SENSE and HPD,
> group all the PHY interrupt setup code in a single location and extract
> it to a separate function.
>
> Signed-off-by: Laurent Pinchart 
> Signed-off-by: Neil Armstrong 
> ---
>  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 50 
> ++-
>  1 file changed, 23 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
> b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 026a0dc..1ed8bc1 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> @@ -1496,7 +1496,7 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct 
> drm_display_mode *mode)
>  }
>  
>  /* Wait until we are registered to enable interrupts */
> -static int dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
> +static void dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
>  {
>   hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL,
>   HDMI_PHY_I2CM_INT_ADDR);
> @@ -1504,15 +1504,6 @@ static int dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
>   hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL |
>   HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL,
>   HDMI_PHY_I2CM_CTLINT_ADDR);
> -
> - /* enable cable hot plug irq */
> - hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> -
> - /* Clear Hotplug interrupts */
> - hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> - HDMI_IH_PHY_STAT0);
> -
> - return 0;
>  }
>  
>  static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi)
> @@ -1630,6 +1621,26 @@ static void dw_hdmi_update_phy_mask(struct dw_hdmi 
> *hdmi)
>   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
>  }
>  
> +static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi)
> +{
> + /*
> +  * Configure the PHY RX SENSE and HPD interrupts polarities and clear
> +  * any pending interrupt.
> +  */
> + hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
> + hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> + HDMI_IH_PHY_STAT0);
> +
> + /* Enable cable hot plug irq. */
> + hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
> +
> + /* Clear and unmute interrupts. */
> + hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> + HDMI_IH_PHY_STAT0);
> + hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
> + HDMI_IH_MUTE_PHY_STAT0);
> +}
> +
>  static enum drm_connector_status
>  dw_hdmi_connector_detect(struct drm_connector *connector, bool force)
>  {
> @@ -2141,29 +2152,14 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
>   hdmi->ddc = NULL;
>   }
>  
> - /*
> -  * Configure registers related to HDMI interrupt
> -  * generation before registering IRQ.
> -  */


I've seen the databook and HPD interrupts are enabled per default
(actually I think most of the interrupts are). I'm thinking
whether we could get spurious interrupts because of not
configuring HPD before registering IRQ (probably thats why the
comment was there). How did you test this? I think that if you
insert the cable before loading modules then you can try to
emulate this condition. What do you think?

Best regards,
Jose Miguel Abreu

> - hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
> -
> - /* Clear Hotplug interrupts */
> - hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
> - HDMI_IH_PHY_STAT0);
> -
>   hdmi->bridge.driver_private = hdmi;
>   hdmi->bridge.funcs = _hdmi_bridge_funcs;
>  #ifdef CONFIG_OF
>   hdmi->bridge.of_node = pdev->dev.of_node;
>  #endif
>  
> - ret = dw_hdmi_fb_registered(hdmi);
> - if (ret)
> - goto err_iahb;
> -
> - /* Unmute interrupts */
> - hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
> - HDMI_IH_MUTE_PHY_STAT0);
> + dw_hdmi_fb_registered(hdmi);
> + dw_hdmi_phy_setup_hpd(hdmi);
>  
>   memset(, 0, sizeof(pdevinfo));
>   pdevinfo.parent = dev;


[PATCH v3 1/6] drm: bridge: dw-hdmi: Extract PHY interrupt setup to a function

2017-03-07 Thread Neil Armstrong
From: Laurent Pinchart 

In preparation for adding PHY operations to handle RX SENSE and HPD,
group all the PHY interrupt setup code in a single location and extract
it to a separate function.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Neil Armstrong 
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 50 ++-
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 026a0dc..1ed8bc1 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -1496,7 +1496,7 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct 
drm_display_mode *mode)
 }
 
 /* Wait until we are registered to enable interrupts */
-static int dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
+static void dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
 {
hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL,
HDMI_PHY_I2CM_INT_ADDR);
@@ -1504,15 +1504,6 @@ static int dw_hdmi_fb_registered(struct dw_hdmi *hdmi)
hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL |
HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL,
HDMI_PHY_I2CM_CTLINT_ADDR);
-
-   /* enable cable hot plug irq */
-   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
-
-   /* Clear Hotplug interrupts */
-   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
-   HDMI_IH_PHY_STAT0);
-
-   return 0;
 }
 
 static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi)
@@ -1630,6 +1621,26 @@ static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi)
hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
 }
 
+static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi)
+{
+   /*
+* Configure the PHY RX SENSE and HPD interrupts polarities and clear
+* any pending interrupt.
+*/
+   hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
+   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
+   HDMI_IH_PHY_STAT0);
+
+   /* Enable cable hot plug irq. */
+   hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
+
+   /* Clear and unmute interrupts. */
+   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
+   HDMI_IH_PHY_STAT0);
+   hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
+   HDMI_IH_MUTE_PHY_STAT0);
+}
+
 static enum drm_connector_status
 dw_hdmi_connector_detect(struct drm_connector *connector, bool force)
 {
@@ -2141,29 +2152,14 @@ static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
hdmi->ddc = NULL;
}
 
-   /*
-* Configure registers related to HDMI interrupt
-* generation before registering IRQ.
-*/
-   hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
-
-   /* Clear Hotplug interrupts */
-   hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
-   HDMI_IH_PHY_STAT0);
-
hdmi->bridge.driver_private = hdmi;
hdmi->bridge.funcs = _hdmi_bridge_funcs;
 #ifdef CONFIG_OF
hdmi->bridge.of_node = pdev->dev.of_node;
 #endif
 
-   ret = dw_hdmi_fb_registered(hdmi);
-   if (ret)
-   goto err_iahb;
-
-   /* Unmute interrupts */
-   hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
-   HDMI_IH_MUTE_PHY_STAT0);
+   dw_hdmi_fb_registered(hdmi);
+   dw_hdmi_phy_setup_hpd(hdmi);
 
memset(, 0, sizeof(pdevinfo));
pdevinfo.parent = dev;
-- 
1.9.1



[PATCH] [media] v4l2-dv-timings: Introduce v4l2_calc_fps()

2017-03-07 Thread Jose Abreu
HDMI Receivers receive video modes which, according to
CEA specification, can have different frames per second
(fps) values.

This patch introduces a helper function in the media core
which can calculate the expected video mode fps given the
pixel clock value and the horizontal/vertical values. HDMI
video receiver drivers are expected to use this helper so
that they can correctly fill the v4l2_streamparm structure
which is requested by vidioc_g_parm callback.

We could also use a lookup table for this but it wouldn't
correctly handle 60Hz vs 59.94Hz situations as this all
depends on the pixel clock value.

Signed-off-by: Jose Abreu 
Cc: Carlos Palminha 
Cc: Mauro Carvalho Chehab 
Cc: Hans Verkuil 
Cc: Charles-Antoine Couret 
Cc: linux-media@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/media/v4l2-core/v4l2-dv-timings.c | 29 +
 include/media/v4l2-dv-timings.h   |  8 
 2 files changed, 37 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 5c8c49d..19946c6 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -814,3 +814,32 @@ struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, 
u8 vert_portrait)
return aspect;
 }
 EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio);
+
+struct v4l2_fract v4l2_calc_fps(const struct v4l2_dv_timings *t)
+{
+   const struct v4l2_bt_timings *bt = >bt;
+   struct v4l2_fract fps_fract = { 1, 1 };
+   unsigned long n, d;
+   unsigned long mask = GENMASK(BITS_PER_LONG - 1, 0);
+   u32 htot, vtot, fps;
+   u64 pclk;
+
+   if (t->type != V4L2_DV_BT_656_1120)
+   return fps_fract;
+
+   htot = V4L2_DV_BT_FRAME_WIDTH(bt);
+   vtot = V4L2_DV_BT_FRAME_HEIGHT(bt);
+   pclk = bt->pixelclock;
+   if (bt->interlaced)
+   htot /= 2;
+
+   fps = (htot * vtot) > 0 ? div_u64((100 * pclk), (htot * vtot)) : 0;
+
+   rational_best_approximation(fps, 100, mask, mask, , );
+
+   fps_fract.numerator = d;
+   fps_fract.denominator = n;
+   return fps_fract;
+}
+EXPORT_SYMBOL_GPL(v4l2_calc_fps);
+
diff --git a/include/media/v4l2-dv-timings.h b/include/media/v4l2-dv-timings.h
index 61a1889..d23b168 100644
--- a/include/media/v4l2-dv-timings.h
+++ b/include/media/v4l2-dv-timings.h
@@ -196,6 +196,14 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned 
hfreq, unsigned vsync,
 struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
 
 /**
+ * v4l2_calc_fps - calculate the frames per seconds based on the
+ * v4l2_dv_timings information.
+ *
+ * @t: the timings data.
+ */
+struct v4l2_fract v4l2_calc_fps(const struct v4l2_dv_timings *t);
+
+/**
  * v4l2_dv_timings_aspect_ratio - calculate the aspect ratio based on the
  * v4l2_dv_timings information.
  *
-- 
1.9.1




Re: [PATCH v10 2/2] media: i2c: Add support for OV5647 sensor.

2017-03-07 Thread Sakari Ailus
Hi Ramiro,

On Mon, Mar 06, 2017 at 11:16:34AM +, Ramiro Oliveira wrote:
...
> +static int __sensor_init(struct v4l2_subdev *sd)
> +{
> + int ret;
> + u8 resetval, rdval;
> + struct i2c_client *client = v4l2_get_subdevdata(sd);
> +
> + dev_dbg(>dev, "sensor init\n");

This looks like a debugging time leftover. Please remove.

With that,

Acked-by: Sakari Ailus 

...

> +static int ov5647_parse_dt(struct device_node *np)
> +{
> + struct v4l2_of_endpoint bus_cfg;
> + struct device_node *ep;
> +
> + int ret;
> +
> + ep = of_graph_get_next_endpoint(np, NULL);
> + if (!ep)
> + return -EINVAL;
> +
> + ret = v4l2_of_parse_endpoint(ep, _cfg);
> +
> + of_node_put(ep);
> + return ret;
> +}

This will conflict with my fwnode patchset. Let's see in which order the
patches will be merged, one of the sets has to be changed. The work is
trivial though.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk


[PATCH v2 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread Wu-Cheng Li
From: Wu-Cheng Li 

VPU firmware has a bug and may return invalid buffer index for
some vp9 videos. Check the buffer indexes before accessing the
buffer.

Signed-off-by: Wu-Cheng Li 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 23 ++-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
 .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 ++
 drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
 4 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index 502877a4b1df..8a9285a84d47 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -420,6 +420,11 @@ static void mtk_vdec_worker(struct work_struct *work)
dst_buf->index,
ret, res_chg);
src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+   if (ret == -EIO) {
+   mutex_lock(>lock);
+   src_buf_info->error = true;
+   mutex_unlock(>lock);
+   }
v4l2_m2m_buf_done(_buf_info->vb, VB2_BUF_STATE_ERROR);
} else if (res_chg == false) {
/*
@@ -1176,6 +1181,11 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb)
   "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
fail=%d, res_chg=%d",
   ctx->id, src_buf->index,
   src_mem.size, ret, res_chg);
+   if (ret == -EIO) {
+   mtk_v4l2_err("[%d] Unrecoverable error in 
vdec_if_decode.",
+   ctx->id);
+   ctx->state = MTK_STATE_ABORT;
+   }
return;
}
 
@@ -1217,14 +1227,17 @@ static void vb2ops_vdec_buf_finish(struct vb2_buffer 
*vb)
struct vb2_v4l2_buffer *vb2_v4l2;
struct mtk_video_dec_buf *buf;
 
-   if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-   return;
-
vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
mutex_lock(>lock);
-   buf->queued_in_v4l2 = false;
-   buf->queued_in_vb2 = false;
+   if (buf->error) {
+   mtk_v4l2_err("Unrecoverable error on buffer.");
+   ctx->state = MTK_STATE_ABORT;
+   }
+   if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+   buf->queued_in_v4l2 = false;
+   buf->queued_in_vb2 = false;
+   }
mutex_unlock(>lock);
 }
 
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
index 362f5a85762e..dc4fc1df63c5 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
@@ -50,6 +50,7 @@ struct vdec_fb {
  * @queued_in_v4l2:Capture buffer is in v4l2 driver, but not in vb2
  * queue yet
  * @lastframe: Intput buffer is last buffer - EOS
+ * @error: An unrecoverable error occurs on this buffer.
  * @frame_buffer:  Decode status, and buffer information of Capture buffer
  *
  * Note : These status information help us track and debug buffer state
@@ -63,6 +64,7 @@ struct mtk_video_dec_buf {
boolqueued_in_vb2;
boolqueued_in_v4l2;
boollastframe;
+   boolerror;
struct vdec_fb  frame_buffer;
 };
 
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
index e91a3b425b0c..5539b1853f16 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
@@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, struct 
vdec_fb **out_fb)
*out_fb = fb;
 }
 
+static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
+   struct vdec_vp9_vsi *vsi) {
+   if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
+   mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.",
+   vsi->sf_frm_idx);
+   return -EIO;
+   }
+   if (vsi->frm_to_show_idx >= VP9_MAX_FRM_BUF_NUM) {
+   mtk_vcodec_err(inst, "Invalid vsi->frm_to_show_idx=%u.",
+   vsi->frm_to_show_idx);
+   return -EIO;
+   }
+   if (vsi->new_fb_idx >= VP9_MAX_FRM_BUF_NUM) {
+   mtk_vcodec_err(inst, "Invalid vsi->new_fb_idx=%u.",
+   vsi->new_fb_idx);
+   return -EIO;
+   }
+   return 0;
+}
+
 static void vdec_vp9_deinit(unsigned long h_vdec)
 {
struct vdec_vp9_inst *inst = (struct 

[PATCH v2 0/1] mtk-vcodec: check the vp9 decoder buffer index from VPU

2017-03-07 Thread Wu-Cheng Li
From: Wu-Cheng Li 

This patch guards against the invalid buffer index from
VPU firmware.

v2: also check the result of vdec_if_decode in mtk_vdec_worker.

Wu-Cheng Li (1):
  mtk-vcodec: check the vp9 decoder buffer index from VPU.

 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 23 ++-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |  2 ++
 .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 ++
 drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
 4 files changed, 48 insertions(+), 5 deletions(-)

-- 
2.12.0.rc1.440.g5b76565f74-goog



[PATCH 2/4] media: platform: dwc: Support for DW CSI-2 Host

2017-03-07 Thread Ramiro Oliveira
Add support for the Synopsys DesignWare CSI-2 Host

Signed-off-by: Ramiro Oliveira 
---
 MAINTAINERS  |   7 +
 drivers/media/platform/Kconfig   |   1 +
 drivers/media/platform/Makefile  |   2 +
 drivers/media/platform/dwc/Kconfig   |   5 +
 drivers/media/platform/dwc/Makefile  |   1 +
 drivers/media/platform/dwc/dw_mipi_csi.c | 653 +++
 drivers/media/platform/dwc/dw_mipi_csi.h | 181 +
 include/media/dwc/csi_host_platform.h|  97 +
 8 files changed, 947 insertions(+)
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 5badfd33e51f..19673dad43b4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11061,6 +11061,13 @@ S: Maintained
 F: drivers/staging/media/st-cec/
 F: Documentation/devicetree/bindings/media/stih-cec.txt
 
+SYNOPSYS DESIGNWARE CSI-2 HOST VIDEO PLATFORM
+M: Ramiro Oliveira 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/platform/dwc/
+
 SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS
 M: Ursula Braun 
 L: linux-s...@vger.kernel.org
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 53f6f12bff0d..4b6e00da763f 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -120,6 +120,7 @@ source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
 source "drivers/media/platform/atmel/Kconfig"
+source "drivers/media/platform/dwc/Kconfig"
 
 config VIDEO_TI_CAL
tristate "TI CAL (Camera Adaptation Layer) driver"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8959f6e6692a..95eae2772c1f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)  += rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
 
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)   += dwc/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/dwc/Kconfig 
b/drivers/media/platform/dwc/Kconfig
new file mode 100644
index ..2cd13d23f897
--- /dev/null
+++ b/drivers/media/platform/dwc/Kconfig
@@ -0,0 +1,5 @@
+config DWC_MIPI_CSI2_HOST
+   tristate "SNPS DWC MIPI CSI2 Host"
+   select GENERIC_PHY
+   help
+ This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
diff --git a/drivers/media/platform/dwc/Makefile 
b/drivers/media/platform/dwc/Makefile
new file mode 100644
index ..5eb076a55123
--- /dev/null
+++ b/drivers/media/platform/dwc/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_DWC_MIPI_CSI2_HOST)   += dw_mipi_csi.o
diff --git a/drivers/media/platform/dwc/dw_mipi_csi.c 
b/drivers/media/platform/dwc/dw_mipi_csi.c
new file mode 100644
index ..6905def40a07
--- /dev/null
+++ b/drivers/media/platform/dwc/dw_mipi_csi.c
@@ -0,0 +1,653 @@
+/*
+ * DWC MIPI CSI-2 Host device driver
+ *
+ * Copyright (C) 2016 Synopsys, Inc. All rights reserved.
+ * Author: Ramiro Oliveira 
+ *
+ * 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 "dw_mipi_csi.h"
+
+/**
+ * @short Video formats supported by the MIPI CSI-2
+ */
+static const struct mipi_fmt dw_mipi_csi_formats[] = {
+   {
+   /* RAW 8 */
+   .code = MEDIA_BUS_FMT_SBGGR8_1X8,
+   .depth = 8,
+   },
+   {
+   /* RAW 10 */
+   .code = MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE,
+   .depth = 10,
+   },
+   {
+   /* RGB 565 */
+   .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
+   .depth = 16,
+   },
+   {
+   /* BGR 565 */
+   .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
+   .depth = 16,
+   },
+   {
+   /* RGB 888 */
+   .code = MEDIA_BUS_FMT_RGB888_2X12_LE,
+   .depth = 24,
+   },
+   {
+   /* BGR 888 */
+   .code = MEDIA_BUS_FMT_RGB888_2X12_BE,
+   .depth = 24,
+   },
+};
+
+static struct mipi_csi_dev *sd_to_mipi_csi_dev(struct v4l2_subdev *sdev)
+{
+   return container_of(sdev, struct mipi_csi_dev, sd);
+}
+
+static void dw_mipi_csi_write(struct mipi_csi_dev *dev,
+ 

[PATCH] [media] atmel-isc: fix off-by-one comparison and out of bounds read issue

2017-03-07 Thread Colin King
From: Colin Ian King 

The are only HIST_ENTRIES worth of entries in  hist_entry however the
for-loop is iterating one too many times leasing to a read access off
the end off the array ctrls->hist_entry.  Fix this by iterating by
the correct number of times.

Detected by CoverityScan, CID#1415279 ("Out-of-bounds read")

Signed-off-by: Colin Ian King 
---
 drivers/media/platform/atmel/atmel-isc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index b380a7d..7dacf8c 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -1298,7 +1298,7 @@ static void isc_hist_count(struct isc_device *isc)
regmap_bulk_read(regmap, ISC_HIS_ENTRY, hist_entry, HIST_ENTRIES);
 
*hist_count = 0;
-   for (i = 0; i <= HIST_ENTRIES; i++)
+   for (i = 0; i < HIST_ENTRIES; i++)
*hist_count += i * (*hist_entry++);
 }
 
-- 
2.10.2



RE: [PATCH 13/29] drivers, media: convert vb2_vmarea_handler.refcount from atomic_t to refcount_t

2017-03-07 Thread Reshetova, Elena
> Hi Elena,
> 
> On Mon, Mar 06, 2017 at 04:21:00PM +0200, Elena Reshetova wrote:
> > refcount_t type and corresponding API should be
> > used instead of atomic_t when the variable is used as
> > a reference counter. This allows to avoid accidental
> > refcounter overflows that might lead to use-after-free
> > situations.
> >
> > Signed-off-by: Elena Reshetova 
> > Signed-off-by: Hans Liljestrand 
> > Signed-off-by: Kees Cook 
> > Signed-off-by: David Windsor 
> > ---
> >  drivers/media/v4l2-core/videobuf2-memops.c | 6 +++---
> >  include/media/videobuf2-memops.h   | 3 ++-
> >  2 files changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
> > b/drivers/media/v4l2-
> core/videobuf2-memops.c
> > index 1cd322e..4bb8424 100644
> > --- a/drivers/media/v4l2-core/videobuf2-memops.c
> > +++ b/drivers/media/v4l2-core/videobuf2-memops.c
> > @@ -96,10 +96,10 @@ static void vb2_common_vm_open(struct
> vm_area_struct *vma)
> > struct vb2_vmarea_handler *h = vma->vm_private_data;
> >
> > pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
> > -  __func__, h, atomic_read(h->refcount), vma->vm_start,
> > +  __func__, h, refcount_read(h->refcount), vma->vm_start,
> >vma->vm_end);
> >
> > -   atomic_inc(h->refcount);
> > +   refcount_inc(h->refcount);
> >  }
> >
> >  /**
> > @@ -114,7 +114,7 @@ static void vb2_common_vm_close(struct
> vm_area_struct *vma)
> > struct vb2_vmarea_handler *h = vma->vm_private_data;
> >
> > pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
> > -  __func__, h, atomic_read(h->refcount), vma->vm_start,
> > +  __func__, h, refcount_read(h->refcount), vma->vm_start,
> >vma->vm_end);
> >
> > h->put(h->arg);
> > diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-
> memops.h
> > index 36565c7a..a6ed091 100644
> > --- a/include/media/videobuf2-memops.h
> > +++ b/include/media/videobuf2-memops.h
> > @@ -16,6 +16,7 @@
> >
> >  #include 
> >  #include 
> > +#include 
> >
> >  /**
> >   * struct vb2_vmarea_handler - common vma refcount tracking handler
> > @@ -25,7 +26,7 @@
> >   * @arg:   argument for @put callback
> >   */
> >  struct vb2_vmarea_handler {
> > -   atomic_t*refcount;
> > +   refcount_t  *refcount;
> 
> This is a pointer to refcount, not refcount itself. The refcount is part of
> a memory type specific struct, the types that you change in the following
> three patches. I guess it would still compile and work as separate patches
> but you'd sure get warnings at least.

Actually it doesn't compile without this patch if I remember it correctly back 
in past when I was initially splitting the patches per variable. 

> 
> How about merging this and the three following patches that change the memop
> refcount types?

Sounds good!

Best Regards,
Elena.
> 
> > void(*put)(void *arg);
> > void*arg;
> >  };
> 
> --
> Kind regards,
> 
> Sakari Ailus
> e-mail: sakari.ai...@iki.fi   XMPP: sai...@retiisi.org.uk


[PATCH 4/4] media: platform: dwc: Support for CSI-2 Host video platform

2017-03-07 Thread Ramiro Oliveira
Add support for the CSI-2 Host video platform. This platform exists only
 to support the Synopsys DW CSI-2 Host bring-up and debug efforts.

Signed-off-by: Ramiro Oliveira 
---
 drivers/media/platform/dwc/Kconfig|  40 ++
 drivers/media/platform/dwc/Makefile   |   2 +
 drivers/media/platform/dwc/csi_video_device.c | 721 +++
 drivers/media/platform/dwc/csi_video_device.h |  83 +++
 drivers/media/platform/dwc/csi_video_plat.c   | 818 ++
 drivers/media/platform/dwc/csi_video_plat.h   | 101 
 6 files changed, 1765 insertions(+)
 create mode 100644 drivers/media/platform/dwc/csi_video_device.c
 create mode 100644 drivers/media/platform/dwc/csi_video_device.h
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.c
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.h

diff --git a/drivers/media/platform/dwc/Kconfig 
b/drivers/media/platform/dwc/Kconfig
index 2cd13d23f897..057208ec3e7b 100644
--- a/drivers/media/platform/dwc/Kconfig
+++ b/drivers/media/platform/dwc/Kconfig
@@ -1,5 +1,45 @@
+config CSI_VIDEO_PLATFORM
+   tristate "Designware Cores CSI-2 VIDEO PLATFORM"
+   select DWC_MIPI_CSI2_HOST
+   select CSI_VIDEO_DEVICE
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF && HAS_DMA
+   help
+ This a V4L2 driver to support the DesignWare Cores CSI-2 Host Video
+ Platform.
+
+ To compile this driver as a module, choose M here
+
+if CSI_VIDEO_PLATFORM
+
 config DWC_MIPI_CSI2_HOST
tristate "SNPS DWC MIPI CSI2 Host"
select GENERIC_PHY
help
  This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
+
+config CSI_VIDEO_DEVICE
+   tristate "DWC VIDEO DEVICE"
+   depends on CSI_VIDEO_PLATFORM
+   help
+ This is a V4L2 driver for the CSI-2 Video platform video device
+
+choice
+   prompt "Video Device Videobuf2 mode"
+   depends on CSI_VIDEO_DEVICE
+   default VIDEO_DWC_DMA_CONTIG
+
+config VIDEO_DWC_DMA_CONTIG
+   bool "Support Videobuf2 DMA CONTIG"
+   select VIDEOBUF2_DMA_CONTIG
+   help
+ Use DMA CONTIG in CSI Video Device
+
+config VIDEO_DWC_VMALLOC
+   bool "Support Videobuf2 VMALLOC"
+   select VIDEOBUF2_VMALLOC
+   help
+ Use VMALLOC in CSI Video Device
+
+endchoice
+
+endif # CSI2_VIDEO_PLATFORM
diff --git a/drivers/media/platform/dwc/Makefile 
b/drivers/media/platform/dwc/Makefile
index 5eb076a55123..ab6f76296b34 100644
--- a/drivers/media/platform/dwc/Makefile
+++ b/drivers/media/platform/dwc/Makefile
@@ -1 +1,3 @@
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)   += csi_video_plat.o
 obj-$(CONFIG_DWC_MIPI_CSI2_HOST)   += dw_mipi_csi.o
+obj-$(CONFIG_CSI_VIDEO_DEVICE) += csi_video_device.o
diff --git a/drivers/media/platform/dwc/csi_video_device.c 
b/drivers/media/platform/dwc/csi_video_device.c
new file mode 100644
index ..c319ea6591f3
--- /dev/null
+++ b/drivers/media/platform/dwc/csi_video_device.c
@@ -0,0 +1,721 @@
+/*
+ * CSI-2 Video platform video device device driver
+ *
+ * Copyright (C) 2016 Synopsys, Inc. All rights reserved.
+ * Author: Ramiro Oliveira 
+ *
+ * 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 "csi_video_device.h"
+
+static const struct plat_csi_fmt vid_dev_formats[] = {
+   {
+   .name = "BGR888",
+   .fourcc = V4L2_PIX_FMT_BGR24,
+   .depth = 24,
+   .mbus_code = MEDIA_BUS_FMT_RGB888_2X12_LE,
+   }, {
+   .name = "RGB565",
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .depth = 16,
+   .mbus_code = MEDIA_BUS_FMT_RGB565_2X8_BE,
+   },
+};
+
+static const struct plat_csi_fmt *vid_dev_find_format(struct v4l2_format *f)
+{
+   const struct plat_csi_fmt *fmt = NULL;
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(vid_dev_formats); ++i) {
+   fmt = _dev_formats[i];
+   if (fmt->fourcc == f->fmt.pix.pixelformat)
+   return fmt;
+   }
+   return NULL;
+}
+
+/*
+ * Video node ioctl operations
+ */
+static int
+vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
+{
+   struct video_device_dev *vid_dev = video_drvdata(file);
+
+   strlcpy(cap->driver, VIDEO_DEVICE_NAME, sizeof(cap->driver));
+   strlcpy(cap->card, VIDEO_DEVICE_NAME, sizeof(cap->card));
+   snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
+dev_name(_dev->pdev->dev));
+   return 0;
+}
+
+static int
+vidioc_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f)
+{
+   const struct plat_csi_fmt *p_fmt;
+
+   if (f->index >= 

Status of CEC?

2017-03-07 Thread Jose Abreu
Hi Hans,


I'm writing to you in order to get more details about current CEC
implementation status. I've seen the code and it appears you have
already support for CEC 2.0, right? I've also seen the
implementation in adv7511 of CEC and I've extracted the following
sequence:

1) Call cec_allocate_adapter with given flags and given
cec_adap_ops (enable, log_addr, transmit, ...)

2) Call cec_register_adapter when all datapath is configured

3) Call cec_received_msg when a msg is received

Is there anything missing? Can you please confirm that these are
the essential points in order to implement CEC?


And about userspace: It should implement the logic of formating
and the following the messages to cec core, right? Does cec-ctl
utility and cec-funcs.h already handles CEC 2.0?


Thank you in advance for your help.


With best regards,

Jose Miguel Abreu



RE: [PATCH 12/29] drivers, media: convert s2255_dev.num_channels from atomic_t to refcount_t

2017-03-07 Thread Reshetova, Elena

> Hi Elena,
> 
> On Mon, Mar 06, 2017 at 04:20:59PM +0200, Elena Reshetova wrote:
> > refcount_t type and corresponding API should be
> > used instead of atomic_t when the variable is used as
> > a reference counter. This allows to avoid accidental
> > refcounter overflows that might lead to use-after-free
> > situations.
> >
> > Signed-off-by: Elena Reshetova 
> > Signed-off-by: Hans Liljestrand 
> > Signed-off-by: Kees Cook 
> > Signed-off-by: David Windsor 
> > ---
> ...
> > @@ -1688,7 +1689,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
> > "failed to register
> video device!\n");
> > break;
> > }
> > -   atomic_inc(>num_channels);
> > +   refcount_set(>num_channels, 1);
> 
> That's not right. The loop runs four iterations and the value after the
> loop should be indeed the number of channels.

Oh, yes, I was blind here, sorry. The problem why it cannot be left as inc is 
because it would do increment from zero here, which is not allowed by 
refcount_t interface. 

> atomic_t isn't really used for reference counting here, but storing out how
> many "channels" there are per hardware device, with maximum number of four
> (4). I'd leave this driver using atomic_t.
Yes, sounds like the best thing to do. I will drop this patch. 

Thank you for reviews!

Best Regards,
Elena.
> 
> > v4l2_info(>v4l2_dev, "V4L2 device registered
> as %s\n",
> >   video_device_node_name(
> >vdev));
> >
> 
> --
> Kind regards,
> 
> Sakari Ailus
> e-mail: sakari.ai...@iki.fi   XMPP: sai...@retiisi.org.uk


[PATCH 3/4] Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

2017-03-07 Thread Ramiro Oliveira
Create device tree bindings documentation for the CSI-2 Host Video
 platform.

Signed-off-by: Ramiro Oliveira 
---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt

diff --git a/Documentation/devicetree/bindings/media/snps,plat-csi2.txt 
b/Documentation/devicetree/bindings/media/snps,plat-csi2.txt
new file mode 100644
index ..f559257a0a44
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/snps,plat-csi2.txt
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 
'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+---
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
+--
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.
+
+Example:
+
+
+   camera {
+   compatible = "snps,plat-csi2", "simple-bus";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   video_device: video-device@0x1 {
+   compatible = "snps,video-device";
+   dmas = <_vdma_0 0>;
+   dma-names = "vdma0";
+   };
+
+   csi2:   csi2@0x03000 {
+   compatible = "snps,dw-mipi-csi";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = < 0x03000 0x7FF>;
+   interrupts = <2>;
+   phys = <_phy_ctrl1 0>;
+   resets = <_rst 1>;
+
+   output-type = <2>;
+   ipi-mode = <0>;
+   ipi-color-mode = <0>;
+   ipi-auto-flush = <1>;
+   virtual-channel = <0>;
+
+   port@1 {
+   reg = <1>;
+   csi1_ep1: endpoint {
+   remote-endpoint = <>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+   };
+   };
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
-- 
2.11.0




[PATCH 0/4] Support for Synopsys DW CSI-2 Host

2017-03-07 Thread Ramiro Oliveira
This patchset adds support for the DW CSI-2 Host and also for a video
device associated with it. 

The first 2 patches are only for the DW CSI-2 Host and the last 2 are for
the video device.

Although this patchset is named as v1 there were already two patchsets
previous to this one, but with a different name: "Add support for the DW
IP Prototyping Kits for MIPI CSI-2 Host".

v3:
 - Correct description errors in Documentation
 - Remove empty functions
 - Change device caps and description setting
 - Remove left-over code
 - Add more VB2 io_modes
 - Add support for dma_contig
 - Correct spelling mistakes

v2: 
 - Add more detailed descriptions in the DT documentation
 - Add binding examples to DT documentation
 - Remove unnecessary debug structures
 - Remove unused fields in structures
 - Change variable types
 - Remove unused functions
 - Declare functions as static
 - Remove some prints
 - Add missing newlines.

Ramiro Oliveira (4):
  Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host
  media: platform: dwc: Support for DW CSI-2 Host
  Documentation: dt: Add bindings documentation for CSI-2 Host Video
Platform
  media: platform: dwc: Support for CSI-2 Host video platform

 .../devicetree/bindings/media/snps,dw-mipi-csi.txt |  37 +
 .../devicetree/bindings/media/snps,plat-csi2.txt   |  77 ++
 MAINTAINERS|   7 +
 drivers/media/platform/Kconfig |   1 +
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/dwc/Kconfig |  45 ++
 drivers/media/platform/dwc/Makefile|   3 +
 drivers/media/platform/dwc/csi_video_device.c  | 721 ++
 drivers/media/platform/dwc/csi_video_device.h  |  83 +++
 drivers/media/platform/dwc/csi_video_plat.c| 818 +
 drivers/media/platform/dwc/csi_video_plat.h| 101 +++
 drivers/media/platform/dwc/dw_mipi_csi.c   | 653 
 drivers/media/platform/dwc/dw_mipi_csi.h   | 181 +
 include/media/dwc/csi_host_platform.h  |  97 +++
 14 files changed, 2826 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/csi_video_device.c
 create mode 100644 drivers/media/platform/dwc/csi_video_device.h
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.c
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.h
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h

-- 
2.11.0




[PATCH 1/4] Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host

2017-03-07 Thread Ramiro Oliveira
Create device tree bindings documentation for the Synopsys DW MIPI CSI-2
 Host.

Signed-off-by: Ramiro Oliveira 
---
 .../devicetree/bindings/media/snps,dw-mipi-csi.txt | 37 ++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt

diff --git a/Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt 
b/Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
new file mode 100644
index ..5b24eb43d760
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
@@ -0,0 +1,37 @@
+Synopsys DesignWare CSI-2 Host controller
+
+Description
+---
+
+This HW block is used to receive image coming from an MIPI CSI-2 compatible
+camera.
+
+Required properties:
+- compatible: shall be "snps,dw-mipi-csi"
+- reg  : physical base address and size of the device memory mapped
+  registers;
+- interrupts   : CSI-2 Host interrupt
+- output-type   : Core output to be used (IPI-> 0 or IDI->1 or BOTH->2) These
+  values choose which of the Core outputs will be used, it can be Image Data
+  Interface or Image Pixel Interface.
+- phys: List of one PHY specifier (as defined in
+  Documentation/devicetree/bindings/phy/phy-bindings.txt). This PHY is a MIPI
+  DPHY working in RX mode.
+- resets: Reference to a reset controller (optional)
+
+Optional properties(if in IPI mode):
+- ipi-mode : Mode to be used when in IPI(Camera -> 0 or Controller -> 1)
+  This property defines if the controller will use the video timings available
+  in the video stream or if it will use pre-defined ones.
+- ipi-color-mode: Bus depth to be used in IPI (48 bits -> 0 or 16 bits -> 1)
+  This property defines the width of the IPI bus.
+- ipi-auto-flush: Data auto-flush (1 -> Yes or 0 -> No). This property defines
+  if the data is automatically flushed in each vsync or if this process is done
+  manually
+- virtual-channel: Virtual channel where data is present when in IPI mode. This
+  property chooses the virtual channel which IPI will use to retrieve the video
+  stream.
+
+The per-board settings:
+ - port sub-node describing a single endpoint connected to the camera as
+   described in video-interfaces.txt[1].
-- 
2.11.0




Re: [PATCH 1/1] media: entity: Swap pads if route is checked from source to sink

2017-03-07 Thread Niklas Söderlund
Hi Sakari,

Thanks for the patch.

On 2016-11-08 12:11:15 +0200, Sakari Ailus wrote:
> This way the pads are always passed to the has_route() op sink pad first.
> Makes sense.
> 
> Signed-off-by: Sakari Ailus 
> ---
> Hi Niklas,
> 
> This should make it easier to implement the has_route() op in drivers.
> 
> Feel free to merge this to "[PATCH 02/32] media: entity: Add
> media_entity_has_route() function" if you like, or add separately after
> the second patch.

I choose to append this as a separated patch on top of Laurents patches 
and include all 3 in my next R-Car VIN series.

> 
>  drivers/media/media-entity.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 747adcb..520f3f6 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -254,6 +254,10 @@ bool media_entity_has_route(struct media_entity *entity, 
> unsigned int pad0,
>   if (!entity->ops || !entity->ops->has_route)
>   return true;
>  
> + if (entity->pads[pad0].flags & MEDIA_PAD_FL_SOURCE
> + && entity->pads[pad1].flags & MEDIA_PAD_FL_SINK)
> + swap(pad0, pad1);
> +
>   return entity->ops->has_route(entity, pad0, pad1);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_has_route);
> -- 
> 2.7.4
> 

-- 
Regards,
Niklas Söderlund


[PATCH] [media] platform: Order the Makefile alphabetically

2017-03-07 Thread Maxime Ripard
The Makefile was a free for all without a clear order defined. Sort all the
options based on the Kconfig symbol.

Signed-off-by: Maxime Ripard 
---
 drivers/media/platform/Makefile | 89 ++---
 1 file changed, 31 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 349ddf6a69da..bd5dc3068cbc 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -1,73 +1,46 @@
 #
 # Makefile for the video capture/playback device drivers.
 #
+ccflags-y += -I$(srctree)/drivers/media/i2c
 
-obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
-
-obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
-obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
-obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
-
-obj-$(CONFIG_VIDEO_OMAP3)  += omap3isp/
-obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
-
-obj-$(CONFIG_VIDEO_VIU) += fsl-viu.o
-
-obj-$(CONFIG_VIDEO_VIVID)  += vivid/
-obj-$(CONFIG_VIDEO_VIM2M)  += vim2m.o
-
-obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe/
-
-obj-$(CONFIG_VIDEO_TI_CAL) += ti-vpe/
-
-obj-$(CONFIG_VIDEO_MX2_EMMAPRP)+= mx2_emmaprp.o
+obj-y  += omap/
+obj-$(CONFIG_ARCH_DAVINCI) += davinci/
+obj-$(CONFIG_BLACKFIN)  += blackfin/
+obj-$(CONFIG_DVB_C8SECTPFE)+= sti/c8sectpfe/
+obj-$(CONFIG_SOC_CAMERA)   += soc_camera/
+obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
+obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
+obj-$(CONFIG_VIDEO_CAFE_CCIC)  += marvell-ccic/
 obj-$(CONFIG_VIDEO_CODA)   += coda/
-
-obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
-
+obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
+obj-$(CONFIG_VIDEO_MEDIATEK_MDP)   += mtk-mdp/
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC)+= mtk-vcodec/
+obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)+= m2m-deinterlace.o
-
+obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
+obj-$(CONFIG_VIDEO_MX2_EMMAPRP)+= mx2_emmaprp.o
+obj-$(CONFIG_VIDEO_OMAP3)  += omap3isp/
+obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
+obj-$(CONFIG_VIDEO_RCAR_VIN)   += rcar-vin/
+obj-$(CONFIG_VIDEO_RENESAS_FCP)+= rcar-fcp.o
+obj-$(CONFIG_VIDEO_RENESAS_FDP1)   += rcar_fdp1.o
+obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
+obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)+= s5p-mfc/
-
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D)+= s5p-g2d/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC) += exynos-gsc/
-
+obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
+obj-$(CONFIG_VIDEO_SH_VOU) += sh_vou.o
 obj-$(CONFIG_VIDEO_STI_BDISP)  += sti/bdisp/
-obj-$(CONFIG_VIDEO_STI_HVA)+= sti/hva/
-obj-$(CONFIG_DVB_C8SECTPFE)+= sti/c8sectpfe/
-
 obj-$(CONFIG_VIDEO_STI_DELTA)  += sti/delta/
-
-obj-$(CONFIG_BLACKFIN)  += blackfin/
-
-obj-$(CONFIG_ARCH_DAVINCI) += davinci/
-
-obj-$(CONFIG_VIDEO_SH_VOU) += sh_vou.o
-
-obj-$(CONFIG_SOC_CAMERA)   += soc_camera/
-
-obj-$(CONFIG_VIDEO_RENESAS_FCP)+= rcar-fcp.o
-obj-$(CONFIG_VIDEO_RENESAS_FDP1)   += rcar_fdp1.o
-obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
-obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
-
-obj-y  += omap/
-
-obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
-
+obj-$(CONFIG_VIDEO_STI_HVA)+= sti/hva/
+obj-$(CONFIG_VIDEO_TI_CAL) += ti-vpe/
+obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe/
+obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
+obj-$(CONFIG_VIDEO_VIM2M)  += vim2m.o
+obj-$(CONFIG_VIDEO_VIU)+= fsl-viu.o
+obj-$(CONFIG_VIDEO_VIVID)  += vivid/
 obj-$(CONFIG_VIDEO_XILINX) += xilinx/
-
-obj-$(CONFIG_VIDEO_RCAR_VIN)   += rcar-vin/
-
-obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
-
-ccflags-y += -I$(srctree)/drivers/media/i2c
-
-obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
-
-obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC)+= mtk-vcodec/
-
-obj-$(CONFIG_VIDEO_MEDIATEK_MDP)   += mtk-mdp/
-- 
2.11.0



Re: [PATCH 1/1] media: entity: Swap pads if route is checked from source to sink

2017-03-07 Thread Sakari Ailus
Hi Niklas,

On 03/07/17 13:15, Niklas Söderlund wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On 2016-11-08 12:11:15 +0200, Sakari Ailus wrote:
>> This way the pads are always passed to the has_route() op sink pad first.
>> Makes sense.
>>
>> Signed-off-by: Sakari Ailus 
>> ---
>> Hi Niklas,
>>
>> This should make it easier to implement the has_route() op in drivers.
>>
>> Feel free to merge this to "[PATCH 02/32] media: entity: Add
>> media_entity_has_route() function" if you like, or add separately after
>> the second patch.
> 
> I choose to append this as a separated patch on top of Laurents patches 
> and include all 3 in my next R-Car VIN series.


Ack. Thanks for the info.

-- 
Sakari Ailus
sakari.ai...@linux.intel.com


Re: [PATCH] media: vpif: use a configurable i2c_adapter_id for vpif display

2017-03-07 Thread Bartosz Golaszewski
2017-02-16 19:08 GMT+01:00 Bartosz Golaszewski :
> The vpif display driver uses a static i2c adapter ID of 1 but on the
> da850-evm board in DT boot mode the i2c adapter ID is actually 0.
>
> Make the adapter ID configurable like it already is for vpif capture.
>
> Signed-off-by: Bartosz Golaszewski 
> Acked-by: Kevin Hilman 
> ---

Hi Mauro, Prabhakar,

can we get an ack on this? Sekhar already merged the rest of the
patches that need this to make vpif display work on the da850-evm
board. I think it's best if it goes through his tree.

Thanks,
Bartosz


Re: [Patch v2 11/11] Documention: v4l: Documentation for HEVC CIDs

2017-03-07 Thread Andrzej Hajda

On 03.03.2017 10:07, Smitha T Murthy wrote:
> Added V4l2 controls for HEVC encoder

It should be rather "Document controls for HEVC encoder" or sth similar.

In general most of comments are in previous patch.
Few additional comments:
- please be careful about control names - they are exported to userspace
and becomes ABI, so it will be difficult to change them later (this
comment is rather to previous patch),
- please provide good documentation as for most users this documentation
will be the only available source of information,
- in short: bugs in the driver can be easily fixed(usually), wrong
control names will be hard to fix, weak documentation will prevent using it.

And regarding this patch:
- please expand all acronyms (pb, tmv, BIT,...),
- please consider using menu instead of numbers for profile, level,
tier, types, generally everywhere where control value enumerates
'things' and is not a pure number (coefficient, counter,...),
- if control is per-frame please drop it, V4L2 does not support it at
the moment ( I suppose ),

Regards
Andrzej




Re: Status of CEC?

2017-03-07 Thread Hans Verkuil

On 03/07/2017 12:44 PM, Jose Abreu wrote:

Hi Hans,


I'm writing to you in order to get more details about current CEC
implementation status. I've seen the code and it appears you have
already support for CEC 2.0, right? I've also seen the
implementation in adv7511 of CEC and I've extracted the following
sequence:

1) Call cec_allocate_adapter with given flags and given
cec_adap_ops (enable, log_addr, transmit, ...)

2) Call cec_register_adapter when all datapath is configured

3) Call cec_received_msg when a msg is received

Is there anything missing? Can you please confirm that these are
the essential points in order to implement CEC?


And you need to implement a few callbacks:

adap_enable, adap_log_addr and adap_transmit at minimum.

See also:

https://hverkuil.home.xs4all.nl/spec/kapi/cec-core.html

Starting with 4.10 the CEC framework is now mainlined.

The main missing piece is this:

https://www.spinics.net/lists/linux-samsung-soc/msg58035.html

I need to make a v5 of this patch series. Whether you need this or
not depends on your HW architecture.




And about userspace: It should implement the logic of formating
and the following the messages to cec core, right? Does cec-ctl
utility and cec-funcs.h already handles CEC 2.0?


Yes. In fact, by default cec-ctl will configure a CEC adapter as a
2.0 CEC device.

Also see cec-compliance to do CEC protocol compliance testing and
cec-follower, which will emulate a CEC device as a follower.

The code in cec-follower is dual licensed as GPLv2 and BSD, so you
can use code from that when you write your own follower. The cec
public headers (including cec-funcs.h) are all dual licensed.

Regards,

Hans


Re: [Patch v2 10/11] s5p-mfc: Add support for HEVC encoder

2017-03-07 Thread Andrzej Hajda
On 03.03.2017 10:07, Smitha T Murthy wrote:
> Add HEVC encoder support and necessary registers, V4L2 CIDs,
> and hevc encoder parameters
>
> Signed-off-by: Smitha T Murthy 
> ---
>  drivers/media/platform/s5p-mfc/regs-mfc-v10.h   |   28 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc.c|1 +
>  drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c |3 +
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   55 ++-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|  595 
> +++
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr.h|8 +
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |  200 
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.h |8 +
>  8 files changed, 896 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v10.h 
> b/drivers/media/platform/s5p-mfc/regs-mfc-v10.h
> index 846dcf5..caf02ff 100644
> --- a/drivers/media/platform/s5p-mfc/regs-mfc-v10.h
> +++ b/drivers/media/platform/s5p-mfc/regs-mfc-v10.h
> @@ -20,13 +20,35 @@
>  #define S5P_FIMV_MFC_STATE_V10   0x7124
>  #define S5P_FIMV_D_STATIC_BUFFER_ADDR_V100xF570
>  #define S5P_FIMV_D_STATIC_BUFFER_SIZE_V100xF574
> +#define S5P_FIMV_E_NUM_T_LAYER_V10   0xFBAC
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER0_V100xFBB0
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER1_V100xFBB4
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER2_V100xFBB8
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER3_V100xFBBC
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER4_V100xFBC0
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER5_V100xFBC4
> +#define S5P_FIMV_E_HIERARCHICAL_QP_LAYER6_V100xFBC8
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER0_V10  0xFD18
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER1_V10  0xFD1C
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER2_V10  0xFD20
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER3_V10  0xFD24
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER4_V10  0xFD28
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER5_V10  0xFD2C
> +#define S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER6_V10  0xFD30
> +#define S5P_FIMV_E_HEVC_OPTIONS_V10  0xFDD4
> +#define S5P_FIMV_E_HEVC_REFRESH_PERIOD_V10   0xFDD8
> +#define S5P_FIMV_E_HEVC_CHROMA_QP_OFFSET_V10 0xFDDC
> +#define S5P_FIMV_E_HEVC_LF_BETA_OFFSET_DIV2_V10  0xFDE0
> +#define S5P_FIMV_E_HEVC_LF_TC_OFFSET_DIV2_V100xFDE4
> +#define S5P_FIMV_E_HEVC_NAL_CONTROL_V10  0xFDE8
>  
>  /* MFCv10 Context buffer sizes */
>  #define MFC_CTX_BUF_SIZE_V10 (30 * SZ_1K)/* 30KB */
>  #define MFC_H264_DEC_CTX_BUF_SIZE_V10(2 * SZ_1M) /* 2MB */
>  #define MFC_OTHER_DEC_CTX_BUF_SIZE_V10   (20 * SZ_1K)/* 20KB */
>  #define MFC_H264_ENC_CTX_BUF_SIZE_V10(100 * SZ_1K)   /* 100KB */
> -#define MFC_OTHER_ENC_CTX_BUF_SIZE_V10   (15 * SZ_1K)/* 15KB */
> +#define MFC_HEVC_ENC_CTX_BUF_SIZE_V10(30 * SZ_1K)/* 30KB */
> +#define MFC_OTHER_ENC_CTX_BUF_SIZE_V10  (15 * SZ_1K) /* 15KB */
>  
>  /* MFCv10 variant defines */
>  #define MAX_FW_SIZE_V10  (SZ_1M) /* 1MB */
> @@ -58,5 +80,9 @@
>  #define ENC_V100_VP8_ME_SIZE(x, y) \
>   ENC_V100_BASE_SIZE(x, y)
>  
> +#define ENC_V100_HEVC_ME_SIZE(x, y)  \
> + (((x + 3) * (y + 3) * 32)   \
> +  + ((y * 128) + 1280) * DIV_ROUND_UP(x, 4))
> +
>  #endif /*_REGS_MFC_V10_H*/
>  
> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
> index b014038..b01c556 100644
> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
> @@ -1549,6 +1549,7 @@ static int s5p_mfc_resume(struct device *dev)
>   .h264_dec_ctx   = MFC_H264_DEC_CTX_BUF_SIZE_V10,
>   .other_dec_ctx  = MFC_OTHER_DEC_CTX_BUF_SIZE_V10,
>   .h264_enc_ctx   = MFC_H264_ENC_CTX_BUF_SIZE_V10,
> + .hevc_enc_ctx   = MFC_HEVC_ENC_CTX_BUF_SIZE_V10,
>   .other_enc_ctx  = MFC_OTHER_ENC_CTX_BUF_SIZE_V10,
>  };
>  
> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c 
> b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
> index 102b47e..7521fce 100644
> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
> @@ -122,6 +122,9 @@ static int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx 
> *ctx)
>   case S5P_MFC_CODEC_VP8_ENC:
>   codec_type = S5P_FIMV_CODEC_VP8_ENC_V7;
>   break;
> + case S5P_MFC_CODEC_HEVC_ENC:
> + codec_type = S5P_FIMV_CODEC_HEVC_ENC;
> + break;
>   default:
>   codec_type = S5P_FIMV_CODEC_NONE_V6;
>   }
> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
> index e720ce6..c55fa6c 100644
> --- 

Re: [PATCH 11/29] drivers, media: convert cx88_core.refcount from atomic_t to refcount_t

2017-03-07 Thread Sergei Shtylyov

On 3/7/2017 10:52 AM, Reshetova, Elena wrote:


refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.

Signed-off-by: Elena Reshetova 
Signed-off-by: Hans Liljestrand 
Signed-off-by: Kees Cook 
Signed-off-by: David Windsor 

[...]

diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index 115414c..16c1313 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h

[...]

@@ -339,7 +340,7 @@ struct cx8802_dev;

 struct cx88_core {
struct list_head   devlist;
-   atomic_t   refcount;
+   refcount_t   refcount;


Could you please keep the name aligned with above and below?


You mean "not aligned" to devlist, but with a shift like it was before?


   I mean aligned, like it was before. :-)


Sure, will fix. Is the patch ok otherwise?


   I haven't noticed anything else...


Best Regards,
Elena.

[...]

MBR, Sergei


RE: [PATCH 21/29] drivers, s390: convert fc_fcp_pkt.ref_cnt from atomic_t to refcount_t

2017-03-07 Thread Reshetova, Elena
> On 03/06/2017 03:21 PM, Elena Reshetova wrote:
> > refcount_t type and corresponding API should be
> > used instead of atomic_t when the variable is used as
> > a reference counter. This allows to avoid accidental
> > refcounter overflows that might lead to use-after-free
> > situations.
> 
> The subject is wrong, should be something like "scsi: libfc convert
> fc_fcp_pkt.ref_cnt from atomic_t to refcount_t" but not s390.

Very sorry about this: the error in the subject got from the time when I was 
trying to break the bigger drivers patch set into per-variable part and trying 
to automate the process too much :(
I will fix it in the end version!

Best Regards,
Elena

> 
> Other than that
> Acked-by: Johannes Thumshirn 
> 
> --
> Johannes Thumshirn  Storage
> jthumsh...@suse.de+49 911 74053 689
> SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
> GF: Felix Imendörffer, Jane Smithard, Graham Norton
> HRB 21284 (AG Nürnberg)
> Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


Re: [PATCH 08/26] brcmsmac: make some local variables 'static const' to reduce stack size

2017-03-07 Thread Arend Van Spriel
On 7-3-2017 10:44, Kalle Valo wrote:
> Arnd Bergmann  writes:
> 
>> On Mon, Mar 6, 2017 at 5:19 PM, Kalle Valo  wrote:
>>> Arend Van Spriel  writes:
>>>
 On 2-3-2017 17:38, Arnd Bergmann wrote:
> With KASAN and a couple of other patches applied, this driver is one
> of the few remaining ones that actually use more than 2048 bytes of
> kernel stack:
>
> broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function
> 'wlc_phy_workarounds_nphy_gainctrl':
> broadcom/brcm80211/brcmsmac/phy/phy_n.c:16065:1: warning: the
> frame size of 3264 bytes is larger than 2048 bytes
> [-Wframe-larger-than=]
> broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function 
> 'wlc_phy_workarounds_nphy':
> broadcom/brcm80211/brcmsmac/phy/phy_n.c:17138:1: warning: the
> frame size of 2864 bytes is larger than 2048 bytes
> [-Wframe-larger-than=]
>
> Here, I'm reducing the stack size by marking as many local variables as
> 'static const' as I can without changing the actual code.

 Acked-by: Arend van Spriel 
>>>
>>> Arnd, via which tree are you planning to submit these? I'm not sure
>>> what I should do with the wireless drivers patches from this series.
>>
>> I'm not quite sure myself yet. I'd probably want the first few patches that
>> do most of the work get merged through Andrew's linux-mm tree once
>> we have come to agreement on them. The driver specific patches like
>> the brcmsmac ones depend on the introduction of noinline_for_kasan
>> or noinline_if_stackbloat and could either go in along with the first
>> set, or as a follow-up through the normal maintainer trees.
> 
> Either way is fine for me. Just mark clearly if you want the wireless
> drivers patches to go through via my tree, otherwise I'll ignore them.

That (dreaded) phy code does not get a lot of changes so I think it does
not matter which tree is will go through in terms of risk for conflicts.
So going through linux-mm is fine for me as well.

Regards,
Arend


Re: [PATCH 08/26] brcmsmac: make some local variables 'static const' to reduce stack size

2017-03-07 Thread Kalle Valo
Arnd Bergmann  writes:

> On Mon, Mar 6, 2017 at 5:19 PM, Kalle Valo  wrote:
>> Arend Van Spriel  writes:
>>
>>> On 2-3-2017 17:38, Arnd Bergmann wrote:
 With KASAN and a couple of other patches applied, this driver is one
 of the few remaining ones that actually use more than 2048 bytes of
 kernel stack:

 broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function
 'wlc_phy_workarounds_nphy_gainctrl':
 broadcom/brcm80211/brcmsmac/phy/phy_n.c:16065:1: warning: the
 frame size of 3264 bytes is larger than 2048 bytes
 [-Wframe-larger-than=]
 broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function 
 'wlc_phy_workarounds_nphy':
 broadcom/brcm80211/brcmsmac/phy/phy_n.c:17138:1: warning: the
 frame size of 2864 bytes is larger than 2048 bytes
 [-Wframe-larger-than=]

 Here, I'm reducing the stack size by marking as many local variables as
 'static const' as I can without changing the actual code.
>>>
>>> Acked-by: Arend van Spriel 
>>
>> Arnd, via which tree are you planning to submit these? I'm not sure
>> what I should do with the wireless drivers patches from this series.
>
> I'm not quite sure myself yet. I'd probably want the first few patches that
> do most of the work get merged through Andrew's linux-mm tree once
> we have come to agreement on them. The driver specific patches like
> the brcmsmac ones depend on the introduction of noinline_for_kasan
> or noinline_if_stackbloat and could either go in along with the first
> set, or as a follow-up through the normal maintainer trees.

Either way is fine for me. Just mark clearly if you want the wireless
drivers patches to go through via my tree, otherwise I'll ignore them.

-- 
Kalle Valo


Re: [PATCH 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread 李務誠
On Tue, Mar 7, 2017 at 3:59 PM, Tiffany Lin  wrote:
> On Tue, 2017-03-07 at 14:03 +0800, Wu-Cheng Li wrote:
>> From: Wu-Cheng Li 
>>
>> VPU firmware has a bug and may return invalid buffer index for
>> some vp9 videos. Check the buffer indexes before accessing the
>> buffer.
>>
>> Signed-off-by: Wu-Cheng Li 
>> ---
>>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c |  6 +
>>  .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 
>> ++
>>  drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
>>  3 files changed, 34 insertions(+)
>>
>> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
>> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
>> index 502877a4b1df..7ebcf9e57ac7 100644
>> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
>> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
>> @@ -1176,6 +1176,12 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer 
>> *vb)
>>  "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
>> fail=%d, res_chg=%d",
>>  ctx->id, src_buf->index,
>>  src_mem.size, ret, res_chg);
>> +
>> + if (ret == -EIO) {
>> + mtk_v4l2_err("[%d] Unrecoverable error in 
>> vdec_if_decode.",
>> + ctx->id);
>> + ctx->state = MTK_STATE_ABORT;
>> + }
> Could we use v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
> VB2_BUF_STATE_ERROR); instead ctx->state = MTK_STATE_ABORT;
> In this case, the behavior will be same as vdec_if_decode called in
> mtk_vdec_worker.
If we use VB2_BUF_STATE_ERROR, dqbuf will return V4L2_BUF_FLAG_ERROR.
It means a recoverable error.

"The driver may also set V4L2_BUF_FLAG_ERROR in the flags field. It indicates
a non-critical (recoverable) streaming error. In such case the application may
continue as normal, but should be aware that data in the dequeued buffer might
be corrupted."
https://static.lwn.net/kerneldoc/media/uapi/v4l/vidioc-qbuf.html
> And we could also get information about what output buffer make vpu
> crash.
>
> best regards,
> Tiffany
>>   return;
>>   }
>>
>> diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
>> b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
>> index e91a3b425b0c..5539b1853f16 100644
>> --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
>> +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
>> @@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, 
>> struct vdec_fb **out_fb)
>>   *out_fb = fb;
>>  }
>>
>> +static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
>> + struct vdec_vp9_vsi *vsi) {
>> + if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
>> + mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.",
>> + vsi->sf_frm_idx);
>> + return -EIO;
>> + }
>> + if (vsi->frm_to_show_idx >= VP9_MAX_FRM_BUF_NUM) {
>> + mtk_vcodec_err(inst, "Invalid vsi->frm_to_show_idx=%u.",
>> + vsi->frm_to_show_idx);
>> + return -EIO;
>> + }
>> + if (vsi->new_fb_idx >= VP9_MAX_FRM_BUF_NUM) {
>> + mtk_vcodec_err(inst, "Invalid vsi->new_fb_idx=%u.",
>> + vsi->new_fb_idx);
>> + return -EIO;
>> + }
>> + return 0;
>> +}
>> +
>>  static void vdec_vp9_deinit(unsigned long h_vdec)
>>  {
>>   struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec;
>> @@ -834,6 +854,12 @@ static int vdec_vp9_decode(unsigned long h_vdec, struct 
>> mtk_vcodec_mem *bs,
>>   goto DECODE_ERROR;
>>   }
>>
>> + ret = validate_vsi_array_indexes(inst, vsi);
>> + if (ret) {
>> + mtk_vcodec_err(inst, "Invalid values from VPU.");
>> + goto DECODE_ERROR;
>> + }
>> +
>>   if (vsi->resolution_changed) {
>>   if (!vp9_alloc_work_buf(inst)) {
>>   ret = -EINVAL;
>> diff --git a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h 
>> b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
>> index db6b5205ffb1..ded1154481cd 100644
>> --- a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
>> +++ b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
>> @@ -85,6 +85,8 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx);
>>   * @res_chg  : [out] resolution change happens if current bs have different
>>   *   picture width/height
>>   * Note: To flush the decoder when reaching EOF, set input bitstream as 
>> NULL.
>> + *
>> + * Return: 0 on success. -EIO on unrecoverable error.
>>   */
>>  int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
>>  struct vdec_fb *fb, bool *res_chg);
>
>


Re: [Patch v2 07/11] Documentation: v4l: Documentation for HEVC v4l2 definition

2017-03-07 Thread Andrzej Hajda
On 03.03.2017 10:07, Smitha T Murthy wrote:
> Add V4L2 definition for HEVC compressed format
> 
> Signed-off-by: Smitha T Murthy 

Reviewed-by: Andrzej Hajda 



> ---
>  Documentation/media/uapi/v4l/pixfmt-013.rst |5 +
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/media/uapi/v4l/pixfmt-013.rst 
> b/Documentation/media/uapi/v4l/pixfmt-013.rst
> index 728d7ed..ff4cac2 100644
> --- a/Documentation/media/uapi/v4l/pixfmt-013.rst
> +++ b/Documentation/media/uapi/v4l/pixfmt-013.rst
> @@ -90,3 +90,8 @@ Compressed Formats
>- ``V4L2_PIX_FMT_VP9``
>- 'VP90'
>- VP9 video elementary stream.
> +* .. _V4L2-PIX-FMT-HEVC:
> +
> +  - ``V4L2_PIX_FMT_HEVC``
> +  - 'HEVC'
> +  - HEVC video elementary stream.
> 



Re: [PATCH 13/29] drivers, media: convert vb2_vmarea_handler.refcount from atomic_t to refcount_t

2017-03-07 Thread Sakari Ailus
Hi Elena,

On Mon, Mar 06, 2017 at 04:21:00PM +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 
> ---
>  drivers/media/v4l2-core/videobuf2-memops.c | 6 +++---
>  include/media/videobuf2-memops.h   | 3 ++-
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
> b/drivers/media/v4l2-core/videobuf2-memops.c
> index 1cd322e..4bb8424 100644
> --- a/drivers/media/v4l2-core/videobuf2-memops.c
> +++ b/drivers/media/v4l2-core/videobuf2-memops.c
> @@ -96,10 +96,10 @@ static void vb2_common_vm_open(struct vm_area_struct *vma)
>   struct vb2_vmarea_handler *h = vma->vm_private_data;
>  
>   pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
> -__func__, h, atomic_read(h->refcount), vma->vm_start,
> +__func__, h, refcount_read(h->refcount), vma->vm_start,
>  vma->vm_end);
>  
> - atomic_inc(h->refcount);
> + refcount_inc(h->refcount);
>  }
>  
>  /**
> @@ -114,7 +114,7 @@ static void vb2_common_vm_close(struct vm_area_struct 
> *vma)
>   struct vb2_vmarea_handler *h = vma->vm_private_data;
>  
>   pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
> -__func__, h, atomic_read(h->refcount), vma->vm_start,
> +__func__, h, refcount_read(h->refcount), vma->vm_start,
>  vma->vm_end);
>  
>   h->put(h->arg);
> diff --git a/include/media/videobuf2-memops.h 
> b/include/media/videobuf2-memops.h
> index 36565c7a..a6ed091 100644
> --- a/include/media/videobuf2-memops.h
> +++ b/include/media/videobuf2-memops.h
> @@ -16,6 +16,7 @@
>  
>  #include 
>  #include 
> +#include 
>  
>  /**
>   * struct vb2_vmarea_handler - common vma refcount tracking handler
> @@ -25,7 +26,7 @@
>   * @arg: argument for @put callback
>   */
>  struct vb2_vmarea_handler {
> - atomic_t*refcount;
> + refcount_t  *refcount;

This is a pointer to refcount, not refcount itself. The refcount is part of
a memory type specific struct, the types that you change in the following
three patches. I guess it would still compile and work as separate patches
but you'd sure get warnings at least.

How about merging this and the three following patches that change the memop
refcount types?

>   void(*put)(void *arg);
>   void*arg;
>  };

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk


Re: [Patch v2 09/11] v4l2: Add v4l2 control IDs for HEVC encoder

2017-03-07 Thread Andrzej Hajda
On 03.03.2017 10:07, Smitha T Murthy wrote:
> Add v4l2 controls for HEVC encoder
>
> Signed-off-by: Smitha T Murthy 
> ---
>  drivers/media/v4l2-core/v4l2-ctrls.c |   51 +
>  include/uapi/linux/v4l2-controls.h   |  129 
> ++
>  2 files changed, 180 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
> b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 47001e2..b3ec7a3 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -775,6 +775,57 @@ static bool is_new_manual(const struct v4l2_ctrl *master)
>   case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP:return "VPX 
> P-Frame QP Value";
>   case V4L2_CID_MPEG_VIDEO_VPX_PROFILE:   return "VPX 
> Profile";
>  
> + /* HEVC controls */
> + case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP:   return "HEVC I 
> frame QP value";
> + case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP:   return "HEVC P 
> frame QP value";
> + case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP:   return "HEVC B 
> frame QP value";
> + case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP:   return "HEVC 
> Minimum QP value";
> + case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP:   return "HEVC 
> Maximum QP value";
> + case V4L2_CID_MPEG_VIDEO_HEVC_ADAPTIVE_RC_DARK: return "HEVC 
> Dark region adaptive";
> + case V4L2_CID_MPEG_VIDEO_HEVC_ADAPTIVE_RC_SMOOTH:   return "HEVC 
> Smooth region adaptive";
> + case V4L2_CID_MPEG_VIDEO_HEVC_ADAPTIVE_RC_STATIC:   return "HEVC 
> Static region adaptive";
> + case V4L2_CID_MPEG_VIDEO_HEVC_ADAPTIVE_RC_ACTIVITY: return "HEVC 
> Region adaptive rate control";
> + case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:  return "HEVC 
> Profile";
> + case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:return "HEVC 
> Level";
> + case V4L2_CID_MPEG_VIDEO_HEVC_TIER_FLAG:return "HEVC 
> tier_flag default is Main";
> + case V4L2_CID_MPEG_VIDEO_HEVC_RC_FRAME_RATE:return "HEVC 
> Frame rate";
> + case V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH:  return "HEVC 
> Maximum coding unit depth";
> + case V4L2_CID_MPEG_VIDEO_HEVC_REF_NUMBER_FOR_PFRAMES:   return "HEVC 
> Number of reference frames for P Frames";
> + case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE: return "HEVC 
> Refresh type";
> + case V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED_ENABLE:  return "HEVC 
> Constant intra prediction enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU_ENABLE:   return "HEVC 
> Lossless encoding enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT_ENABLE: return "HEVC 
> Wavefront enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_LF_DISABLE:   return "HEVC 
> Loop filter disable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_LF_SLICE_BOUNDARY:return "HEVC 
> Loop filtering across slice boundary or not";
> + case V4L2_CID_MPEG_VIDEO_HEVC_LTR_ENABLE:   return "HEVC 
> long term reference enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_QP_ENABLE:   return "HEVC QP 
> values for temporal layer";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_TYPE: return "HEVC 
> Hierarchical Coding Type";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER:return "HEVC 
> Hierarchical Coding Layer";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_QP:return "HEVC 
> Hierarchical Coding Layer QP";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT0:return 
> "HEVC Hierarchical Coding Layer BIT0";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT1:return 
> "HEVC Hierarchical Coding Layer BIT1";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT2:return 
> "HEVC Hierarchical Coding Layer BIT2";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT3:return 
> "HEVC Hierarchical Coding Layer BIT3";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT4:return 
> "HEVC Hierarchical Coding Layer BIT4";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT5:return 
> "HEVC Hierarchical Coding Layer BIT5";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_BIT6:return 
> "HEVC Hierarchical Coding Layer BIT6";
> + case V4L2_CID_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_LAYER_CH:return "HEVC 
> Hierarchical Coding Layer Change";
> + case V4L2_CID_MPEG_VIDEO_HEVC_SIGN_DATA_HIDING: return "HEVC 
> Sign data hiding";
> + case V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB_ENABLE:return "HEVC 
> General pb enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID_ENABLE:   return "HEVC 
> Temporal id enable";
> + case V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOTHING_FLAG: return "HEVC 
> Strong intra smoothing flag";
> + case 

Re: [PATCH 12/29] drivers, media: convert s2255_dev.num_channels from atomic_t to refcount_t

2017-03-07 Thread Sakari Ailus
Hi Elena,

On Mon, Mar 06, 2017 at 04:20:59PM +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 
> ---
...
> @@ -1688,7 +1689,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
>   "failed to register video device!\n");
>   break;
>   }
> - atomic_inc(>num_channels);
> + refcount_set(>num_channels, 1);

That's not right. The loop runs four iterations and the value after the
loop should be indeed the number of channels.

atomic_t isn't really used for reference counting here, but storing out how
many "channels" there are per hardware device, with maximum number of four
(4). I'd leave this driver using atomic_t.

>   v4l2_info(>v4l2_dev, "V4L2 device registered as %s\n",
> video_device_node_name(>vdev));
>  

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk


Re: [PATCH 11/29] drivers, media: convert cx88_core.refcount from atomic_t to refcount_t

2017-03-07 Thread Sakari Ailus
On Mon, Mar 06, 2017 at 04:20:58PM +0200, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> 
> Signed-off-by: Elena Reshetova 
> Signed-off-by: Hans Liljestrand 
> Signed-off-by: Kees Cook 
> Signed-off-by: David Windsor 

Acked-by: Sakari Ailus 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk


Re: [PATCH 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU.

2017-03-07 Thread Tiffany Lin
On Tue, 2017-03-07 at 14:03 +0800, Wu-Cheng Li wrote:
> From: Wu-Cheng Li 
> 
> VPU firmware has a bug and may return invalid buffer index for
> some vp9 videos. Check the buffer indexes before accessing the
> buffer.
> 
> Signed-off-by: Wu-Cheng Li 
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c |  6 +
>  .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   | 26 
> ++
>  drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  2 ++
>  3 files changed, 34 insertions(+)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> index 502877a4b1df..7ebcf9e57ac7 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> @@ -1176,6 +1176,12 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer 
> *vb)
>  "[%d] vdec_if_decode() src_buf=%d, size=%zu, 
> fail=%d, res_chg=%d",
>  ctx->id, src_buf->index,
>  src_mem.size, ret, res_chg);
> +
> + if (ret == -EIO) {
> + mtk_v4l2_err("[%d] Unrecoverable error in 
> vdec_if_decode.",
> + ctx->id);
> + ctx->state = MTK_STATE_ABORT;
> + }
Could we use v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
VB2_BUF_STATE_ERROR); instead ctx->state = MTK_STATE_ABORT;
In this case, the behavior will be same as vdec_if_decode called in
mtk_vdec_worker.
And we could also get information about what output buffer make vpu
crash.

best regards,
Tiffany
>   return;
>   }
>  
> diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
> b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> index e91a3b425b0c..5539b1853f16 100644
> --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
> @@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, 
> struct vdec_fb **out_fb)
>   *out_fb = fb;
>  }
>  
> +static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
> + struct vdec_vp9_vsi *vsi) {
> + if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
> + mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.",
> + vsi->sf_frm_idx);
> + return -EIO;
> + }
> + if (vsi->frm_to_show_idx >= VP9_MAX_FRM_BUF_NUM) {
> + mtk_vcodec_err(inst, "Invalid vsi->frm_to_show_idx=%u.",
> + vsi->frm_to_show_idx);
> + return -EIO;
> + }
> + if (vsi->new_fb_idx >= VP9_MAX_FRM_BUF_NUM) {
> + mtk_vcodec_err(inst, "Invalid vsi->new_fb_idx=%u.",
> + vsi->new_fb_idx);
> + return -EIO;
> + }
> + return 0;
> +}
> +
>  static void vdec_vp9_deinit(unsigned long h_vdec)
>  {
>   struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec;
> @@ -834,6 +854,12 @@ static int vdec_vp9_decode(unsigned long h_vdec, struct 
> mtk_vcodec_mem *bs,
>   goto DECODE_ERROR;
>   }
>  
> + ret = validate_vsi_array_indexes(inst, vsi);
> + if (ret) {
> + mtk_vcodec_err(inst, "Invalid values from VPU.");
> + goto DECODE_ERROR;
> + }
> +
>   if (vsi->resolution_changed) {
>   if (!vp9_alloc_work_buf(inst)) {
>   ret = -EINVAL;
> diff --git a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h 
> b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
> index db6b5205ffb1..ded1154481cd 100644
> --- a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
> +++ b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h
> @@ -85,6 +85,8 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx);
>   * @res_chg  : [out] resolution change happens if current bs have different
>   *   picture width/height
>   * Note: To flush the decoder when reaching EOF, set input bitstream as NULL.
> + *
> + * Return: 0 on success. -EIO on unrecoverable error.
>   */
>  int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
>  struct vdec_fb *fb, bool *res_chg);