From f80d87ce56916edf52dce4a311f3d512443ca7f7 Mon Sep 17 00:00:00 2001
From: Aman Gupta <aman@tmm1.net>
Date: Thu, 22 Aug 2019 22:31:37 +0000
Subject: [PATCH] staging: bcm2835-codec: add support for
 V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME

fixes #3171

Signed-off-by: Aman Gupta <aman@tmm1.net>
---
 .../bcm2835-codec/bcm2835-v4l2-codec.c        | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

--- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
+++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
@@ -1587,6 +1587,20 @@ static int bcm2835_codec_s_ctrl(struct v
 		ret = bcm2835_codec_set_level_profile(ctx, ctrl);
 		break;
 
+	case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: {
+		u32 mmal_bool = 1;
+
+		if (!ctx->component)
+			break;
+
+		ret = vchiq_mmal_port_parameter_set(ctx->dev->instance,
+						    &ctx->component->output[0],
+						    MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
+						    &mmal_bool,
+						    sizeof(mmal_bool));
+		break;
+	}
+
 	default:
 		v4l2_err(&ctx->dev->v4l2_dev, "Invalid control\n");
 		return -EINVAL;
@@ -2311,7 +2325,7 @@ static int bcm2835_codec_open(struct fil
 	hdl = &ctx->hdl;
 	if (dev->role == ENCODE) {
 		/* Encode controls */
-		v4l2_ctrl_handler_init(hdl, 6);
+		v4l2_ctrl_handler_init(hdl, 7);
 
 		v4l2_ctrl_new_std_menu(hdl, &bcm2835_codec_ctrl_ops,
 				       V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
@@ -2355,6 +2369,9 @@ static int bcm2835_codec_open(struct fil
 					 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
 					 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
 					V4L2_MPEG_VIDEO_H264_PROFILE_HIGH);
+		v4l2_ctrl_new_std(hdl, &bcm2835_codec_ctrl_ops,
+				  V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME,
+				  0, 0, 0, 0);
 		if (hdl->error) {
 			rc = hdl->error;
 			goto free_ctrl_handler;
