[PATCH v3 13/13] [media] s5p-mfc: fix a race in interrupt flags handling

2014-10-21 Thread Arun Kumar K
From: Pawel Osciak 

Interrupt result flags have to be cleared before a hardware job is run.
Otherwise, if they are cleared asynchronously, we may end up clearing them
after the interrupt for which we wanted to wait has already arrived, thus
overwriting the job results that we intended to wait for.

To prevent this, clear the flags only under hw_lock and before running
a hardware job.

Signed-off-by: Pawel Osciak 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c|3 ---
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|1 -
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c |   13 ++---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   12 ++--
 5 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 7c3eaa5..86d43d9 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -468,7 +468,6 @@ int s5p_mfc_open_mfc_inst(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx)
}
 
set_work_bit_irqsave(ctx);
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
if (s5p_mfc_wait_for_done_ctx(ctx,
S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET, 0)) {
@@ -494,7 +493,6 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx)
 {
ctx->state = MFCINST_RETURN_INST;
set_work_bit_irqsave(ctx);
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
/* Wait until instance is returned or timeout occurred */
if (s5p_mfc_wait_for_done_ctx(ctx,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index de90465..74bcec8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -334,7 +334,6 @@ static int vidioc_g_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
MFCINST_RES_CHANGE_END)) {
/* If the MFC is parsing the header,
 * so wait until it is finished */
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_SEQ_DONE_RET,
0);
}
@@ -746,7 +745,6 @@ static int s5p_mfc_dec_g_v_ctrl(struct v4l2_ctrl *ctrl)
return -EINVAL;
}
/* Should wait for the header to be parsed */
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_wait_for_done_ctx(ctx,
S5P_MFC_R2H_CMD_SEQ_DONE_RET, 0);
if (ctx->state >= MFCINST_HEAD_PARSED &&
@@ -1058,7 +1056,6 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q)
if (IS_MFCV6_PLUS(dev) && (ctx->state == MFCINST_RUNNING)) {
ctx->state = MFCINST_FLUSH;
set_work_bit_irqsave(ctx);
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
if (s5p_mfc_wait_for_done_ctx(ctx,
S5P_MFC_R2H_CMD_DPB_FLUSH_RET, 0))
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 6a1c890..7f919e4 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1663,7 +1663,6 @@ static int s5p_mfc_enc_g_v_ctrl(struct v4l2_ctrl *ctrl)
return -EINVAL;
}
/* Should wait for the header to be produced */
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_wait_for_done_ctx(ctx,
S5P_MFC_R2H_CMD_SEQ_DONE_RET, 0);
if (ctx->state >= MFCINST_HEAD_PARSED &&
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index 7cf0796..0c4fcf2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1178,7 +1178,6 @@ static void s5p_mfc_run_res_change(struct s5p_mfc_ctx 
*ctx)
 
s5p_mfc_set_dec_stream_buffer_v5(ctx, 0, 0, 0);
dev->curr_ctx = ctx->num;
-   s5p_mfc_clean_ctx_int_flags(ctx);
s5p_mfc_decode_one_frame_v5(ctx, MFC_DEC_RES_CHANGE);
 }
 
@@ -1192,7 +1191,6 @@ static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx, 
int last_frame)
last_frame = MFC_DEC_LAST_FRAME;
s5p_mfc_set_dec_stream_buffer_v5(ctx, 0, 0, 0);
dev->curr_

[PATCH v3 12/13] [media] s5p-mfc: fix V4L2_CID_MIN_BUFFERS_FOR_CAPTURE on resolution change.

2014-10-21 Thread Arun Kumar K
From: Pawel Osciak 

G_CTRL on V4L2_CID_MIN_BUFFERS_FOR_CAPTURE will fail if userspace happens to
query it after getting a resolution change event and before the codec has
a chance to parse the header and switch to an initialized state.

Signed-off-by: Pawel Osciak 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index a98fe02..de90465 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -740,7 +740,8 @@ static int s5p_mfc_dec_g_v_ctrl(struct v4l2_ctrl *ctrl)
ctx->state < MFCINST_ABORT) {
ctrl->val = ctx->pb_count;
break;
-   } else if (ctx->state != MFCINST_INIT) {
+   } else if (ctx->state != MFCINST_INIT &&
+   ctx->state != MFCINST_RES_CHANGE_END) {
v4l2_err(&dev->v4l2_dev, "Decoding not initialised\n");
return -EINVAL;
}
-- 
1.7.9.5

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


[PATCH v3 10/13] [media] s5p-mfc: flush dpbs when resolution changes

2014-10-21 Thread Arun Kumar K
From: Kiran AVND 

While resolution change is detected by MFC, we flush out
older dpbs, send the resolution change event to application,
and then accept further queuing of new src buffers.

Sometimes, we error out during dpb flush because of lack of src
buffers. Since we have not started decoding new resolution yet,
it is simpler to push zero-size buffer until we flush out all dpbs.

This is already been done while handling EOS command, and this patch
extends the same logic to resolution change as well.

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   20 ++--
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 8798b14..7b1cf73 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1532,27 +1532,11 @@ static inline int s5p_mfc_get_new_ctx(struct 
s5p_mfc_dev *dev)
 static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
 {
struct s5p_mfc_dev *dev = ctx->dev;
-   struct s5p_mfc_buf *temp_vb;
-   unsigned long flags;
-
-   spin_lock_irqsave(&dev->irqlock, flags);
-
-   /* Frames are being decoded */
-   if (list_empty(&ctx->src_queue)) {
-   mfc_debug(2, "No src buffers.\n");
-   spin_unlock_irqrestore(&dev->irqlock, flags);
-   return;
-   }
-   /* Get the next source buffer */
-   temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
-   temp_vb->flags |= MFC_BUF_FLAG_USED;
-   s5p_mfc_set_dec_stream_buffer_v6(ctx,
-   vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
-   spin_unlock_irqrestore(&dev->irqlock, flags);
 
+   s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
dev->curr_ctx = ctx->num;
s5p_mfc_clean_ctx_int_flags(ctx);
-   s5p_mfc_decode_one_frame_v6(ctx, 1);
+   s5p_mfc_decode_one_frame_v6(ctx, MFC_DEC_LAST_FRAME);
 }
 
 static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
-- 
1.7.9.5

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


[PATCH v3 11/13] [media] s5p-mfc: Remove unused alloc field from private buffer struct.

2014-10-21 Thread Arun Kumar K
From: Pawel Osciak 

This field is no longer used as MFC driver doesn't use vb2 alloc contexts
anymore.

Signed-off-by: Pawel Osciak 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 5b0c334..15f7663 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -237,8 +237,6 @@ struct s5p_mfc_variant {
 
 /**
  * struct s5p_mfc_priv_buf - represents internal used buffer
- * @alloc: allocation-specific context for each buffer
- * (videobuf2 allocator)
  * @ofs:   offset of each buffer, will be used for MFC
  * @virt:  kernel virtual address, only valid when the
  * buffer accessed by driver
@@ -246,7 +244,6 @@ struct s5p_mfc_variant {
  * @size:  size of the buffer
  */
 struct s5p_mfc_priv_buf {
-   void*alloc;
unsigned long   ofs;
void*virt;
dma_addr_t  dma;
-- 
1.7.9.5

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


[PATCH v3 06/13] [media] s5p-mfc: check mfc bus ctrl before reset

2014-10-21 Thread Arun Kumar K
From: Kiran AVND 

during reset sequence, it is advisable to follow the below
sequence, in order to avoid unexpected behavior from MFC
. set SFR 0x7110 MFC_BUS_RESET_CTRL 0x1
  // wait for REQ_STATUS to be 1
. get SFR 0x7110 MFC_BUS_RESET_CTRL 0x3
  // reset now

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h  |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   25 -
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 51cb2dd..83e01f3 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -71,6 +71,7 @@
 #define S5P_FIMV_R2H_CMD_ENC_BUFFER_FUL_RET_V6 16
 #define S5P_FIMV_R2H_CMD_ERR_RET_V632
 
+#define S5P_FIMV_MFC_BUS_RESET_CTRL0x7110
 #define S5P_FIMV_FW_VERSION_V6 0xf000
 
 #define S5P_FIMV_INSTANCE_ID_V60xf008
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index f5bb6b2..0d3661b 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -129,6 +129,25 @@ int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev)
return 0;
 }
 
+int s5p_mfc_bus_reset(struct s5p_mfc_dev *dev)
+{
+   unsigned int status;
+   unsigned long timeout;
+
+   /* Reset */
+   mfc_write(dev, 0x1, S5P_FIMV_MFC_BUS_RESET_CTRL);
+   timeout = jiffies + msecs_to_jiffies(MFC_BW_TIMEOUT);
+   /* Check bus status */
+   do {
+   if (time_after(jiffies, timeout)) {
+   mfc_err("Timeout while resetting MFC.\n");
+   return -EIO;
+   }
+   status = mfc_read(dev, S5P_FIMV_MFC_BUS_RESET_CTRL);
+   } while ((status & 0x2) == 0);
+   return 0;
+}
+
 /* Reset the device */
 int s5p_mfc_reset(struct s5p_mfc_dev *dev)
 {
@@ -147,11 +166,15 @@ int s5p_mfc_reset(struct s5p_mfc_dev *dev)
for (i = 0; i < S5P_FIMV_REG_CLEAR_COUNT_V6; i++)
mfc_write(dev, 0, S5P_FIMV_REG_CLEAR_BEGIN_V6 + (i*4));
 
+   /* check bus reset control before reset */
+   if (dev->risc_on)
+   if (s5p_mfc_bus_reset(dev))
+   return -EIO;
/* Reset
 * set RISC_ON to 0 during power_on & wake_up.
 * V6 needs RISC_ON set to 0 during reset also.
 */
-   if ((!dev->risc_on) || (!IS_MFCV7(dev)))
+   if ((!dev->risc_on) || (!IS_MFCV7_PLUS(dev)))
mfc_write(dev, 0, S5P_FIMV_RISC_ON_V6);
 
mfc_write(dev, 0x1FFF, S5P_FIMV_MFC_RESET_V6);
-- 
1.7.9.5

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


[PATCH v3 07/13] [media] s5p-mfc: Don't crash the kernel if the watchdog kicks in.

2014-10-21 Thread Arun Kumar K
From: Pawel Osciak 

If the software watchdog kicks in, the watchdog worker is not synchronized
with hardware interrupts and does not block other instances. It's possible
for it to clear the hw_lock, making other instances trigger a BUG() on
hw_lock checks. Since it's not fatal to clear the hw_lock to zero twice,
just WARN in those cases for now. We should not explode, as firmware will
return errors as needed for other instances after it's reloaded, or they
will time out.

A clean fix should involve killing other instances when watchdog kicks in,
but requires a major redesign of locking in the driver.

Signed-off-by: Pawel Osciak 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |   21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index eb71055..8620236 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -342,8 +342,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
ctx->state = MFCINST_RES_CHANGE_INIT;
s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
wake_up_ctx(ctx, reason, err);
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
s5p_mfc_clock_off();
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
return;
@@ -415,8 +414,7 @@ leave_handle_frame:
clear_work_bit(ctx);
s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
wake_up_ctx(ctx, reason, err);
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
s5p_mfc_clock_off();
/* if suspending, wake up device and do not try_run again*/
if (test_bit(0, &dev->enter_suspend))
@@ -463,8 +461,7 @@ static void s5p_mfc_handle_error(struct s5p_mfc_dev *dev,
break;
}
}
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
s5p_mfc_clock_off();
wake_up_dev(dev, reason, err);
@@ -518,8 +515,7 @@ static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx,
}
s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
clear_work_bit(ctx);
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
s5p_mfc_clock_off();
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
wake_up_ctx(ctx, reason, err);
@@ -557,16 +553,14 @@ static void s5p_mfc_handle_init_buffers(struct 
s5p_mfc_ctx *ctx,
} else {
ctx->dpb_flush_flag = 0;
}
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
 
s5p_mfc_clock_off();
 
wake_up(&ctx->queue);
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
} else {
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
 
s5p_mfc_clock_off();
 
@@ -643,8 +637,7 @@ static irqreturn_t s5p_mfc_irq(int irq, void *priv)
mfc_err("post_frame_start() failed\n");
s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, 
dev);
wake_up_ctx(ctx, reason, err);
-   if (test_and_clear_bit(0, &dev->hw_lock) == 0)
-   BUG();
+   WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
s5p_mfc_clock_off();
s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
} else {
-- 
1.7.9.5

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


[PATCH v3 09/13] [media] s5p-mfc: De-init MFC when watchdog kicks in

2014-10-21 Thread Arun Kumar K
From: Arun Mankuzhi 

If the software watchdog kicks in, we need to de-init MFC
before reloading firmware and re-intializing it again.

Signed-off-by: Arun Mankuzhi 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8620236..39f8f2a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -159,6 +159,10 @@ static void s5p_mfc_watchdog_worker(struct work_struct 
*work)
}
clear_bit(0, &dev->hw_lock);
spin_unlock_irqrestore(&dev->irqlock, flags);
+
+   /* De-init MFC */
+   s5p_mfc_deinit_hw(dev);
+
/* Double check if there is at least one instance running.
 * If no instance is in memory than no firmware should be present */
if (dev->num_inst > 0) {
-- 
1.7.9.5

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


[PATCH v3 08/13] [media] s5p-mfc: modify mfc wakeup sequence for V8

2014-10-21 Thread Arun Kumar K
From: Arun Mankuzhi 

>From MFC V8, the MFC wakeup sequence has changed.
MFC wakeup command has to be sent after the host receives
firmware load complete status from risc.

Signed-off-by: Arun Mankuzhi 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   78 +++--
 1 file changed, 61 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 0d3661b..7c3eaa5 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -353,6 +353,58 @@ int s5p_mfc_sleep(struct s5p_mfc_dev *dev)
return ret;
 }
 
+static int s5p_mfc_v8_wait_wakeup(struct s5p_mfc_dev *dev)
+{
+   int ret;
+
+   /* Release reset signal to the RISC */
+   dev->risc_on = 1;
+   mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6);
+
+   if (s5p_mfc_wait_for_done_dev(dev, S5P_MFC_R2H_CMD_FW_STATUS_RET)) {
+   mfc_err("Failed to reset MFCV8\n");
+   return -EIO;
+   }
+   mfc_debug(2, "Write command to wakeup MFCV8\n");
+   ret = s5p_mfc_hw_call(dev->mfc_cmds, wakeup_cmd, dev);
+   if (ret) {
+   mfc_err("Failed to send command to MFCV8 - timeout\n");
+   return ret;
+   }
+
+   if (s5p_mfc_wait_for_done_dev(dev, S5P_MFC_R2H_CMD_WAKEUP_RET)) {
+   mfc_err("Failed to wakeup MFC\n");
+   return -EIO;
+   }
+   return ret;
+}
+
+static int s5p_mfc_wait_wakeup(struct s5p_mfc_dev *dev)
+{
+   int ret;
+
+   /* Send MFC wakeup command */
+   ret = s5p_mfc_hw_call(dev->mfc_cmds, wakeup_cmd, dev);
+   if (ret) {
+   mfc_err("Failed to send command to MFC - timeout\n");
+   return ret;
+   }
+
+   /* Release reset signal to the RISC */
+   if (IS_MFCV6_PLUS(dev)) {
+   dev->risc_on = 1;
+   mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6);
+   } else {
+   mfc_write(dev, 0x3ff, S5P_FIMV_SW_RESET);
+   }
+
+   if (s5p_mfc_wait_for_done_dev(dev, S5P_MFC_R2H_CMD_WAKEUP_RET)) {
+   mfc_err("Failed to wakeup MFC\n");
+   return -EIO;
+   }
+   return ret;
+}
+
 int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
 {
int ret;
@@ -365,6 +417,7 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
ret = s5p_mfc_reset(dev);
if (ret) {
mfc_err("Failed to reset MFC - timeout\n");
+   s5p_mfc_clock_off();
return ret;
}
mfc_debug(2, "Done MFC reset..\n");
@@ -373,25 +426,16 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
/* 2. Initialize registers of channel I/F */
s5p_mfc_clear_cmds(dev);
s5p_mfc_clean_dev_int_flags(dev);
-   /* 3. Initialize firmware */
-   ret = s5p_mfc_hw_call(dev->mfc_cmds, wakeup_cmd, dev);
-   if (ret) {
-   mfc_err("Failed to send command to MFC - timeout\n");
-   return ret;
-   }
-   /* 4. Release reset signal to the RISC */
-   if (IS_MFCV6_PLUS(dev)) {
-   dev->risc_on = 1;
-   mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6);
-   }
+   /* 3. Send MFC wakeup command and wait for completion*/
+   if (IS_MFCV8(dev))
+   ret = s5p_mfc_v8_wait_wakeup(dev);
else
-   mfc_write(dev, 0x3ff, S5P_FIMV_SW_RESET);
-   mfc_debug(2, "Ok, now will write a command to wakeup the system\n");
-   if (s5p_mfc_wait_for_done_dev(dev, S5P_MFC_R2H_CMD_WAKEUP_RET)) {
-   mfc_err("Failed to load firmware\n");
-   return -EIO;
-   }
+   ret = s5p_mfc_wait_wakeup(dev);
+
s5p_mfc_clock_off();
+   if (ret)
+   return ret;
+
dev->int_cond = 0;
if (dev->int_err != 0 || dev->int_type !=
S5P_MFC_R2H_CMD_WAKEUP_RET) {
-- 
1.7.9.5

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


[PATCH v3 01/13] [media] s5p-mfc: support MIN_BUFFERS query for encoder

2014-10-21 Thread Arun Kumar K
From: Kiran AVND 

Add V4L2_CID_MIN_BUFFERS_FOR_OUTPUT query for encoder.
Once mfc encoder state is HEAD_PARSED, which is sequence
header produced, dpb_count is avaialable. Let user space
query this value.

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index a904a1c..4816f31 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -690,6 +690,16 @@ static struct mfc_control controls[] = {
.step = 1,
.default_value = 0,
},
+   {
+   .id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .name = "Minimum number of output bufs",
+   .minimum = 1,
+   .maximum = 32,
+   .step = 1,
+   .default_value = 1,
+   .is_volatile = 1,
+   },
 };
 
 #define NUM_CTRLS ARRAY_SIZE(controls)
@@ -1624,8 +1634,40 @@ static int s5p_mfc_enc_s_ctrl(struct v4l2_ctrl *ctrl)
return ret;
 }
 
+static int s5p_mfc_enc_g_v_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
+   struct s5p_mfc_dev *dev = ctx->dev;
+
+   switch (ctrl->id) {
+   case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
+   if (ctx->state >= MFCINST_HEAD_PARSED &&
+   ctx->state < MFCINST_ABORT) {
+   ctrl->val = ctx->pb_count;
+   break;
+   } else if (ctx->state != MFCINST_INIT) {
+   v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
+   return -EINVAL;
+   }
+   /* Should wait for the header to be produced */
+   s5p_mfc_clean_ctx_int_flags(ctx);
+   s5p_mfc_wait_for_done_ctx(ctx,
+   S5P_MFC_R2H_CMD_SEQ_DONE_RET, 0);
+   if (ctx->state >= MFCINST_HEAD_PARSED &&
+   ctx->state < MFCINST_ABORT) {
+   ctrl->val = ctx->pb_count;
+   } else {
+   v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
+   return -EINVAL;
+   }
+   break;
+   }
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops s5p_mfc_enc_ctrl_ops = {
.s_ctrl = s5p_mfc_enc_s_ctrl,
+   .g_volatile_ctrl = s5p_mfc_enc_g_v_ctrl,
 };
 
 static int vidioc_s_parm(struct file *file, void *priv,
-- 
1.7.9.5

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


[PATCH v3 04/13] [media] s5p-mfc: Only set timestamp/timecode for new frames.

2014-10-21 Thread Arun Kumar K
From: Ilja Friedel 

Timestamp i of a previously decoded buffer was overwritten for some
H.264 streams with timestamp i+1 of the next buffer. This happened when
encountering frame_type S5P_FIMV_DECODE_FRAME_SKIPPED, indicating no
new frame.

In most cases this wrong indexing might not have been noticed except
for a one frame delay in frame presentation. For H.264 streams though
that require reordering of frames for presentation, it caused a slightly
erratic presentation time lookup and consequently dropped frames in the
Pepper Flash plugin.

Signed-off-by: Ilja H. Friedel 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 79c9537..eb71055 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -220,11 +220,14 @@ static void s5p_mfc_handle_frame_copy_time(struct 
s5p_mfc_ctx *ctx)
size_t dec_y_addr;
unsigned int frame_type;
 
-   dec_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dec_y_adr, dev);
+   /* Make sure we actually have a new frame before continuing. */
frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev);
+   if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED)
+   return;
+   dec_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dec_y_adr, dev);
 
/* Copy timestamp / timecode from decoded src to dst and set
-  appropriate flags */
+  appropriate flags. */
src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dec_y_addr) 
{
@@ -250,6 +253,11 @@ static void s5p_mfc_handle_frame_copy_time(struct 
s5p_mfc_ctx *ctx)
dst_buf->b->v4l2_buf.flags |=
V4L2_BUF_FLAG_BFRAME;
break;
+   default:
+   /* Don't know how to handle
+  S5P_FIMV_DECODE_FRAME_OTHER_FRAME. */
+   mfc_debug(2, "Unexpected frame type: %d\n",
+   frame_type);
}
break;
}
-- 
1.7.9.5

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


[PATCH v3 02/13] [media] s5p-mfc: Fix REQBUFS(0) for encoder.

2014-10-21 Thread Arun Kumar K
From: Pawel Osciak 

Handle REQBUFS(0) for CAPTURE queue as well. Also use the proper queue to call
it on for OUTPUT.

Signed-off-by: Pawel Osciak 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c |   13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 4816f31..6a1c890 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1147,6 +1147,11 @@ static int vidioc_reqbufs(struct file *file, void *priv,
(reqbufs->memory != V4L2_MEMORY_USERPTR))
return -EINVAL;
if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+   if (reqbufs->count == 0) {
+   ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+   ctx->capture_state = QUEUE_FREE;
+   return ret;
+   }
if (ctx->capture_state != QUEUE_FREE) {
mfc_err("invalid capture state: %d\n",
ctx->capture_state);
@@ -1168,6 +1173,14 @@ static int vidioc_reqbufs(struct file *file, void *priv,
return -ENOMEM;
}
} else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+   if (reqbufs->count == 0) {
+   mfc_debug(2, "Freeing buffers\n");
+   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+   s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers,
+   ctx);
+   ctx->output_state = QUEUE_FREE;
+   return ret;
+   }
if (ctx->output_state != QUEUE_FREE) {
mfc_err("invalid output state: %d\n",
ctx->output_state);
-- 
1.7.9.5

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


[PATCH v3 05/13] [media] s5p-mfc: keep RISC ON during reset for V7/V8

2014-10-21 Thread Arun Kumar K
From: Kiran AVND 

Reset sequence for MFC V7 and V8 do not need RISC_ON
to be set to 0, while for MFC V6 it is still needed.

Also, remove a couple of register settings during Reset
which are not needed from V6 onwards.

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   25 ++-
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 3e41ca1..5b0c334 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -340,6 +340,7 @@ struct s5p_mfc_dev {
struct s5p_mfc_hw_cmds *mfc_cmds;
const struct s5p_mfc_regs *mfc_regs;
enum s5p_mfc_fw_ver fw_ver;
+   bool risc_on; /* indicates if RISC is on or off */
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 0c885a8..f5bb6b2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -139,12 +139,6 @@ int s5p_mfc_reset(struct s5p_mfc_dev *dev)
mfc_debug_enter();
 
if (IS_MFCV6_PLUS(dev)) {
-   /* Reset IP */
-   /*  except RISC, reset */
-   mfc_write(dev, 0xFEE, S5P_FIMV_MFC_RESET_V6);
-   /*  reset release */
-   mfc_write(dev, 0x0, S5P_FIMV_MFC_RESET_V6);
-
/* Zero Initialization of MFC registers */
mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD_V6);
mfc_write(dev, 0, S5P_FIMV_HOST2RISC_CMD_V6);
@@ -153,8 +147,13 @@ int s5p_mfc_reset(struct s5p_mfc_dev *dev)
for (i = 0; i < S5P_FIMV_REG_CLEAR_COUNT_V6; i++)
mfc_write(dev, 0, S5P_FIMV_REG_CLEAR_BEGIN_V6 + (i*4));
 
-   /* Reset */
-   mfc_write(dev, 0, S5P_FIMV_RISC_ON_V6);
+   /* Reset
+* set RISC_ON to 0 during power_on & wake_up.
+* V6 needs RISC_ON set to 0 during reset also.
+*/
+   if ((!dev->risc_on) || (!IS_MFCV7(dev)))
+   mfc_write(dev, 0, S5P_FIMV_RISC_ON_V6);
+
mfc_write(dev, 0x1FFF, S5P_FIMV_MFC_RESET_V6);
mfc_write(dev, 0, S5P_FIMV_MFC_RESET_V6);
} else {
@@ -226,6 +225,7 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
/* 0. MFC reset */
mfc_debug(2, "MFC reset..\n");
s5p_mfc_clock_on();
+   dev->risc_on = 0;
ret = s5p_mfc_reset(dev);
if (ret) {
mfc_err("Failed to reset MFC - timeout\n");
@@ -238,8 +238,10 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
s5p_mfc_clear_cmds(dev);
/* 3. Release reset signal to the RISC */
s5p_mfc_clean_dev_int_flags(dev);
-   if (IS_MFCV6_PLUS(dev))
+   if (IS_MFCV6_PLUS(dev)) {
+   dev->risc_on = 1;
mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6);
+   }
else
mfc_write(dev, 0x3ff, S5P_FIMV_SW_RESET);
mfc_debug(2, "Will now wait for completion of firmware transfer\n");
@@ -336,6 +338,7 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
/* 0. MFC reset */
mfc_debug(2, "MFC reset..\n");
s5p_mfc_clock_on();
+   dev->risc_on = 0;
ret = s5p_mfc_reset(dev);
if (ret) {
mfc_err("Failed to reset MFC - timeout\n");
@@ -354,8 +357,10 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
return ret;
}
/* 4. Release reset signal to the RISC */
-   if (IS_MFCV6_PLUS(dev))
+   if (IS_MFCV6_PLUS(dev)) {
+   dev->risc_on = 1;
mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6);
+   }
else
mfc_write(dev, 0x3ff, S5P_FIMV_SW_RESET);
mfc_debug(2, "Ok, now will write a command to wakeup the system\n");
-- 
1.7.9.5

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


[PATCH v3 03/13] [media] s5p-mfc: clear 'enter_suspend' flag if suspend fails

2014-10-21 Thread Arun Kumar K
From: Prathyush K 

The enter_suspend flag is set after we enter mfc suspend function but if
suspend fails after that due to any reason (like hardware timeout etc),
this flag must be cleared before returning an error. Otherwise, this
flag never gets cleared and the MFC suspend will always return an error
on subsequent tries. If clock off fails, disable hw_lock also.

Signed-off-by: Prathyush K 
Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 165bc86..79c9537 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1284,11 +1284,17 @@ static int s5p_mfc_suspend(struct device *dev)
m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT));
if (ret == 0) {
mfc_err("Waiting for hardware to finish timed out\n");
+   clear_bit(0, &m_dev->enter_suspend);
return -EIO;
}
}
 
-   return s5p_mfc_sleep(m_dev);
+   ret = s5p_mfc_sleep(m_dev);
+   if (ret) {
+   clear_bit(0, &m_dev->enter_suspend);
+   clear_bit(0, &m_dev->hw_lock);
+   }
+   return ret;
 }
 
 static int s5p_mfc_resume(struct device *dev)
-- 
1.7.9.5

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


[PATCH v3 00/13] Fixes from Chrome OS tree for MFC driver

2014-10-21 Thread Arun Kumar K
Upstreaming the fixes which have gone in to Chrome OS tree for MFC driver.
Tested on MFCV8, MFCV7 and MFCV6 based Exynos5 based boards, peach-pi
(5800), peach-pit (5420) and snow (5250).

Changes from v2:
1) Rebased on latest media-tree
2) Dropped the patch (14/14) from previous set
   s5p-mfc: Don't change the image size to smaller than the request.

Changes from v1:
1) Addressed all review comments from Kamil.
2) Dropped patches
   [media] s5p-mfc: set B-frames as 2 while encoding
   [media] s5p-mfc: remove reduntant clock on & clock off
   [media] s5p-mfc: don't disable clock when next ctx is pending
3) Rebased on media-tree

Arun Mankuzhi (2):
  [media] s5p-mfc: modify mfc wakeup sequence for V8
  [media] s5p-mfc: De-init MFC when watchdog kicks in

Ilja Friedel (1):
  [media] s5p-mfc: Only set timestamp/timecode for new frames.

Kiran AVND (4):
  [media] s5p-mfc: support MIN_BUFFERS query for encoder
  [media] s5p-mfc: keep RISC ON during reset for V7/V8
  [media] s5p-mfc: check mfc bus ctrl before reset
  [media] s5p-mfc: flush dpbs when resolution changes

Pawel Osciak (5):
  [media] s5p-mfc: Fix REQBUFS(0) for encoder.
  [media] s5p-mfc: Don't crash the kernel if the watchdog kicks in.
  [media] s5p-mfc: Remove unused alloc field from private buffer
struct.
  [media] s5p-mfc: fix V4L2_CID_MIN_BUFFERS_FOR_CAPTURE on resolution
change.
  [media] s5p-mfc: fix a race in interrupt flags handling

Prathyush K (1):
  [media] s5p-mfc: clear 'enter_suspend' flag if suspend fails

 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
 drivers/media/platform/s5p-mfc/s5p_mfc.c|   45 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |  122 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c|6 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|   54 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c |   13 +--
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   32 +-
 8 files changed, 188 insertions(+), 89 deletions(-)

-- 
1.7.9.5

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


Re: [PATCH v2 07/14] [media] s5p-mfc: Don't crash the kernel if the watchdog kicks in.

2014-10-21 Thread Arun Kumar K
Hi Kamil,

Kiran will not be available to handle review comments of these patches.
So I will be pushing the updated patchset rebased on media-tree.

I hope all patches are good to merge except
[media] s5p-mfc: Don't change the image size to smaller than the request.

I will drop this one patch and send all others in v3 version.

Regards
Arun

On Wed, Oct 8, 2014 at 3:56 PM, Kamil Debski  wrote:
> Hi,
>
> This patch does not apply to the current media tree.
>
> commit cf3167cf1e969b17671a4d3d956d22718a8ceb85)
> Author: Antti Palosaari 
> Date:   Fri Sep 26 22:45:36 2014 -0300
>
> [media] pt3: fix DTV FE I2C driver load error paths
>
> Best wishes,
> --
> Kamil Debski
> Samsung R&D Institute Poland
>
>
>> -Original Message-
>> From: Kiran AVND [mailto:avnd.ki...@samsung.com]
>> Sent: Friday, September 26, 2014 6:52 AM
>> To: linux-media@vger.kernel.org
>> Cc: k.deb...@samsung.com; wuchen...@chromium.org; posc...@chromium.org;
>> aru...@samsung.com; i...@chromium.org; prathyus...@samsung.com;
>> arun...@samsung.com; ki...@chromium.org
>> Subject: [PATCH v2 07/14] [media] s5p-mfc: Don't crash the kernel if
>> the watchdog kicks in.
>>
>> From: Pawel Osciak 
>>
>> If the software watchdog kicks in, the watchdog worker is not
>> synchronized with hardware interrupts and does not block other
>> instances. It's possible for it to clear the hw_lock, making other
>> instances trigger a BUG() on hw_lock checks. Since it's not fatal to
>> clear the hw_lock to zero twice, just WARN in those cases for now. We
>> should not explode, as firmware will return errors as needed for other
>> instances after it's reloaded, or they will time out.
>>
>> A clean fix should involve killing other instances when watchdog kicks
>> in, but requires a major redesign of locking in the driver.
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Kiran AVND 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c |   25 +++---
>> ---
>>  1 file changed, 7 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> index 3fc2f8a..8d5da0c 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -337,8 +337,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx
>> *ctx,
>>   ctx->state = MFCINST_RES_CHANGE_INIT;
>>   s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
>>   wake_up_ctx(ctx, reason, err);
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_clock_off();
>>   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
>>   return;
>> @@ -410,8 +409,7 @@ leave_handle_frame:
>>   clear_work_bit(ctx);
>>   s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
>>   wake_up_ctx(ctx, reason, err);
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_clock_off();
>>   /* if suspending, wake up device and do not try_run again*/
>>   if (test_bit(0, &dev->enter_suspend))
>> @@ -458,8 +456,7 @@ static void s5p_mfc_handle_error(struct s5p_mfc_dev
>> *dev,
>>   break;
>>   }
>>   }
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
>>   s5p_mfc_clock_off();
>>   wake_up_dev(dev, reason, err);
>> @@ -513,8 +510,7 @@ static void s5p_mfc_handle_seq_done(struct
>> s5p_mfc_ctx *ctx,
>>   }
>>   s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
>>   clear_work_bit(ctx);
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_clock_off();
>>   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
>>   wake_up_ctx(ctx, reason, err);
>> @@ -552,19 +548,13 @@ static void s5p_mfc_handle_init_buffers(struct
>> s5p_mfc_ctx *ctx,
>>   } else {
>>   ctx->dpb_flush_flag = 0;
>>   }
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> -
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_clock_off();
>> -
>>   wake_up(&ctx->queue);
>>   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
>>   } else {
>> - if (test_and_clear_bit(0, &dev->hw_lock) == 0)
>> - BUG();
>> -
>> + WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
>>   s5p_mfc_clock_off();
>> -
>>   wake_up(&ctx->queue);
>>   }
>>  }
>> @@ -638,8 +628,7 @@ static irqreturn_t s5p_mfc_irq(int irq, void *

Re: [PATCH 1/3] s5p-mfc: Fix selective sclk_mfc init

2014-07-08 Thread Arun Kumar K
Hi Jacek,

On Tue, Jul 8, 2014 at 6:33 PM, Jacek Anaszewski
 wrote:
> fc906b6d "Remove special clock usage in driver" removed
> initialization of MFC special clock, arguing that there's
> no need to do it explicitly, since it's one of MFC gate clock's
> dependencies and gets enabled along with it. However, there's
> no promise of keeping this hierarchy across Exynos SoC
> releases, therefore this approach fails to provide a stable,
> portable solution.
>
> Out of all MFC versions, only v6 doesn't use special clock at all.
>
> Signed-off-by: Mateusz Zalega 
> Signed-off-by: Seung-Woo Kim 
> Signed-off-by: Jacek Anaszewski 
> Signed-off-by: Kyungmin Park 
> ---
>  drivers/media/platform/s5p-mfc/s5p_mfc_pm.c |   26 ++
>  1 file changed, 26 insertions(+)
>
> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c 
> b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
> index 11d5f1d..cc562fc 100644
> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
> @@ -21,6 +21,8 @@
>  #include "s5p_mfc_pm.h"
>
>  #define MFC_GATE_CLK_NAME  "mfc"
> +#define MFC_CLK_NAME   "sclk-mfc"
> +#define MFC_CLK_RATE   (200 * 100)
>
>  #define CLK_DEBUG
>
> @@ -50,6 +52,23 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
> goto err_p_ip_clk;
> }
>
> +   if (dev->variant->version != MFC_VERSION_V6) {
> +   pm->clock = clk_get(&dev->plat_dev->dev, MFC_CLK_NAME);
> +   if (IS_ERR(pm->clock)) {
> +   mfc_err("Failed to get gating clock control\n");
> +   ret = PTR_ERR(pm->clock);
> +   goto err_s_clk;
> +   }
> +

Agree to your point above that some SoCs may have different hierarchy
which needs
to enable this clock explicitly. But other SoCs using v5, v7 and v8
still works fine
without this special clock and those DT nodes doesnt provide this clock now.
So I would suggest not to error return if the clock is not provided
and keep it as
an optional parameter to maintain backward compatibility. With this
current patch
all the working SoCs like 5420, 5800 etc will fail in probe.

Regards
Arun


> +   clk_set_rate(pm->clock, MFC_CLK_RATE);
> +   ret = clk_prepare_enable(pm->clock);
> +   if (ret) {
> +   mfc_err("Failed to enable MFC core operating 
> clock\n");
> +   ret = PTR_ERR(pm->clock);
> +   goto err_s_clk;
> +   }
> +   }
> +
> atomic_set(&pm->power, 0);
>  #ifdef CONFIG_PM_RUNTIME
> pm->device = &dev->plat_dev->dev;
> @@ -59,6 +78,9 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
> atomic_set(&clk_ref, 0);
>  #endif
> return 0;
> +
> +err_s_clk:
> +   clk_put(pm->clock);
>  err_p_ip_clk:
> clk_put(pm->clock_gate);
>  err_g_ip_clk:
> @@ -67,6 +89,10 @@ err_g_ip_clk:
>
>  void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
>  {
> +   if (dev->variant->version != MFC_VERSION_V6) {
> +   clk_disable_unprepare(pm->clock);
> +   clk_put(pm->clock);
> +   }
> clk_unprepare(pm->clock_gate);
> clk_put(pm->clock_gate);
>  #ifdef CONFIG_PM_RUNTIME
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/3] [media] s5p-mfc: Add init buffer cmd to MFCV6

2014-05-21 Thread Arun Kumar K
Latest MFC v6 firmware requires tile mode and loop filter
setting to be done as part of Init buffer command, in sync
with v7. This patch adds this support for new v6 firmware.

Signed-off-by: Arun Kumar K 
Signed-off-by: Kiran AVND 
Reviewed-by: Tomasz Figa 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 4f5e0ea..c1c12f8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -48,6 +48,8 @@
 #define WRITEL(data, reg) \
(WARN_ON_ONCE(!(reg)) ? 0 : writel((data), (reg)))
 
+#define IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
+
 /* Allocate temporary buffers for decoding */
 static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
 {
@@ -1352,7 +1354,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
}
 
-   if (IS_MFCV7_PLUS(dev)) {
+   if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
WRITEL(reg, mfc_regs->d_dec_options);
reg = 0;
}
@@ -1367,7 +1369,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7_PLUS(dev))
+   if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
WRITEL(reg, mfc_regs->d_init_buffer_options);
else
WRITEL(reg, mfc_regs->d_dec_options);
-- 
1.7.9.5

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


[PATCH v2 1/3] [media] s5p-mfc: Remove duplicate function s5p_mfc_reload_firmware

2014-05-21 Thread Arun Kumar K
The function s5p_mfc_reload_firmware is exactly same as
s5p_mfc_load_firmware. So removing the duplicate function.

Signed-off-by: Arun Kumar K 
Reviewed-by: Tomasz Figa 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   33 -
 2 files changed, 1 insertion(+), 34 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 9ed0985..8da4c23 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -162,7 +162,7 @@ static void s5p_mfc_watchdog_worker(struct work_struct 
*work)
/* Double check if there is at least one instance running.
 * If no instance is in memory than no firmware should be present */
if (dev->num_inst > 0) {
-   ret = s5p_mfc_reload_firmware(dev);
+   ret = s5p_mfc_load_firmware(dev);
if (ret) {
mfc_err("Failed to reload FW\n");
goto unlock;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 6c3f8f7..c97c7c8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -107,39 +107,6 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
return 0;
 }
 
-/* Reload firmware to MFC */
-int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev)
-{
-   struct firmware *fw_blob;
-   int err;
-
-   /* Firmare has to be present as a separate file or compiled
-* into kernel. */
-   mfc_debug_enter();
-
-   err = request_firmware((const struct firmware **)&fw_blob,
-dev->variant->fw_name, dev->v4l2_dev.dev);
-   if (err != 0) {
-   mfc_err("Firmware is not present in the /lib/firmware directory 
nor compiled in kernel\n");
-   return -EINVAL;
-   }
-   if (fw_blob->size > dev->fw_size) {
-   mfc_err("MFC firmware is too big to be loaded\n");
-   release_firmware(fw_blob);
-   return -ENOMEM;
-   }
-   if (!dev->fw_virt_addr) {
-   mfc_err("MFC firmware is not allocated\n");
-   release_firmware(fw_blob);
-   return -EINVAL;
-   }
-   memcpy(dev->fw_virt_addr, fw_blob->data, fw_blob->size);
-   wmb();
-   release_firmware(fw_blob);
-   mfc_debug_leave();
-   return 0;
-}
-
 /* Release firmware memory */
 int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev)
 {
-- 
1.7.9.5

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


[PATCH v2 2/3] [media] s5p-mfc: Support multiple firmware sub-versions

2014-05-21 Thread Arun Kumar K
For MFC firmwares, improved versions with bug fixes and
feature additions are released keeping the firmware version
including major and minor number same. The issue came with
the release of a new MFCv6 firmware with an interface change.
This patch adds the support of accepting multiple firmware
binaries for every version with the driver trying to load
firmwares starting from latest. This ensures full backward
compatibility regardless of which firmware version and kernel
version is used.

Signed-off-by: Arun Kumar K 
Reviewed-by: Tomasz Figa 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c|   13 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   11 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   15 ---
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8da4c23..7092b84 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1343,7 +1343,7 @@ static struct s5p_mfc_variant mfc_drvdata_v5 = {
.port_num   = MFC_NUM_PORTS,
.buf_size   = &buf_size_v5,
.buf_align  = &mfc_buf_align_v5,
-   .fw_name= "s5p-mfc.fw",
+   .fw_name[0] = "s5p-mfc.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
@@ -1370,7 +1370,12 @@ static struct s5p_mfc_variant mfc_drvdata_v6 = {
.port_num   = MFC_NUM_PORTS_V6,
.buf_size   = &buf_size_v6,
.buf_align  = &mfc_buf_align_v6,
-   .fw_name= "s5p-mfc-v6.fw",
+   .fw_name[0] = "s5p-mfc-v6.fw",
+   /*
+* v6-v2 firmware contains bug fixes and interface change
+* for init buffer command
+*/
+   .fw_name[1] = "s5p-mfc-v6-v2.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = {
@@ -1397,7 +1402,7 @@ static struct s5p_mfc_variant mfc_drvdata_v7 = {
.port_num   = MFC_NUM_PORTS_V7,
.buf_size   = &buf_size_v7,
.buf_align  = &mfc_buf_align_v7,
-   .fw_name= "s5p-mfc-v7.fw",
+   .fw_name[0] = "s5p-mfc-v7.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
@@ -1424,7 +1429,7 @@ static struct s5p_mfc_variant mfc_drvdata_v8 = {
.port_num   = MFC_NUM_PORTS_V8,
.buf_size   = &buf_size_v8,
.buf_align  = &mfc_buf_align_v8,
-   .fw_name= "s5p-mfc-v8.fw",
+   .fw_name[0] = "s5p-mfc-v8.fw",
 };
 
 static struct platform_device_id mfc_driver_ids[] = {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 89681c3..de60185 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -38,6 +38,8 @@
 #define MFC_BANK2_ALIGN_ORDER  13
 #define MFC_BASE_ALIGN_ORDER   17
 
+#define MFC_FW_MAX_VERSIONS2
+
 #include 
 
 static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b)
@@ -163,6 +165,11 @@ enum s5p_mfc_decode_arg {
MFC_DEC_RES_CHANGE,
 };
 
+enum s5p_mfc_fw_ver {
+   MFC_FW_V1,
+   MFC_FW_V2,
+};
+
 #define MFC_BUF_FLAG_USED  (1 << 0)
 #define MFC_BUF_FLAG_EOS   (1 << 1)
 
@@ -225,7 +232,7 @@ struct s5p_mfc_variant {
u32 version_bit;
struct s5p_mfc_buf_size *buf_size;
struct s5p_mfc_buf_align *buf_align;
-   char*fw_name;
+   char*fw_name[MFC_FW_MAX_VERSIONS];
 };
 
 /**
@@ -287,6 +294,7 @@ struct s5p_mfc_priv_buf {
  * @warn_start:hardware error code from which warnings start
  * @mfc_ops:   ops structure holding HW operation function pointers
  * @mfc_cmds:  cmd structure holding HW commands function pointers
+ * @fw_ver:loaded firmware sub-version
  *
  */
 struct s5p_mfc_dev {
@@ -331,6 +339,7 @@ struct s5p_mfc_dev {
struct s5p_mfc_hw_ops *mfc_ops;
struct s5p_mfc_hw_cmds *mfc_cmds;
const struct s5p_mfc_regs *mfc_regs;
+   enum s5p_mfc_fw_ver fw_ver;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index c97c7c8..452ad02 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -78,14 +78,23 @@ int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev)
 int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
 {
struct firmware *fw_blob;
-   int err;
+   int i, err = -EINVAL;
 
/* Firmare has to be present as a separate file or compiled
 * into kernel. */
mfc_debug_enter();
 
-   err = request_firmware((const struct firmware **)&fw_blob,
-dev->variant->fw_name, dev->v4l2_dev.dev);
+   for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0;

[PATCH v2 0/3] Support for multiple MFC FW sub-versions

2014-05-21 Thread Arun Kumar K
This patchset is for supporting multple firmware sub-versions
for MFC. Newer firmwares come with changed interfaces and fixes
without any change in the fw version number.
So this implementation is as per Tomasz Figa's suggestion [1].
[1] http://permalink.gmane.org/gmane.linux.kernel.samsung-soc/31735

Changes from v1
- Addressed nits pointed by Sachin on PATCH 2/3

Arun Kumar K (3):
  [media] s5p-mfc: Remove duplicate function s5p_mfc_reload_firmware
  [media] s5p-mfc: Support multiple firmware sub-versions
  [media] s5p-mfc: Add init buffer cmd to MFCV6

 drivers/media/platform/s5p-mfc/s5p_mfc.c|   15 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   11 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   44 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |6 ++--
 4 files changed, 34 insertions(+), 42 deletions(-)

-- 
1.7.9.5

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


Re: [PATCH 2/3] [media] s5p-mfc: Support multiple firmware sub-versions

2014-05-21 Thread Arun Kumar K
Hi Sachin,

On Tue, May 20, 2014 at 5:15 PM, Sachin Kamat  wrote:
> Hi Arun,
>
> On 20 May 2014 15:47, Arun Kumar K  wrote:
>> For MFC firmwares, improved versions with bug fixes and
>> feature additions are released keeping the firmware version
>> including major and minor number same. The issue came with
>> the release of a new MFCv6 firmware with an interface change.
>> This patch adds the support of accepting multiple firmware
>> binaries for every version with the driver trying to load
>> firmwares starting from latest. This ensures full backward
>> compatibility regardless of which firmware version and kernel
>> version is used.
>>
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c|9 +
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   11 ++-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   15 ---
>>  3 files changed, 27 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> index 8da4c23..514e7ec 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -1343,7 +1343,7 @@ static struct s5p_mfc_variant mfc_drvdata_v5 = {
>> .port_num   = MFC_NUM_PORTS,
>> .buf_size   = &buf_size_v5,
>> .buf_align  = &mfc_buf_align_v5,
>> -   .fw_name= "s5p-mfc.fw",
>> +   .fw_name[0] = "s5p-mfc.fw",
>>  };
>>
>>  struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
>> @@ -1370,7 +1370,8 @@ static struct s5p_mfc_variant mfc_drvdata_v6 = {
>> .port_num   = MFC_NUM_PORTS_V6,
>> .buf_size   = &buf_size_v6,
>> .buf_align  = &mfc_buf_align_v6,
>> -   .fw_name= "s5p-mfc-v6.fw",
>> +   .fw_name[0] = "s5p-mfc-v6.fw",
>> +   .fw_name[1] = "s5p-mfc-v6-v2.fw",
>
> Probably a simple 1 line comment about the difference between the
> versions would help.
>

Ok will add.

>>  };
>>
>>  struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = {
>> @@ -1397,7 +1398,7 @@ static struct s5p_mfc_variant mfc_drvdata_v7 = {
>> .port_num   = MFC_NUM_PORTS_V7,
>> .buf_size   = &buf_size_v7,
>> .buf_align  = &mfc_buf_align_v7,
>> -   .fw_name= "s5p-mfc-v7.fw",
>> +   .fw_name[0] = "s5p-mfc-v7.fw",
>>  };
>>
>>  struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
>> @@ -1424,7 +1425,7 @@ static struct s5p_mfc_variant mfc_drvdata_v8 = {
>> .port_num   = MFC_NUM_PORTS_V8,
>> .buf_size   = &buf_size_v8,
>> .buf_align  = &mfc_buf_align_v8,
>> -   .fw_name= "s5p-mfc-v8.fw",
>> +   .fw_name[0] = "s5p-mfc-v8.fw",
>>  };
>>
>>  static struct platform_device_id mfc_driver_ids[] = {
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> index 89681c3..de60185 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> @@ -38,6 +38,8 @@
>>  #define MFC_BANK2_ALIGN_ORDER  13
>>  #define MFC_BASE_ALIGN_ORDER   17
>>
>> +#define MFC_FW_MAX_VERSIONS2
>> +
>>  #include 
>>
>>  static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b)
>> @@ -163,6 +165,11 @@ enum s5p_mfc_decode_arg {
>> MFC_DEC_RES_CHANGE,
>>  };
>>
>> +enum s5p_mfc_fw_ver {
>> +   MFC_FW_V1,
>> +   MFC_FW_V2,
>> +};
>> +
>>  #define MFC_BUF_FLAG_USED  (1 << 0)
>>  #define MFC_BUF_FLAG_EOS   (1 << 1)
>>
>> @@ -225,7 +232,7 @@ struct s5p_mfc_variant {
>> u32 version_bit;
>> struct s5p_mfc_buf_size *buf_size;
>> struct s5p_mfc_buf_align *buf_align;
>> -   char*fw_name;
>> +   char*fw_name[MFC_FW_MAX_VERSIONS];
>>  };
>>
>>  /**
>> @@ -287,6 +294,7 @@ struct s5p_mfc_priv_buf {
>>   * @warn_start:hardware error code from which warnings start
>>   * @mfc_ops:   ops structure holding HW operation function pointers
>>   * @mfc_cmds:  cmd structure holding HW commands function pointers
>> + * @fw_ver:loaded firmware sub-version
>>   *
>>   */
>>  struct s5p_mfc_dev {
>> @@ -3

[PATCH 3/3] [media] s5p-mfc: Add init buffer cmd to MFCV6

2014-05-20 Thread Arun Kumar K
Latest MFC v6 firmware requires tile mode and loop filter
setting to be done as part of Init buffer command, in sync
with v7. This patch adds this support for new v6 firmware.

Signed-off-by: Arun Kumar K 
Signed-off-by: Kiran AVND 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 4f5e0ea..c1c12f8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -48,6 +48,8 @@
 #define WRITEL(data, reg) \
(WARN_ON_ONCE(!(reg)) ? 0 : writel((data), (reg)))
 
+#define IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
+
 /* Allocate temporary buffers for decoding */
 static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
 {
@@ -1352,7 +1354,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
}
 
-   if (IS_MFCV7_PLUS(dev)) {
+   if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
WRITEL(reg, mfc_regs->d_dec_options);
reg = 0;
}
@@ -1367,7 +1369,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7_PLUS(dev))
+   if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
WRITEL(reg, mfc_regs->d_init_buffer_options);
else
WRITEL(reg, mfc_regs->d_dec_options);
-- 
1.7.9.5

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


[PATCH 1/3] [media] s5p-mfc: Remove duplicate function s5p_mfc_reload_firmware

2014-05-20 Thread Arun Kumar K
The function s5p_mfc_reload_firmware is exactly same as
s5p_mfc_load_firmware. So removing the duplicate function.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   33 -
 2 files changed, 1 insertion(+), 34 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 9ed0985..8da4c23 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -162,7 +162,7 @@ static void s5p_mfc_watchdog_worker(struct work_struct 
*work)
/* Double check if there is at least one instance running.
 * If no instance is in memory than no firmware should be present */
if (dev->num_inst > 0) {
-   ret = s5p_mfc_reload_firmware(dev);
+   ret = s5p_mfc_load_firmware(dev);
if (ret) {
mfc_err("Failed to reload FW\n");
goto unlock;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 6c3f8f7..c97c7c8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -107,39 +107,6 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
return 0;
 }
 
-/* Reload firmware to MFC */
-int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev)
-{
-   struct firmware *fw_blob;
-   int err;
-
-   /* Firmare has to be present as a separate file or compiled
-* into kernel. */
-   mfc_debug_enter();
-
-   err = request_firmware((const struct firmware **)&fw_blob,
-dev->variant->fw_name, dev->v4l2_dev.dev);
-   if (err != 0) {
-   mfc_err("Firmware is not present in the /lib/firmware directory 
nor compiled in kernel\n");
-   return -EINVAL;
-   }
-   if (fw_blob->size > dev->fw_size) {
-   mfc_err("MFC firmware is too big to be loaded\n");
-   release_firmware(fw_blob);
-   return -ENOMEM;
-   }
-   if (!dev->fw_virt_addr) {
-   mfc_err("MFC firmware is not allocated\n");
-   release_firmware(fw_blob);
-   return -EINVAL;
-   }
-   memcpy(dev->fw_virt_addr, fw_blob->data, fw_blob->size);
-   wmb();
-   release_firmware(fw_blob);
-   mfc_debug_leave();
-   return 0;
-}
-
 /* Release firmware memory */
 int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev)
 {
-- 
1.7.9.5

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


[PATCH 2/3] [media] s5p-mfc: Support multiple firmware sub-versions

2014-05-20 Thread Arun Kumar K
For MFC firmwares, improved versions with bug fixes and
feature additions are released keeping the firmware version
including major and minor number same. The issue came with
the release of a new MFCv6 firmware with an interface change.
This patch adds the support of accepting multiple firmware
binaries for every version with the driver trying to load
firmwares starting from latest. This ensures full backward
compatibility regardless of which firmware version and kernel
version is used.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c|9 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   11 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   15 ---
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8da4c23..514e7ec 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1343,7 +1343,7 @@ static struct s5p_mfc_variant mfc_drvdata_v5 = {
.port_num   = MFC_NUM_PORTS,
.buf_size   = &buf_size_v5,
.buf_align  = &mfc_buf_align_v5,
-   .fw_name= "s5p-mfc.fw",
+   .fw_name[0] = "s5p-mfc.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
@@ -1370,7 +1370,8 @@ static struct s5p_mfc_variant mfc_drvdata_v6 = {
.port_num   = MFC_NUM_PORTS_V6,
.buf_size   = &buf_size_v6,
.buf_align  = &mfc_buf_align_v6,
-   .fw_name= "s5p-mfc-v6.fw",
+   .fw_name[0] = "s5p-mfc-v6.fw",
+   .fw_name[1] = "s5p-mfc-v6-v2.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = {
@@ -1397,7 +1398,7 @@ static struct s5p_mfc_variant mfc_drvdata_v7 = {
.port_num   = MFC_NUM_PORTS_V7,
.buf_size   = &buf_size_v7,
.buf_align  = &mfc_buf_align_v7,
-   .fw_name= "s5p-mfc-v7.fw",
+   .fw_name[0] = "s5p-mfc-v7.fw",
 };
 
 struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
@@ -1424,7 +1425,7 @@ static struct s5p_mfc_variant mfc_drvdata_v8 = {
.port_num   = MFC_NUM_PORTS_V8,
.buf_size   = &buf_size_v8,
.buf_align  = &mfc_buf_align_v8,
-   .fw_name= "s5p-mfc-v8.fw",
+   .fw_name[0] = "s5p-mfc-v8.fw",
 };
 
 static struct platform_device_id mfc_driver_ids[] = {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 89681c3..de60185 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -38,6 +38,8 @@
 #define MFC_BANK2_ALIGN_ORDER  13
 #define MFC_BASE_ALIGN_ORDER   17
 
+#define MFC_FW_MAX_VERSIONS2
+
 #include 
 
 static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b)
@@ -163,6 +165,11 @@ enum s5p_mfc_decode_arg {
MFC_DEC_RES_CHANGE,
 };
 
+enum s5p_mfc_fw_ver {
+   MFC_FW_V1,
+   MFC_FW_V2,
+};
+
 #define MFC_BUF_FLAG_USED  (1 << 0)
 #define MFC_BUF_FLAG_EOS   (1 << 1)
 
@@ -225,7 +232,7 @@ struct s5p_mfc_variant {
u32 version_bit;
struct s5p_mfc_buf_size *buf_size;
struct s5p_mfc_buf_align *buf_align;
-   char*fw_name;
+   char*fw_name[MFC_FW_MAX_VERSIONS];
 };
 
 /**
@@ -287,6 +294,7 @@ struct s5p_mfc_priv_buf {
  * @warn_start:hardware error code from which warnings start
  * @mfc_ops:   ops structure holding HW operation function pointers
  * @mfc_cmds:  cmd structure holding HW commands function pointers
+ * @fw_ver:loaded firmware sub-version
  *
  */
 struct s5p_mfc_dev {
@@ -331,6 +339,7 @@ struct s5p_mfc_dev {
struct s5p_mfc_hw_ops *mfc_ops;
struct s5p_mfc_hw_cmds *mfc_cmds;
const struct s5p_mfc_regs *mfc_regs;
+   enum s5p_mfc_fw_ver fw_ver;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index c97c7c8..7aabcdb 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -78,14 +78,23 @@ int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev)
 int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
 {
struct firmware *fw_blob;
-   int err;
+   int err = -EINVAL, i;
 
/* Firmare has to be present as a separate file or compiled
 * into kernel. */
mfc_debug_enter();
 
-   err = request_firmware((const struct firmware **)&fw_blob,
-dev->variant->fw_name, dev->v4l2_dev.dev);
+   for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0; i--) {
+   if (!dev->variant->fw_name[i])
+   continue;
+   err = request_firmware((const struct firmware **)&am

[PATCH 0/3] Support for multiple MFC FW sub-versions

2014-05-20 Thread Arun Kumar K
This patchset is for supporting multple firmware sub-versions
for MFC. Newer firmwares come with changed interfaces and fixes
without any change in the fw version number.
So this implementation is as per Tomasz Figa's suggestion [1].
[1] http://permalink.gmane.org/gmane.linux.kernel.samsung-soc/31735

Arun Kumar K (3):
  [media] s5p-mfc: Remove duplicate function s5p_mfc_reload_firmware
  [media] s5p-mfc: Support multiple firmware sub-versions
  [media] s5p-mfc: Add init buffer cmd to MFCV6

 drivers/media/platform/s5p-mfc/s5p_mfc.c|   11 +++---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |   11 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   44 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |6 ++--
 4 files changed, 30 insertions(+), 42 deletions(-)

-- 
1.7.9.5

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


Re: [PATCH v2] [media] s5p-mfc: Dequeue sequence header after STREAMON

2014-05-19 Thread Arun Kumar K
Hi Kamil,

On 05/15/14 20:47, Kamil Debski wrote:
> Hi Arun,
> 
>> From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
>> ow...@vger.kernel.org] On Behalf Of Arun Kumar K
>> Sent: Wednesday, May 14, 2014 10:10 AM
>>
>> Hi Hans,
>>
>> On 05/14/14 12:39, Hans Verkuil wrote:
>>> On 05/14/2014 08:29 AM, Arun Kumar K wrote:
>>>> MFCv6 encoder needs specific minimum number of buffers to be queued
>>>> in the CAPTURE plane. This minimum number will be known only when
>> the
>>>> sequence header is generated.
>>>> So we used to allow STREAMON on the CAPTURE plane only after
>> sequence
>>>> header is generated and checked with the minimum buffer requirement.
>>>>
>>>> But this causes a problem that we call a vb2_buffer_done for the
>>>> sequence header buffer before doing a STREAON on the CAPTURE plane.
>>>
>>> How could this ever have worked? Buffers aren't queued to the driver
>>> until STREAMON is called, and calling vb2_buffer_done for a buffer
>>> that is not queued first to the driver will mess up internal data (q-
>>> queued_count for one).
>>>
>>
>> This worked till now because __enqueue_in_driver is called first and
>> then start_streaming qop is called. In MFCv6, the start_streaming
>> driver callback used to wait till sequence header interrupt is received
>> and it used to do vb2_buffer_done in that interrupt context. So it
>> happened after buffers are enqueued in driver and before completing the
>> vb2_streamon.
>>
>>>> This used to still work fine until this patch was merged -
>>>> b3379c6 : vb2: only call start_streaming if sufficient buffers are
>>>> queued
>>>
>>> Are you testing with CONFIG_VIDEO_ADV_DEBUG set? If not, you should
>> do
>>> so. That will check whether all the vb2 calls are balanced.
>>>
>>> BTW, that's a small typo in s5p_mfc_enc.c (search for 'inavlid').
>>>
>>
>> I got it. Will post a patch fixing them. Thanks for spotting this.
>>
>>>> This problem should also come in earlier MFC firmware versions if
>> the
>>>> application calls STREAMON on CAPTURE with some delay after doing
>>>> STREAMON on OUTPUT.
>>>
>>> You can also play around with the min_buffers_needed field. My
>>> rule-of-thumb is that when start_streaming is called everything
>> should
>>> be ready to stream. It is painful for drivers to have to keep track
>> of the 'do I have enough buffers' status.
>>>
>>> For that reason I introduced the min_buffers_needed field. What I
>>> believe you can do here is to set it initially to a large value,
>>> preventing start_streaming from being called, and once you really
>> know
>>> the minimum number of buffers that you need it can be updated again
>> to the actual value.
>>
>> If a large value is kept in min_buffers_needed, there will be some
>> unnecessary memory initialization needed for say 16 full HD raw YUV
>> buffers when actual needed is only 4. And once the encoding is started,
>> updating the min_buffers_needed to actual value doesnt give any
>> advantage as nobody checks for it after that.
>> So the whole idea is to not enforce a worst case buffer allocation
>> requirement beforehand itself. I hope the current scheme of things
>> works well for the requirement.
> 
> I was looking in the code of the MFC encoder and handling of this situation
> seems wrong to me.
> 
> You say that a minimum number of buffers has to be queued for MFC encoder to
> work. But this number is not checked in s5p_mfc_ctx_ready in s5p_mfc_enc.c.
> 

The situation is bit tricky here. The s5p_mfc_ctx_ready has to be true
for giving the first frame to encode which generates the sequence
header. So this condition still holds good -
/* context is ready to make header */
if (ctx->state == MFCINST_GOT_INST && ctx->dst_queue_cnt >= 1)
return 1;

So at this moment, atleast 1 buffer has to be queued in CAPTURE plane so
as to generate sequence header. But once that is generated, then only
the total buffer requirement will be known as per the v6+ firmware.
So if we make ctx_ready only after STREAMON on CAPTURE is done, then
there is no way to check for min. buffer requirement and the application
will start the encoding and will fail during runtime.

> It is only checked during reqbufs. This way it does not ensure that there is
> a minimum number of buffers queued.
> 
> Also there is a control V4L2_CID_MIN_BUFFERS_

[PATCH 2/2] [media] s5p-mfc: Core support for v8 encoder

2014-05-19 Thread Arun Kumar K
From: Kiran AVND 

This patch adds core support for v8 encoder. This
patch also adds register definitions and buffer size
requirements for H264 & VP8 encoding, needed for new
firmware version v8 for MFC

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h|   30 
 drivers/media/platform/s5p-mfc/s5p_mfc.c|2 +
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|   12 ++---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   56 +++
 4 files changed, 85 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
index c84d120..cc7cbec 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
@@ -72,16 +72,46 @@
 /* SEI related information */
 #define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
 
+/* Encoder Registers */
+#define S5P_FIMV_E_FIXED_PICTURE_QP_V8 0xf794
+#define S5P_FIMV_E_RC_CONFIG_V80xf798
+#define S5P_FIMV_E_RC_QP_BOUND_V8  0xf79c
+#define S5P_FIMV_E_RC_RPARAM_V80xf7a4
+#define S5P_FIMV_E_MB_RC_CONFIG_V8 0xf7a8
+#define S5P_FIMV_E_PADDING_CTRL_V8 0xf7ac
+#define S5P_FIMV_E_MV_HOR_RANGE_V8 0xf7b4
+#define S5P_FIMV_E_MV_VER_RANGE_V8 0xf7b8
+
+#define S5P_FIMV_E_VBV_BUFFER_SIZE_V8  0xf78c
+#define S5P_FIMV_E_VBV_INIT_DELAY_V8   0xf790
+
+#define S5P_FIMV_E_ASPECT_RATIO_V8 0xfb4c
+#define S5P_FIMV_E_EXTENDED_SAR_V8 0xfb50
+#define S5P_FIMV_E_H264_OPTIONS_V8 0xfb54
+
 /* MFCv8 Context buffer sizes */
 #define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
 #define MFC_H264_DEC_CTX_BUF_SIZE_V8   (2 * SZ_1M) /*  2MB */
 #define MFC_OTHER_DEC_CTX_BUF_SIZE_V8  (20 * SZ_1K)/*  20KB */
+#define MFC_H264_ENC_CTX_BUF_SIZE_V8   (100 * SZ_1K)   /* 100KB */
+#define MFC_OTHER_ENC_CTX_BUF_SIZE_V8  (10 * SZ_1K)/*  10KB */
 
 /* Buffer size defines */
+#define S5P_FIMV_TMV_BUFFER_SIZE_V8(w, h)  (((w) + 1) * ((h) + 1) * 8)
+
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(w, h)(((w) * 704) + 2176)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(w, h) \
(((w) * 576 + (h) * 128)  + 4128)
 
+#define S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(w, h) \
+   (((w) * 592) + 2336)
+#define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(w, h) \
+   (((w) * 576) + 10512 + \
+   ((w) * 16) * ((h) * 16)) * 3) / 2) * 4))
+#define S5P_FIMV_ME_BUFFER_SIZE_V8(imw, imh, mbw, mbh) \
+   ((DIV_ROUND_UP((mbw * 16), 64) *  DIV_ROUND_UP((mbh * 16), 64) * 256) \
++ (DIV_ROUND_UP((mbw) * (mbh), 32) * 16))
+
 /* BUffer alignment defines */
 #define S5P_FIMV_D_ALIGN_PLANE_SIZE_V8 64
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 6c466a3..9ed0985 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1404,6 +1404,8 @@ struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
.dev_ctx= MFC_CTX_BUF_SIZE_V8,
.h264_dec_ctx   = MFC_H264_DEC_CTX_BUF_SIZE_V8,
.other_dec_ctx  = MFC_OTHER_DEC_CTX_BUF_SIZE_V8,
+   .h264_enc_ctx   = MFC_H264_ENC_CTX_BUF_SIZE_V8,
+   .other_enc_ctx  = MFC_OTHER_ENC_CTX_BUF_SIZE_V8,
 };
 
 struct s5p_mfc_buf_size buf_size_v8 = {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index ad759b9..56d1edd 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -58,7 +58,7 @@ static struct s5p_mfc_fmt formats[] = {
.codec_mode = S5P_MFC_CODEC_NONE,
.type   = MFC_FMT_RAW,
.num_planes = 2,
-   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
+   .versions   = MFC_V5 | MFC_V6 | MFC_V7 | MFC_V8,
},
{
.name   = "4:2:0 2 Planes Y/CrCb",
@@ -66,7 +66,7 @@ static struct s5p_mfc_fmt formats[] = {
.codec_mode = S5P_MFC_CODEC_NONE,
.type   = MFC_FMT_RAW,
.num_planes = 2,
-   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
+   .versions   = MFC_V5 | MFC_V6 | MFC_V7 | MFC_V8,
},
{
.name   = "H264 Encoded Stream",
@@ -74,7 +74,7 @@ static struct s5p_mfc_fmt formats[] = {
.codec_mode = S5P_MFC_CODEC_H264_ENC,
.type   = MFC_FMT_ENC,
.num_planes = 1,
-   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
+   .versions   = MFC_V5 | MFC_V6 | MFC_V7 | MFC_V8,
},
{
.name  

[PATCH 1/2] [media] s5p-mfc: Core support to add v8 decoder

2014-05-19 Thread Arun Kumar K
From: Kiran AVND 

This patch adds variant data and core support for
V8 decoder. This patch also adds the register definition
file for new firmware version v8 for MFC.

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |   94 
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   31 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|5 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |   28 +++---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|   85 --
 6 files changed, 223 insertions(+), 23 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

diff --git a/Documentation/devicetree/bindings/media/s5p-mfc.txt 
b/Documentation/devicetree/bindings/media/s5p-mfc.txt
index f418168..3e3c5f3 100644
--- a/Documentation/devicetree/bindings/media/s5p-mfc.txt
+++ b/Documentation/devicetree/bindings/media/s5p-mfc.txt
@@ -10,7 +10,8 @@ Required properties:
   - compatible : value should be either one among the following
(a) "samsung,mfc-v5" for MFC v5 present in Exynos4 SoCs
(b) "samsung,mfc-v6" for MFC v6 present in Exynos5 SoCs
-   (b) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (c) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (d) "samsung,mfc-v8" for MFC v8 present in Exynos5800 SoC
 
   - reg : Physical base address of the IP registers and length of memory
  mapped region.
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
new file mode 100644
index 000..c84d120
--- /dev/null
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
@@ -0,0 +1,94 @@
+/*
+ * Register definition file for Samsung MFC V8.x Interface (FIMV) driver
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _REGS_MFC_V8_H
+#define _REGS_MFC_V8_H
+
+#include 
+#include "regs-mfc-v7.h"
+
+/* Additional registers for v8 */
+#define S5P_FIMV_D_MVC_NUM_VIEWS_V80xf104
+#define S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8 0xf144
+#define S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V80xf148
+#define S5P_FIMV_D_MV_BUFFER_SIZE_V8   0xf150
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8  0xf138
+#define S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8 0xf13c
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_V8  0xf160
+#define S5P_FIMV_D_SECOND_PLANE_DPB_V8 0xf260
+#define S5P_FIMV_D_MV_BUFFER_V80xf460
+
+#define S5P_FIMV_D_NUM_MV_V8   0xf134
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8  0xf154
+
+#define S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8  0xf560
+#define S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8  0xf564
+
+#define S5P_FIMV_D_CPB_BUFFER_ADDR_V8  0xf5b0
+#define S5P_FIMV_D_CPB_BUFFER_SIZE_V8  0xf5b4
+#define S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8 0xf5bc
+#define S5P_FIMV_D_CPB_BUFFER_OFFSET_V80xf5c0
+#define S5P_FIMV_D_SLICE_IF_ENABLE_V8  0xf5c4
+#define S5P_FIMV_D_STREAM_DATA_SIZE_V8 0xf5d0
+
+/* Display information register */
+#define S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8  0xf600
+#define S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8 0xf604
+
+/* Display status */
+#define S5P_FIMV_D_DISPLAY_STATUS_V8   0xf608
+
+#define S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8 0xf60c
+#define S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V80xf610
+
+#define S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8   0xf618
+#define S5P_FIMV_D_DISPLAY_CROP_INFO1_V8   0xf61c
+#define S5P_FIMV_D_DISPLAY_CROP_INFO2_V8   0xf620
+#define S5P_FIMV_D_DISPLAY_PICTURE_PROFILE_V8  0xf624
+
+/* Decoded picture information register */
+#define S5P_FIMV_D_DECODED_STATUS_V8   0xf644
+#define S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8 0xf648
+#define S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V80xf64c
+#define S5P_FIMV_D_DECODED_THIRD_PLANE_ADDR_V8 0xf650
+#define S5P_FIMV_D_DECODED_FRAME_TYPE_V8   0xf654
+#define S5P_FIMV_D_DECODED_NAL_SIZE_V8  0xf664
+
+/* Returned value register for specific setting */
+#define S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8  0xf674
+#define S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8  0xf678
+#define S5P_FIMV_D_MVC_VIEW_ID_V8  0xf6d8
+
+/* SEI related information */
+#define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
+
+/* MFCv8 Context buffer sizes */
+#define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
+#define MFC_H264_DEC_CTX_BUF_SIZE_V8   (2 * SZ_1M) /*  2MB */
+#define MFC_OTHER_DEC_CTX_BUF_SIZE_V8  (20 * SZ_1K)/*  20KB */
+
+/* Buffer size defines */

[PATCH 0/2] Re-send MFCv8 support patches

2014-05-19 Thread Arun Kumar K
These 2 patches for MFCv8 support are rebased onto
[1] with the dependencies as mentioned below.
Changes include adding the MFC_V8 version to formats.

- Re-send MFC patches
  https://www.mail-archive.com/linux-samsung-soc@vger.kernel.org/msg31051.html
- Adding version information to formats by Kamil
  v4l: s5p-mfc: Fix default pixel format selection for decoder
  v4l: s5p-mfc: Limit enum_fmt to output formats of current version

[1] http://git.linuxtv.org/cgit.cgi/kdebski/media_tree_2.git/?h=for-3.16-2

Kiran AVND (2):
  [media] s5p-mfc: Core support to add v8 decoder
  [media] s5p-mfc: Core support for v8 encoder

 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |  124 +
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   33 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|5 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |   28 ++--
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c   |   12 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|  141 +---
 7 files changed, 308 insertions(+), 38 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

-- 
1.7.9.5

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


[PATCH 03/10] [media] s5p-mfc: Extract open/close MFC instance commands.

2014-05-19 Thread Arun Kumar K
From: Pawel Osciak 

This is in preparation for a new flow to fix issues with streamon, which
should not be allocating buffer memory.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |   19 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   61 +
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h |3 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |   28 +++-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c  |   18 ++--
 5 files changed, 74 insertions(+), 55 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 6ef6bd1..861087c 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -877,24 +877,7 @@ static int s5p_mfc_release(struct file *file)
 * return instance and free resources */
if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
mfc_debug(2, "Has to free instance\n");
-   ctx->state = MFCINST_RETURN_INST;
-   set_work_bit_irqsave(ctx);
-   s5p_mfc_clean_ctx_int_flags(ctx);
-   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
-   /* Wait until instance is returned or timeout occurred */
-   if (s5p_mfc_wait_for_done_ctx
-   (ctx, S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET, 0)) {
-   s5p_mfc_clock_off();
-   mfc_err("Err returning instance\n");
-   }
-   mfc_debug(2, "After free instance\n");
-   /* Free resources */
-   s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx);
-   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
-   if (ctx->type == MFCINST_DECODER)
-   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer,
-   ctx);
-
+   s5p_mfc_close_mfc_inst(dev, ctx);
ctx->inst_no = MFC_NO_INSTANCE_SET;
}
/* hardware locking scheme */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index ee05f2d..6f6e50a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -400,3 +400,64 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
return 0;
 }
 
+int s5p_mfc_open_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)
+{
+   int ret = 0;
+
+   ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_instance_buffer, ctx);
+   if (ret) {
+   mfc_err("Failed allocating instance buffer\n");
+   goto err;
+   }
+
+   if (ctx->type == MFCINST_DECODER) {
+   ret = s5p_mfc_hw_call(dev->mfc_ops,
+   alloc_dec_temp_buffers, ctx);
+   if (ret) {
+   mfc_err("Failed allocating temporary buffers\n");
+   goto err_free_inst_buf;
+   }
+   }
+
+   set_work_bit_irqsave(ctx);
+   s5p_mfc_clean_ctx_int_flags(ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+   if (s5p_mfc_wait_for_done_ctx(ctx,
+   S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET, 0)) {
+   /* Error or timeout */
+   mfc_err("Error getting instance from hardware\n");
+   ret = -EIO;
+   goto err_free_desc_buf;
+   }
+
+   mfc_debug(2, "Got instance number: %d\n", ctx->inst_no);
+   return ret;
+
+err_free_desc_buf:
+   if (ctx->type == MFCINST_DECODER)
+   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
+err_free_inst_buf:
+   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
+err:
+   return ret;
+}
+
+void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)
+{
+   ctx->state = MFCINST_RETURN_INST;
+   set_work_bit_irqsave(ctx);
+   s5p_mfc_clean_ctx_int_flags(ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+   /* Wait until instance is returned or timeout occurred */
+   if (s5p_mfc_wait_for_done_ctx(ctx,
+   S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET, 0))
+   mfc_err("Err returning instance\n");
+
+   /* Free resources */
+   s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
+   if (ctx->type == MFCINST_DECODER)
+   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
+
+   ctx->state = MFCINST_FREE;
+}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h
index 6a9b6f8..8e5df04 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_

[PATCH 10/10] [media] s5p-mfc: Rename IS_MFCV7 macro

2014-05-19 Thread Arun Kumar K
Renaming the IS_MFCV7 macro to IS_MFCV7_PLUS for the
addition of MFCv8 support which reuses the v7 code.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   12 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 662fcef..993c993 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -701,6 +701,6 @@ void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
(dev->variant->port_num ? 1 : 0) : 0) : 0)
 #define IS_TWOPORT(dev)(dev->variant->port_num == 2 ? 1 : 0)
 #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
-#define IS_MFCV7(dev)  (dev->variant->version >= 0x70 ? 1 : 0)
+#define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
 
 #endif /* S5P_MFC_COMMON_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 1a55487..d09c2e1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1039,7 +1039,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
return -EINVAL;
}
 
-   if (!IS_MFCV7(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
+   if (!IS_MFCV7_PLUS(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
mfc_err("VP8 is supported only in MFC v7\n");
return -EINVAL;
}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 37a054a..cbea828 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -113,7 +113,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct 
s5p_mfc_ctx *ctx)
(ctx->mv_count * ctx->mv_size);
break;
case S5P_MFC_CODEC_MPEG4_DEC:
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
ctx->scratch_buf_size =
S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
mb_width,
@@ -354,7 +354,7 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx 
*ctx)
ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
 
/* MFCv7 needs pad bytes for Luma and Chroma */
-   if (IS_MFCV7(ctx->dev)) {
+   if (IS_MFCV7_PLUS(ctx->dev)) {
ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
}
@@ -1303,7 +1303,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
}
 
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
WRITEL(reg, mfc_regs->d_dec_options);
reg = 0;
}
@@ -1318,7 +1318,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7(dev))
+   if (IS_MFCV7_PLUS(dev))
WRITEL(reg, mfc_regs->d_init_buffer_options);
else
WRITEL(reg, mfc_regs->d_dec_options);
@@ -1406,7 +1406,7 @@ static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
}
 
/* Set stride lengths for v7 & above */
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
WRITEL(ctx->img_width, mfc_regs->e_source_first_plane_stride);
WRITEL(ctx->img_width, mfc_regs->e_source_second_plane_stride);
}
@@ -2148,7 +2148,7 @@ const struct s5p_mfc_regs 
*s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
R(e_h264_frame_packing_sei_info,
S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
 
-   if (!IS_MFCV7(dev))
+   if (!IS_MFCV7_PLUS(dev))
goto done;
 
/* Initialize registers used in MFC v7 */
-- 
1.7.9.5

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


[PATCH 07/10] [media] s5p-mfc: Update scratch buffer size for MPEG4

2014-05-19 Thread Arun Kumar K
Update the MPEG4 decoder scratch buffer size as per the
new v6 firmware. This updation is increasing the size and so
is backward compatible with older v6 firmwares.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 8d0b686..8e4021c 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -381,8 +381,7 @@
 (DIV_ROUND_UP((mbw) * (mbh), 32) * 16))
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(w, h)(((w) * 192) + 64)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(w, h) \
-   ((w) * ((h) * 64 + 144) + (2048/16 * (h) * 64) + \
-(2048/16 * 256 + 8320))
+   ((w) * 144 + 8192 * (h) + 49216 + 1048576)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(w, h) \
(2096 * ((w) + (h) + 1))
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(w, h)((w) * 400)
-- 
1.7.9.5

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


[PATCH 05/10] [media] s5p-mfc: Update scratch buffer size for VP8 encoder

2014-05-19 Thread Arun Kumar K
From: Kiran AVND 

Scratch buffer size updated for vp8 encoding as per
the latest v7 firmware. As the new macro increases the
scratch buffer size, it is backward compatible with the older
firmware too.

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index ea5ec2a..5dfa149 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -56,6 +56,7 @@
(SZ_1M + ((w) * 144) + (8192 * (h)) + 49216)
 
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(w, h) \
-   (((w) * 48) + (((w) + 1) / 2 * 128) + 144 + 8192)
+   (((w) * 48) + 8192 + w) + 1) / 2) * 128) + 144 + \
+   ((w) * 16) * ((h) * 16)) * 3) / 2) * 4))
 
 #endif /*_REGS_MFC_V7_H*/
-- 
1.7.9.5

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


[PATCH 08/10] [media] s5p-mfc: Move INIT_BUFFER_OPTIONS from v7 to v6

2014-05-19 Thread Arun Kumar K
The register S5P_FIMV_D_INIT_BUFFER_OPTIONS holds good for v6
firmware too. So moving the definition from v7 regs to v6.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h|2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 8e4021c..51cb2dd 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -141,6 +141,7 @@
 #define S5P_FIMV_D_SLICE_IF_ENABLE_V6  0xf4c4
 #define S5P_FIMV_D_PICTURE_TAG_V6  0xf4c8
 #define S5P_FIMV_D_STREAM_DATA_SIZE_V6 0xf4d0
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6  0xf47c
 
 /* Display information register */
 #define S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6  0xf500
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index 5dfa149..1a5c6fd 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -18,8 +18,6 @@
 #define S5P_FIMV_CODEC_VP8_ENC_V7  25
 
 /* Additional registers for v7 */
-#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7  0xf47c
-
 #define S5P_FIMV_E_SOURCE_FIRST_ADDR_V70xf9e0
 #define S5P_FIMV_E_SOURCE_SECOND_ADDR_V7   0xf9e4
 #define S5P_FIMV_E_SOURCE_THIRD_ADDR_V70xf9e8
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index f64621a..518d9a0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1310,7 +1310,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
if (IS_MFCV7(dev))
-   WRITEL(reg, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7);
+   WRITEL(reg, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
else
WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
 
-- 
1.7.9.5

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


[PATCH 00/10] Re-send MFC patches

2014-05-19 Thread Arun Kumar K
These patches for s5p-mfc are completed review and
accepted. These are rebased onto [1] and fixed conflicts
for merging.

[1] http://git.linuxtv.org/cgit.cgi/kdebski/media_tree_2.git/?h=for-3.16-2

Arun Kumar K (3):
  [media] s5p-mfc: Update scratch buffer size for MPEG4
  [media] s5p-mfc: Move INIT_BUFFER_OPTIONS from v7 to v6
  [media] s5p-mfc: Rename IS_MFCV7 macro

Kiran AVND (2):
  [media] s5p-mfc: Update scratch buffer size for VP8 encoder
  [media] s5p-mfc: Add variants to access mfc registers

Pawel Osciak (5):
  [media] s5p-mfc: Copy timestamps only when a frame is produced.
  [media] s5p-mfc: Fixes for decode REQBUFS.
  [media] s5p-mfc: Extract open/close MFC instance commands.
  [media] s5p-mfc: Don't allocate codec buffers on STREAMON.
  [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for
decode.

 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|4 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h|5 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c|   35 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |3 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |   62 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h   |3 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c|  216 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|   20 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.c|6 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.h|  254 
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |  703 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.h |7 +-
 12 files changed, 904 insertions(+), 414 deletions(-)

-- 
1.7.9.5

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


[PATCH 02/10] [media] s5p-mfc: Fixes for decode REQBUFS.

2014-05-19 Thread Arun Kumar K
From: Pawel Osciak 

- Honor return values from vb2_reqbufs on REQBUFS(0).

- Do not set the number of allocated buffers to 0 if userspace tries
  to request buffers again without freeing them.

- There is no need to verify correct instance state on reqbufs, as we will
  verify this in queue_setup().

- There is also no need to verify that vb2_reqbufs() was able to allocate enough
  buffers (pb_count) and call buf_init on that many buffers (i.e. dst_buf_count
  is at least pb_count), because this will be verified by second queue_setup()
  call as well and vb2_reqbufs() will fail otherwise.

- Only verify state is MFCINST_INIT when allocating, not when freeing.

- Refactor and simplify code.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |  178 ++
 1 file changed, 99 insertions(+), 79 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 58b7bba..99a55e6 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -462,104 +462,124 @@ out:
return ret;
 }
 
-/* Reqeust buffers */
-static int vidioc_reqbufs(struct file *file, void *priv,
- struct v4l2_requestbuffers *reqbufs)
+static int reqbufs_output(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
+   struct v4l2_requestbuffers *reqbufs)
 {
-   struct s5p_mfc_dev *dev = video_drvdata(file);
-   struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
int ret = 0;
 
-   if (reqbufs->memory != V4L2_MEMORY_MMAP) {
-   mfc_err("Only V4L2_MEMORY_MAP is supported\n");
-   return -EINVAL;
-   }
-   if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-   /* Can only request buffers after an instance has been opened.*/
-   if (ctx->state == MFCINST_INIT) {
-   ctx->src_bufs_cnt = 0;
-   if (reqbufs->count == 0) {
-   mfc_debug(2, "Freeing buffers\n");
-   s5p_mfc_clock_on();
-   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
-   s5p_mfc_clock_off();
-   return ret;
-   }
-   /* Decoding */
-   if (ctx->output_state != QUEUE_FREE) {
-   mfc_err("Bufs have already been requested\n");
-   return -EINVAL;
-   }
-   s5p_mfc_clock_on();
-   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
-   s5p_mfc_clock_off();
-   if (ret) {
-   mfc_err("vb2_reqbufs on output failed\n");
-   return ret;
-   }
-   mfc_debug(2, "vb2_reqbufs: %d\n", ret);
-   ctx->output_state = QUEUE_BUFS_REQUESTED;
+   s5p_mfc_clock_on();
+
+   if (reqbufs->count == 0) {
+   mfc_debug(2, "Freeing buffers\n");
+   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+   if (ret)
+   goto out;
+   ctx->src_bufs_cnt = 0;
+   } else if (ctx->output_state == QUEUE_FREE) {
+   /* Can only request buffers after the instance
+* has been opened.
+*/
+   WARN_ON(ctx->src_bufs_cnt != 0);
+   if (ctx->state != MFCINST_INIT) {
+   mfc_err("Reqbufs called in an invalid state\n");
+   ret = -EINVAL;
+   goto out;
}
-   } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+
+   mfc_debug(2, "Allocating %d buffers for OUTPUT queue\n",
+   reqbufs->count);
+   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+   if (ret)
+   goto out;
+
+   ctx->output_state = QUEUE_BUFS_REQUESTED;
+   } else {
+   mfc_err("Buffers have already been requested\n");
+   ret = -EINVAL;
+   }
+out:
+   s5p_mfc_clock_off();
+   if (ret)
+   mfc_err("Failed allocating buffers for OUTPUT queue\n");
+   return ret;
+}
+
+static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
+   struct v4l2_requestbuffers *reqbufs)
+{
+   int ret = 0;
+
+   s5p_mfc_clock_on();
+
+   if (reqbufs->count == 0) {
+   mfc_debug(2, "Freeing buffers\n");
+   ret = vb2_reqbufs(&ctx-

[PATCH 04/10] [media] s5p-mfc: Don't allocate codec buffers on STREAMON.

2014-05-19 Thread Arun Kumar K
From: Pawel Osciak 

Currently, we allocate private codec buffers on STREAMON, which may fail
if we are out of memory. We don't check for failure though, which will
make us crash with the codec accessing random memory.

We shouldn't be failing STREAMON with out of memory errors though. So move
the allocation of private codec buffers to REQBUFS for OUTPUT queue. Also,
move MFC instance opening and closing to REQBUFS as well, as it's tied to
allocation and deallocation of private codec buffers.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |8 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |   30 +++--
 3 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 861087c..70f728f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -643,6 +643,7 @@ static irqreturn_t s5p_mfc_irq(int irq, void *priv)
 
case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET:
clear_work_bit(ctx);
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
wake_up(&ctx->queue);
goto irq_cleanup_hw;
@@ -763,7 +764,7 @@ static int s5p_mfc_open(struct file *file)
goto err_bad_node;
}
ctx->fh.ctrl_handler = &ctx->ctrl_handler;
-   ctx->inst_no = -1;
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
/* Load firmware if this is the first instance */
if (dev->num_inst == 1) {
dev->watchdog_timer.expires = jiffies +
@@ -873,12 +874,11 @@ static int s5p_mfc_release(struct file *file)
vb2_queue_release(&ctx->vq_dst);
/* Mark context as idle */
clear_work_bit_irqsave(ctx);
-   /* If instance was initialised then
+   /* If instance was initialised and not yet freed,
 * return instance and free resources */
-   if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
+   if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) {
mfc_debug(2, "Has to free instance\n");
s5p_mfc_close_mfc_inst(dev, ctx);
-   ctx->inst_no = MFC_NO_INSTANCE_SET;
}
/* hardware locking scheme */
if (dev->curr_ctx == ctx->num)
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 6f6e50a..6c3f8f7 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -459,5 +459,6 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx)
if (ctx->type == MFCINST_DECODER)
s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
 
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
 }
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 995cee2..a4e6668 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -475,11 +475,11 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
if (ret)
goto out;
+   s5p_mfc_close_mfc_inst(dev, ctx);
ctx->src_bufs_cnt = 0;
+   ctx->output_state = QUEUE_FREE;
} else if (ctx->output_state == QUEUE_FREE) {
-   /* Can only request buffers after the instance
-* has been opened.
-*/
+   /* Can only request buffers when we have a valid format set. */
WARN_ON(ctx->src_bufs_cnt != 0);
if (ctx->state != MFCINST_INIT) {
mfc_err("Reqbufs called in an invalid state\n");
@@ -493,6 +493,13 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
if (ret)
goto out;
 
+   ret = s5p_mfc_open_mfc_inst(dev, ctx);
+   if (ret) {
+   reqbufs->count = 0;
+   vb2_reqbufs(&ctx->vq_src, reqbufs);
+   goto out;
+   }
+
ctx->output_state = QUEUE_BUFS_REQUESTED;
} else {
mfc_err("Buffers have already been requested\n");
@@ -594,7 +601,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
return -EINVAL;
}
mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
-   if (ctx->state == MFCINST_INIT &&
+   if (ct

[PATCH 06/10] [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.

2014-05-19 Thread Arun Kumar K
From: Pawel Osciak 

Currently, for formats that are not H264, MFC driver will check
the consumed stream size returned by the firmware and, based on that,
will try to decide whether the bitstream buffer contained more than
one frame. If the size of the buffer is larger than the consumed
stream, it assumes that there are more frames in the buffer and that the
buffer should be resubmitted for decode. This rarely works though and
actually introduces problems, because:

- v7 firmware will always return consumed stream size equal to whatever
the driver passed to it when running decode (which is the size of the whole
buffer), which means we will never try to resubmit, because the firmware
will always tell us that it consumed all the data we passed to it;

- v6 firmware will return the number of consumed bytes, but will not
include the padding ("stuffing") bytes that are allowed after the frame
in VP8. Since there is no way of figuring out how many of those bytes
follow the frame without getting the frame size from IVF headers (or
somewhere else, but not from the stream itself), the driver tries to guess that
padding size is not larger than 4 bytes, which is not always true;

The only way to make it work is to queue only one frame per buffer from
userspace and the check in the kernel is useless and wrong for VP8.
So adding VP8 also along with H264 to disallow re-submitting of buffer
back to hardware for decode.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 70f728f..297d681 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -368,6 +368,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops,
get_consumed_stream, dev);
if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
+   ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC &&
ctx->consumed_stream + STUFF_BYTE <
src_buf->b->v4l2_planes[0].bytesused) {
/* Run MFC again on the same buffer */
-- 
1.7.9.5

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


[PATCH 01/10] [media] s5p-mfc: Copy timestamps only when a frame is produced.

2014-05-19 Thread Arun Kumar K
From: Pawel Osciak 

Timestamps for destination buffers are assigned by copying them from
corresponding source buffers when the decode operation results in a frame
being outputted to a destination buffer. But the decision when to do this, i.e.
whether the decode operation on current source buffer produced a destination
frame, is wrongly based on "display status". Display status reflects the status
of the destination buffer, not source.

This used to work for firmwares version <= 6, because in addition to the above,
we'd check the decoded frame type register, which was set to "skipped" if
a destination frame was not produced, exiting early from
s5p_mfc_handle_frame_new().
Firmware >=7 does not set the frame type register for frames that were not
decoded anymore though, which results in us wrongly overwriting timestamps of
previously decoded buffers (firmware reports the same destination buffer address
as previously decoded one if a frame wasn't decoded during current operation).

To do it properly, we should be basing our decision to copy the timestamp on the
status of the source buffer, i.e. "decode status". The decode status register
values are confusing, because in its case "display" means "a frame has been
outputted to a destination buffer". We should copy if "decode and display"
is returned in it. This also works on <= v6 firmware, which behaves in the same
way with regards to decode status register.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 89356ae..6ef6bd1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -309,12 +309,15 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
 {
struct s5p_mfc_dev *dev = ctx->dev;
unsigned int dst_frame_status;
+   unsigned int dec_frame_status;
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
+   dec_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dec_status, dev)
+   & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_RESOLUTION_MASK)
>> S5P_FIMV_DEC_STATUS_RESOLUTION_SHIFT;
@@ -347,8 +350,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
}
}
 
-   if (dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY ||
-   dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_ONLY)
+   if (dec_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY)
s5p_mfc_handle_frame_copy_time(ctx);
 
/* A frame has been decoded and is in the buffer  */
-- 
1.7.9.5

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


Re: [PATCH 2/2] v4l: s5p-mfc: Limit enum_fmt to output formats of current version

2014-05-19 Thread Arun Kumar K
Hi Kamil,

Only a small correction.

On Fri, May 16, 2014 at 5:33 PM, Kamil Debski  wrote:
> MFC versions support a different set of formats, this specially applies
> to the raw YUV formats. This patch changes enum_fmt, so that it only
> reports formats that are supported by the used MFC version.
>
> Signed-off-by: Kamil Debski 
> ---
>  drivers/media/platform/s5p-mfc/s5p_mfc.c|3 ++
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |7 
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c|   49 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|   50 
> ---
>  4 files changed, 67 insertions(+), 42 deletions(-)
>

[snip]

> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
> b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
> index d09c2e1..1ddd152 100644
> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
> @@ -42,6 +42,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_NONE,
> .type   = MFC_FMT_RAW,
> .num_planes = 2,
> +   .versions   = MFC_V6 | MFC_V7,
> },
> {
> .name   = "4:2:0 2 Planes 64x32 Tiles",
> @@ -49,6 +50,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_NONE,
> .type   = MFC_FMT_RAW,
> .num_planes = 2,
> +   .versions   = MFC_V5,
> },
> {
> .name   = "4:2:0 2 Planes Y/CbCr",
> @@ -56,6 +58,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_NONE,
> .type   = MFC_FMT_RAW,
> .num_planes = 2,
> +   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
> },
> {
> .name   = "4:2:0 2 Planes Y/CrCb",
> @@ -63,6 +66,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_NONE,
> .type   = MFC_FMT_RAW,
> .num_planes = 2,
> +   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
> },
> {
> .name   = "H264 Encoded Stream",
> @@ -70,6 +74,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_H264_ENC,
> .type   = MFC_FMT_ENC,
> .num_planes = 1,
> +   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
> },
> {
> .name   = "MPEG4 Encoded Stream",
> @@ -77,6 +82,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_MPEG4_ENC,
> .type   = MFC_FMT_ENC,
> .num_planes = 1,
> +   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
> },
> {
> .name   = "H263 Encoded Stream",
> @@ -84,6 +90,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_H263_ENC,
> .type   = MFC_FMT_ENC,
> .num_planes = 1,
> +   .versions   = MFC_V5 | MFC_V6 | MFC_V7,
> },
> {
> .name   = "VP8 Encoded Stream",
> @@ -91,6 +98,7 @@ static struct s5p_mfc_fmt formats[] = {
> .codec_mode = S5P_MFC_CODEC_VP8_ENC,
> .type   = MFC_FMT_ENC,
> .num_planes = 1,
> +   .versions   = MFC_V6 | MFC_V7,

VP8 encodig is supported only from v7 onwards.
So you can remove MFC_V6 from this.

Otherwise looks good to me.

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


Re: [PATCH v2] [media] s5p-mfc: Dequeue sequence header after STREAMON

2014-05-14 Thread Arun Kumar K
Hi Hans,

On 05/14/14 12:39, Hans Verkuil wrote:
> On 05/14/2014 08:29 AM, Arun Kumar K wrote:
>> MFCv6 encoder needs specific minimum number of buffers to
>> be queued in the CAPTURE plane. This minimum number will
>> be known only when the sequence header is generated.
>> So we used to allow STREAMON on the CAPTURE plane only after
>> sequence header is generated and checked with the minimum
>> buffer requirement.
>>
>> But this causes a problem that we call a vb2_buffer_done
>> for the sequence header buffer before doing a STREAON on the
>> CAPTURE plane. 
> 
> How could this ever have worked? Buffers aren't queued to the driver until
> STREAMON is called, and calling vb2_buffer_done for a buffer that is not 
> queued
> first to the driver will mess up internal data (q->queued_count for one).
> 

This worked till now because __enqueue_in_driver is called first and
then start_streaming qop is called. In MFCv6, the start_streaming driver
callback used to wait till sequence header interrupt is received and it
used to do vb2_buffer_done in that interrupt context. So it happened
after buffers are enqueued in driver and before completing the vb2_streamon.

>> This used to still work fine until this patch
>> was merged -
>> b3379c6 : vb2: only call start_streaming if sufficient buffers are queued
> 
> Are you testing with CONFIG_VIDEO_ADV_DEBUG set? If not, you should do so. 
> That
> will check whether all the vb2 calls are balanced.
> 
> BTW, that's a small typo in s5p_mfc_enc.c (search for 'inavlid').
> 

I got it. Will post a patch fixing them. Thanks for spotting this.

>> This problem should also come in earlier MFC firmware versions
>> if the application calls STREAMON on CAPTURE with some delay
>> after doing STREAMON on OUTPUT.
> 
> You can also play around with the min_buffers_needed field. My rule-of-thumb 
> is that
> when start_streaming is called everything should be ready to stream. It is 
> painful
> for drivers to have to keep track of the 'do I have enough buffers' status.
> 
> For that reason I introduced the min_buffers_needed field. What I believe you 
> can
> do here is to set it initially to a large value, preventing start_streaming 
> from
> being called, and once you really know the minimum number of buffers that you 
> need
> it can be updated again to the actual value.

If a large value is kept in min_buffers_needed, there will be some
unnecessary memory initialization needed for say 16 full HD raw YUV
buffers when actual needed is only 4. And once the encoding is started,
updating the min_buffers_needed to actual value doesnt give any
advantage as nobody checks for it after that.
So the whole idea is to not enforce a worst case buffer allocation
requirement beforehand itself. I hope the current scheme of things works
well for the requirement.

Regards
Arun

> 
> I don't know this driver well enough to tell whether that works here or not, 
> but
> it is worth looking at IMHO.
> 
> Regards,
> 
>   Hans
> 
>> So this patch keeps the header buffer until the other frame
>> buffers are ready and dequeues it just before the first frame
>> is ready.
>>
>> Signed-off-by: Arun Kumar K 
>> ---
>> Changes from v1
>> - Addressed review comments from Sachin
>>   https://patchwork.linuxtv.org/patch/23839/
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
>>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|6 +-
>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> index f5404a6..cc2b96e 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> @@ -523,6 +523,7 @@ struct s5p_mfc_codec_ops {
>>   * @output_state:   state of the output buffers queue
>>   * @src_bufs:   information on allocated source buffers
>>   * @dst_bufs:   information on allocated destination buffers
>> + * @header_mb:  buffer pointer of the encoded sequence header
>>   * @sequence:   counter for the sequence number for v4l2
>>   * @dec_dst_flag:   flags for buffers queued in the hardware
>>   * @dec_src_buf_size:   size of the buffer for source buffers in 
>> decoding
>> @@ -607,6 +608,7 @@ struct s5p_mfc_ctx {
>>  int src_bufs_cnt;
>>  struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
>>  int dst_bufs_cnt;
>> +struct s5p_mfc_buf *header_mb;
>>  
>>  unsigned int sequence;
&

[PATCH v5 2/2] [media] s5p-mfc: Add support for resolution change event

2014-05-14 Thread Arun Kumar K
From: Pawel Osciak 

When a resolution change point is reached, queue an event to signal the
userspace that a new set of buffers is required before decoding can
continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |8 
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 6b04f17..f3a4576 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -349,8 +349,16 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
/* All frames remaining in the buffer have been extracted  */
if (dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_EMPTY) {
if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
+   static const struct v4l2_event ev_src_ch = {
+   .type = V4L2_EVENT_SOURCE_CHANGE,
+   .u.src_change.changes =
+   V4L2_EVENT_SRC_CH_RESOLUTION,
+   };
+
s5p_mfc_handle_frame_all_extracted(ctx);
ctx->state = MFCINST_RES_CHANGE_END;
+   v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
+
goto leave_handle_frame;
} else {
s5p_mfc_handle_frame_all_extracted(ctx);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4586186..326d8db 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -851,6 +851,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_EOS:
return v4l2_event_subscribe(fh, sub, 2, NULL);
+   case V4L2_EVENT_SOURCE_CHANGE:
+   return v4l2_src_change_event_subscribe(fh, sub);
default:
return -EINVAL;
}
-- 
1.7.9.5

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


[PATCH v5 1/2] [media] v4l: Add source change event

2014-05-14 Thread Arun Kumar K
This event indicates that the video device has encountered
a source parameter change during runtime. This can typically be a
resolution change detected by a video decoder OR a format change
detected by an input connector.

This needs to be nofified to the userspace and the application may
be expected to reallocate buffers before proceeding. The application
can subscribe to events on a specific pad or input port which
it is interested in.

Signed-off-by: Arun Kumar K 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   33 ++
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   20 +++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 5 files changed, 101 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 89891ad..820f86e 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -242,6 +242,22 @@
   
 
 
+
+  struct v4l2_event_src_change
+  
+   &cs-str;
+   
+ 
+   __u32
+   changes
+   
+ A bitmask that tells what has changed. See .
+   
+ 
+   
+  
+
+
 
   Changes
   
@@ -270,6 +286,23 @@

   
 
+
+
+  Source Changes
+  
+   &cs-def;
+   
+ 
+   V4L2_EVENT_SRC_CH_RESOLUTION
+   0x0001
+   This event gets triggered when a resolution change is
+   detected at an input. This can come from an input connector or
+   from a video decoder.
+   
+ 
+   
+  
+
   
   
 &return-value;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..f016254 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,26 @@

  
  
+   V4L2_EVENT_SOURCE_CHANGE
+   5
+   
+ This event is triggered when a source parameter change is
+  detected during runtime by the video device. It can be a
+  runtime resolution change triggered by a video decoder or the
+  format change happening on an input connector.
+  This event requires that the id
+  matches the input index (when used with a video device node)
+  or the pad index (when used with a subdevice node) from which
+  you want to receive events.
+
+  This event has a &v4l2-event-source-change; associated
+ with it. The changes bitfield denotes
+ what has changed for the subscribed pad. If multiple events
+ occurred before application could dequeue them, then the changes
+ will have the ORed value of all the events generated.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/drivers/media/v4l2-core/v4l2-event.c 
b/drivers/media/v4l2-core/v4l2-event.c
index 86dcb54..8761aab 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, 
struct v4l2_fh *fh,
return v4l2_event_unsubscribe(fh, sub);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
+
+static void v4l2_event_src_replace(struct v4l2_event *old,
+   const struct v4l2_event *new)
+{
+   u32 old_changes = old->u.src_change.changes;
+
+   old->u.src_change = new->u.src_change;
+   old->u.src_change.changes |= old_changes;
+}
+
+static void v4l2_event_src_merge(const struct v4l2_event *old,
+   struct v4l2_event *new)
+{
+   new->u.src_change.changes |= old->u.src_change.changes;
+}
+
+static const struct v4l2_subscribed_event_ops v4l2_event_src_ch_ops = {
+   .replace = v4l2_event_src_replace,
+   .merge = v4l2_event_src_merge,
+};
+
+int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
+   const struct v4l2_event_subscription *sub)
+{
+   if (sub->type == V4L2_EVENT_SOURCE_CHANGE)
+   return v4l2_event_subscribe(fh, sub, 0, &v4l2_event_src_ch_ops);
+   return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subscribe);
+
+int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
+   struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+   return v4l2_src_change_event_subscribe(fh, sub);
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subd

[PATCH v5 0/2] Add resolution change event

2014-05-14 Thread Arun Kumar K
This patchset adds a source_change event to the v4l2-events.
This can be used for notifying the userspace about runtime
format changes happening on video nodes / pads like resolution
change in video decoder.

Changes from v4
--
- Addressed comments from Hans
  https://patchwork.linuxtv.org/patch/23892/
  https://patchwork.linuxtv.org/patch/23893/

Changes from v3
--
- Addressed comments from Laurent / Hans
  https://patchwork.kernel.org/patch/4135731/

Changes from v2
---
- Event can be subscribed on specific pad / port as
  suggested by Hans.

Changes from v1
---
- Addressed review comments from Hans and Laurent
  https://patchwork.kernel.org/patch/4000951/

Arun Kumar K (1):
  [media] v4l: Add source change event

Pawel Osciak (1):
  [media] s5p-mfc: Add support for resolution change event

 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   33 ++
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   20 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |8 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |2 ++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 7 files changed, 111 insertions(+)

-- 
1.7.9.5

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


[PATCH v2 4/4] [media] s5p-mfc: Core support for v8 encoder

2014-05-13 Thread Arun Kumar K
From: Kiran AVND 

This patch adds core support for v8 encoder. This
patch also adds register definitions and buffer size
requirements for H264 & VP8 encoding, needed for new
firmware version v8 for MFC

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h|   30 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c|2 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   61 +++
 3 files changed, 83 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
index c84d120..cc7cbec 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
@@ -72,16 +72,46 @@
 /* SEI related information */
 #define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
 
+/* Encoder Registers */
+#define S5P_FIMV_E_FIXED_PICTURE_QP_V8 0xf794
+#define S5P_FIMV_E_RC_CONFIG_V80xf798
+#define S5P_FIMV_E_RC_QP_BOUND_V8  0xf79c
+#define S5P_FIMV_E_RC_RPARAM_V80xf7a4
+#define S5P_FIMV_E_MB_RC_CONFIG_V8 0xf7a8
+#define S5P_FIMV_E_PADDING_CTRL_V8 0xf7ac
+#define S5P_FIMV_E_MV_HOR_RANGE_V8 0xf7b4
+#define S5P_FIMV_E_MV_VER_RANGE_V8 0xf7b8
+
+#define S5P_FIMV_E_VBV_BUFFER_SIZE_V8  0xf78c
+#define S5P_FIMV_E_VBV_INIT_DELAY_V8   0xf790
+
+#define S5P_FIMV_E_ASPECT_RATIO_V8 0xfb4c
+#define S5P_FIMV_E_EXTENDED_SAR_V8 0xfb50
+#define S5P_FIMV_E_H264_OPTIONS_V8 0xfb54
+
 /* MFCv8 Context buffer sizes */
 #define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
 #define MFC_H264_DEC_CTX_BUF_SIZE_V8   (2 * SZ_1M) /*  2MB */
 #define MFC_OTHER_DEC_CTX_BUF_SIZE_V8  (20 * SZ_1K)/*  20KB */
+#define MFC_H264_ENC_CTX_BUF_SIZE_V8   (100 * SZ_1K)   /* 100KB */
+#define MFC_OTHER_ENC_CTX_BUF_SIZE_V8  (10 * SZ_1K)/*  10KB */
 
 /* Buffer size defines */
+#define S5P_FIMV_TMV_BUFFER_SIZE_V8(w, h)  (((w) + 1) * ((h) + 1) * 8)
+
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(w, h)(((w) * 704) + 2176)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(w, h) \
(((w) * 576 + (h) * 128)  + 4128)
 
+#define S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(w, h) \
+   (((w) * 592) + 2336)
+#define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(w, h) \
+   (((w) * 576) + 10512 + \
+   ((w) * 16) * ((h) * 16)) * 3) / 2) * 4))
+#define S5P_FIMV_ME_BUFFER_SIZE_V8(imw, imh, mbw, mbh) \
+   ((DIV_ROUND_UP((mbw * 16), 64) *  DIV_ROUND_UP((mbh * 16), 64) * 256) \
++ (DIV_ROUND_UP((mbw) * (mbh), 32) * 16))
+
 /* BUffer alignment defines */
 #define S5P_FIMV_D_ALIGN_PLANE_SIZE_V8 64
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index c8d7ba0..ea72502 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1441,6 +1441,8 @@ struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
.dev_ctx= MFC_CTX_BUF_SIZE_V8,
.h264_dec_ctx   = MFC_H264_DEC_CTX_BUF_SIZE_V8,
.other_dec_ctx  = MFC_OTHER_DEC_CTX_BUF_SIZE_V8,
+   .h264_enc_ctx   = MFC_H264_ENC_CTX_BUF_SIZE_V8,
+   .other_enc_ctx  = MFC_OTHER_ENC_CTX_BUF_SIZE_V8,
 };
 
 struct s5p_mfc_buf_size buf_size_v8 = {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index eeaf122..43d0bb8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -80,7 +80,12 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx 
*ctx)
  ctx->luma_size, ctx->chroma_size, ctx->mv_size);
mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
} else if (ctx->type == MFCINST_ENCODER) {
-   ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
+   if (IS_MFCV8(dev))
+   ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
+   ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
+   S5P_FIMV_TMV_BUFFER_ALIGN_V6);
+   else
+   ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
S5P_FIMV_TMV_BUFFER_ALIGN_V6);
 
@@ -90,10 +95,16 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct 
s5p_mfc_ctx *ctx)
ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
-   ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
-  

[PATCH v2 3/4] [media] s5p-mfc: Core support to add v8 decoder

2014-05-13 Thread Arun Kumar K
From: Kiran AVND 

This patch adds variant data and core support for
V8 decoder. This patch also adds the register definition
file for new firmware version v8 for MFC.

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |   94 
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   30 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |4 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|   85 --
 6 files changed, 210 insertions(+), 10 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

diff --git a/Documentation/devicetree/bindings/media/s5p-mfc.txt 
b/Documentation/devicetree/bindings/media/s5p-mfc.txt
index f418168..3e3c5f3 100644
--- a/Documentation/devicetree/bindings/media/s5p-mfc.txt
+++ b/Documentation/devicetree/bindings/media/s5p-mfc.txt
@@ -10,7 +10,8 @@ Required properties:
   - compatible : value should be either one among the following
(a) "samsung,mfc-v5" for MFC v5 present in Exynos4 SoCs
(b) "samsung,mfc-v6" for MFC v6 present in Exynos5 SoCs
-   (b) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (c) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (d) "samsung,mfc-v8" for MFC v8 present in Exynos5800 SoC
 
   - reg : Physical base address of the IP registers and length of memory
  mapped region.
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
new file mode 100644
index 000..c84d120
--- /dev/null
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
@@ -0,0 +1,94 @@
+/*
+ * Register definition file for Samsung MFC V8.x Interface (FIMV) driver
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _REGS_MFC_V8_H
+#define _REGS_MFC_V8_H
+
+#include 
+#include "regs-mfc-v7.h"
+
+/* Additional registers for v8 */
+#define S5P_FIMV_D_MVC_NUM_VIEWS_V80xf104
+#define S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8 0xf144
+#define S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V80xf148
+#define S5P_FIMV_D_MV_BUFFER_SIZE_V8   0xf150
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8  0xf138
+#define S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8 0xf13c
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_V8  0xf160
+#define S5P_FIMV_D_SECOND_PLANE_DPB_V8 0xf260
+#define S5P_FIMV_D_MV_BUFFER_V80xf460
+
+#define S5P_FIMV_D_NUM_MV_V8   0xf134
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8  0xf154
+
+#define S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8  0xf560
+#define S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8  0xf564
+
+#define S5P_FIMV_D_CPB_BUFFER_ADDR_V8  0xf5b0
+#define S5P_FIMV_D_CPB_BUFFER_SIZE_V8  0xf5b4
+#define S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8 0xf5bc
+#define S5P_FIMV_D_CPB_BUFFER_OFFSET_V80xf5c0
+#define S5P_FIMV_D_SLICE_IF_ENABLE_V8  0xf5c4
+#define S5P_FIMV_D_STREAM_DATA_SIZE_V8 0xf5d0
+
+/* Display information register */
+#define S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8  0xf600
+#define S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8 0xf604
+
+/* Display status */
+#define S5P_FIMV_D_DISPLAY_STATUS_V8   0xf608
+
+#define S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8 0xf60c
+#define S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V80xf610
+
+#define S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8   0xf618
+#define S5P_FIMV_D_DISPLAY_CROP_INFO1_V8   0xf61c
+#define S5P_FIMV_D_DISPLAY_CROP_INFO2_V8   0xf620
+#define S5P_FIMV_D_DISPLAY_PICTURE_PROFILE_V8  0xf624
+
+/* Decoded picture information register */
+#define S5P_FIMV_D_DECODED_STATUS_V8   0xf644
+#define S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8 0xf648
+#define S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V80xf64c
+#define S5P_FIMV_D_DECODED_THIRD_PLANE_ADDR_V8 0xf650
+#define S5P_FIMV_D_DECODED_FRAME_TYPE_V8   0xf654
+#define S5P_FIMV_D_DECODED_NAL_SIZE_V8  0xf664
+
+/* Returned value register for specific setting */
+#define S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8  0xf674
+#define S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8  0xf678
+#define S5P_FIMV_D_MVC_VIEW_ID_V8  0xf6d8
+
+/* SEI related information */
+#define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
+
+/* MFCv8 Context buffer sizes */
+#define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
+#define MFC_H264_DEC_CTX_BUF_SIZE_V8   (2 * SZ_1M) /*  2MB */
+#define MFC_OTHER_DEC_CTX_BUF_SIZE_V8  (20 * SZ_1K)/*  20KB */
+
+/* Buffer size defines */

[PATCH v2 2/4] [media] s5p-mfc: Rename IS_MFCV7 macro

2014-05-13 Thread Arun Kumar K
Renaming the IS_MFCV7 macro to IS_MFCV7_PLUS for the
addition of MFCv8 support which reuses the v7 code.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   14 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 8d85590..7b7053d 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -706,6 +706,6 @@ void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
(dev->variant->port_num ? 1 : 0) : 0) : 0)
 #define IS_TWOPORT(dev)(dev->variant->port_num == 2 ? 1 : 0)
 #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
-#define IS_MFCV7(dev)  (dev->variant->version >= 0x70 ? 1 : 0)
+#define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
 
 #endif /* S5P_MFC_COMMON_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 0c8d593e..e7dddb0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1049,7 +1049,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
return -EINVAL;
}
 
-   if (!IS_MFCV7(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
+   if (!IS_MFCV7_PLUS(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
mfc_err("VP8 is supported only in MFC v7\n");
return -EINVAL;
}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 47890e8..9a503ca 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -116,7 +116,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct 
s5p_mfc_ctx *ctx)
(ctx->mv_count * ctx->mv_size);
break;
case S5P_MFC_CODEC_MPEG4_DEC:
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
ctx->scratch_buf_size =
S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
mb_width,
@@ -357,7 +357,7 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx 
*ctx)
ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
 
/* MFCv7 needs pad bytes for Luma and Chroma */
-   if (IS_MFCV7(ctx->dev)) {
+   if (IS_MFCV7_PLUS(ctx->dev)) {
ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
}
@@ -1283,7 +1283,7 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx 
*ctx)
 /* Check if newer v6 firmware with changed init buffer interface */
 static bool s5p_mfc_is_v6_fw_v2(struct s5p_mfc_dev *dev)
 {
-   if (IS_MFCV7(dev))
+   if (IS_MFCV7_PLUS(dev))
return false;
/*
 * FW date is in BCD format xx120629. So checking for
@@ -1320,7 +1320,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
}
 
-   if (IS_MFCV7(dev) || s5p_mfc_is_v6_fw_v2(dev)) {
+   if (IS_MFCV7_PLUS(dev) || s5p_mfc_is_v6_fw_v2(dev)) {
WRITEL(reg, mfc_regs->d_dec_options);
reg = 0;
}
@@ -1335,7 +1335,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7(dev) || s5p_mfc_is_v6_fw_v2(dev))
+   if (IS_MFCV7_PLUS(dev) || s5p_mfc_is_v6_fw_v2(dev))
WRITEL(reg, mfc_regs->d_init_buffer_options);
else
WRITEL(reg, mfc_regs->d_dec_options);
@@ -1423,7 +1423,7 @@ static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
}
 
/* Set stride lengths for v7 & above */
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
WRITEL(ctx->img_width, mfc_regs->e_source_first_plane_stride);
WRITEL(ctx->img_width, mfc_regs->e_source_second_plane_stride);
}
@@ -2165,7 +2165,7 @@ const struct s5p_mfc_regs 
*s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
R(e_h264_frame_packing_sei_info,
S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
 
-   if (!IS_MFCV7(dev))
+   if (!IS_MFCV7_PLUS(dev))
goto done;
 
/* Initialize registers used in MFC v7 */
-- 
1.7

[PATCH v2 0/4] Add MFCv8 support

2014-05-13 Thread Arun Kumar K
This patchset adds MFCv8 support to the s5p-mfc driver.
MFCv8 has the same operation sequence as that of v6+, but
there is some shuffling of the registers happened. So to
re-use the exisiting code, register access uses context
variables instead of macros.
The patchset modifies opr_v6 file to use register variables
and is tested on mfc v5, v6, v7 and v8 based boards.

The patchset is based on the following set of patches
posted for MFC which are currently under review:

s5p-mfc: Update scratch buffer size for MPEG4
s5p-mfc: Add support for resolution change event
v4l: Add source change event
s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.
s5p-mfc: Update scratch buffer size for VP8 encoder
s5p-mfc: Dequeue sequence header after STREAMON
s5p-mfc: Don't allocate codec buffers on STREAMON.
s5p-mfc: Extract open/close MFC instance commands.
s5p-mfc: Fixes for decode REQBUFS.
s5p-mfc: Copy timestamps only when a frame is produced.
s5p-mfc: add init buffer cmd to MFCV6
s5p-mfc: Add a control for IVF format for VP8 encoder

Changes from v1
- Included encoder support for v8 patch
- Addressed review comments from Kamil & Sachin
  https://patchwork.linuxtv.org/patch/23770/
  https://patchwork.linuxtv.org/patch/23768/

Arun Kumar K (1):
  [media] s5p-mfc: Rename IS_MFCV7 macro

Kiran AVND (3):
  [media] s5p-mfc: Add variants to access mfc registers
  [media] s5p-mfc: Core support to add v8 decoder
  [media] s5p-mfc: Core support for v8 encoder

 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |  124 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   33 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|7 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |4 +
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c   |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.c   |6 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.h   |  254 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|  849 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.h|7 +-
 10 files changed, 1007 insertions(+), 282 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

-- 
1.7.9.5

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


[PATCH] [media] s5p-mfc: Update scratch buffer size for MPEG4

2014-05-13 Thread Arun Kumar K
Update the MPEG4 decoder scratch buffer size as per the
new v6 firmware. This updation is increasing the size and so
is backward compatible with older v6 firmwares.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index b47567c..fd04f84 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -382,8 +382,7 @@
 (DIV_ROUND_UP((mbw) * (mbh), 32) * 16))
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(w, h)(((w) * 192) + 64)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(w, h) \
-   ((w) * ((h) * 64 + 144) + (2048/16 * (h) * 64) + \
-(2048/16 * 256 + 8320))
+   ((w) * 144 + 8192 * (h) + 49216 + 1048576)
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(w, h) \
(2096 * ((w) + (h) + 1))
 #define S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(w, h)((w) * 400)
-- 
1.7.9.5

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


[PATCH v2] [media] s5p-mfc: Dequeue sequence header after STREAMON

2014-05-13 Thread Arun Kumar K
MFCv6 encoder needs specific minimum number of buffers to
be queued in the CAPTURE plane. This minimum number will
be known only when the sequence header is generated.
So we used to allow STREAMON on the CAPTURE plane only after
sequence header is generated and checked with the minimum
buffer requirement.

But this causes a problem that we call a vb2_buffer_done
for the sequence header buffer before doing a STREAON on the
CAPTURE plane. This used to still work fine until this patch
was merged -
b3379c6 : vb2: only call start_streaming if sufficient buffers are queued

This problem should also come in earlier MFC firmware versions
if the application calls STREAMON on CAPTURE with some delay
after doing STREAMON on OUTPUT.

So this patch keeps the header buffer until the other frame
buffers are ready and dequeues it just before the first frame
is ready.

Signed-off-by: Arun Kumar K 
---
Changes from v1
- Addressed review comments from Sachin
  https://patchwork.linuxtv.org/patch/23839/
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|6 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index f5404a6..cc2b96e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -523,6 +523,7 @@ struct s5p_mfc_codec_ops {
  * @output_state:  state of the output buffers queue
  * @src_bufs:  information on allocated source buffers
  * @dst_bufs:  information on allocated destination buffers
+ * @header_mb: buffer pointer of the encoded sequence header
  * @sequence:  counter for the sequence number for v4l2
  * @dec_dst_flag:  flags for buffers queued in the hardware
  * @dec_src_buf_size:  size of the buffer for source buffers in decoding
@@ -607,6 +608,7 @@ struct s5p_mfc_ctx {
int src_bufs_cnt;
struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
int dst_bufs_cnt;
+   struct s5p_mfc_buf *header_mb;
 
unsigned int sequence;
unsigned long dec_dst_flag;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index f8c7053..0c8d593e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -787,7 +787,7 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
ctx->dst_queue_cnt--;
vb2_set_plane_payload(dst_mb->b, 0,
s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev));
-   vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE);
+   ctx->header_mb = dst_mb;
spin_unlock_irqrestore(&dev->irqlock, flags);
}
 
@@ -845,6 +845,10 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
unsigned int strm_size;
unsigned long flags;
 
+   if (ctx->header_mb) {
+   vb2_buffer_done(ctx->header_mb->b, VB2_BUF_STATE_DONE);
+   ctx->header_mb = NULL;
+   }
slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
mfc_debug(2, "Encoded slice type: %d\n", slice_type);
-- 
1.7.9.5

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


[PATCH v2] [media] s5p-mfc: Don't allocate codec buffers on STREAMON.

2014-05-13 Thread Arun Kumar K
From: Pawel Osciak 

Currently, we allocate private codec buffers on STREAMON, which may fail
if we are out of memory. We don't check for failure though, which will
make us crash with the codec accessing random memory.

We shouldn't be failing STREAMON with out of memory errors though. So move
the allocation of private codec buffers to REQBUFS for OUTPUT queue. Also,
move MFC instance opening and closing to REQBUFS as well, as it's tied to
allocation and deallocation of private codec buffers.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
Posting only patch 3/3 of the patchset -
MFC cleanup of reqbuf, streamon, open and close
addressing a minor comment from Kamil.
Other dependent patches are:
s5p-mfc: Extract open/close MFC instance commands.
s5p-mfc: Fixes for decode REQBUFS.

Changes from v1
- Addressed review comment from Kamil
  https://patchwork.linuxtv.org/patch/23162/
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |8 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |   30 +++--
 3 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 2faf7e6..aa08aa2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -650,6 +650,7 @@ static irqreturn_t s5p_mfc_irq(int irq, void *priv)
 
case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET:
clear_work_bit(ctx);
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
wake_up(&ctx->queue);
goto irq_cleanup_hw;
@@ -770,7 +771,7 @@ static int s5p_mfc_open(struct file *file)
goto err_bad_node;
}
ctx->fh.ctrl_handler = &ctx->ctrl_handler;
-   ctx->inst_no = -1;
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
/* Load firmware if this is the first instance */
if (dev->num_inst == 1) {
dev->watchdog_timer.expires = jiffies +
@@ -880,12 +881,11 @@ static int s5p_mfc_release(struct file *file)
vb2_queue_release(&ctx->vq_dst);
/* Mark context as idle */
clear_work_bit_irqsave(ctx);
-   /* If instance was initialised then
+   /* If instance was initialised and not yet freed,
 * return instance and free resources */
-   if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
+   if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) {
mfc_debug(2, "Has to free instance\n");
s5p_mfc_close_mfc_inst(dev, ctx);
-   ctx->inst_no = MFC_NO_INSTANCE_SET;
}
/* hardware locking scheme */
if (dev->curr_ctx == ctx->num)
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 84d4f9d..2001a75 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -459,5 +459,6 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx)
if (ctx->type == MFCINST_DECODER)
s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
 
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
 }
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index efc78ae..4586186 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -475,11 +475,11 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
if (ret)
goto out;
+   s5p_mfc_close_mfc_inst(dev, ctx);
ctx->src_bufs_cnt = 0;
+   ctx->output_state = QUEUE_FREE;
} else if (ctx->output_state == QUEUE_FREE) {
-   /* Can only request buffers after the instance
-* has been opened.
-*/
+   /* Can only request buffers when we have a valid format set. */
WARN_ON(ctx->src_bufs_cnt != 0);
if (ctx->state != MFCINST_INIT) {
mfc_err("Reqbufs called in an invalid state\n");
@@ -493,6 +493,13 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
if (ret)
goto out;
 
+   ret = s5p_mfc_open_mfc_inst(dev, ctx);
+   if (ret) {
+   reqbufs->count = 0;
+   vb2_reqbufs(&ctx->vq_src, reqbufs);
+   goto out;
+   }
+
ctx->output_state = QUEUE_BUFS_REQUESTED;
} else {
mfc_err(

[PATCH v3] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-05-13 Thread Arun Kumar K
From: avnd kiran 

Latest MFC v6 firmware requires tile mode and loop filter
setting to be done as part of Init buffer command, in sync
with v7. Since there are two versions of v6 firmware with
different interfaces, it is differenciated using the version
number read back from firmware which is a hexadecimal value
based on the firmware date.

Signed-off-by: avnd kiran 
Signed-off-by: Arun Kumar K 
---
Changes from v2
- Addressed Kamil's comment
  https://patchwork.linuxtv.org/patch/22989/
Changes from v1
- Check for v6 firmware date for differenciating old and new firmware
  as per comments from Kamil and Sylwester.
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h|2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |8 
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   21 ++---
 5 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 8d0b686..b47567c 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -132,6 +132,7 @@
 #define S5P_FIMV_D_METADATA_BUFFER_ADDR_V6 0xf448
 #define S5P_FIMV_D_METADATA_BUFFER_SIZE_V6 0xf44c
 #define S5P_FIMV_D_NUM_MV_V6   0xf478
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6  0xf47c
 #define S5P_FIMV_D_CPB_BUFFER_ADDR_V6  0xf4b0
 #define S5P_FIMV_D_CPB_BUFFER_SIZE_V6  0xf4b4
 
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index ea5ec2a..82c96fa 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -18,8 +18,6 @@
 #define S5P_FIMV_CODEC_VP8_ENC_V7  25
 
 /* Additional registers for v7 */
-#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7  0xf47c
-
 #define S5P_FIMV_E_SOURCE_FIRST_ADDR_V70xf9e0
 #define S5P_FIMV_E_SOURCE_SECOND_ADDR_V7   0xf9e4
 #define S5P_FIMV_E_SOURCE_THIRD_ADDR_V70xf9e8
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 4d17df9..f5404a6 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -287,6 +287,7 @@ struct s5p_mfc_priv_buf {
  * @warn_start:hardware error code from which warnings start
  * @mfc_ops:   ops structure holding HW operation function pointers
  * @mfc_cmds:  cmd structure holding HW commands function pointers
+ * @ver:   firmware sub version
  *
  */
 struct s5p_mfc_dev {
@@ -330,6 +331,7 @@ struct s5p_mfc_dev {
int warn_start;
struct s5p_mfc_hw_ops *mfc_ops;
struct s5p_mfc_hw_cmds *mfc_cmds;
+   int ver;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index ee05f2d..b86744f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -238,7 +238,6 @@ static inline void s5p_mfc_clear_cmds(struct s5p_mfc_dev 
*dev)
 /* Initialize hardware */
 int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
 {
-   unsigned int ver;
int ret;
 
mfc_debug_enter();
@@ -300,12 +299,13 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
return -EIO;
}
if (IS_MFCV6_PLUS(dev))
-   ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
+   dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
else
-   ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
+   dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
 
mfc_debug(2, "MFC F/W version : %02xyy, %02xmm, %02xdd\n",
-   (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
+   (dev->ver >> 16) & 0xFF, (dev->ver >> 8) & 0xFF,
+   dev->ver & 0xFF);
s5p_mfc_clock_off();
mfc_debug_leave();
return 0;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 90edb19..444f0e8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -48,6 +48,9 @@
 #define OFFSETA(x) (((x) - dev->port_a) >> S5P_FIMV_MEM_OFFSET)
 #define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET)
 
+/* v2 interface version date of MFCv6 firmware */
+#define MFC_V6_FIRMWARE_INTERFACE_V2 0x120629
+
 /* Allocate temporary buffers for decoding */
 static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
 {
@@ -1269,6 +1272,18 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx 
*ctx)

Re: [PATCH] [media] s5p-mfc: Dequeue sequence header after STREAMON

2014-05-13 Thread Arun Kumar K
Hi Sachin,

Thank you for the review.
Will address your comments and post updated version.

Regards
Arun

On Thu, May 8, 2014 at 3:09 PM, Sachin Kamat  wrote:
> Hi Arun,
>
> Just 2 small nits.
>
> On 7 May 2014 17:00, Arun Kumar K  wrote:
>> MFCv6 encoder needs specific minimum number of buffers to
>> be queued in the CAPTURE plane. This minimum number will
>> be known only when the sequence header is generated.
>> So we used to allow STREAMON on the CAPTURE plane only after
>> sequence header is generated and checked with the minimum
>> buffer requirement.
>>
>> But this causes a problem that we call a vb2_buffer_done
>> for the sequence header buffer before doing a STREAON on the
>> CAPTURE plane. This used to still work fine until this patch
>> was merged b3379c6201bb3555298cdbf0aa004af260f2a6a4.
>
> Please provide the patch title too along with commit ID
> (first 12 characters of ID is enough).
>
>>
>> This problem should also come in earlier MFC firmware versions
>> if the application calls STREAMON on CAPTURE with some delay
>> after doing STREAMON on OUTPUT.
>>
>> So this patch keeps the header buffer until the other frame
>> buffers are ready and dequeues it just before the first frame
>> is ready.
>>
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
>>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|6 +-
>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> index d64b680..4fd1034 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> @@ -523,6 +523,7 @@ struct s5p_mfc_codec_ops {
>>   * @output_state:  state of the output buffers queue
>>   * @src_bufs:  information on allocated source buffers
>>   * @dst_bufs:  information on allocated destination buffers
>> + * @header_mb: buf pointer of the encoded sequence header
>
> s/buf/buffer
>
> --
> With warm regards,
> Sachin
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] [media] s5p-mfc: Add variants to access mfc registers

2014-05-13 Thread Arun Kumar K
Hi Kamil,

On 05/13/14 16:02, Kamil Debski wrote:
> Hi, 
> 
> One small comment below,
> 
>> -Original Message-----
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com] On Behalf Of Arun
>> Kumar K
>> Sent: Wednesday, April 23, 2014 2:58 PM
>> To: linux-media@vger.kernel.org; linux-samsung-...@vger.kernel.org
>> Cc: k.deb...@samsung.com; s.nawro...@samsung.com; posc...@chromium.org;
>> avnd.ki...@samsung.com; arunkk.sams...@gmail.com
>> Subject: [PATCH 1/3] [media] s5p-mfc: Add variants to access mfc
>> registers
>>
>> From: Kiran AVND 
>>
>> This patch is needed in preparation to add MFC V8
>> where the register offsets are changed w.r.t MFC V6/V7.
>>
>> This patch adds variants of MFC V6 and V7 while
>> accessing MFC registers. Registers are kept in mfc context
>> and are initialized to a particular MFC variant during probe,
>> which is used instead of macros.
>>
>> This avoids duplication of the code for MFC variants
>> V6 & V7, and reduces the if_else checks while accessing
>> registers of different MFC variants.
>>
>> Signed-off-by: Kiran AVND 
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c|1 +
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |1 +
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr.c|6 +
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr.h|  254 +
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |  697
>> +++
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.h |7 +-
>>  6 files changed, 710 insertions(+), 256 deletions(-)
>>

[snip]

>>  if (p_h264->fmo) {
>> @@ -988,10 +991,12 @@ static int s5p_mfc_set_enc_params_h264(struct
>> s5p_mfc_ctx *ctx)
>>  case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
>>  if (p_h264->fmo_slice_grp > 4)
>>  p_h264->fmo_slice_grp = 4;
>> -for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
>> +for (i = 0; i < ARRAY_SIZE(p_h264->fmo_run_len)
>> +&& i < p_h264->fmo_slice_grp; i++) {
> 
> What do you think about moving this to separate path? This seems
> like it slipped with the register patches.
> 

Sure I will remove this change from this patch. Thanks for spotting this.

Regards
Arun

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


Re: [PATCH v4 1/2] [media] v4l: Add source change event

2014-05-13 Thread Arun Kumar K
Hi Hans,

Will make the changes you suggested.

Thanks & regards
Arun

On Tue, May 13, 2014 at 1:30 PM, Hans Verkuil  wrote:
> Hi Arun,
>
> I've got some more comments w.r.t. the documentation:
>
> On 05/13/14 07:59, Arun Kumar K wrote:
>> This event indicates that the video device has encountered
>> a source parameter change during runtime. This can typically be a
>> resolution change detected by a video decoder OR a format change
>> detected by an HDMI connector.
>>
>> This needs to be nofified to the userspace and the application may
>> be expected to reallocate buffers before proceeding. The application
>> can subscribe to events on a specific pad or input port which
>> it is interested in.
>>
>> Signed-off-by: Arun Kumar K 
>> ---
>>  Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
>>  drivers/media/v4l2-core/v4l2-event.c   |   36 
>> 
>>  include/media/v4l2-event.h |4 +++
>>  include/uapi/linux/videodev2.h |8 +
>>  5 files changed, 99 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
>> b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>> index 89891ad..6afabaa 100644
>> --- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>> +++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>> @@ -242,6 +242,22 @@
>>
>>  
>>
>> +
>> +  struct v4l2_event_src_change
>> +  
>> + &cs-str;
>> + 
>> +   
>> + __u32
>> + changes
>> + 
>> +   A bitmask that tells what has changed. See > linkend="src-changes-flags" />.
>> + 
>> +   
>> + 
>> +  
>> +
>> +
>>  
>>Changes
>>
>> @@ -270,6 +286,22 @@
>>   
>>
>>  
>> +
>> +
>> +  Source Changes
>> +  
>> + &cs-def;
>> + 
>> +   
>> + V4L2_EVENT_SRC_CH_RESOLUTION
>> + 0x0001
>> + This event gets triggered when a resolution change is
>> + detected at runtime. This can typically come from a video decoder.
>
> I would rewrite this as:
>
> "This event gets triggered when a resolution change is detected at an input.
> This can come from an input connector or from a video decoder."
>
>> + 
>> +   
>> + 
>> +  
>> +
>>
>>
>>  &return-value;
>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> index 5c70b61..067a0d5 100644
>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> @@ -155,6 +155,25 @@
>>   
>> 
>> 
>> + V4L2_EVENT_SOURCE_CHANGE
>> + 5
>> + 
>> +   This event is triggered when a source parameter change is
>> +detected during runtime by the video device. It can be a
>> +runtime resolution change triggered by a video decoder or the
>> +format change happening on an HDMI connector.
>
> s/an HDMI/an input/
>
> It's valid for e.g. a composite input as well (or DVI, or VGA, etc.)
>
>> +This event requires that the id
>> +matches the pad / input index from which you want to receive
>
> This should be more explicit:
>
> "matches the input index (when used with a video device node) or the pad
> index (when used with a subdevice node) from which you want to receive"
>
>> +events.
>> +  This event has a &v4l2-event-source-change; associated
>> +   with it. The changes bitfield denotes
>> +   what has changed for the subscribed pad. If multiple events
>> +   occured before application could dequeue them, then the changes
>
> s/occured/occurred/
>
>> +   will have the ORed value of all the events generated.
>> + 
>> +   
>> +   
>>   V4L2_EVENT_PRIVATE_START
>>   0x0800
>>   Base event number for driver-private events.
>> diff --git a/drivers/media/v4l2-core/v4l2-event.c 
>> b/drivers/media/v4l2-core/v4l2-e

Re: [PATCH v4 2/2] [media] s5p-mfc: Add support for resolution change event

2014-05-13 Thread Arun Kumar K
Hi Hans,

On Tue, May 13, 2014 at 1:29 PM, Hans Verkuil  wrote:
> On 05/13/14 07:59, Arun Kumar K wrote:
>> From: Pawel Osciak 
>>
>> When a resolution change point is reached, queue an event to signal the
>> userspace that a new set of buffers is required before decoding can
>> continue.
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c |7 +++
>>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
>>  2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> index 54f7ba1..2d7d1ae 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -320,6 +320,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
>>   struct s5p_mfc_buf *src_buf;
>>   unsigned long flags;
>>   unsigned int res_change;
>> + struct v4l2_event ev;
>>
>>   dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
>>   & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
>> @@ -351,6 +352,12 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx 
>> *ctx,
>>   if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
>>   s5p_mfc_handle_frame_all_extracted(ctx);
>>   ctx->state = MFCINST_RES_CHANGE_END;
>> +
>> + memset(&ev, 0, sizeof(struct v4l2_event));
>> + ev.type = V4L2_EVENT_SOURCE_CHANGE;
>> + ev.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
>
> I would replace this by:
>
> static const struct v4l2_event ev_src_ch = {
> .type = V4L2_EVENT_SOURCE_CHANGE,
> .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
> };
>
> No need for memsets or filling in structs at runtime.
>

Ok will make this change.

Regards
Arun

> Regards,
>
> Hans
>
>> + v4l2_event_queue_fh(&ctx->fh, &ev);
>> +
>>   goto leave_handle_frame;
>>   } else {
>>   s5p_mfc_handle_frame_all_extracted(ctx);
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
>> index 4f94491..b383829 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
>> @@ -855,6 +855,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
>>   switch (sub->type) {
>>   case V4L2_EVENT_EOS:
>>   return v4l2_event_subscribe(fh, sub, 2, NULL);
>> + case V4L2_EVENT_SOURCE_CHANGE:
>> + return v4l2_src_change_event_subscribe(fh, sub);
>>   default:
>>   return -EINVAL;
>>   }
>>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-05-13 Thread Arun Kumar K
Hi Kamil,

On Tue, May 13, 2014 at 2:49 PM, Kamil Debski  wrote:
> Hi,
>
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com] On Behalf Of Arun
>> Kumar K
>> Sent: Tuesday, March 11, 2014 10:16 AM
>>
>> From: avnd kiran 
>>
>> Latest MFC v6 firmware requires tile mode and loop filter setting to be
>> done as part of Init buffer command, in sync with v7. Since there are
>> two versions of v6 firmware with different interfaces, it is
>> differenciated using the version number read back from firmware which
>> is a hexadecimal value based on the firmware date.
>>
>> Signed-off-by: avnd kiran 
>> Signed-off-by: Arun Kumar K 
>> ---
>> Changes from v1
>> ---
>> - Check for v6 firmware date for differenciating old and new firmware
>>   as per comments from Kamil and Sylwester.
>> ---
>>  drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
>>  drivers/media/platform/s5p-mfc/regs-mfc-v7.h|2 --
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
>>  drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |8 +++---
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   30
>> ---
>>  5 files changed, 34 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
>> b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
>> index 8d0b686..b47567c 100644
>> --- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
>> +++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
>> @@ -132,6 +132,7 @@
>>  #define S5P_FIMV_D_METADATA_BUFFER_ADDR_V6   0xf448
>>  #define S5P_FIMV_D_METADATA_BUFFER_SIZE_V6   0xf44c
>>  #define S5P_FIMV_D_NUM_MV_V6 0xf478
>> +#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V60xf47c
>>  #define S5P_FIMV_D_CPB_BUFFER_ADDR_V60xf4b0
>>  #define S5P_FIMV_D_CPB_BUFFER_SIZE_V60xf4b4
>>
>> diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
>> b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
>> index ea5ec2a..82c96fa 100644
>> --- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
>> +++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
>> @@ -18,8 +18,6 @@
>>  #define S5P_FIMV_CODEC_VP8_ENC_V725
>>
>>  /* Additional registers for v7 */
>> -#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V70xf47c
>> -
>>  #define S5P_FIMV_E_SOURCE_FIRST_ADDR_V7  0xf9e0
>>  #define S5P_FIMV_E_SOURCE_SECOND_ADDR_V7 0xf9e4
>>  #define S5P_FIMV_E_SOURCE_THIRD_ADDR_V7  0xf9e8
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> index 4d17df9..f5404a6 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>> @@ -287,6 +287,7 @@ struct s5p_mfc_priv_buf {
>>   * @warn_start:  hardware error code from which warnings
> start
>>   * @mfc_ops: ops structure holding HW operation function
>> pointers
>>   * @mfc_cmds:cmd structure holding HW commands function
>> pointers
>> + * @ver: firmware sub version
>>   *
>>   */
>>  struct s5p_mfc_dev {
>> @@ -330,6 +331,7 @@ struct s5p_mfc_dev {
>>   int warn_start;
>>   struct s5p_mfc_hw_ops *mfc_ops;
>>   struct s5p_mfc_hw_cmds *mfc_cmds;
>> + int ver;
>>  };
>>
>>  /**
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> index 2475a3c..ba1d302 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> @@ -240,7 +240,6 @@ static inline void s5p_mfc_clear_cmds(struct
>> s5p_mfc_dev *dev)
>>  /* Initialize hardware */
>>  int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)  {
>> - unsigned int ver;
>>   int ret;
>>
>>   mfc_debug_enter();
>> @@ -302,12 +301,13 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
>>   return -EIO;
>>   }
>>   if (IS_MFCV6_PLUS(dev))
>> - ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
>> + dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
>>   else
>> - ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
>> + dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
>>
>>   mfc_debug(2, "MFC F/W version : %02xyy, %02xmm, %02xdd\n",
>> - (ver >> 16) & 0xFF, (ver >&g

[PATCH v4 1/2] [media] v4l: Add source change event

2014-05-12 Thread Arun Kumar K
This event indicates that the video device has encountered
a source parameter change during runtime. This can typically be a
resolution change detected by a video decoder OR a format change
detected by an HDMI connector.

This needs to be nofified to the userspace and the application may
be expected to reallocate buffers before proceeding. The application
can subscribe to events on a specific pad or input port which
it is interested in.

Signed-off-by: Arun Kumar K 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 5 files changed, 99 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 89891ad..6afabaa 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -242,6 +242,22 @@
   
 
 
+
+  struct v4l2_event_src_change
+  
+   &cs-str;
+   
+ 
+   __u32
+   changes
+   
+ A bitmask that tells what has changed. See .
+   
+ 
+   
+  
+
+
 
   Changes
   
@@ -270,6 +286,22 @@

   
 
+
+
+  Source Changes
+  
+   &cs-def;
+   
+ 
+   V4L2_EVENT_SRC_CH_RESOLUTION
+   0x0001
+   This event gets triggered when a resolution change is
+   detected at runtime. This can typically come from a video decoder.
+   
+ 
+   
+  
+
   
   
 &return-value;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..067a0d5 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,25 @@

  
  
+   V4L2_EVENT_SOURCE_CHANGE
+   5
+   
+ This event is triggered when a source parameter change is
+  detected during runtime by the video device. It can be a
+  runtime resolution change triggered by a video decoder or the
+  format change happening on an HDMI connector.
+  This event requires that the id
+  matches the pad / input index from which you want to receive
+  events.
+
+  This event has a &v4l2-event-source-change; associated
+ with it. The changes bitfield denotes
+ what has changed for the subscribed pad. If multiple events
+ occured before application could dequeue them, then the changes
+ will have the ORed value of all the events generated.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/drivers/media/v4l2-core/v4l2-event.c 
b/drivers/media/v4l2-core/v4l2-event.c
index 86dcb54..8761aab 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, 
struct v4l2_fh *fh,
return v4l2_event_unsubscribe(fh, sub);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
+
+static void v4l2_event_src_replace(struct v4l2_event *old,
+   const struct v4l2_event *new)
+{
+   u32 old_changes = old->u.src_change.changes;
+
+   old->u.src_change = new->u.src_change;
+   old->u.src_change.changes |= old_changes;
+}
+
+static void v4l2_event_src_merge(const struct v4l2_event *old,
+   struct v4l2_event *new)
+{
+   new->u.src_change.changes |= old->u.src_change.changes;
+}
+
+static const struct v4l2_subscribed_event_ops v4l2_event_src_ch_ops = {
+   .replace = v4l2_event_src_replace,
+   .merge = v4l2_event_src_merge,
+};
+
+int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
+   const struct v4l2_event_subscription *sub)
+{
+   if (sub->type == V4L2_EVENT_SOURCE_CHANGE)
+   return v4l2_event_subscribe(fh, sub, 0, &v4l2_event_src_ch_ops);
+   return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subscribe);
+
+int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
+   struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+   return v4l2_src_change_event_subscribe(fh, sub);
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subdev_subscribe);
diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h
index be05d01..1ab9045 100644
--- a/include/me

[PATCH v4 2/2] [media] s5p-mfc: Add support for resolution change event

2014-05-12 Thread Arun Kumar K
From: Pawel Osciak 

When a resolution change point is reached, queue an event to signal the
userspace that a new set of buffers is required before decoding can
continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |7 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 54f7ba1..2d7d1ae 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -320,6 +320,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
+   struct v4l2_event ev;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
@@ -351,6 +352,12 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
s5p_mfc_handle_frame_all_extracted(ctx);
ctx->state = MFCINST_RES_CHANGE_END;
+
+   memset(&ev, 0, sizeof(struct v4l2_event));
+   ev.type = V4L2_EVENT_SOURCE_CHANGE;
+   ev.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
+   v4l2_event_queue_fh(&ctx->fh, &ev);
+
goto leave_handle_frame;
} else {
s5p_mfc_handle_frame_all_extracted(ctx);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4f94491..b383829 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -855,6 +855,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_EOS:
return v4l2_event_subscribe(fh, sub, 2, NULL);
+   case V4L2_EVENT_SOURCE_CHANGE:
+   return v4l2_src_change_event_subscribe(fh, sub);
default:
return -EINVAL;
}
-- 
1.7.9.5

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


[PATCH v4 0/2] Add resolution change event

2014-05-12 Thread Arun Kumar K
This patchset adds a source_change event to the v4l2-events.
This can be used for notifying the userspace about runtime
format changes happening on video nodes / pads like resolution
change in video decoder.

Changes from v3
--
- Addressed comments from Laurent / Hans
  https://patchwork.kernel.org/patch/4135731/

Changes from v2
---
- Event can be subscribed on specific pad / port as
  suggested by Hans.

Changes from v1
---
- Addressed review comments from Hans and Laurent
  https://patchwork.kernel.org/patch/4000951/

Arun Kumar K (1):
  [media] v4l: Add source change event

Pawel Osciak (1):
  [media] s5p-mfc: Add support for resolution change event

 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |7 
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |2 ++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 7 files changed, 108 insertions(+)

-- 
1.7.9.5

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


Re: [PATCH v3 1/2] [media] v4l: Add source change event

2014-05-12 Thread Arun Kumar K
Hi Hans, Laurent,

On 05/09/14 18:45, Hans Verkuil wrote:
> On 05/09/2014 03:09 PM, Laurent Pinchart wrote:
>> Hi Arun,
>>
>> Thank you for the patch. We're slowly getting there :-)
>>
>> On Thursday 08 May 2014 17:19:15 Arun Kumar K wrote:
>>> This event indicates that the video device has encountered
>>> a source parameter change during runtime. This can typically be a
>>> resolution change detected by a video decoder OR a format change
>>> detected by an HDMI connector.
>>>
>>> This needs to be nofified to the userspace and the application may
>>> be expected to reallocate buffers before proceeding. The application
>>> can subscribe to events on a specific pad or input/output port which
>>> it is interested in.
>>>
>>> Signed-off-by: Arun Kumar K 
>>> ---
>>>  Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
>>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
>>>  drivers/media/v4l2-core/v4l2-event.c   |   36 +
>>>  include/media/v4l2-event.h |4 +++
>>>  include/uapi/linux/videodev2.h |8 +
>>>  5 files changed, 99 insertions(+)
>>>
>>> diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>>> b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml index 89891ad..6afabaa
>>> 100644
>>> --- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>>> +++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
>>> @@ -242,6 +242,22 @@
>>>
>>>  
>>>
>>> +
>>> +  struct v4l2_event_src_change
>>> +  
>>> +   &cs-str;
>>> +   
>>> + 
>>> +   __u32
>>> +   changes
>>> +   
>>> + A bitmask that tells what has changed. See >> linkend="src-changes-flags" />. +   
>>> + 
>>> +   
>>> +  
>>> +
>>> +
>>>  
>>>Changes
>>>
>>> @@ -270,6 +286,22 @@
>>> 
>>>
>>>  
>>> +
>>> +
>>> +  Source Changes
>>> +  
>>> +   &cs-def;
>>> +   
>>> + 
>>> +   V4L2_EVENT_SRC_CH_RESOLUTION
>>> +   0x0001
>>> +   This event gets triggered when a resolution change is
>>> +   detected at runtime. This can typically come from a video decoder.
>>> +   
>>> + 
>>> +   
>>> +  
>>> +
>>>
>>>
>>>  &return-value;
>>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml index
>>> 5c70b61..8012829 100644
>>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> @@ -155,6 +155,25 @@
>>> 
>>>   
>>>   
>>> +   V4L2_EVENT_SOURCE_CHANGE
>>> +   5
>>> +   
>>> + This event is triggered when a format change is
>>> +  detected during runtime by the video device. It can be a
>>> +  runtime resolution change triggered by a video decoder or the
>>> +  format change happening on an HDMI connector.
>>> +  This event requires that the id
>>> +   matches the pad/input/output index from which you want to
>>> +  receive events.
>>> +
>>> +  This event has a &v4l2-event-source-change; associated
>>> + with it. The changes bitfield denotes
>>> + what has changed for the subscribed pad. If multiple events
>>> + occured before application could dequeue them, then the changes
>>> + will have the ORed value of all the events generated.
>>> +   
>>> + 
>>> + 
>>> V4L2_EVENT_PRIVATE_START
>>> 0x0800
>>> Base event number for driver-private events.
>>> diff --git a/drivers/media/v4l2-core/v4l2-event.c
>>> b/drivers/media/v4l2-core/v4l2-event.c index 86dcb54..8761aab 100644
>>> --- a/drivers/media/v4l2-core/v4l2-event.c
>>> +++ b/drivers/media/v4l2-core/v4l2-event.c
>>> @@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_s

[PATCH v2] [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.

2014-05-12 Thread Arun Kumar K
From: Pawel Osciak 

Currently, for formats that are not H264, MFC driver will check
the consumed stream size returned by the firmware and, based on that,
will try to decide whether the bitstream buffer contained more than
one frame. If the size of the buffer is larger than the consumed
stream, it assumes that there are more frames in the buffer and that the
buffer should be resubmitted for decode. This rarely works though and
actually introduces problems, because:

- v7 firmware will always return consumed stream size equal to whatever
the driver passed to it when running decode (which is the size of the whole
buffer), which means we will never try to resubmit, because the firmware
will always tell us that it consumed all the data we passed to it;

- v6 firmware will return the number of consumed bytes, but will not
include the padding ("stuffing") bytes that are allowed after the frame
in VP8. Since there is no way of figuring out how many of those bytes
follow the frame without getting the frame size from IVF headers (or
somewhere else, but not from the stream itself), the driver tries to guess that
padding size is not larger than 4 bytes, which is not always true;

The only way to make it work is to queue only one frame per buffer from
userspace and the check in the kernel is useless and wrong for VP8.
So adding VP8 also along with H264 to disallow re-submitting of buffer
back to hardware for decode.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
Changes from v1
- Made the condition to specifically add VP8 case only
  suggested by Kamil.
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 0f796ad..2d7d1ae 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -382,6 +382,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops,
get_consumed_stream, dev);
if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
+   ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC &&
ctx->consumed_stream + STUFF_BYTE <
src_buf->b->v4l2_planes[0].bytesused) {
/* Run MFC again on the same buffer */
-- 
1.7.9.5

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


Re: [PATCH 1/3] [media] s5p-mfc: Add variants to access mfc registers

2014-05-08 Thread Arun Kumar K
Hi Tomasz,

On 05/09/14 10:50, Tomasz Figa wrote:
> Hi Arun, Paweł,
> 
> On 09.05.2014 06:49, Arun Kumar K wrote:
>> Hi Kamil,
>>
>> On 05/09/14 06:30, Pawel Osciak wrote:
>>> Hi Kamil,
>>>
>>> On Fri, May 9, 2014 at 1:31 AM, Kamil Debski  wrote:
>>>>
>>>> Hi Arun,
>>>>
>>>> I think that this driver is getting too complicated now.
>>>>
>>>> First there are separate files for MFC versions, but in addition there are
>>>> many
>>>> IF_MFCVx in there.
>>>
>>> The intention of this patch is to actually get rid of IF_MFCVx
>>> conditionals wherever possible.
>>>
>>>>
>>>> I am curious how many additional lines it would take to
>>>> add s5p_mfc_cmd_v8.* and s5p_mfc_opr_v8.*.
>>>>
>>>> I get the point that this approach may result in less lines added, but
>>>> having a callback specific for version use register pointers specific for
>>>> another version makes the code look unreadable and difficult to maintain.
>>>
>>> Could you please give an example of how this reduces readability?
>>> I personally feel this patch makes things much more readable (see below).
>>>
>>> On the other hand, if we continued without the current method, we
>>> would have to sprinkle
>>> IF_MFCVx macros all around actual functions/operations, instead of
>>> just containing this
>>> to the regs structure, and the only difference in each path would be
>>> register name defines.
>>> I don't feel this would be a better direction to be honest.
>>>
>>> Compare, new, after this patch:
>>>
>>>> + WRITEL(y_addr, mfc_regs->e_source_first_plane_addr);
>>>> + WRITEL(c_addr, mfc_regs->e_source_second_plane_addr);
>>>
>>> vs previously, before this patch:
>>>
>>>> - if (IS_MFCV7(dev)) {
>>>> - WRITEL(y_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
>>>> - WRITEL(c_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
>>>> - } else {
>>>> - WRITEL(y_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
>>>> - WRITEL(c_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
>>>> - }
>>>
>>> And of course adding V8 more would make it even worse with yet another
>>> else if case.
>>>
>>>
>>>> Please give your opinion on another way to add support for v8.
>>>> s5p_mfc_cmd_v8.* and s5p_mfc_opr_v8.* ?
>>>
>>> If we add v7 and v8 files, a majority of their code will look like this:
>>>
>>> s5p_mfc_opr_v6.c:
>>> (...)
>>> void foo_v6(args)
>>> {
>>> foofun(REGISTER_A_V6);
>>> barfun(REGISTER_B_V6);
>>> }
>>> (...)
>>>
>>> s5p_mfc_opr_v7.c:
>>> (...)
>>> void foo_v7(args)
>>> {
>>> foofun(REGISTER_A_V7);
>>> barfun(REGISTER_B_V7);
>>> }
>>> (...)
>>>
>>> s5p_mfc_opr_v8.c:
>>> (...)
>>> void foo_v8(args)
>>> {
>>> foofun(REGISTER_A_V8);
>>> barfun(REGISTER_B_V8);
>>> }
>>> (...)
>>>
>>> I'm not sure this is less error prone and less code...
>>>
>>
>> Adding on to this, I had a discussion with the firmware team and what I
>> got to know is future firmwares are also going to keep the operation
>> sequence same as v6, but there can be more changes in register offsets
>> as they accomodate more features. So if we go with opr_v8.c, we _might_
>> need opr_v9.c also with hardly any change in the code except register
>> offset modifications.
> 
> If register offsets make for most of the differences between particular 
> MFC versions, then probably having the register pointers used instead of 
> base + OFFSET could be useful. Unfortunately we don't have much 
> information about the newer variants, so it's hard to say.
> 
> Btw. I wonder why the firmware team couldn't simply add new registers at 
> the end of the address space, without breaking software compatibility 
> with every new version, even though rest of programming model mostly 
> stays intact, which is a pure nonsense. Couldn't you complain to the for 
> this if you have contact with them? Otherwise this madness will never stop.
> 

I had a detailed discussion with the firmware team regarding this and
updated them the concerns. The need to do it is because, the register
offsets are grouped codec-wise. Like
0x000a H264
0x000d MPEG4
0x000f VP8
etc.

There are some holes given for future register additions also, but
sometimes many additional features are added to specific codecs and also
in the common feature set which doesnt fit in the pre-defined holes. So
as per them, the re-shuffle of registers was done in v8 so as to make it
more clean and taking into consideration future feature requirements.
But again it might have few changes here and there in the next version.
Since these register offsets are not really in our control, this
approach is best in the driver to absorb these changes without many if -
else conditions. The firware team assured me that they will try to avoid
these kind of changes as much as possible in future.

Regards
Arun


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


Re: [PATCH] [media] s5p-mfc: Add IOMMU support

2014-05-08 Thread Arun Kumar K
Hi Kamil,

On 05/08/14 21:54, Kamil Debski wrote:
> Hi Arun,
> 
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com]
>> Sent: Tuesday, April 22, 2014 2:22 PM
>>
>> Hi Laurent,
>>
>> Thank you for the review.
>>
>> On Tue, Apr 22, 2014 at 5:23 PM, Laurent Pinchart
>>  wrote:
>>> Hi Arun,
>>>
>>> Thank you for the patch.
>>>
>>> On Tuesday 22 April 2014 16:32:48 Arun Kumar K wrote:
>>>> The patch adds IOMMU support for MFC driver.
>>>
>>> I've been working on an IOMMU driver lately, which led me to think
>>> about how drivers should be interfaced with IOMMUs. Runtime IOMMU
>>> handling is performed by the DMA mapping API, but in many cases
>>> (including Exynos platforms) the
>>> arm_iommu_create_mapping() and arm_iommu_attach_device() functions
>>> still need to be called explicitly by drivers, which doesn't seem a
>> very good idea to me.
>>> Ideally IOMMU usage should be completely transparent for bus master
>>> drivers, without requiring any driver modification to use the IOMMU.
>>>
>>> What would you think about improving the Exynos IOMMU driver to
>> create
>>> the mapping and attach the device instead of having to modify all bus
>>> master drivers ? See the ipmmu_add_device() function in
>>> http://www.spinics.net/lists/linux-sh/msg30488.html for a possible
>>> implementation.
>>>
>>
>> Yes that would be a better solution. But as far as I know, exynos
>> platforms has few more complications where multiple IOMMUs are present
>> for single IP.
>> The exynos iommu work is still under progress and KyonHo Cho will have
>> some inputs / comments on this. This seems to me a valid usecase which
>> can be considered for exynos iommu also.
> 
> Arun, could you tell me how did you test this?

It is tested on the IOMMU patches sent by KyongHo Cho (v11 series)
 https://lkml.org/lkml/2014/3/14/9
I found it to work well with v12 too.

> I think that the MFC driver should not be modified to use iommu. Dma_mapping
> should be used. On Tizenorg there is a 3.10 kernel with an iommu driver that
> works with MFC without any patches to the MFC drvier.

This is as per the mainline IOMMU driver patches which are being
reviewed now. I could see the exynos DRM also using this kind of
approach and is already in mainline. Thats why I thought of sending this.

> 
> I disagree to merging this patch, sorry. This should be done the correct way.
> 

Ok. I agree we can wait till the merging of Samsung IOMMU. If it takes
care of making the mapping and attaching the device without the master
driver intervention, then we can skip this patch. But till now it is not
taken care in the patches which are under review for samsung IOMMU.

Regards
Arun

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


Re: [PATCH v2] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-05-08 Thread Arun Kumar K
Hi Kamil,

On 05/08/14 21:52, Kamil Debski wrote:
> Hi,
> 
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com] On Behalf Of Arun
>> Kumar K
>> Sent: Tuesday, March 11, 2014 10:16 AM
>>
>> From: avnd kiran 
>>
>> Latest MFC v6 firmware requires tile mode and loop filter setting to be
>> done as part of Init buffer command, in sync with v7. Since there are
>> two versions of v6 firmware with different interfaces, it is
>> differenciated using the version number read back from firmware which
>> is a hexadecimal value based on the firmware date.
> 
> MFC version has two parts major and minor. Are you sure that date is 
> the only way to check if the interface has changed? Maybe the major number
> should stay the same (6) in this case, and the minor should be updates?
> Do you have contact with persons writing the firmware?
> 

Yes I contacted with the firmware team and there is no difference in the
minor number too. Both the versions will read as MFC v6.5. Only
difference is the firmware date.

> Also, I don't see a patch with the newer firmware posted to linux-firmware.
> When it is going to be sent?
> 

I will send it along with the v7 firmware.

Regards
Arun

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


Re: [PATCH] [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.

2014-05-08 Thread Arun Kumar K
Hi Kamil,

On 05/08/14 21:52, Kamil Debski wrote:
> Hi,
> 
> 
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com] On Behalf Of Arun
>> Kumar K
>> Sent: Friday, March 07, 2014 9:26 AM
>>
>> From: Pawel Osciak 
>>
>> Currently, for formats that are not H264, MFC driver will check the
>> consumed stream size returned by the firmware and, based on that, will
>> try to decide whether the bitstream buffer contained more than one
>> frame. If the size of the buffer is larger than the consumed stream, it
>> assumes that there are more frames in the buffer and that the buffer
>> should be resubmitted for decode. This rarely works though and actually
>> introduces problems, because:
>>
>> - v7 firmware will always return consumed stream size equal to whatever
>> the driver passed to it when running decode (which is the size of the
>> whole buffer), which means we will never try to resubmit, because the
>> firmware will always tell us that it consumed all the data we passed to
>> it;
>>
>> - v6 firmware will return the number of consumed bytes, but will not
>> include the padding ("stuffing") bytes that are allowed after the frame
>> in VP8. Since there is no way of figuring out how many of those bytes
>> follow the frame without getting the frame size from IVF headers (or
>> somewhere else, but not from the stream itself), the driver tries to
>> guess that padding size is not larger than 4 bytes, which is not always
>> true;
>>
>> The only way to make it work is to queue only one frame per buffer from
>> userspace and the check in the kernel is useless and wrong for VP8.
>> MPEG4 still seems to require it, so keep it only for that format.
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c |2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> index e2aac59..66c1775 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -360,7 +360,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx
>> *ctx,
>>  list);
>>  ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops,
>>  get_consumed_stream, dev);
>> -if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
>> +if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC &&
>>  ctx->consumed_stream + STUFF_BYTE <
>>  src_buf->b->v4l2_planes[0].bytesused) {
>>  /* Run MFC again on the same buffer */
> 
> I expressed my doubts to this patch in my previous email.
> I think that packed PB can also be found in other codecs such as H263.
> So please change to the following if this is a workaround for VP8 only.
> (The title says that it only changes behavior of VP8 decoding, so it is
> misleading).
> 

Yes it is seen as affecting only VP8 decoding.

> - if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
> + if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
> + ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC &&
> 

Ok. I will change it this way.

> 
> Did you try to revert your patch https://patchwork.linuxtv.org/patch/15448/
> and checking if this fixes the problem for VP8?
> 

I am afraid it will not solve the VP8 issue as before that patch, it
used to check for ctx->codec_mode != S5P_MFC_CODEC_H264_DEC and frame
type is S5P_FIMV_DECODE_FRAME_P_FRAME, buffer was sent again to decode.
This condition can be triggered in VP8 case causing erroneous behaviour.

So I will make the change as you suggested above.

Regards
Arun

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


[PATCH v3 1/2] [media] v4l: Add source change event

2014-05-08 Thread Arun Kumar K
This event indicates that the video device has encountered
a source parameter change during runtime. This can typically be a
resolution change detected by a video decoder OR a format change
detected by an HDMI connector.

This needs to be nofified to the userspace and the application may
be expected to reallocate buffers before proceeding. The application
can subscribe to events on a specific pad or input/output port which
it is interested in.

Signed-off-by: Arun Kumar K 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 5 files changed, 99 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 89891ad..6afabaa 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -242,6 +242,22 @@
   
 
 
+
+  struct v4l2_event_src_change
+  
+   &cs-str;
+   
+ 
+   __u32
+   changes
+   
+ A bitmask that tells what has changed. See .
+   
+ 
+   
+  
+
+
 
   Changes
   
@@ -270,6 +286,22 @@

   
 
+
+
+  Source Changes
+  
+   &cs-def;
+   
+ 
+   V4L2_EVENT_SRC_CH_RESOLUTION
+   0x0001
+   This event gets triggered when a resolution change is
+   detected at runtime. This can typically come from a video decoder.
+   
+ 
+   
+  
+
   
   
 &return-value;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..8012829 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,25 @@

  
  
+   V4L2_EVENT_SOURCE_CHANGE
+   5
+   
+ This event is triggered when a format change is
+  detected during runtime by the video device. It can be a
+  runtime resolution change triggered by a video decoder or the
+  format change happening on an HDMI connector.
+  This event requires that the id
+   matches the pad/input/output index from which you want to
+  receive events.
+
+  This event has a &v4l2-event-source-change; associated
+ with it. The changes bitfield denotes
+ what has changed for the subscribed pad. If multiple events
+ occured before application could dequeue them, then the changes
+ will have the ORed value of all the events generated.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/drivers/media/v4l2-core/v4l2-event.c 
b/drivers/media/v4l2-core/v4l2-event.c
index 86dcb54..8761aab 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, 
struct v4l2_fh *fh,
return v4l2_event_unsubscribe(fh, sub);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
+
+static void v4l2_event_src_replace(struct v4l2_event *old,
+   const struct v4l2_event *new)
+{
+   u32 old_changes = old->u.src_change.changes;
+
+   old->u.src_change = new->u.src_change;
+   old->u.src_change.changes |= old_changes;
+}
+
+static void v4l2_event_src_merge(const struct v4l2_event *old,
+   struct v4l2_event *new)
+{
+   new->u.src_change.changes |= old->u.src_change.changes;
+}
+
+static const struct v4l2_subscribed_event_ops v4l2_event_src_ch_ops = {
+   .replace = v4l2_event_src_replace,
+   .merge = v4l2_event_src_merge,
+};
+
+int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
+   const struct v4l2_event_subscription *sub)
+{
+   if (sub->type == V4L2_EVENT_SOURCE_CHANGE)
+   return v4l2_event_subscribe(fh, sub, 0, &v4l2_event_src_ch_ops);
+   return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subscribe);
+
+int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
+   struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+   return v4l2_src_change_event_subscribe(fh, sub);
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subdev_subscribe);
diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h
index be05d01..1ab9045 100644
--- a/include/me

[PATCH v3 0/2] Add resolution change event

2014-05-08 Thread Arun Kumar K
This patchset adds a source_change event to the v4l2-events.
This can be used for notifying the userspace about runtime
format changes happening on video nodes / pads like resolution
change in video decoder.

This version includes suggestions from Hans and Laurent
to make it more generic and to be used by all kinds of
video devices to notify userspace about runtime parameter
changes. The discussion can be seen here [1]

If this is accepted, I can send another series implementing
v4l2_event_init() for zeoring the data array addressing
compatibility issues as discussed in [1].

[1] https://patchwork.kernel.org/patch/4023131/

Changes from v2
---
- Event can be subscribed on specific pad / port as
  suggested by Hans.

Changes from v1
---
- Addressed review comments from Hans and Laurent
  https://patchwork.kernel.org/patch/4000951/

Arun Kumar K (1):
  [media] v4l: Add source change event

Pawel Osciak (1):
  [media] s5p-mfc: Add support for resolution change event

 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   32 +
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   19 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |7 
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |2 ++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 7 files changed, 108 insertions(+)

-- 
1.7.9.5

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


[PATCH v3 2/2] [media] s5p-mfc: Add support for resolution change event

2014-05-08 Thread Arun Kumar K
From: Pawel Osciak 

When a resolution change point is reached, queue an event to signal the
userspace that a new set of buffers is required before decoding can
continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |7 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 07c3d5e..c25a2b0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -320,6 +320,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
+   struct v4l2_event ev;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
@@ -351,6 +352,12 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
s5p_mfc_handle_frame_all_extracted(ctx);
ctx->state = MFCINST_RES_CHANGE_END;
+
+   memset(&ev, 0, sizeof(struct v4l2_event));
+   ev.type = V4L2_EVENT_SOURCE_CHANGE;
+   ev.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION;
+   v4l2_event_queue_fh(&ctx->fh, &ev);
+
goto leave_handle_frame;
} else {
s5p_mfc_handle_frame_all_extracted(ctx);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4f94491..b383829 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -855,6 +855,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_EOS:
return v4l2_event_subscribe(fh, sub, 2, NULL);
+   case V4L2_EVENT_SOURCE_CHANGE:
+   return v4l2_src_change_event_subscribe(fh, sub);
default:
return -EINVAL;
}
-- 
1.7.9.5

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


[PATCH] [media] s5p-mfc: Update scratch buffer size for VP8 encoder

2014-05-07 Thread Arun Kumar K
From: Kiran AVND 

Scratch buffer size updated for vp8 encoding as per
the latest v7 firmware. As the new macro increases the
scratch buffer size, it is backward compatible with the older
firmware too.

Signed-off-by: Kiran AVND 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index 82c96fa..1a5c6fd 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -54,6 +54,7 @@
(SZ_1M + ((w) * 144) + (8192 * (h)) + 49216)
 
 #define S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(w, h) \
-   (((w) * 48) + (((w) + 1) / 2 * 128) + 144 + 8192)
+   (((w) * 48) + 8192 + w) + 1) / 2) * 128) + 144 + \
+   ((w) * 16) * ((h) * 16)) * 3) / 2) * 4))
 
 #endif /*_REGS_MFC_V7_H*/
-- 
1.7.9.5

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


[PATCH] [media] s5p-mfc: Dequeue sequence header after STREAMON

2014-05-07 Thread Arun Kumar K
MFCv6 encoder needs specific minimum number of buffers to
be queued in the CAPTURE plane. This minimum number will
be known only when the sequence header is generated.
So we used to allow STREAMON on the CAPTURE plane only after
sequence header is generated and checked with the minimum
buffer requirement.

But this causes a problem that we call a vb2_buffer_done
for the sequence header buffer before doing a STREAON on the
CAPTURE plane. This used to still work fine until this patch
was merged b3379c6201bb3555298cdbf0aa004af260f2a6a4.

This problem should also come in earlier MFC firmware versions
if the application calls STREAMON on CAPTURE with some delay
after doing STREAMON on OUTPUT.

So this patch keeps the header buffer until the other frame
buffers are ready and dequeues it just before the first frame
is ready.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|6 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index d64b680..4fd1034 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -523,6 +523,7 @@ struct s5p_mfc_codec_ops {
  * @output_state:  state of the output buffers queue
  * @src_bufs:  information on allocated source buffers
  * @dst_bufs:  information on allocated destination buffers
+ * @header_mb: buf pointer of the encoded sequence header
  * @sequence:  counter for the sequence number for v4l2
  * @dec_dst_flag:  flags for buffers queued in the hardware
  * @dec_src_buf_size:  size of the buffer for source buffers in decoding
@@ -607,6 +608,7 @@ struct s5p_mfc_ctx {
int src_bufs_cnt;
struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
int dst_bufs_cnt;
+   struct s5p_mfc_buf *header_mb;
 
unsigned int sequence;
unsigned long dec_dst_flag;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index a9a23e1..e7dddb0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -787,7 +787,7 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
ctx->dst_queue_cnt--;
vb2_set_plane_payload(dst_mb->b, 0,
s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev));
-   vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE);
+   ctx->header_mb = dst_mb;
spin_unlock_irqrestore(&dev->irqlock, flags);
}
 
@@ -845,6 +845,10 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
unsigned int strm_size;
unsigned long flags;
 
+   if (ctx->header_mb) {
+   vb2_buffer_done(ctx->header_mb->b, VB2_BUF_STATE_DONE);
+   ctx->header_mb = NULL;
+   }
slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
mfc_debug(2, "Encoded slice type: %d\n", slice_type);
-- 
1.7.9.5

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


Re: [PATCH v2 1/2] v4l: Add resolution change event.

2014-05-05 Thread Arun Kumar K
Hi Hans,

On Wed, Apr 30, 2014 at 8:03 PM, Hans Verkuil  wrote:
> On 04/30/2014 12:38 PM, Arun Kumar K wrote:
>> Hi Hans,
>>
>>
>> On 04/22/14 18:22, Hans Verkuil wrote:
>>> On 04/21/2014 11:26 AM, Arun Kumar K wrote:
>>>> From: Pawel Osciak 
>>>>
>>>> This event indicates that the decoder has reached a point in the stream,
>>>> at which the resolution changes. The userspace is expected to provide a new
>>>> set of CAPTURE buffers for the new format before decoding can continue.
>>>> The event can also be used for more generic events involving resolution
>>>> or format changes at runtime for all kinds of video devices.
>>>>
>>>> Signed-off-by: Pawel Osciak 
>>>> Signed-off-by: Arun Kumar K 
>>>> ---
>>>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   16 
>>>>  include/uapi/linux/videodev2.h |6 ++
>>>>  2 files changed, 22 insertions(+)
>>>>
>>>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
>>>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>>> index 5c70b61..0aec831 100644
>>>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>>> @@ -155,6 +155,22 @@
>>>> 
>>>>   
>>>>   
>>>> +   V4L2_EVENT_SOURCE_CHANGE
>>>> +   5
>>>> +   
>>>> + This event is triggered when a resolution or format change
>>>> +  is detected during runtime by the video device. It can be a
>>>> +  runtime resolution change triggered by a video decoder or the
>>>> +  format change happening on an HDMI connector. Application may
>>>> +  need to reinitialize buffers before proceeding further.
>>>> +
>>>> +  This event has a &v4l2-event-source-change; associated
>>>> + with it. This has significance only for v4l2 subdevs where the
>>>> + pad_num field will be updated with
>>>> + the pad number on which the event is triggered.
>>>> +   
>>>> + 
>>>> + 
>>>> V4L2_EVENT_PRIVATE_START
>>>> 0x0800
>>>> Base event number for driver-private events.
>>>> diff --git a/include/uapi/linux/videodev2.h 
>>>> b/include/uapi/linux/videodev2.h
>>>> index 6ae7bbe..12e0614 100644
>>>> --- a/include/uapi/linux/videodev2.h
>>>> +++ b/include/uapi/linux/videodev2.h
>>>> @@ -1733,6 +1733,7 @@ struct v4l2_streamparm {
>>>>  #define V4L2_EVENT_EOS 2
>>>>  #define V4L2_EVENT_CTRL3
>>>>  #define V4L2_EVENT_FRAME_SYNC  4
>>>> +#define V4L2_EVENT_SOURCE_CHANGE   5
>>>>  #define V4L2_EVENT_PRIVATE_START   0x0800
>>>>
>>>>  /* Payload for V4L2_EVENT_VSYNC */
>>>> @@ -1764,12 +1765,17 @@ struct v4l2_event_frame_sync {
>>>> __u32 frame_sequence;
>>>>  };
>>>>
>>>> +struct v4l2_event_source_change {
>>>> +   __u32 pad_num;
>>>> +};
>>>> +
>>>>  struct v4l2_event {
>>>> __u32   type;
>>>> union {
>>>> struct v4l2_event_vsync vsync;
>>>> struct v4l2_event_ctrl  ctrl;
>>>> struct v4l2_event_frame_syncframe_sync;
>>>> +   struct v4l2_event_source_change source_change;
>>>> __u8data[64];
>>>> } u;
>>>> __u32   pending;
>>>>
>>>
>>> This needs to be done differently. The problem is that you really have 
>>> multiple
>>> events that you want to subscribe to: one for each pad (or input: see the 
>>> way
>>> VIDIOC_G/S_EDID maps pad to an input or output index when used with a video 
>>> node,
>>> we have to support that for this event as well).
>>>
>>> What you want to do is similar to what is done for control events: there 
>>> you can
>>> subscribe for a specific control and get notified when that control changes.
>>>
>>> The way that works in the ev

Re: [PATCH v2 1/2] v4l: Add resolution change event.

2014-04-30 Thread Arun Kumar K
Hi Hans,


On 04/22/14 18:22, Hans Verkuil wrote:
> On 04/21/2014 11:26 AM, Arun Kumar K wrote:
>> From: Pawel Osciak 
>>
>> This event indicates that the decoder has reached a point in the stream,
>> at which the resolution changes. The userspace is expected to provide a new
>> set of CAPTURE buffers for the new format before decoding can continue.
>> The event can also be used for more generic events involving resolution
>> or format changes at runtime for all kinds of video devices.
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   16 
>>  include/uapi/linux/videodev2.h |6 ++
>>  2 files changed, 22 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> index 5c70b61..0aec831 100644
>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> @@ -155,6 +155,22 @@
>>  
>>
>>
>> +V4L2_EVENT_SOURCE_CHANGE
>> +5
>> +
>> +  This event is triggered when a resolution or format change
>> +   is detected during runtime by the video device. It can be a
>> +   runtime resolution change triggered by a video decoder or the
>> +   format change happening on an HDMI connector. Application may
>> +   need to reinitialize buffers before proceeding further.
>> +
>> +  This event has a &v4l2-event-source-change; associated
>> +  with it. This has significance only for v4l2 subdevs where the
>> +  pad_num field will be updated with
>> +  the pad number on which the event is triggered.
>> +
>> +  
>> +  
>>  V4L2_EVENT_PRIVATE_START
>>  0x0800
>>  Base event number for driver-private events.
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index 6ae7bbe..12e0614 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -1733,6 +1733,7 @@ struct v4l2_streamparm {
>>  #define V4L2_EVENT_EOS  2
>>  #define V4L2_EVENT_CTRL 3
>>  #define V4L2_EVENT_FRAME_SYNC   4
>> +#define V4L2_EVENT_SOURCE_CHANGE5
>>  #define V4L2_EVENT_PRIVATE_START0x0800
>>  
>>  /* Payload for V4L2_EVENT_VSYNC */
>> @@ -1764,12 +1765,17 @@ struct v4l2_event_frame_sync {
>>  __u32 frame_sequence;
>>  };
>>  
>> +struct v4l2_event_source_change {
>> +__u32 pad_num;
>> +};
>> +
>>  struct v4l2_event {
>>  __u32   type;
>>  union {
>>  struct v4l2_event_vsync vsync;
>>  struct v4l2_event_ctrl  ctrl;
>>  struct v4l2_event_frame_syncframe_sync;
>> +struct v4l2_event_source_change source_change;
>>  __u8data[64];
>>  } u;
>>  __u32   pending;
>>
> 
> This needs to be done differently. The problem is that you really have 
> multiple
> events that you want to subscribe to: one for each pad (or input: see the way
> VIDIOC_G/S_EDID maps pad to an input or output index when used with a video 
> node,
> we have to support that for this event as well).
> 
> What you want to do is similar to what is done for control events: there you 
> can
> subscribe for a specific control and get notified when that control changes.
> 
> The way that works in the event code is that the 'id' field in the v4l2_event
> struct contains that control ID, or, in this case, the pad/input/output index.
> 

As I am new to v4l2-events itself, I might have some noob questions.
I understood filling pad index into id field. But for video nodes,
the application is supposed to put v4l2_buf_type in the id field?


> In the application you will subscribe to the SOURCE_CHANGE event for a 
> specific
> pad/input/output index.
> 
> In other words, the pad_num field should be dropped and the id field used
> instead.
> 
> Assuming we will also add a 'changes' field (see my reply to the other post
> on that topic), then you should also provide replace and merge ops (see
> v4l2-ctrls.c). That way it is sufficient to use just one element when calling
> v

Re: [PATCH 2/3] [media] s5p-mfc: Core support to add v8 decoder

2014-04-29 Thread Arun Kumar K
Hi Sachin,

On Wed, Apr 30, 2014 at 11:19 AM, Sachin Kamat  wrote:
> Hi Arun,
>
> On 30 April 2014 11:15, Arun Kumar K  wrote:
>> Hi Sachin,
>>
>> Thank you for the review.
>>
>>
>> On 04/29/14 22:45, Sachin Kamat wrote:
>>>
>>> Hi Arun,
>>>
>>> On 23 April 2014 18:27, Arun Kumar K  wrote:
>>>>
>>>> From: Kiran AVND 
>>>>
>>>> This patch adds variant data and core support for
>>>> V8 decoder. This patch also adds the register definition
>>>> file for new firmware version v8 for MFC.
>>>>
>>>> Signed-off-by: Kiran AVND 
>>>> Signed-off-by: Pawel Osciak 
>>>> Signed-off-by: Arun Kumar K 
>>>> ---
>>>
>>> <...>
>>>>
>>>> +
>>>> +/* Returned value register for specific setting */
>>>> +#define S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8  0xf674
>>>> +#define S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8  0xf678
>>>> +#define S5P_FIMV_D_MVC_VIEW_ID_V8  0xf6d8
>>>> +
>>>> +/* SEI related information */
>>>> +#define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
>>>> +
>>>> +/* MFCv8 Context buffer sizes */
>>>> +#define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
>>>
>>>
>>> Please include header file for size macros.
>>>
>>
>> The file linux/sizes.h is included in regs-mfc-v6.h which
>> inturn gets included in this file. Isnt that fine?
>
> Direct inclusions are encouraged. Please add it in this file.
>

Ok will add it.

>>
>>
>>> <...>
>>>>
>>>>   };
>>>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>>>> b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>>>> index 48a14b5..f0e63f5 100644
>>>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>>>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
>>>> @@ -23,8 +23,7 @@
>>>>   #include 
>>>>   #include 
>>>>   #include "regs-mfc.h"
>>>> -#include "regs-mfc-v6.h"
>>>> -#include "regs-mfc-v7.h"
>>>> +#include "regs-mfc-v8.h"
>>>>
>>>>   /* Definitions related to MFC memory */
>>>>
>>>> @@ -705,5 +704,6 @@ void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
>>>>   #define IS_TWOPORT(dev)(dev->variant->port_num == 2 ? 1
>>>> : 0)
>>>>   #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
>>>>   #define IS_MFCV7(dev)  (dev->variant->version >= 0x70 ? 1 : 0)
>>>
>>>
>>> Is MFC v8 superset of MFC v7?
>>>
>>
>> Yes it is a superset.
>> So the last patch in this series renames IS_MFCV7 to IS_MFCV7_PLUS.
>
> Shouldn't that be done first in that case?
>

Adding variants to access MFC registers patch actually removes lot of
such IS_MFCV7 checks from opr_v6.c file. Thats why I put that patch as the
last in the series to have minimal changes as possible.

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


Re: [PATCH 2/3] [media] s5p-mfc: Core support to add v8 decoder

2014-04-29 Thread Arun Kumar K

Hi Sachin,

Thank you for the review.

On 04/29/14 22:45, Sachin Kamat wrote:

Hi Arun,

On 23 April 2014 18:27, Arun Kumar K  wrote:

From: Kiran AVND 

This patch adds variant data and core support for
V8 decoder. This patch also adds the register definition
file for new firmware version v8 for MFC.

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---

<...>

+
+/* Returned value register for specific setting */
+#define S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8  0xf674
+#define S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8  0xf678
+#define S5P_FIMV_D_MVC_VIEW_ID_V8  0xf6d8
+
+/* SEI related information */
+#define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
+
+/* MFCv8 Context buffer sizes */
+#define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */


Please include header file for size macros.



The file linux/sizes.h is included in regs-mfc-v6.h which
inturn gets included in this file. Isnt that fine?


<...>

  };
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 48a14b5..f0e63f5 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -23,8 +23,7 @@
  #include 
  #include 
  #include "regs-mfc.h"
-#include "regs-mfc-v6.h"
-#include "regs-mfc-v7.h"
+#include "regs-mfc-v8.h"

  /* Definitions related to MFC memory */

@@ -705,5 +704,6 @@ void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
  #define IS_TWOPORT(dev)(dev->variant->port_num == 2 ? 1 : 0)
  #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
  #define IS_MFCV7(dev)  (dev->variant->version >= 0x70 ? 1 : 0)


Is MFC v8 superset of MFC v7?



Yes it is a superset.
So the last patch in this series renames IS_MFCV7 to IS_MFCV7_PLUS.

Regards
Arun


+#define IS_MFCV8(dev)  (dev->variant->version >= 0x80 ? 1 : 0)



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


[PATCH 3/3] [media] s5p-mfc: Rename IS_MFCV7 macro

2014-04-23 Thread Arun Kumar K
With the inclusion of MFCv8 which reuses the v7 code,
the macro IS_MFCV7 is modified to IS_MFCV7_PLUS.

Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   14 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index f0e63f5..d64b680 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -703,7 +703,7 @@ void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
(dev->variant->port_num ? 1 : 0) : 0) : 0)
 #define IS_TWOPORT(dev)(dev->variant->port_num == 2 ? 1 : 0)
 #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
-#define IS_MFCV7(dev)  (dev->variant->version >= 0x70 ? 1 : 0)
+#define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
 #define IS_MFCV8(dev)  (dev->variant->version >= 0x80 ? 1 : 0)
 
 #endif /* S5P_MFC_COMMON_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index f8c7053..a9a23e1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1045,7 +1045,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
return -EINVAL;
}
 
-   if (!IS_MFCV7(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
+   if (!IS_MFCV7_PLUS(dev) && (fmt->fourcc == V4L2_PIX_FMT_VP8)) {
mfc_err("VP8 is supported only in MFC v7\n");
return -EINVAL;
}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 4324f2e..d0705b1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -120,7 +120,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct 
s5p_mfc_ctx *ctx)
(ctx->mv_count * ctx->mv_size);
break;
case S5P_MFC_CODEC_MPEG4_DEC:
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
ctx->scratch_buf_size =
S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
mb_width,
@@ -373,7 +373,7 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx 
*ctx)
ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
 
/* MFCv7 needs pad bytes for Luma and Chroma */
-   if (IS_MFCV7(ctx->dev)) {
+   if (IS_MFCV7_PLUS(ctx->dev)) {
ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
}
@@ -1312,7 +1312,7 @@ static bool s5p_mfc_is_v6_new(struct s5p_mfc_dev *dev)
unsigned long cur_fw, v6_new_fw;
unsigned int y, m, d;
 
-   if (IS_MFCV7(dev))
+   if (IS_MFCV7_PLUS(dev))
return false;
 
y = bcd2bin((dev->ver >> 16) & 0xFF) + 2000;
@@ -1357,7 +1357,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
}
 
-   if (IS_MFCV7(dev) || s5p_mfc_is_v6_new(dev)) {
+   if (IS_MFCV7_PLUS(dev) || s5p_mfc_is_v6_new(dev)) {
WRITEL(reg, mfc_regs->d_dec_options);
reg = 0;
}
@@ -1372,7 +1372,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7(dev) || s5p_mfc_is_v6_new(dev))
+   if (IS_MFCV7_PLUS(dev) || s5p_mfc_is_v6_new(dev))
WRITEL(reg, mfc_regs->d_init_buffer_options);
else
WRITEL(reg, mfc_regs->d_dec_options);
@@ -1460,7 +1460,7 @@ static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
}
 
/* Set stride lengths for v7 & above */
-   if (IS_MFCV7(dev)) {
+   if (IS_MFCV7_PLUS(dev)) {
WRITEL(ctx->img_width, mfc_regs->e_source_first_plane_stride);
WRITEL(ctx->img_width, mfc_regs->e_source_second_plane_stride);
}
@@ -2202,7 +2202,7 @@ const struct s5p_mfc_regs 
*s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
R(e_h264_frame_packing_sei_info,
S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
 
-   if (!IS_MFCV7(dev))
+   if (!IS_MFCV7_PLUS(dev))
goto done;
 
/* Initialize registers used in MFC v7+ */
-- 
1.7.9

[PATCH 0/3] Add MFCv8 support

2014-04-23 Thread Arun Kumar K
This patchset adds MFCv8 support to the s5p-mfc driver.
MFCv8 has the same operation sequence as that of v6+, but
there is some shuffling of the registers happened. So to
re-use the exisiting code, register access uses context
variables instead of macros.
The patchset modifies opr_v6 file to use register variables
and is tested on mfc v6, v7 and v8 based boards.

The patchset is based on the following set of patches
posted for MFC which are currently under review:

[media] s5p-mfc: Add support for resolution change event
v4l: Add resolution change event.
[media] s5p-mfc: Don't allocate codec buffers on STREAMON.
[media] s5p-mfc: Extract open/close MFC instance commands.
[media] s5p-mfc: Fixes for decode REQBUFS.
[media] s5p-mfc: Copy timestamps only when a frame is produced.
[media] s5p-mfc: add init buffer cmd to MFCV6
[media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.
[media] s5p-mfc: Add a control for IVF format for VP8 encoder

Arun Kumar K (1):
  [media] s5p-mfc: Rename IS_MFCV7 macro

Kiran AVND (2):
  [media] s5p-mfc: Add variants to access mfc registers
  [media] s5p-mfc: Core support to add v8 decoder

 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |   93 +++
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   31 +
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|7 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |4 +
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c   |2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.c   |6 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.h   |  254 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|  792 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.h|7 +-
 10 files changed, 926 insertions(+), 273 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

-- 
1.7.9.5

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


[PATCH 2/3] [media] s5p-mfc: Core support to add v8 decoder

2014-04-23 Thread Arun Kumar K
From: Kiran AVND 

This patch adds variant data and core support for
V8 decoder. This patch also adds the register definition
file for new firmware version v8 for MFC.

Signed-off-by: Kiran AVND 
Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 .../devicetree/bindings/media/s5p-mfc.txt  |3 +-
 drivers/media/platform/s5p-mfc/regs-mfc-v8.h   |   93 
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |   30 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h|4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |4 +
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c|   85 --
 6 files changed, 209 insertions(+), 10 deletions(-)
 create mode 100644 drivers/media/platform/s5p-mfc/regs-mfc-v8.h

diff --git a/Documentation/devicetree/bindings/media/s5p-mfc.txt 
b/Documentation/devicetree/bindings/media/s5p-mfc.txt
index f418168..3e3c5f3 100644
--- a/Documentation/devicetree/bindings/media/s5p-mfc.txt
+++ b/Documentation/devicetree/bindings/media/s5p-mfc.txt
@@ -10,7 +10,8 @@ Required properties:
   - compatible : value should be either one among the following
(a) "samsung,mfc-v5" for MFC v5 present in Exynos4 SoCs
(b) "samsung,mfc-v6" for MFC v6 present in Exynos5 SoCs
-   (b) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (c) "samsung,mfc-v7" for MFC v7 present in Exynos5420 SoC
+   (d) "samsung,mfc-v8" for MFC v8 present in Exynos5800 SoC
 
   - reg : Physical base address of the IP registers and length of memory
  mapped region.
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v8.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
new file mode 100644
index 000..747907c
--- /dev/null
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v8.h
@@ -0,0 +1,93 @@
+/*
+ * Register definition file for Samsung MFC V8.x Interface (FIMV) driver
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _REGS_MFC_V8_H
+#define _REGS_MFC_V8_H
+
+#include "regs-mfc-v7.h"
+
+/* Additional registers for v8 */
+#define S5P_FIMV_D_MVC_NUM_VIEWS_V80xf104
+#define S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8 0xf144
+#define S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V80xf148
+#define S5P_FIMV_D_MV_BUFFER_SIZE_V8   0xf150
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8  0xf138
+#define S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8 0xf13c
+
+#define S5P_FIMV_D_FIRST_PLANE_DPB_V8  0xf160
+#define S5P_FIMV_D_SECOND_PLANE_DPB_V8 0xf260
+#define S5P_FIMV_D_MV_BUFFER_V80xf460
+
+#define S5P_FIMV_D_NUM_MV_V8   0xf134
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8  0xf154
+
+#define S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8  0xf560
+#define S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8  0xf564
+
+#define S5P_FIMV_D_CPB_BUFFER_ADDR_V8  0xf5b0
+#define S5P_FIMV_D_CPB_BUFFER_SIZE_V8  0xf5b4
+#define S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8 0xf5bc
+#define S5P_FIMV_D_CPB_BUFFER_OFFSET_V80xf5c0
+#define S5P_FIMV_D_SLICE_IF_ENABLE_V8  0xf5c4
+#define S5P_FIMV_D_STREAM_DATA_SIZE_V8 0xf5d0
+
+/* Display information register */
+#define S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8  0xf600
+#define S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8 0xf604
+
+/* Display status */
+#define S5P_FIMV_D_DISPLAY_STATUS_V8   0xf608
+
+#define S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8 0xf60c
+#define S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V80xf610
+
+#define S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8   0xf618
+#define S5P_FIMV_D_DISPLAY_CROP_INFO1_V8   0xf61c
+#define S5P_FIMV_D_DISPLAY_CROP_INFO2_V8   0xf620
+#define S5P_FIMV_D_DISPLAY_PICTURE_PROFILE_V8  0xf624
+
+/* Decoded picture information register */
+#define S5P_FIMV_D_DECODED_STATUS_V8   0xf644
+#define S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8 0xf648
+#define S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V80xf64c
+#define S5P_FIMV_D_DECODED_THIRD_PLANE_ADDR_V8 0xf650
+#define S5P_FIMV_D_DECODED_FRAME_TYPE_V8   0xf654
+#define S5P_FIMV_D_DECODED_NAL_SIZE_V8  0xf664
+
+/* Returned value register for specific setting */
+#define S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8  0xf674
+#define S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8  0xf678
+#define S5P_FIMV_D_MVC_VIEW_ID_V8  0xf6d8
+
+/* SEI related information */
+#define S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8 0xf6dc
+
+/* MFCv8 Context buffer sizes */
+#define MFC_CTX_BUF_SIZE_V8(30 * SZ_1K)/*  30KB */
+#define MFC_H264_DEC_CTX_BUF_SIZE_V8   (2 * SZ_1M) /*  2MB */
+#define MFC_OTHER_DEC_CTX_BUF_SIZE_V8  (20 * SZ_1K)/*  20KB */
+
+/* Buffer size defines */
+#define S5P_FI

Re: [PATCH] [media] s5p-mfc: Add IOMMU support

2014-04-22 Thread Arun Kumar K
Hi Laurent,

Thank you for the review.

On Tue, Apr 22, 2014 at 5:23 PM, Laurent Pinchart
 wrote:
> Hi Arun,
>
> Thank you for the patch.
>
> On Tuesday 22 April 2014 16:32:48 Arun Kumar K wrote:
>> The patch adds IOMMU support for MFC driver.
>
> I've been working on an IOMMU driver lately, which led me to think about how
> drivers should be interfaced with IOMMUs. Runtime IOMMU handling is performed
> by the DMA mapping API, but in many cases (including Exynos platforms) the
> arm_iommu_create_mapping() and arm_iommu_attach_device() functions still need
> to be called explicitly by drivers, which doesn't seem a very good idea to me.
> Ideally IOMMU usage should be completely transparent for bus master drivers,
> without requiring any driver modification to use the IOMMU.
>
> What would you think about improving the Exynos IOMMU driver to create the
> mapping and attach the device instead of having to modify all bus master
> drivers ? See the ipmmu_add_device() function in
> http://www.spinics.net/lists/linux-sh/msg30488.html for a possible
> implementation.
>

Yes that would be a better solution. But as far as I know, exynos platforms has
few more complications where multiple IOMMUs are present for single IP.
The exynos iommu work is still under progress and KyonHo Cho will have
some inputs / comments on this. This seems to me a valid usecase which can
be considered for exynos iommu also.

Regards
Arun

>> Signed-off-by: Arun Kumar K 
>> ---
>> This patch is tested on IOMMU support series [1] posted
>> by KyonHo Cho.
>> [1] https://lkml.org/lkml/2014/3/14/9
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c |   33 +++
>>  1 file changed, 33 insertions(+)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c index 89356ae..1f248ba 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -32,11 +32,18 @@
>>  #include "s5p_mfc_opr.h"
>>  #include "s5p_mfc_cmd.h"
>>  #include "s5p_mfc_pm.h"
>> +#ifdef CONFIG_EXYNOS_IOMMU
>> +#include 
>> +#endif
>>
>>  #define S5P_MFC_NAME "s5p-mfc"
>>  #define S5P_MFC_DEC_NAME "s5p-mfc-dec"
>>  #define S5P_MFC_ENC_NAME "s5p-mfc-enc"
>>
>> +#ifdef CONFIG_EXYNOS_IOMMU
>> +static struct dma_iommu_mapping *mapping;
>> +#endif
>> +
>>  int debug;
>>  module_param(debug, int, S_IRUGO | S_IWUSR);
>>  MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose
>> messages"); @@ -1013,6 +1020,23 @@ static void *mfc_get_drv_data(struct
>> platform_device *pdev);
>>
>>  static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
>>  {
>> +#ifdef CONFIG_EXYNOS_IOMMU
>> + struct device *mdev = &dev->plat_dev->dev;
>> +
>> + mapping = arm_iommu_create_mapping(&platform_bus_type, 0x2000,
>> + SZ_256M);
>> + if (mapping == NULL) {
>> + mfc_err("IOMMU mapping failed\n");
>> + return -EFAULT;
>> + }
>> + mdev->dma_parms = devm_kzalloc(&dev->plat_dev->dev,
>> + sizeof(*mdev->dma_parms), GFP_KERNEL);
>> + dma_set_max_seg_size(mdev, 0xu);
>> + arm_iommu_attach_device(mdev, mapping);
>> +
>> + dev->mem_dev_l = dev->mem_dev_r = mdev;
>> + return 0;
>> +#else
>>   unsigned int mem_info[2] = { };
>>
>>   dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
>> @@ -1049,6 +1073,7 @@ static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev
>> *dev) return -ENOMEM;
>>   }
>>   return 0;
>> +#endif
>>  }
>>
>>  /* MFC probe function */
>> @@ -1228,6 +1253,10 @@ err_mem_init_ctx_1:
>>   vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
>>  err_res:
>>   s5p_mfc_final_pm(dev);
>> +#ifdef CONFIG_EXYNOS_IOMMU
>> + if (mapping)
>> + arm_iommu_release_mapping(mapping);
>> +#endif
>>
>>   pr_debug("%s-- with error\n", __func__);
>>   return ret;
>> @@ -1256,6 +1285,10 @@ static int s5p_mfc_remove(struct platform_device
>> *pdev) put_device(dev->mem_dev_r);
>>   }
>>
>> +#ifdef CONFIG_EXYNOS_IOMMU
>> + if (mapping)
>> + arm_iommu_release_mapping(mapping);
>> +#endif
>>   s5p_mfc_final_pm(dev);
>>   return 0;
>>  }
>
> --
> Regards,
>
> Laurent Pinchart
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] s5p-mfc: Add IOMMU support

2014-04-22 Thread Arun Kumar K
The patch adds IOMMU support for MFC driver.

Signed-off-by: Arun Kumar K 
---
This patch is tested on IOMMU support series [1] posted
by KyonHo Cho.
[1] https://lkml.org/lkml/2014/3/14/9
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |   33 ++
 1 file changed, 33 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 89356ae..1f248ba 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -32,11 +32,18 @@
 #include "s5p_mfc_opr.h"
 #include "s5p_mfc_cmd.h"
 #include "s5p_mfc_pm.h"
+#ifdef CONFIG_EXYNOS_IOMMU
+#include 
+#endif
 
 #define S5P_MFC_NAME   "s5p-mfc"
 #define S5P_MFC_DEC_NAME   "s5p-mfc-dec"
 #define S5P_MFC_ENC_NAME   "s5p-mfc-enc"
 
+#ifdef CONFIG_EXYNOS_IOMMU
+static struct dma_iommu_mapping *mapping;
+#endif
+
 int debug;
 module_param(debug, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose 
messages");
@@ -1013,6 +1020,23 @@ static void *mfc_get_drv_data(struct platform_device 
*pdev);
 
 static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
 {
+#ifdef CONFIG_EXYNOS_IOMMU
+   struct device *mdev = &dev->plat_dev->dev;
+
+   mapping = arm_iommu_create_mapping(&platform_bus_type, 0x2000,
+   SZ_256M);
+   if (mapping == NULL) {
+   mfc_err("IOMMU mapping failed\n");
+   return -EFAULT;
+   }
+   mdev->dma_parms = devm_kzalloc(&dev->plat_dev->dev,
+   sizeof(*mdev->dma_parms), GFP_KERNEL);
+   dma_set_max_seg_size(mdev, 0xu);
+   arm_iommu_attach_device(mdev, mapping);
+
+   dev->mem_dev_l = dev->mem_dev_r = mdev;
+   return 0;
+#else
unsigned int mem_info[2] = { };
 
dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
@@ -1049,6 +1073,7 @@ static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
return -ENOMEM;
}
return 0;
+#endif
 }
 
 /* MFC probe function */
@@ -1228,6 +1253,10 @@ err_mem_init_ctx_1:
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
 err_res:
s5p_mfc_final_pm(dev);
+#ifdef CONFIG_EXYNOS_IOMMU
+   if (mapping)
+   arm_iommu_release_mapping(mapping);
+#endif
 
pr_debug("%s-- with error\n", __func__);
return ret;
@@ -1256,6 +1285,10 @@ static int s5p_mfc_remove(struct platform_device *pdev)
put_device(dev->mem_dev_r);
}
 
+#ifdef CONFIG_EXYNOS_IOMMU
+   if (mapping)
+   arm_iommu_release_mapping(mapping);
+#endif
s5p_mfc_final_pm(dev);
return 0;
 }
-- 
1.7.9.5

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


Re: [PATCH v2 1/2] v4l: Add resolution change event.

2014-04-21 Thread Arun Kumar K
Hi Laurent,

Thank you for the review.

On Mon, Apr 21, 2014 at 3:54 PM, Laurent Pinchart
 wrote:
> Hi Arun,
>
> Thank you for the patch.
>
> On Monday 21 April 2014 14:56:01 Arun Kumar K wrote:
>> From: Pawel Osciak 
>>
>> This event indicates that the decoder has reached a point in the stream,
>> at which the resolution changes. The userspace is expected to provide a new
>> set of CAPTURE buffers for the new format before decoding can continue.
>> The event can also be used for more generic events involving resolution
>> or format changes at runtime for all kinds of video devices.
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   16 
>>  include/uapi/linux/videodev2.h |6 ++
>>  2 files changed, 22 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml index
>> 5c70b61..0aec831 100644
>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>> @@ -155,6 +155,22 @@
>>   
>> 
>> 
>> + V4L2_EVENT_SOURCE_CHANGE
>> + 5
>> + 
>> +   This event is triggered when a resolution or format change
>> +is detected during runtime by the video device. It can be a
>> +runtime resolution change triggered by a video decoder or the
>> +format change happening on an HDMI connector. Application may
>> +need to reinitialize buffers before proceeding further.
>> +
>> +  This event has a &v4l2-event-source-change; associated
>> +   with it. This has significance only for v4l2 subdevs where the
>> +   pad_num field will be updated with
>> +   the pad number on which the event is triggered.
>> + 
>> +   
>> +   
>>   V4L2_EVENT_PRIVATE_START
>>   0x0800
>>   Base event number for driver-private events.
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index 6ae7bbe..12e0614 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -1733,6 +1733,7 @@ struct v4l2_streamparm {
>>  #define V4L2_EVENT_EOS   2
>>  #define V4L2_EVENT_CTRL  3
>>  #define V4L2_EVENT_FRAME_SYNC4
>> +#define V4L2_EVENT_SOURCE_CHANGE 5
>>  #define V4L2_EVENT_PRIVATE_START 0x0800
>>
>>  /* Payload for V4L2_EVENT_VSYNC */
>> @@ -1764,12 +1765,17 @@ struct v4l2_event_frame_sync {
>>   __u32 frame_sequence;
>>  };
>>
>> +struct v4l2_event_source_change {
>> + __u32 pad_num;
>
> I would call the field just "pad",
>

Ok.

>> +};
>> +
>>  struct v4l2_event {
>>   __u32   type;
>>   union {
>>   struct v4l2_event_vsync vsync;
>>   struct v4l2_event_ctrl  ctrl;
>>   struct v4l2_event_frame_syncframe_sync;
>> + struct v4l2_event_source_change source_change;
>>   __u8data[64];
>
> This looks pretty good to me, but I'm a bit concerned about future
> compatibility. We might need to report more information to userspace, and in
> particular what has been changed at the source (resolution, format, ...). In
> order to do so, we'll need to add a flag field to v4l2_event_source_change.

Ok a flag can be added with bitfields for reporting specific event type.

> The next __u32 right after the source_change field must thus be zeroed. I see
> two ways of doing so:
>
> - zeroing the whole data array before setting event-specific data
> - adding a reserved must-be-zeroed field to v4l2_event_source_change
>
> I like the former better as it's more generic, but we then need to ensure that
> all drivers zero the whole data field correctly. Adding a new
> v4l2_event_init() function would help with that.
>

Is that a good idea to have an init() function just for zeroing the data field?
If this is agreed upon, I can add this, but it can be easily missed
out by drivers.
Also how about the drivers already using the v4l2_event. Should we
update those drivers too with v4l2_event_init() ?

Regards
Arun

>>   } u;
>>   __u32   pending;
>
> --
> Regards,
>
> Laurent Pinchart
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] v4l: Add resolution change event.

2014-04-21 Thread Arun Kumar K
Hi Pawel,

On Mon, Apr 21, 2014 at 2:58 PM, Pawel Osciak  wrote:
> Arun, I think it'd better if you attributed this patch to yourself, I'm not
> the author of it. I only wrote patch 2/2 in this series.
> Thanks,
> Pawel
>
>

Sure I will change it. I kept your name as it was a rework of your patch from
chrome tree. Will update the author name and post v3 if there are no other
comments on this.

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


[PATCH v2 1/2] v4l: Add resolution change event.

2014-04-21 Thread Arun Kumar K
From: Pawel Osciak 

This event indicates that the decoder has reached a point in the stream,
at which the resolution changes. The userspace is expected to provide a new
set of CAPTURE buffers for the new format before decoding can continue.
The event can also be used for more generic events involving resolution
or format changes at runtime for all kinds of video devices.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   16 
 include/uapi/linux/videodev2.h |6 ++
 2 files changed, 22 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..0aec831 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,22 @@

  
  
+   V4L2_EVENT_SOURCE_CHANGE
+   5
+   
+ This event is triggered when a resolution or format change
+  is detected during runtime by the video device. It can be a
+  runtime resolution change triggered by a video decoder or the
+  format change happening on an HDMI connector. Application may
+  need to reinitialize buffers before proceeding further.
+
+  This event has a &v4l2-event-source-change; associated
+ with it. This has significance only for v4l2 subdevs where the
+ pad_num field will be updated with
+ the pad number on which the event is triggered.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 6ae7bbe..12e0614 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1733,6 +1733,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_EOS 2
 #define V4L2_EVENT_CTRL3
 #define V4L2_EVENT_FRAME_SYNC  4
+#define V4L2_EVENT_SOURCE_CHANGE   5
 #define V4L2_EVENT_PRIVATE_START   0x0800
 
 /* Payload for V4L2_EVENT_VSYNC */
@@ -1764,12 +1765,17 @@ struct v4l2_event_frame_sync {
__u32 frame_sequence;
 };
 
+struct v4l2_event_source_change {
+   __u32 pad_num;
+};
+
 struct v4l2_event {
__u32   type;
union {
struct v4l2_event_vsync vsync;
struct v4l2_event_ctrl  ctrl;
struct v4l2_event_frame_syncframe_sync;
+   struct v4l2_event_source_change source_change;
__u8data[64];
} u;
__u32   pending;
-- 
1.7.9.5

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


[PATCH v2 0/2] Add resolution change event

2014-04-21 Thread Arun Kumar K
This patchset adds the resolution change event to the MFC
decoder. This will be used for triggering the runtime resolution
change.

Changes from v1
---
- Addressed review comments from Hans and Laurent
  https://patchwork.kernel.org/patch/4000951/

Pawel Osciak (2):
  v4l: Add resolution change event.
  [media] s5p-mfc: Add support for resolution change event

 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   16 
 drivers/media/platform/s5p-mfc/s5p_mfc.c   |6 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |2 ++
 include/uapi/linux/videodev2.h |6 ++
 4 files changed, 30 insertions(+)

-- 
1.7.9.5

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


[PATCH v2 2/2] [media] s5p-mfc: Add support for resolution change event

2014-04-21 Thread Arun Kumar K
From: Pawel Osciak 

When a resolution change point is reached, queue an event to signal the
userspace that a new set of buffers is required before decoding can
continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |6 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 4ee5a02..5152a23 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -308,6 +308,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
+   struct v4l2_event ev;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
@@ -339,6 +340,11 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
s5p_mfc_handle_frame_all_extracted(ctx);
ctx->state = MFCINST_RES_CHANGE_END;
+
+   memset(&ev, 0, sizeof(struct v4l2_event));
+   ev.type = V4L2_EVENT_SOURCE_CHANGE;
+   v4l2_event_queue_fh(&ctx->fh, &ev);
+
goto leave_handle_frame;
} else {
s5p_mfc_handle_frame_all_extracted(ctx);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4586186..069d354 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -851,6 +851,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_EOS:
return v4l2_event_subscribe(fh, sub, 2, NULL);
+   case V4L2_EVENT_SOURCE_CHANGE:
+   return v4l2_event_subscribe(fh, sub, 2, NULL);
default:
return -EINVAL;
}
-- 
1.7.9.5

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


Re: [PATCH 1/2] v4l: Add resolution change event.

2014-04-16 Thread Arun Kumar K
Hi Laurent and Hans,

Thank you for the review.

On Wed, Apr 16, 2014 at 7:46 PM, Hans Verkuil  wrote:
> On 04/16/2014 04:09 PM, Laurent Pinchart wrote:
>> Hi Arun,
>>
>> Thank you for the patch.
>> On Wednesday 16 April 2014 18:29:21 Arun Kumar K wrote:
>>> From: Pawel Osciak 
>>>
>>> This event indicates that the decoder has reached a point in the stream,
>>> at which the resolution changes. The userspace is expected to provide a new
>>> set of CAPTURE buffers for the new format before decoding can continue.
>>>
>>> Signed-off-by: Pawel Osciak 
>>> Signed-off-by: Arun Kumar K 
>>> ---
>>>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |8 
>>>  include/uapi/linux/videodev2.h |1 +
>>>  2 files changed, 9 insertions(+)
>>>
>>> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml index
>>> 5c70b61..d848628 100644
>>> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
>>> @@ -155,6 +155,14 @@
>>>  
>>>
>>>
>>> +V4L2_EVENT_RESOLUTION_CHANGE
>>> +5
>>> +This event is triggered when a resolution change is detected
>>> +during runtime by the video decoder. Application may need to
>>> +reinitialize buffers before proceeding further.
>>> +
>>> +  
>>
>> Would it make sense to report the new resolution in the event data ? I 
>> suppose
>> it might not be available in all cases though. If we can't report it, would 
>> it
>> make sense to document how applications should proceed to retrieve it ?
>
> I wouldn't report that. We played with this in Cisco, and in the end you just
> want to know something changed and you can take it from there. Besides, what
> constitutes a 'resolution' change? If my HDMI input switches from 720p60 to
> 720p30 the resolution stays the same, but I most definitely have to get the 
> new
> timings.
>
> So I would call the event something different: EVENT_SOURCE_CHANGE or 
> something
> like that.
>
> Getting the new timings is done through QUERYSTD or QUERY_DV_TIMINGS.
>

Ok will use the name V4L2_EVENT_SOURCE_CHANGE and update description
to reflect the generic usecase (not just for video decoders).

>> A similar resolution change event might be useful on subdevs, in which case 
>> we
>> would need to add a pad number to the event data. We could possibly leave 
>> that
>> for later, but it would be worth considering the problem already.
>
> Actually, I would add that right away. That's some thing that the adv7604
> driver can implement right away: it has multiple inputs and it can detect
> when something is plugged in or unplugged.
>

Ok will add support for mentioning pad number in event data.

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


[PATCH 2/2] [media] s5p-mfc: Add support for resolution change event

2014-04-16 Thread Arun Kumar K
From: Pawel Osciak 

When a resolution change point is reached, queue an event to signal the
userspace that a new set of buffers is required before decoding can
continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |6 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 4ee5a02..2efa758 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -308,6 +308,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
+   struct v4l2_event ev;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
@@ -339,6 +340,11 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
s5p_mfc_handle_frame_all_extracted(ctx);
ctx->state = MFCINST_RES_CHANGE_END;
+
+   memset(&ev, 0, sizeof(struct v4l2_event));
+   ev.type = V4L2_EVENT_RESOLUTION_CHANGE;
+   v4l2_event_queue_fh(&ctx->fh, &ev);
+
goto leave_handle_frame;
} else {
s5p_mfc_handle_frame_all_extracted(ctx);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4586186..dd0ec6f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -851,6 +851,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_EOS:
return v4l2_event_subscribe(fh, sub, 2, NULL);
+   case V4L2_EVENT_RESOLUTION_CHANGE:
+   return v4l2_event_subscribe(fh, sub, 2, NULL);
default:
return -EINVAL;
}
-- 
1.7.9.5

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


[PATCH 1/2] v4l: Add resolution change event.

2014-04-16 Thread Arun Kumar K
From: Pawel Osciak 

This event indicates that the decoder has reached a point in the stream,
at which the resolution changes. The userspace is expected to provide a new
set of CAPTURE buffers for the new format before decoding can continue.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |8 
 include/uapi/linux/videodev2.h |1 +
 2 files changed, 9 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..d848628 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,14 @@

  
  
+   V4L2_EVENT_RESOLUTION_CHANGE
+   5
+   This event is triggered when a resolution change is detected
+   during runtime by the video decoder. Application may need to
+   reinitialize buffers before proceeding further.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 6ae7bbe..58488b7 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1733,6 +1733,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_EOS 2
 #define V4L2_EVENT_CTRL3
 #define V4L2_EVENT_FRAME_SYNC  4
+#define V4L2_EVENT_RESOLUTION_CHANGE   5
 #define V4L2_EVENT_PRIVATE_START   0x0800
 
 /* Payload for V4L2_EVENT_VSYNC */
-- 
1.7.9.5

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


[PATCH 0/3] MFC cleanup of reqbuf, streamon, open and close

2014-03-21 Thread Arun Kumar K
This patch series contain some fixes and cleanups done to the
s5p-mfc decoder in reqbuf, streamon and open/close commands. These
patches are present in the ChromeOS tree and just rebased onto the
media-tree and tested.

Pawel Osciak (3):
  [media] s5p-mfc: Fixes for decode REQBUFS.
  [media] s5p-mfc: Extract open/close MFC instance commands.
  [media] s5p-mfc: Don't allocate codec buffers on STREAMON.

 drivers/media/platform/s5p-mfc/s5p_mfc.c  |   29 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   62 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h |3 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |  216 -
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c  |   18 +--
 5 files changed, 182 insertions(+), 146 deletions(-)

-- 
1.7.9.5

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


[PATCH 2/3] [media] s5p-mfc: Extract open/close MFC instance commands.

2014-03-21 Thread Arun Kumar K
From: Pawel Osciak 

This is in preparation for a new flow to fix issues with streamon, which
should not be allocating buffer memory.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |   19 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |   61 +
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h |3 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |   28 +++-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c  |   18 ++--
 5 files changed, 74 insertions(+), 55 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index d636789..04030f5 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -872,24 +872,7 @@ static int s5p_mfc_release(struct file *file)
 * return instance and free resources */
if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
mfc_debug(2, "Has to free instance\n");
-   ctx->state = MFCINST_RETURN_INST;
-   set_work_bit_irqsave(ctx);
-   s5p_mfc_clean_ctx_int_flags(ctx);
-   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
-   /* Wait until instance is returned or timeout occurred */
-   if (s5p_mfc_wait_for_done_ctx
-   (ctx, S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET, 0)) {
-   s5p_mfc_clock_off();
-   mfc_err("Err returning instance\n");
-   }
-   mfc_debug(2, "After free instance\n");
-   /* Free resources */
-   s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx);
-   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
-   if (ctx->type == MFCINST_DECODER)
-   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer,
-   ctx);
-
+   s5p_mfc_close_mfc_inst(dev, ctx);
ctx->inst_no = MFC_NO_INSTANCE_SET;
}
/* hardware locking scheme */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index ba1d302..ccbfcb3 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -402,3 +402,64 @@ int s5p_mfc_wakeup(struct s5p_mfc_dev *dev)
return 0;
 }
 
+int s5p_mfc_open_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)
+{
+   int ret = 0;
+
+   ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_instance_buffer, ctx);
+   if (ret) {
+   mfc_err("Failed allocating instance buffer\n");
+   goto err;
+   }
+
+   if (ctx->type == MFCINST_DECODER) {
+   ret = s5p_mfc_hw_call(dev->mfc_ops,
+   alloc_dec_temp_buffers, ctx);
+   if (ret) {
+   mfc_err("Failed allocating temporary buffers\n");
+   goto err_free_inst_buf;
+   }
+   }
+
+   set_work_bit_irqsave(ctx);
+   s5p_mfc_clean_ctx_int_flags(ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+   if (s5p_mfc_wait_for_done_ctx(ctx,
+   S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET, 0)) {
+   /* Error or timeout */
+   mfc_err("Error getting instance from hardware\n");
+   ret = -EIO;
+   goto err_free_desc_buf;
+   }
+
+   mfc_debug(2, "Got instance number: %d\n", ctx->inst_no);
+   return ret;
+
+err_free_desc_buf:
+   if (ctx->type == MFCINST_DECODER)
+   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
+err_free_inst_buf:
+   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
+err:
+   return ret;
+}
+
+void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)
+{
+   ctx->state = MFCINST_RETURN_INST;
+   set_work_bit_irqsave(ctx);
+   s5p_mfc_clean_ctx_int_flags(ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+   /* Wait until instance is returned or timeout occurred */
+   if (s5p_mfc_wait_for_done_ctx(ctx,
+   S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET, 0))
+   mfc_err("Err returning instance\n");
+
+   /* Free resources */
+   s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx);
+   s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx);
+   if (ctx->type == MFCINST_DECODER)
+   s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
+
+   ctx->state = MFCINST_FREE;
+}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h
index 6a9b6f8..8e5df04 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_

[PATCH 3/3] [media] s5p-mfc: Don't allocate codec buffers on STREAMON.

2014-03-21 Thread Arun Kumar K
From: Pawel Osciak 

Currently, we allocate private codec buffers on STREAMON, which may fail
if we are out of memory. We don't check for failure though, which will
make us crash with the codec accessing random memory.

We shouldn't be failing STREAMON with out of memory errors though. So move
the allocation of private codec buffers to REQBUFS for OUTPUT queue. Also,
move MFC instance opening and closing to REQBUFS as well, as it's tied to
allocation and deallocation of private codec buffers.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c  |   10 -
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c  |   30 +++--
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 04030f5..4ee5a02 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -637,8 +637,9 @@ static irqreturn_t s5p_mfc_irq(int irq, void *priv)
goto irq_cleanup_hw;
 
case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET:
-   clear_work_bit(ctx);
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
+   clear_work_bit(ctx);
wake_up(&ctx->queue);
goto irq_cleanup_hw;
 
@@ -758,7 +759,7 @@ static int s5p_mfc_open(struct file *file)
goto err_bad_node;
}
ctx->fh.ctrl_handler = &ctx->ctrl_handler;
-   ctx->inst_no = -1;
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
/* Load firmware if this is the first instance */
if (dev->num_inst == 1) {
dev->watchdog_timer.expires = jiffies +
@@ -868,12 +869,11 @@ static int s5p_mfc_release(struct file *file)
vb2_queue_release(&ctx->vq_dst);
/* Mark context as idle */
clear_work_bit_irqsave(ctx);
-   /* If instance was initialised then
+   /* If instance was initialised and not yet freed,
 * return instance and free resources */
-   if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
+   if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) {
mfc_debug(2, "Has to free instance\n");
s5p_mfc_close_mfc_inst(dev, ctx);
-   ctx->inst_no = MFC_NO_INSTANCE_SET;
}
/* hardware locking scheme */
if (dev->curr_ctx == ctx->num)
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index ccbfcb3..865e9e0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -461,5 +461,6 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx)
if (ctx->type == MFCINST_DECODER)
s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx);
 
+   ctx->inst_no = MFC_NO_INSTANCE_SET;
ctx->state = MFCINST_FREE;
 }
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index efc78ae..4586186 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -475,11 +475,11 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
if (ret)
goto out;
+   s5p_mfc_close_mfc_inst(dev, ctx);
ctx->src_bufs_cnt = 0;
+   ctx->output_state = QUEUE_FREE;
} else if (ctx->output_state == QUEUE_FREE) {
-   /* Can only request buffers after the instance
-* has been opened.
-*/
+   /* Can only request buffers when we have a valid format set. */
WARN_ON(ctx->src_bufs_cnt != 0);
if (ctx->state != MFCINST_INIT) {
mfc_err("Reqbufs called in an invalid state\n");
@@ -493,6 +493,13 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct 
s5p_mfc_ctx *ctx,
if (ret)
goto out;
 
+   ret = s5p_mfc_open_mfc_inst(dev, ctx);
+   if (ret) {
+   reqbufs->count = 0;
+   vb2_reqbufs(&ctx->vq_src, reqbufs);
+   goto out;
+   }
+
ctx->output_state = QUEUE_BUFS_REQUESTED;
} else {
mfc_err("Buffers have already been requested\n");
@@ -594,7 +601,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
return -EINVAL;
}
mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
- 

[PATCH 1/3] [media] s5p-mfc: Fixes for decode REQBUFS.

2014-03-21 Thread Arun Kumar K
From: Pawel Osciak 

- Honor return values from vb2_reqbufs on REQBUFS(0).

- Do not set the number of allocated buffers to 0 if userspace tries
  to request buffers again without freeing them.

- There is no need to verify correct instance state on reqbufs, as we will
  verify this in queue_setup().

- There is also no need to verify that vb2_reqbufs() was able to allocate enough
  buffers (pb_count) and call buf_init on that many buffers (i.e. dst_buf_count
  is at least pb_count), because this will be verified by second queue_setup()
  call as well and vb2_reqbufs() will fail otherwise.

- Only verify state is MFCINST_INIT when allocating, not when freeing.

- Refactor and simplify code.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |  178 ++
 1 file changed, 99 insertions(+), 79 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 8faf969..1ff82f2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -462,104 +462,124 @@ out:
return ret;
 }
 
-/* Reqeust buffers */
-static int vidioc_reqbufs(struct file *file, void *priv,
- struct v4l2_requestbuffers *reqbufs)
+static int reqbufs_output(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
+   struct v4l2_requestbuffers *reqbufs)
 {
-   struct s5p_mfc_dev *dev = video_drvdata(file);
-   struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
int ret = 0;
 
-   if (reqbufs->memory != V4L2_MEMORY_MMAP) {
-   mfc_err("Only V4L2_MEMORY_MAP is supported\n");
-   return -EINVAL;
-   }
-   if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-   /* Can only request buffers after an instance has been opened.*/
-   if (ctx->state == MFCINST_INIT) {
-   ctx->src_bufs_cnt = 0;
-   if (reqbufs->count == 0) {
-   mfc_debug(2, "Freeing buffers\n");
-   s5p_mfc_clock_on();
-   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
-   s5p_mfc_clock_off();
-   return ret;
-   }
-   /* Decoding */
-   if (ctx->output_state != QUEUE_FREE) {
-   mfc_err("Bufs have already been requested\n");
-   return -EINVAL;
-   }
-   s5p_mfc_clock_on();
-   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
-   s5p_mfc_clock_off();
-   if (ret) {
-   mfc_err("vb2_reqbufs on output failed\n");
-   return ret;
-   }
-   mfc_debug(2, "vb2_reqbufs: %d\n", ret);
-   ctx->output_state = QUEUE_BUFS_REQUESTED;
+   s5p_mfc_clock_on();
+
+   if (reqbufs->count == 0) {
+   mfc_debug(2, "Freeing buffers\n");
+   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+   if (ret)
+   goto out;
+   ctx->src_bufs_cnt = 0;
+   } else if (ctx->output_state == QUEUE_FREE) {
+   /* Can only request buffers after the instance
+* has been opened.
+*/
+   WARN_ON(ctx->src_bufs_cnt != 0);
+   if (ctx->state != MFCINST_INIT) {
+   mfc_err("Reqbufs called in an invalid state\n");
+   ret = -EINVAL;
+   goto out;
}
-   } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+
+   mfc_debug(2, "Allocating %d buffers for OUTPUT queue\n",
+   reqbufs->count);
+   ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+   if (ret)
+   goto out;
+
+   ctx->output_state = QUEUE_BUFS_REQUESTED;
+   } else {
+   mfc_err("Buffers have already been requested\n");
+   ret = -EINVAL;
+   }
+out:
+   s5p_mfc_clock_off();
+   if (ret)
+   mfc_err("Failed allocating buffers for OUTPUT queue\n");
+   return ret;
+}
+
+static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
+   struct v4l2_requestbuffers *reqbufs)
+{
+   int ret = 0;
+
+   s5p_mfc_clock_on();
+
+   if (reqbufs->count == 0) {
+   mfc_debug(2, "Freeing buffers\n");
+   ret = vb2_reqbufs(&ctx-

[PATCH] [media] s5p-mfc: Copy timestamps only when a frame is produced.

2014-03-18 Thread Arun Kumar K
From: Pawel Osciak 

Timestamps for destination buffers are assigned by copying them from
corresponding source buffers when the decode operation results in a frame
being outputted to a destination buffer. But the decision when to do this, i.e.
whether the decode operation on current source buffer produced a destination
frame, is wrongly based on "display status". Display status reflects the status
of the destination buffer, not source.

This used to work for firmwares version <= 6, because in addition to the above,
we'd check the decoded frame type register, which was set to "skipped" if
a destination frame was not produced, exiting early from
s5p_mfc_handle_frame_new().
Firmware >=7 does not set the frame type register for frames that were not
decoded anymore though, which results in us wrongly overwriting timestamps of
previously decoded buffers (firmware reports the same destination buffer address
as previously decoded one if a frame wasn't decoded during current operation).

To do it properly, we should be basing our decision to copy the timestamp on the
status of the source buffer, i.e. "decode status". The decode status register
values are confusing, because in its case "display" means "a frame has been
outputted to a destination buffer". We should copy if "decode and display"
is returned in it. This also works on <= v6 firmware, which behaves in the same
way with regards to decode status register.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 66c1775..d636789 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -304,12 +304,15 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
 {
struct s5p_mfc_dev *dev = ctx->dev;
unsigned int dst_frame_status;
+   unsigned int dec_frame_status;
struct s5p_mfc_buf *src_buf;
unsigned long flags;
unsigned int res_change;
 
dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
+   dec_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dec_status, dev)
+   & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
& S5P_FIMV_DEC_STATUS_RESOLUTION_MASK)
>> S5P_FIMV_DEC_STATUS_RESOLUTION_SHIFT;
@@ -342,8 +345,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
}
}
 
-   if (dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY ||
-   dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_ONLY)
+   if (dec_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY)
s5p_mfc_handle_frame_copy_time(ctx);
 
/* A frame has been decoded and is in the buffer  */
-- 
1.7.9.5

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


Re: [PATCH] [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.

2014-03-11 Thread Arun Kumar K
Hi Kamil,

On Tue, Mar 11, 2014 at 4:59 PM, Kamil Debski  wrote:
> Hi Arun,
>
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com] On Behalf Of Arun
>> Kumar K
>> Sent: Friday, March 07, 2014 9:26 AM
>>
>> From: Pawel Osciak 
>>
>> Currently, for formats that are not H264, MFC driver will check the
>> consumed stream size returned by the firmware and, based on that, will
>> try to decide whether the bitstream buffer contained more than one
>> frame. If the size of the buffer is larger than the consumed stream, it
>> assumes that there are more frames in the buffer and that the buffer
>> should be resubmitted for decode. This rarely works though and actually
>> introduces problems, because:
>>
>> - v7 firmware will always return consumed stream size equal to whatever
>> the driver passed to it when running decode (which is the size of the
>> whole buffer), which means we will never try to resubmit, because the
>> firmware will always tell us that it consumed all the data we passed to
>> it;
>
> This does sound like a hardware bug/feature. So in v7 the buffer is never
> resubmitted, yes? And this patch makes no difference for v7?
>

To give some background to this - I have added this patch [1] so that
multi-frame input buffer is supported by the driver.
[1] https://patchwork.linuxtv.org/patch/15448/

This patch was added to address one test case in VP8 decoding where
2 frames used to come in a single buffer. Without this patch, it used to
skip decoding of the 2nd frame even though firmware returned
consumed bytes as only 1 frame size.

Now this concept gave issues when we tried to decode the VP8 stream
encoded using v7 firmware. In that case, an arbitrary amount of padding
bytes were added by the firmware after every frame which is allowed as
per VP8 standard. While decoding this using v6, firmware returns less
consumed bytes than the input buffer, but the remaining bytes are just
padding. So firmware used to throw error if we re-submit this stuffing bytes
as a new frame. In v7 firmware, this problem doesnt exist as it consumes
(atleast indicates that it consumed) all the input buffer.

So we came to the conclusion that the testcase of giving multiple frames
in one input buffer itself was wrong and hence it was removed.
Now this concept is needed only for MPEG4 packed PB case which this
code for resubmitting input buffer was meant for (before my patch made
it generic).

>>
>> - v6 firmware will return the number of consumed bytes, but will not
>> include the padding ("stuffing") bytes that are allowed after the frame
>> in VP8. Since there is no way of figuring out how many of those bytes
>> follow the frame without getting the frame size from IVF headers (or
>> somewhere else, but not from the stream itself), the driver tries to
>> guess that padding size is not larger than 4 bytes, which is not always
>> true;
>
> How about v5 of MFC? I need to do some additional testing, as I don't want
> to introduce any regressions. I remember that this check was a result of a
> fair amount of work and testing with v5.
>

I hope it wont give any issues in v5 also as it was never meant to handle
multiple frames in one input buffer.


>> The only way to make it work is to queue only one frame per buffer from
>> userspace and the check in the kernel is useless and wrong for VP8.
>> MPEG4 still seems to require it, so keep it only for that format.
>
> Is your goal to give more than one frame in a single buffer and have the
> buffer resubmitted? Or the opposite - you are getting the frame resubmitted
> without the need? By the contents of this patch I guess the latter, on the
> other hand I do remember that at some point the idea was to be able to queue
> more than one frame per buffer. I don't remember exactly who was opting for
> the ability to queue more frames in a single buffer...
>

I hope now it is clear. We want to disallow multiple frames in one buffer as the
behavior is not consistent in v6 and its not allowed anyway from v7 onwards.

Regards
Arun

> Best wishes,
> --
> Kamil Debski
> Samsung R&D Institute Poland
>
>>
>> Signed-off-by: Pawel Osciak 
>> Signed-off-by: Arun Kumar K 
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c |2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> index e2aac59..66c1775 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
>> @@ -360,7 +360,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx
>> *ctx,
>>  

[PATCH v2] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-03-11 Thread Arun Kumar K
From: avnd kiran 

Latest MFC v6 firmware requires tile mode and loop filter
setting to be done as part of Init buffer command, in sync
with v7. Since there are two versions of v6 firmware with
different interfaces, it is differenciated using the version
number read back from firmware which is a hexadecimal value
based on the firmware date.

Signed-off-by: avnd kiran 
Signed-off-by: Arun Kumar K 
---
Changes from v1
---
- Check for v6 firmware date for differenciating old and new firmware
  as per comments from Kamil and Sylwester.
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h|2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |2 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c   |8 +++---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   30 ---
 5 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 8d0b686..b47567c 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -132,6 +132,7 @@
 #define S5P_FIMV_D_METADATA_BUFFER_ADDR_V6 0xf448
 #define S5P_FIMV_D_METADATA_BUFFER_SIZE_V6 0xf44c
 #define S5P_FIMV_D_NUM_MV_V6   0xf478
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6  0xf47c
 #define S5P_FIMV_D_CPB_BUFFER_ADDR_V6  0xf4b0
 #define S5P_FIMV_D_CPB_BUFFER_SIZE_V6  0xf4b4
 
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index ea5ec2a..82c96fa 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -18,8 +18,6 @@
 #define S5P_FIMV_CODEC_VP8_ENC_V7  25
 
 /* Additional registers for v7 */
-#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7  0xf47c
-
 #define S5P_FIMV_E_SOURCE_FIRST_ADDR_V70xf9e0
 #define S5P_FIMV_E_SOURCE_SECOND_ADDR_V7   0xf9e4
 #define S5P_FIMV_E_SOURCE_THIRD_ADDR_V70xf9e8
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 4d17df9..f5404a6 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -287,6 +287,7 @@ struct s5p_mfc_priv_buf {
  * @warn_start:hardware error code from which warnings start
  * @mfc_ops:   ops structure holding HW operation function pointers
  * @mfc_cmds:  cmd structure holding HW commands function pointers
+ * @ver:   firmware sub version
  *
  */
 struct s5p_mfc_dev {
@@ -330,6 +331,7 @@ struct s5p_mfc_dev {
int warn_start;
struct s5p_mfc_hw_ops *mfc_ops;
struct s5p_mfc_hw_cmds *mfc_cmds;
+   int ver;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 2475a3c..ba1d302 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -240,7 +240,6 @@ static inline void s5p_mfc_clear_cmds(struct s5p_mfc_dev 
*dev)
 /* Initialize hardware */
 int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
 {
-   unsigned int ver;
int ret;
 
mfc_debug_enter();
@@ -302,12 +301,13 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
return -EIO;
}
if (IS_MFCV6_PLUS(dev))
-   ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
+   dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION_V6);
else
-   ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
+   dev->ver = mfc_read(dev, S5P_FIMV_FW_VERSION);
 
mfc_debug(2, "MFC F/W version : %02xyy, %02xmm, %02xdd\n",
-   (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
+   (dev->ver >> 16) & 0xFF, (dev->ver >> 8) & 0xFF,
+   dev->ver & 0xFF);
s5p_mfc_clock_off();
mfc_debug_leave();
return 0;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 90edb19..356cfe5 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -14,6 +14,7 @@
 
 #undef DEBUG
 
+#include 
 #include 
 #include 
 #include 
@@ -1269,6 +1270,29 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx 
*ctx)
return 0;
 }
 
+/* Check if newer v6 firmware with changed init buffer interface */
+static bool s5p_mfc_is_v6_new(struct s5p_mfc_dev *dev)
+{
+   unsigned long cur_fw, v6_new_fw;
+   unsigned int y, m, d;
+
+   if (IS_MFCV7(dev))
+   return false;
+
+   y = bcd2bin((dev->ver >> 16) & 0xFF) + 2000;
+   m = bcd2bin((dev->ver >> 8) & 0xFF);
+   d = bc

Re: [PATCH] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-03-09 Thread Arun Kumar K
Hi Kamil,

On Fri, Mar 7, 2014 at 6:18 PM, Kamil Debski  wrote:
> Hi Arun,
>
>> From: Arun Kumar K [mailto:arunkk.sams...@gmail.com]
>> Sent: Friday, March 07, 2014 12:10 PM
>>
>> Hi Sylwester,
>>
>> On Fri, Mar 7, 2014 at 2:59 PM, Sylwester Nawrocki
>>  wrote:
>> > Hi,
>> >
>> > On 07/03/14 09:31, Arun Kumar K wrote:
>> >> From: avnd kiran 
>> >>
>> >> Latest MFC v6 firmware requires tile mode and loop filter setting to
>> >> be done as part of Init buffer command, in sync with v7. So, move
>> >> these settings out of decode options reg.
>> >> Also, make this register definition applicable from v6 onwards.
>> >>
>> >> Signed-off-by: avnd kiran 
>> >> Signed-off-by: Arun Kumar K 
>> >
>> > Will the driver also work with older version of the firmware after
>> > this change ? If not, shouldn't things like this be done depending on
>> > what firmware version is loaded ?
>> >
>>
>> The original code was for the initial version of v6 firmware.
>> After that the v6 firmware has got many fixes and updates which also
>> got updated in the products running the same.
>> As such there are no official multiple versions of v6 firmware, but
>> only fixes / updates to older version. I will update the s5p-mfc-v6.fw
>> in the linux-firmware also with the newer version. Hope that will be
>> fine.
>
> Unfortunately, I share the same concerns as Sylwester. We have two problems:
> 1) new kernel + old firmware
>
> In this case, someone will update the kernel and find out that video
> decoding is not working. An assumption that I think is common, is that
> updating the kernel should not break anything. If it was working with the
> previous version it should work with the next.
>
> The solution I can suggest is that a check which firmware version is used
> has to be implemented. Maybe you can use the date of firmware to do this
> check?
>

Yes this concern is valid. I think its better to check for firmware date as the
old firmware is already submitted in mainline.

> 2) old kernel + new firmware
>
> I see no clear solution to this problem. If the kernel is old and the
> firmware is behaving differently, the video decoding will not work. I can
> guess that this case would be less common, but still a person can update the
> firmware and leave the old kernel. Changing the firmware can be done by
> replacing a single file.
>
> In addition to the above, you need to clearly specify in the
> linux-firmware.git what is going on. A readme file is a must. Maybe a second
> v6 firmware file should be included?
>


Yes I can put the newer version of v6 firmware also in linux-firmware with a
readme detailing the difference between the same.
I hope this is a valid solution.

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


Re: [PATCH] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-03-07 Thread Arun Kumar K
Hi Sylwester,

On Fri, Mar 7, 2014 at 2:59 PM, Sylwester Nawrocki
 wrote:
> Hi,
>
> On 07/03/14 09:31, Arun Kumar K wrote:
>> From: avnd kiran 
>>
>> Latest MFC v6 firmware requires tile mode and loop filter
>> setting to be done as part of Init buffer command, in sync
>> with v7. So, move these settings out of decode options reg.
>> Also, make this register definition applicable from v6 onwards.
>>
>> Signed-off-by: avnd kiran 
>> Signed-off-by: Arun Kumar K 
>
> Will the driver also work with older version of the firmware
> after this change ? If not, shouldn't things like this be done
> depending on what firmware version is loaded ?
>

The original code was for the initial version of v6 firmware.
After that the v6 firmware has got many fixes and updates which
also got updated in the products running the same.
As such there are no official multiple versions of v6 firmware, but only
fixes / updates to older version. I will update the s5p-mfc-v6.fw in the
linux-firmware also with the newer version. Hope that will be fine.

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


[PATCH] [media] s5p-mfc: add init buffer cmd to MFCV6

2014-03-07 Thread Arun Kumar K
From: avnd kiran 

Latest MFC v6 firmware requires tile mode and loop filter
setting to be done as part of Init buffer command, in sync
with v7. So, move these settings out of decode options reg.
Also, make this register definition applicable from v6 onwards.

Signed-off-by: avnd kiran 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/regs-mfc-v6.h|1 +
 drivers/media/platform/s5p-mfc/regs-mfc-v7.h|2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |   11 +++
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
index 8d0b686..b47567c 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v6.h
@@ -132,6 +132,7 @@
 #define S5P_FIMV_D_METADATA_BUFFER_ADDR_V6 0xf448
 #define S5P_FIMV_D_METADATA_BUFFER_SIZE_V6 0xf44c
 #define S5P_FIMV_D_NUM_MV_V6   0xf478
+#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6  0xf47c
 #define S5P_FIMV_D_CPB_BUFFER_ADDR_V6  0xf4b0
 #define S5P_FIMV_D_CPB_BUFFER_SIZE_V6  0xf4b4
 
diff --git a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h 
b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
index ea5ec2a..82c96fa 100644
--- a/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
+++ b/drivers/media/platform/s5p-mfc/regs-mfc-v7.h
@@ -18,8 +18,6 @@
 #define S5P_FIMV_CODEC_VP8_ENC_V7  25
 
 /* Additional registers for v7 */
-#define S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7  0xf47c
-
 #define S5P_FIMV_E_SOURCE_FIRST_ADDR_V70xf9e0
 #define S5P_FIMV_E_SOURCE_SECOND_ADDR_V7   0xf9e4
 #define S5P_FIMV_E_SOURCE_THIRD_ADDR_V70xf9e8
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 90edb19..b226d75 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1296,10 +1296,8 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx 
*ctx)
WRITEL(ctx->display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
}
 
-   if (IS_MFCV7(dev)) {
-   WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
-   reg = 0;
-   }
+   WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
+   reg = 0;
 
/* Setup loop filter, for decoding this is only valid for MPEG4 */
if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
@@ -1311,10 +1309,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx 
*ctx)
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
 
-   if (IS_MFCV7(dev))
-   WRITEL(reg, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7);
-   else
-   WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
+   WRITEL(reg, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
 
/* 0: NV12(CbCr), 1: NV21(CrCb) */
if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
-- 
1.7.9.5

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


[PATCH] [media] s5p-mfc: Don't try to resubmit VP8 bitstream buffer for decode.

2014-03-07 Thread Arun Kumar K
From: Pawel Osciak 

Currently, for formats that are not H264, MFC driver will check
the consumed stream size returned by the firmware and, based on that,
will try to decide whether the bitstream buffer contained more than
one frame. If the size of the buffer is larger than the consumed
stream, it assumes that there are more frames in the buffer and that the
buffer should be resubmitted for decode. This rarely works though and
actually introduces problems, because:

- v7 firmware will always return consumed stream size equal to whatever
the driver passed to it when running decode (which is the size of the whole
buffer), which means we will never try to resubmit, because the firmware
will always tell us that it consumed all the data we passed to it;

- v6 firmware will return the number of consumed bytes, but will not
include the padding ("stuffing") bytes that are allowed after the frame
in VP8. Since there is no way of figuring out how many of those bytes
follow the frame without getting the frame size from IVF headers (or
somewhere else, but not from the stream itself), the driver tries to guess that
padding size is not larger than 4 bytes, which is not always true;

The only way to make it work is to queue only one frame per buffer from
userspace and the check in the kernel is useless and wrong for VP8.
MPEG4 still seems to require it, so keep it only for that format.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 drivers/media/platform/s5p-mfc/s5p_mfc.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index e2aac59..66c1775 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -360,7 +360,7 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
list);
ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops,
get_consumed_stream, dev);
-   if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
+   if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC &&
ctx->consumed_stream + STUFF_BYTE <
src_buf->b->v4l2_planes[0].bytesused) {
/* Run MFC again on the same buffer */
-- 
1.7.9.5

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


[PATCH] [media] s5p-mfc: Add a control for IVF format for VP8 encoder

2014-03-05 Thread Arun Kumar K
From: Pawel Osciak 

Add a control to enable/disable IVF output stream format for VP8 encode.
Set the IVF format output to disabled as default.

Signed-off-by: Pawel Osciak 
Signed-off-by: Arun Kumar K 
---
 Documentation/DocBook/media/v4l/controls.xml|8 
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |1 +
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c|   11 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c |2 ++
 drivers/media/v4l2-core/v4l2-ctrls.c|1 +
 include/uapi/linux/v4l2-controls.h  |1 +
 6 files changed, 24 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index 0e1770c..07fb64a 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -3222,6 +3222,14 @@ V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD as a 
golden frame.
 Acceptable values are 0, 1, 2 and 3 corresponding to encoder profiles 0, 1, 2 
and 3.
  
 
+ 
+ 
+   V4L2_CID_MPEG_VIDEO_VPX_IVF_FORMATĀ 
+   boolean
+ 
+ Outputs the VP8 encoded stream in 
IVF file format.
+ 
+
   
 
   
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 5c28cc3..4d17df9 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -418,6 +418,7 @@ struct s5p_mfc_vp8_enc_params {
u8 rc_frame_qp;
u8 rc_p_frame_qp;
u8 profile;
+   bool ivf;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index df83cd1..a67913e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -676,6 +676,14 @@ static struct mfc_control controls[] = {
.step = 1,
.default_value = 0,
},
+   {
+   .id = V4L2_CID_MPEG_VIDEO_VPX_IVF_FORMAT,
+   .type = V4L2_CTRL_TYPE_BOOLEAN,
+   .minimum = 0,
+   .maximum = 1,
+   .step = 1,
+   .default_value = 0,
+   },
 };
 
 #define NUM_CTRLS ARRAY_SIZE(controls)
@@ -1636,6 +1644,9 @@ static int s5p_mfc_enc_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_MPEG_VIDEO_VPX_PROFILE:
p->codec.vp8.profile = ctrl->val;
break;
+   case V4L2_CID_MPEG_VIDEO_VPX_IVF_FORMAT:
+   p->codec.vp8.ivf = ctrl->val;
+   break;
default:
v4l2_err(&dev->v4l2_dev, "Invalid control, id=%d, val=%d\n",
ctrl->id, ctrl->val);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index f64621a..90edb19 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1243,6 +1243,8 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx 
*ctx)
 
/* VP8 specific params */
reg = 0;
+   /* Bit set to 1 disables IVF stream format. */
+   reg |= p_vp8->ivf ? 0 : (0x1 << 12);
reg |= (p_vp8->imd_4x4 & 0x1) << 10;
switch (p_vp8->num_partitions) {
case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index e9e12c4..19e78df 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -752,6 +752,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP:return "VPX 
I-Frame QP Value";
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";
+   case V4L2_CID_MPEG_VIDEO_VPX_IVF_FORMAT:return "VPX 
Output stream in IVF format";
 
/* CAMERA controls */
/* Keep the order of the 'case's the same as in videodev2.h! */
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index cda6fa0..b2763d6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -565,6 +565,7 @@ enum v4l2_vp8_golden_frame_sel {
 #define V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (V4L2_CID_MPEG_BASE+509)
 #define V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (V4L2_CID_MPEG_BASE+510)
 #define V4L2_CID_MPEG_VIDEO_VPX_PROFILE
(V4L2_CID_MPEG_BASE+511)
+#define V4L2_CID_MPEG_VIDEO_VPX_IVF_FORMAT (V4L2_CID_MPEG_BASE+512)
 
 /*  MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */
 #def

  1   2   3   4   5   >