msm: camera: isp: Update Bus and CSID to support RAW16 format

Add support for RAW16 format to be output over the RDI path. RDI path
needs to select the decode format based on output being MIPI or PLAIN16.

Change-Id: I8fb95dc9606cd8f66eaeafe39a18323e999cf83a
Signed-off-by: Harsh Shah <harshs@codeaurora.org>
Signed-off-by: Junzhe Zou <jnzhezou@codeaurora.org>
diff --git a/drivers/media/platform/msm/camera/cam_isp/cam_isp_context.c b/drivers/media/platform/msm/camera/cam_isp/cam_isp_context.c
index 6470063..0ee368d 100644
--- a/drivers/media/platform/msm/camera/cam_isp/cam_isp_context.c
+++ b/drivers/media/platform/msm/camera/cam_isp/cam_isp_context.c
@@ -691,7 +691,7 @@ static int __cam_isp_ctx_apply_req_in_activated_state(
 	 */
 	ctx_isp = (struct cam_isp_context *) ctx->ctx_priv;
 	if (ctx_isp->active_req_cnt >=  2) {
-		CAM_DBG(CAM_ISP,
+		CAM_ERR_RATE_LIMIT(CAM_ISP,
 			"Reject apply request due to congestion(cnt = %d)",
 			ctx_isp->active_req_cnt);
 		rc = -EFAULT;
@@ -706,6 +706,9 @@ static int __cam_isp_ctx_apply_req_in_activated_state(
 	 * we are in the middle of the error handling. Need to reject this apply
 	 */
 	if (req->request_id != apply->request_id) {
+		CAM_ERR_RATE_LIMIT(CAM_ISP,
+			"Invalid Request Id asking %llu existing %llu",
+			apply->request_id, req->request_id);
 		rc = -EFAULT;
 		goto end;
 	}
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c
index 27b9f4a..d0b0751 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c
@@ -69,11 +69,11 @@ static int cam_ife_mgr_get_hw_caps(void *hw_mgr_priv,
 	return rc;
 }
 
-static int cam_ife_hw_mgr_is_rdi_res(uint32_t format)
+static int cam_ife_hw_mgr_is_rdi_res(uint32_t res_id)
 {
 	int rc = 0;
 
-	switch (format) {
+	switch (res_id) {
 	case CAM_ISP_IFE_OUT_RES_RDI_0:
 	case CAM_ISP_IFE_OUT_RES_RDI_1:
 	case CAM_ISP_IFE_OUT_RES_RDI_2:
@@ -379,11 +379,12 @@ static void cam_ife_mgr_add_base_info(
 	uint32_t    i;
 
 	if (!ctx->num_base) {
-		CAM_DBG(CAM_ISP, "Add split id = %d for base idx = %d",
-			split_id, base_idx);
 		ctx->base[0].split_id = split_id;
 		ctx->base[0].idx      = base_idx;
 		ctx->num_base++;
+		CAM_DBG(CAM_ISP,
+			"Add split id = %d for base idx = %d num_base=%d",
+			split_id, base_idx, ctx->num_base);
 	} else {
 		/*Check if base index is alreay exist in the list */
 		for (i = 0; i < CAM_IFE_HW_NUM_MAX; i++) {
@@ -398,11 +399,12 @@ static void cam_ife_mgr_add_base_info(
 		}
 
 		if (i == CAM_IFE_HW_NUM_MAX) {
-			CAM_DBG(CAM_ISP, "Add split id = %d for base idx = %d",
-				 split_id, base_idx);
 			ctx->base[ctx->num_base].split_id = split_id;
 			ctx->base[ctx->num_base].idx      = base_idx;
 			ctx->num_base++;
+			CAM_DBG(CAM_ISP,
+				"Add split_id=%d for base idx=%d num_base=%d",
+				 split_id, base_idx, ctx->num_base);
 		}
 	}
 }
@@ -427,15 +429,12 @@ static int cam_ife_mgr_process_base_info(
 		for (i = 0; i < CAM_ISP_HW_SPLIT_MAX; i++) {
 			if (!hw_mgr_res->hw_res[i])
 				continue;
-			res = hw_mgr_res->hw_res[i];
-			if (res->res_id == CAM_ISP_HW_VFE_IN_CAMIF)
-				cam_ife_mgr_add_base_info(ctx, i,
-					res->hw_intf->hw_idx);
 
-			else
-				cam_ife_mgr_add_base_info(ctx,
-						CAM_ISP_HW_SPLIT_MAX,
-						res->hw_intf->hw_idx);
+			res = hw_mgr_res->hw_res[i];
+			cam_ife_mgr_add_base_info(ctx, i,
+					res->hw_intf->hw_idx);
+			CAM_DBG(CAM_ISP, "add base info for hw %d",
+				res->hw_intf->hw_idx);
 		}
 	}
 	CAM_DBG(CAM_ISP, "ctx base num = %d", ctx->num_base);
@@ -676,7 +675,6 @@ static int cam_ife_hw_mgr_acquire_res_ife_src(
 
 		vfe_acquire.rsrc_type = CAM_ISP_RESOURCE_VFE_IN;
 		vfe_acquire.tasklet = ife_ctx->common.tasklet_info;
-		vfe_acquire.rsrc_type = CAM_ISP_RESOURCE_VFE_IN;
 		vfe_acquire.vfe_in.cdm_ops = ife_ctx->cdm_ops;
 
 		switch (csid_res->res_id) {
@@ -787,6 +785,7 @@ static int cam_ife_hw_mgr_acquire_res_ife_csid_ipp(
 	csid_acquire.res_id = CAM_IFE_PIX_PATH_RES_IPP;
 	csid_acquire.cid = cid_res_id;
 	csid_acquire.in_port = in_port;
+	csid_acquire.out_port = in_port->data;
 
 	if (in_port->usage_type)
 		csid_acquire.sync_mode = CAM_ISP_HW_SYNC_MASTER;
@@ -1288,8 +1287,10 @@ static int cam_ife_mgr_acquire_hw(void *hw_mgr_priv,
 	}
 
 	/* Check whether context has only RDI resource */
-	if (!num_pix_port)
+	if (!num_pix_port) {
 		ife_ctx->is_rdi_only_context = 1;
+		CAM_DBG(CAM_ISP, "RDI only context");
+	}
 
 	/* Process base info */
 	rc = cam_ife_mgr_process_base_info(ife_ctx);
@@ -1342,7 +1343,8 @@ static int cam_ife_mgr_config_hw(void *hw_mgr_priv,
 		return -EPERM;
 	}
 
-	CAM_DBG(CAM_ISP, "Enter ctx id:%d", ctx->ctx_index);
+	CAM_DBG(CAM_ISP, "Enter ctx id:%d num_hw_upd_entries %d",
+		ctx->ctx_index, cfg->num_hw_update_entries);
 
 	if (cfg->num_hw_update_entries > 0) {
 		cdm_cmd = ctx->cdm_cmd;
@@ -1359,6 +1361,7 @@ static int cam_ife_mgr_config_hw(void *hw_mgr_priv,
 			cdm_cmd->cmd[i].len = cmd->len;
 		}
 
+		CAM_DBG(CAM_ISP, "Submit to CDM");
 		rc = cam_cdm_submit_bls(ctx->cdm_handle, cdm_cmd);
 		if (rc)
 			CAM_ERR(CAM_ISP, "Failed to apply the configs");
@@ -1914,7 +1917,6 @@ static int cam_ife_mgr_prepare_hw_update(void *hw_mgr_priv,
 	if (rc)
 		return rc;
 
-	CAM_DBG(CAM_ISP, "enter");
 	/* Pre parse the packet*/
 	rc = cam_packet_util_get_kmd_buffer(prepare->packet, &kmd_buf);
 	if (rc)
@@ -2011,14 +2013,22 @@ static int cam_ife_mgr_prepare_hw_update(void *hw_mgr_priv,
 		/* Add change base */
 		rc = cam_isp_add_change_base(prepare, &ctx->res_list_ife_src,
 			ctx->base[i].idx, &kmd_buf);
-		if (rc)
+		if (rc) {
+			CAM_ERR(CAM_ISP,
+				"Failed in change base adding reg_update cmd i=%d, idx=%d, rc=%d",
+				i, ctx->base[i].idx, rc);
 			goto end;
+		}
 
 		/*Add reg update */
 		rc = cam_isp_add_reg_update(prepare, &ctx->res_list_ife_src,
 			ctx->base[i].idx, &kmd_buf);
-		if (rc)
+		if (rc) {
+			CAM_ERR(CAM_ISP,
+				"Add Reg_update cmd Failed i=%d, idx=%d, rc=%d",
+				i, ctx->base[i].idx, rc);
 			goto end;
+		}
 	}
 
 end:
@@ -2804,10 +2814,10 @@ static int cam_ife_hw_mgr_handle_sof(
 						ife_hw_mgr_ctx->common.cb_priv,
 						CAM_ISP_HW_EVENT_SOF,
 						&sof_done_event_data);
+					CAM_DBG(CAM_ISP, "sof_status = %d",
+						sof_status);
 				}
 
-				CAM_DBG(CAM_ISP, "sof_status = %d", sof_status);
-
 				/* this is RDI only context so exit from here */
 				return 0;
 			}
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c
index 3ef96db..698a4c8 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c
@@ -696,6 +696,8 @@ int cam_isp_add_reg_update(
 			if (rc)
 				return rc;
 
+			CAM_DBG(CAM_ISP, "Reg update added for res %d hw_id %d",
+				res->res_id, res->hw_intf->hw_idx);
 			reg_update_size += get_regup.used_bytes;
 		}
 	}
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.c
index a2f773e..9103136 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.c
@@ -32,12 +32,14 @@
 #define CAM_IFE_CSID_TIMEOUT_SLEEP_US                  1000
 #define CAM_IFE_CSID_TIMEOUT_ALL_US                    1000000
 
+#define MEASURE_EN                                     0
+
 static int cam_ife_csid_is_ipp_format_supported(
-				uint32_t decode_fmt)
+	uint32_t in_format)
 {
 	int rc = -EINVAL;
 
-	switch (decode_fmt) {
+	switch (in_format) {
 	case CAM_FORMAT_MIPI_RAW_6:
 	case CAM_FORMAT_MIPI_RAW_8:
 	case CAM_FORMAT_MIPI_RAW_10:
@@ -59,127 +61,221 @@ static int cam_ife_csid_is_ipp_format_supported(
 	return rc;
 }
 
-static int cam_ife_csid_get_format(uint32_t input_fmt,
-	uint32_t *path_fmt)
+static int cam_ife_csid_get_format_rdi(
+	uint32_t in_format, uint32_t out_format,
+	uint32_t *decode_fmt, uint32_t *plain_fmt)
 {
 	int rc = 0;
 
-	switch (input_fmt) {
+	switch (in_format) {
 	case CAM_FORMAT_MIPI_RAW_6:
-		*path_fmt  = 0;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_6:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN8:
+			*decode_fmt = 0x0;
+			*plain_fmt = 0x0;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_8:
-		*path_fmt  = 1;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_8:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN8:
+			*decode_fmt = 0x1;
+			*plain_fmt = 0x0;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_10:
-		*path_fmt  = 2;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_10:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN16_10:
+			*decode_fmt = 0x2;
+			*plain_fmt = 0x1;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_12:
-		*path_fmt  = 3;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_12:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN16_12:
+			*decode_fmt = 0x3;
+			*plain_fmt = 0x1;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_14:
-		*path_fmt  = 4;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_14:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN16_14:
+			*decode_fmt = 0x4;
+			*plain_fmt = 0x1;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_16:
-		*path_fmt  = 5;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_16:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN16_16:
+			*decode_fmt = 0x5;
+			*plain_fmt = 0x1;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_MIPI_RAW_20:
-		*path_fmt  = 6;
+		switch (out_format) {
+		case CAM_FORMAT_MIPI_RAW_20:
+			*decode_fmt = 0xf;
+			break;
+		case CAM_FORMAT_PLAIN32_20:
+			*decode_fmt = 0x6;
+			*plain_fmt = 0x2;
+			break;
+		default:
+			rc = -EINVAL;
+			break;
+		}
 		break;
 	case CAM_FORMAT_DPCM_10_6_10:
-		*path_fmt  = 7;
+		*decode_fmt  = 0x7;
+		*plain_fmt = 0x1;
 		break;
 	case CAM_FORMAT_DPCM_10_8_10:
-		*path_fmt  = 8;
+		*decode_fmt  = 0x8;
+		*plain_fmt = 0x1;
 		break;
 	case CAM_FORMAT_DPCM_12_6_12:
-		*path_fmt  = 9;
+		*decode_fmt  = 0x9;
+		*plain_fmt = 0x1;
 		break;
 	case CAM_FORMAT_DPCM_12_8_12:
-		*path_fmt  = 0xA;
+		*decode_fmt  = 0xA;
+		*plain_fmt = 0x1;
 		break;
 	case CAM_FORMAT_DPCM_14_8_14:
-		*path_fmt  = 0xB;
+		*decode_fmt  = 0xB;
+		*plain_fmt = 0x1;
 		break;
 	case CAM_FORMAT_DPCM_14_10_14:
-		*path_fmt  = 0xC;
+		*decode_fmt  = 0xC;
+		*plain_fmt = 0x1;
 		break;
 	default:
-		CAM_ERR(CAM_ISP, "CSID:%d un supported format",
-			input_fmt);
+		rc = -EINVAL;
+		break;
+	}
+
+	if (rc)
+		CAM_ERR(CAM_ISP, "Unsupported format pair in %d out %d\n",
+			in_format, out_format);
+
+	return rc;
+}
+
+static int cam_ife_csid_get_format_ipp(
+	uint32_t in_format,
+	uint32_t *decode_fmt, uint32_t *plain_fmt)
+{
+	int rc = 0;
+
+	CAM_DBG(CAM_ISP, "input format:%d",
+		 in_format);
+
+	switch (in_format) {
+	case CAM_FORMAT_MIPI_RAW_6:
+		*decode_fmt  = 0;
+		*plain_fmt = 0;
+		break;
+	case CAM_FORMAT_MIPI_RAW_8:
+		*decode_fmt  = 0x1;
+		*plain_fmt = 0;
+		break;
+	case CAM_FORMAT_MIPI_RAW_10:
+		*decode_fmt  = 0x2;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_MIPI_RAW_12:
+		*decode_fmt  = 0x3;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_MIPI_RAW_14:
+		*decode_fmt  = 0x4;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_MIPI_RAW_16:
+		*decode_fmt  = 0x5;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_MIPI_RAW_20:
+		*decode_fmt  = 0x6;
+		*plain_fmt = 0x2;
+		break;
+	case CAM_FORMAT_DPCM_10_6_10:
+		*decode_fmt  = 0x7;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_DPCM_10_8_10:
+		*decode_fmt  = 0x8;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_DPCM_12_6_12:
+		*decode_fmt  = 0x9;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_DPCM_12_8_12:
+		*decode_fmt  = 0xA;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_DPCM_14_8_14:
+		*decode_fmt  = 0xB;
+		*plain_fmt = 0x1;
+		break;
+	case CAM_FORMAT_DPCM_14_10_14:
+		*decode_fmt  = 0xC;
+		*plain_fmt = 0x1;
+		break;
+	default:
+		CAM_ERR(CAM_ISP, "Unsupported format %d",
+			in_format);
 		rc = -EINVAL;
 	}
 
+	CAM_DBG(CAM_ISP, "decode_fmt:%d plain_fmt:%d",
+		 *decode_fmt, *plain_fmt);
+
 	return rc;
 }
 
-static int cam_ife_csid_get_rdi_format(uint32_t input_fmt,
-	uint32_t output_fmt, uint32_t *path_fmt, uint32_t *plain_fmt)
-{
-	int rc = 0;
-
-	CAM_DBG(CAM_ISP, "input format:%d output format:%d",
-		 input_fmt, output_fmt);
-
-	switch (output_fmt) {
-	case CAM_FORMAT_MIPI_RAW_6:
-	case CAM_FORMAT_MIPI_RAW_8:
-	case CAM_FORMAT_MIPI_RAW_10:
-	case CAM_FORMAT_MIPI_RAW_12:
-	case CAM_FORMAT_MIPI_RAW_14:
-	case CAM_FORMAT_MIPI_RAW_16:
-	case CAM_FORMAT_MIPI_RAW_20:
-	case CAM_FORMAT_DPCM_10_6_10:
-	case CAM_FORMAT_DPCM_10_8_10:
-	case CAM_FORMAT_DPCM_12_6_12:
-	case CAM_FORMAT_DPCM_12_8_12:
-	case CAM_FORMAT_DPCM_14_8_14:
-	case CAM_FORMAT_DPCM_14_10_14:
-		*path_fmt  = 0xF;
-		*plain_fmt = 0;
-		break;
-
-	case CAM_FORMAT_PLAIN8:
-		rc = cam_ife_csid_get_format(input_fmt, path_fmt);
-		if (rc)
-			goto error;
-
-		*plain_fmt = 0;
-		break;
-	case CAM_FORMAT_PLAIN16_8:
-	case CAM_FORMAT_PLAIN16_10:
-	case CAM_FORMAT_PLAIN16_12:
-	case CAM_FORMAT_PLAIN16_14:
-	case CAM_FORMAT_PLAIN16_16:
-		rc = cam_ife_csid_get_format(input_fmt, path_fmt);
-		if (rc)
-			goto error;
-
-		*plain_fmt = 1;
-		break;
-	case CAM_FORMAT_PLAIN32_20:
-		rc = cam_ife_csid_get_format(input_fmt, path_fmt);
-		if (rc)
-			goto error;
-
-		*plain_fmt = 2;
-		break;
-	default:
-		*path_fmt  = 0xF;
-		*plain_fmt = 0;
-		break;
-	}
-
-	CAM_DBG(CAM_ISP, "path format value:%d plain format value:%d",
-		 *path_fmt, *plain_fmt);
-
-	return 0;
-error:
-	return rc;
-
-}
-
-
 static int cam_ife_csid_cid_get(struct cam_ife_csid_hw *csid_hw,
 	struct cam_isp_resource_node **res, int32_t vc, uint32_t dt,
 	uint32_t res_type)
@@ -549,7 +645,7 @@ static int cam_ife_csid_cid_reserve(struct cam_ife_csid_hw *csid_hw,
 				goto end;
 				}
 		} else {
-			if (csid_hw->tpg_cfg.decode_fmt !=
+			if (csid_hw->tpg_cfg.in_format !=
 				cid_reserv->in_port->format     ||
 				csid_hw->tpg_cfg.width !=
 				cid_reserv->in_port->left_width ||
@@ -585,7 +681,7 @@ static int cam_ife_csid_cid_reserve(struct cam_ife_csid_hw *csid_hw,
 				rc = -EINVAL;
 				goto end;
 			}
-			csid_hw->tpg_cfg.decode_fmt =
+			csid_hw->tpg_cfg.in_format =
 				cid_reserv->in_port->format;
 			csid_hw->tpg_cfg.width =
 				cid_reserv->in_port->left_width;
@@ -712,20 +808,9 @@ static int cam_ife_csid_path_reserve(struct cam_ife_csid_hw *csid_hw,
 	res->res_state = CAM_ISP_RESOURCE_STATE_RESERVED;
 	path_data = (struct cam_ife_csid_path_cfg   *)res->res_priv;
 
-	/* store the output format for RDI */
-	switch (reserve->res_id) {
-	case CAM_IFE_PIX_PATH_RES_RDI_0:
-	case CAM_IFE_PIX_PATH_RES_RDI_1:
-	case CAM_IFE_PIX_PATH_RES_RDI_2:
-	case CAM_IFE_PIX_PATH_RES_RDI_3:
-		path_data->output_fmt = reserve->out_port->format;
-		break;
-	default:
-		break;
-	}
-
 	path_data->cid = reserve->cid;
-	path_data->decode_fmt = reserve->in_port->format;
+	path_data->in_format = reserve->in_port->format;
+	path_data->out_format = reserve->out_port->format;
 	path_data->master_idx = reserve->master_idx;
 	path_data->sync_mode = reserve->sync_mode;
 	path_data->height  = reserve->in_port->height;
@@ -746,9 +831,14 @@ static int cam_ife_csid_path_reserve(struct cam_ife_csid_hw *csid_hw,
 		path_data->crop_enable = 1;
 		path_data->start_pixel = reserve->in_port->right_start;
 		path_data->width  = reserve->in_port->right_width;
-	} else
+	} else {
 		path_data->crop_enable = 0;
+		path_data->width  = reserve->in_port->left_width;
+		path_data->start_pixel = reserve->in_port->left_start;
+	}
 
+	CAM_DBG(CAM_ISP, "Res %d width %d height %d\n", reserve->res_id,
+		path_data->width, path_data->height);
 	reserve->node_res = res;
 
 end:
@@ -1027,10 +1117,10 @@ static int cam_ife_csid_config_tpg(struct cam_ife_csid_hw   *csid_hw,
 		csid_reg->tpg_reg->csid_tpg_dt_n_cfg_1_addr);
 
 	/*
-	 * decode_fmt is the same as the input resource format.
+	 * in_format is the same as the input resource format.
 	 * it is one larger than the register spec format.
 	 */
-	val = ((csid_hw->tpg_cfg.decode_fmt - 1) << 16) | 0x8;
+	val = ((csid_hw->tpg_cfg.in_format - 1) << 16) | 0x8;
 	cam_io_w_mb(val, soc_info->reg_map[0].mem_base +
 		csid_reg->tpg_reg->csid_tpg_dt_n_cfg_2_addr);
 
@@ -1160,7 +1250,7 @@ static int cam_ife_csid_init_config_ipp_path(
 	struct cam_ife_csid_path_cfg           *path_data;
 	struct cam_ife_csid_reg_offset         *csid_reg;
 	struct cam_hw_soc_info                 *soc_info;
-	uint32_t path_format = 0, val = 0;
+	uint32_t decode_format = 0, plain_format = 0, val = 0;
 
 	path_data = (struct cam_ife_csid_path_cfg  *) res->res_priv;
 	csid_reg = csid_hw->csid_info->csid_reg;
@@ -1173,8 +1263,9 @@ static int cam_ife_csid_init_config_ipp_path(
 		return -EINVAL;
 	}
 
-	CAM_DBG(CAM_ISP, "Enabled IPP Path.......");
-	rc = cam_ife_csid_get_format(path_data->decode_fmt, &path_format);
+	CAM_DBG(CAM_ISP, "Config IPP Path");
+	rc = cam_ife_csid_get_format_ipp(path_data->in_format,
+		&decode_format, &plain_format);
 	if (rc)
 		return rc;
 
@@ -1185,7 +1276,7 @@ static int cam_ife_csid_init_config_ipp_path(
 	val = (path_data->vc << csid_reg->cmn_reg->vc_shift_val) |
 		(path_data->dt << csid_reg->cmn_reg->dt_shift_val) |
 		(path_data->cid << csid_reg->cmn_reg->dt_id_shift_val) |
-		(path_format << csid_reg->cmn_reg->fmt_shift_val) |
+		(decode_format << csid_reg->cmn_reg->fmt_shift_val) |
 		(path_data->crop_enable & 1 <<
 		csid_reg->cmn_reg->crop_h_en_shift_val) |
 		(path_data->crop_enable & 1 <<
@@ -1330,9 +1421,9 @@ static int cam_ife_csid_enable_ipp_path(
 		return -EINVAL;
 	}
 
-	CAM_DBG(CAM_ISP, "enable IPP path.......");
+	CAM_DBG(CAM_ISP, "Enable IPP path");
 
-	/*Resume at frame boundary */
+	/* Resume at frame boundary */
 	if (path_data->sync_mode == CAM_ISP_HW_SYNC_MASTER) {
 		val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 			csid_reg->ipp_reg->csid_ipp_ctrl_addr);
@@ -1432,7 +1523,7 @@ static int cam_ife_csid_disable_ipp_path(
 			csid_reg->ipp_reg->csid_ipp_irq_mask_addr);
 	} else {
 		val &= ~(CSID_PATH_INFO_RST_DONE |
-				CSID_PATH_ERROR_FIFO_OVERFLOW);
+			CSID_PATH_ERROR_FIFO_OVERFLOW);
 		cam_io_w_mb(val, soc_info->reg_map[0].mem_base +
 			csid_reg->ipp_reg->csid_ipp_irq_mask_addr);
 	}
@@ -1462,8 +1553,8 @@ static int cam_ife_csid_init_config_rdi_path(
 		return -EINVAL;
 	}
 
-	rc = cam_ife_csid_get_rdi_format(path_data->decode_fmt,
-		path_data->output_fmt, &path_format, &plain_fmt);
+	rc = cam_ife_csid_get_format_rdi(path_data->in_format,
+		path_data->out_format, &path_format, &plain_fmt);
 	if (rc)
 		return rc;
 
@@ -1536,6 +1627,18 @@ static int cam_ife_csid_init_config_rdi_path(
 	val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 		csid_reg->rdi_reg[id]->csid_rdi_cfg0_addr);
 	val |= (1 << csid_reg->cmn_reg->path_en_shift_val);
+#if MEASURE_EN
+	val |= 0x2;
+	cam_io_w_mb(0x3, soc_info->reg_map[0].mem_base +
+		csid_reg->rdi_reg[id]->csid_rdi_format_measure_cfg0_addr);
+	cam_io_w_mb(path_data->height << 16 | path_data->width,
+		soc_info->reg_map[0].mem_base +
+		csid_reg->rdi_reg[id]->csid_rdi_format_measure_cfg1_addr);
+	CAM_DBG(CAM_ISP, "measure_cfg1 0x%x offset 0x%x\n",
+		path_data->height << 16 | path_data->width,
+		csid_reg->rdi_reg[id]->csid_rdi_format_measure_cfg0_addr);
+
+#endif
 	cam_io_w_mb(val, soc_info->reg_map[0].mem_base +
 		csid_reg->rdi_reg[id]->csid_rdi_cfg0_addr);
 
@@ -1605,7 +1708,11 @@ static int cam_ife_csid_enable_rdi_path(
 			csid_reg->rdi_reg[id]->csid_rdi_ctrl_addr);
 
 	/* Enable the required RDI interrupts */
-	val = CSID_PATH_INFO_RST_DONE | CSID_PATH_ERROR_FIFO_OVERFLOW;
+	val = CSID_PATH_INFO_RST_DONE |
+#if MEASURE_EN
+		CSID_PATH_INFO_INPUT_SOF |
+#endif
+		CSID_PATH_ERROR_FIFO_OVERFLOW;
 	cam_io_w_mb(val, soc_info->reg_map[0].mem_base +
 		csid_reg->rdi_reg[id]->csid_rdi_irq_mask_addr);
 
@@ -2298,6 +2405,9 @@ irqreturn_t cam_ife_csid_irq(int irq_num, void *data)
 	struct cam_ife_csid_reg_offset  *csid_reg;
 	uint32_t i, irq_status_top, irq_status_rx, irq_status_ipp = 0,
 		irq_status_rdi[4];
+#if MEASURE_EN
+	uint32_t val;
+#endif
 
 	csid_hw = (struct cam_ife_csid_hw *)data;
 
@@ -2428,8 +2538,15 @@ irqreturn_t cam_ife_csid_irq(int irq_num, void *data)
 			complete(&csid_hw->csid_rdin_complete[i]);
 		}
 
-		if (irq_status_rdi[i]  & CSID_PATH_INFO_INPUT_SOF)
+		if (irq_status_rdi[i]  & CSID_PATH_INFO_INPUT_SOF) {
 			CAM_DBG(CAM_ISP, "CSID RDI SOF received");
+#if MEASURE_EN
+			val = cam_io_r(soc_info->reg_map[0].mem_base +
+				csid_reg->rdi_reg[i]->
+				csid_rdi_format_measure0_addr);
+			CAM_ERR(CAM_ISP, "measure 0x%x\n", val);
+#endif
+		}
 		if (irq_status_rdi[i]  & CSID_PATH_INFO_INPUT_EOF)
 			CAM_DBG(CAM_ISP, "CSID RDI EOF received");
 
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.h b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.h
index ef585c3..d5f032f 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.h
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_core.h
@@ -320,14 +320,14 @@ struct cam_ife_csid_csi2_rx_cfg  {
  * @width:            width
  * @height:           height
  * @test_pattern :    pattern
- * @decode_format:    decode format
+ * @in_format:        decode format
  *
  */
 struct cam_ife_csid_tpg_cfg  {
 	uint32_t                        width;
 	uint32_t                        height;
 	uint32_t                        test_pattern;
-	uint32_t                        decode_fmt;
+	uint32_t                        in_format;
 };
 
 /**
@@ -353,8 +353,8 @@ struct cam_ife_csid_cid_data {
  * @vc :            Virtual channel number
  * @dt :            Data type number
  * @cid             cid number, it is same as DT_ID number in HW
- * @decode_fmt:     input decode format
- * @output_fmt:     output resource format, needed for RDI resource
+ * @in_format:      input decode format
+ * @out_format:     output format
  * @crop_enable:    crop is enable or disabled, if enabled
  *                  then remaining parameters are valid.
  * @start_pixel:    start pixel
@@ -373,8 +373,8 @@ struct cam_ife_csid_path_cfg {
 	uint32_t                        vc;
 	uint32_t                        dt;
 	uint32_t                        cid;
-	uint32_t                        decode_fmt;
-	uint32_t                        output_fmt;
+	uint32_t                        in_format;
+	uint32_t                        out_format;
 	bool                            crop_enable;
 	uint32_t                        start_pixel;
 	uint32_t                        width;
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/include/cam_ife_csid_hw_intf.h b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/include/cam_ife_csid_hw_intf.h
index 52b712a..a70707a 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/include/cam_ife_csid_hw_intf.h
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/include/cam_ife_csid_hw_intf.h
@@ -10,8 +10,8 @@
  * GNU General Public License for more details.
  */
 
-#ifndef __CAM_CSID_HW_INTF_H__
-#define __CAM_CSID_HW_INTF_H__
+#ifndef _CAM_CSID_HW_INTF_H_
+#define _CAM_CSID_HW_INTF_H_
 
 #include "cam_isp_hw.h"
 #include "cam_hw_intf.h"
@@ -19,7 +19,6 @@
 /* MAX IFE CSID instance */
 #define CAM_IFE_CSID_HW_NUM_MAX                        4
 
-
 /**
  * enum cam_ife_pix_path_res_id - Specify the csid patch
  */
@@ -43,7 +42,6 @@ enum cam_ife_cid_res_id {
 	CAM_IFE_CSID_CID_MAX,
 };
 
-
 /**
  * struct cam_ife_csid_hw_caps- get the CSID hw capability
  * @no_rdis :       number of rdis supported by CSID HW device
@@ -61,7 +59,6 @@ struct cam_ife_csid_hw_caps {
 	uint32_t      version_incr;
 };
 
-
 /**
  * struct cam_csid_hw_reserve_resource- hw reserve
  * @res_type :  reource type CID or PATH
@@ -89,10 +86,8 @@ struct cam_csid_hw_reserve_resource_args {
 	uint32_t                                  master_idx;
 	uint32_t                                  cid;
 	struct cam_isp_resource_node             *node_res;
-
 };
 
-
 /**
  *  enum cam_ife_csid_halt_cmd - Specify the halt command type
  */
@@ -170,4 +165,4 @@ enum cam_ife_csid_cmd_type {
 int cam_ife_csid_hw_init(struct cam_hw_intf **ife_csid_hw,
 	uint32_t hw_idx);
 
-#endif /* __CAM_CSID_HW_INTF_H__ */
+#endif /* _CAM_CSID_HW_INTF_H_ */
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c
index b7db7b3..89db01d 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c
@@ -350,7 +350,11 @@ int cam_vfe_irq_top_half(uint32_t    evt_id,
 	 *  will block everything.
 	 */
 	if (evt_payload->irq_reg_val[1]) {
-		CAM_ERR(CAM_ISP, "Mask all the interrupts");
+		CAM_ERR(CAM_ISP,
+			"Encountered Error Irq_status1=0x%x. Stopping further IRQ processing from this HW",
+			evt_payload->irq_reg_val[1]);
+		CAM_ERR(CAM_ISP, "Violation status = %x",
+			evt_payload->irq_reg_val[2]);
 		cam_io_w(0, handler_priv->mem_base + 0x60);
 		cam_io_w(0, handler_priv->mem_base + 0x5C);
 
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe170/cam_vfe170.h b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe170/cam_vfe170.h
index da96cac..dea906e 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe170/cam_vfe170.h
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe170/cam_vfe170.h
@@ -49,6 +49,7 @@ static struct cam_vfe_camif_ver2_reg vfe170_camif_reg = {
 	.epoch_irq                = 0x000004A0,
 	.raw_crop_width_cfg       = 0x00000CE4,
 	.raw_crop_height_cfg      = 0x00000CE8,
+	.reg_update_cmd           = 0x000004AC,
 };
 
 static struct cam_vfe_camif_reg_data vfe_170_camif_reg_data = {
@@ -66,7 +67,8 @@ static struct cam_vfe_camif_reg_data vfe_170_camif_reg_data = {
 	.extern_reg_update_mask          = 1,
 	.pixel_pattern_shift             = 0,
 	.pixel_pattern_mask              = 0x7,
-	.epoch_line_cfg                  = 0x140000,
+	.reg_update_cmd_data             = 0x1,
+	.epoch_line_cfg                  = 0x00140014,
 	.sof_irq_mask                    = 0x00000001,
 	.epoch0_irq_mask                 = 0x00000004,
 	.reg_update_irq_mask             = 0x00000010,
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c
index b1aaafb..1fbc105 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c
@@ -13,6 +13,7 @@
 #include <linux/ratelimit.h>
 #include <linux/slab.h>
 #include "cam_io_util.h"
+#include "cam_debug_util.h"
 #include "cam_cdm_util.h"
 #include "cam_hw_intf.h"
 #include "cam_ife_hw_mgr.h"
@@ -103,7 +104,6 @@ struct cam_vfe_bus_ver2_wm_resource_data {
 	enum cam_vfe_bus_packer_format pack_fmt;
 
 	uint32_t             burst_len;
-	uint32_t             frame_based;
 
 	uint32_t             en_ubwc;
 	uint32_t             packer_cfg;
@@ -360,7 +360,6 @@ static int cam_vfe_bus_get_num_wm(
 		case CAM_FORMAT_DPCM_14_8_14:
 		case CAM_FORMAT_DPCM_14_10_14:
 		case CAM_FORMAT_PLAIN8:
-		case CAM_FORMAT_PLAIN16_8:
 		case CAM_FORMAT_PLAIN16_10:
 		case CAM_FORMAT_PLAIN16_12:
 		case CAM_FORMAT_PLAIN16_14:
@@ -724,14 +723,72 @@ static int cam_vfe_bus_acquire_wm(
 
 	rsrc_data->width = out_port_info->width;
 	rsrc_data->height = out_port_info->height;
+	CAM_DBG(CAM_ISP, "WM %d width %d height %d", rsrc_data->index,
+		rsrc_data->width, rsrc_data->height);
 
 	if (rsrc_data->index < 3) {
 		/* Write master 0-2 refers to RDI 0/ RDI 1/RDI 2 */
-		rsrc_data->width = CAM_VFE_RDI_BUS_DEFAULT_WIDTH;
-		rsrc_data->height = 0;
-		rsrc_data->stride = CAM_VFE_RDI_BUS_DEFAULT_STRIDE;
-		rsrc_data->pack_fmt = 0x0;
-		rsrc_data->en_cfg = 0x3;
+		switch (rsrc_data->format) {
+		case CAM_FORMAT_MIPI_RAW_6:
+		case CAM_FORMAT_MIPI_RAW_8:
+		case CAM_FORMAT_MIPI_RAW_10:
+		case CAM_FORMAT_MIPI_RAW_12:
+		case CAM_FORMAT_MIPI_RAW_14:
+		case CAM_FORMAT_MIPI_RAW_16:
+		case CAM_FORMAT_MIPI_RAW_20:
+			rsrc_data->width = CAM_VFE_RDI_BUS_DEFAULT_WIDTH;
+			rsrc_data->height = 0;
+			rsrc_data->stride = CAM_VFE_RDI_BUS_DEFAULT_STRIDE;
+			rsrc_data->pack_fmt = 0x0;
+			rsrc_data->en_cfg = 0x3;
+			break;
+		case CAM_FORMAT_PLAIN8:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x1;
+			rsrc_data->width = rsrc_data->width * 2;
+			rsrc_data->stride = rsrc_data->width;
+			break;
+		case CAM_FORMAT_PLAIN16_10:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x2;
+			rsrc_data->width = rsrc_data->width * 2;
+			rsrc_data->stride = rsrc_data->width;
+			break;
+		case CAM_FORMAT_PLAIN16_12:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x3;
+			rsrc_data->width = rsrc_data->width * 2;
+			rsrc_data->stride = rsrc_data->width;
+			break;
+		case CAM_FORMAT_PLAIN16_14:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x4;
+			rsrc_data->width = rsrc_data->width * 2;
+			rsrc_data->stride = rsrc_data->width;
+			break;
+		case CAM_FORMAT_PLAIN16_16:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x5;
+			rsrc_data->width = rsrc_data->width * 2;
+			rsrc_data->stride = rsrc_data->width;
+			break;
+		case CAM_FORMAT_PLAIN32_20:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x9;
+			break;
+		case CAM_FORMAT_PLAIN64:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0xA;
+			break;
+		case CAM_FORMAT_PLAIN128:
+			rsrc_data->en_cfg = 0x1;
+			rsrc_data->pack_fmt = 0x0;
+			break;
+		default:
+			CAM_ERR(CAM_ISP, "Unsupported RDI format %d",
+				rsrc_data->format);
+			return -EINVAL;
+		}
 	} else if (rsrc_data->index < 5 ||
 		rsrc_data->index == 7 || rsrc_data->index == 8) {
 		/* Write master 3, 4 - for Full OUT , 7-8  FD OUT */
@@ -813,9 +870,6 @@ static int cam_vfe_bus_acquire_wm(
 		rsrc_data->height = rsrc_data->height / 2;
 		rsrc_data->en_cfg = 0x1;
 	}
-	if (vfe_out_res_id >= CAM_ISP_IFE_OUT_RES_RDI_0 &&
-		vfe_out_res_id <= CAM_ISP_IFE_OUT_RES_RDI_3)
-		rsrc_data->frame_based = 1;
 
 	*client_done_mask = (1 << wm_idx);
 	*wm_res = wm_res_local;
@@ -837,7 +891,6 @@ static int cam_vfe_bus_release_wm(void   *bus_priv,
 	rsrc_data->format = 0;
 	rsrc_data->pack_fmt = 0;
 	rsrc_data->burst_len = 0;
-	rsrc_data->frame_based = 0;
 	rsrc_data->irq_subsample_period = 0;
 	rsrc_data->irq_subsample_pattern = 0;
 	rsrc_data->framedrop_period = 0;
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.c
index 1d15b5b..f255691 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.c
@@ -14,11 +14,13 @@
 #include <uapi/media/cam_isp.h>
 #include "cam_io_util.h"
 #include "cam_isp_hw_mgr_intf.h"
+#include "cam_isp_hw.h"
 #include "cam_vfe_hw_intf.h"
 #include "cam_vfe_top.h"
 #include "cam_vfe_top_ver2.h"
 #include "cam_vfe_camif_ver2.h"
 #include "cam_debug_util.h"
+#include "cam_cdm_util.h"
 
 struct cam_vfe_mux_camif_data {
 	void __iomem                                *mem_base;
@@ -58,6 +60,55 @@ static int cam_vfe_camif_validate_pix_pattern(uint32_t pattern)
 	return rc;
 }
 
+static int cam_vfe_camif_get_reg_update(
+	struct cam_isp_resource_node  *camif_res,
+	void *cmd_args, uint32_t arg_size)
+{
+	uint32_t                          size = 0;
+	uint32_t                          reg_val_pair[2];
+	struct cam_isp_hw_get_cdm_args   *cdm_args = cmd_args;
+	struct cam_cdm_utils_ops         *cdm_util_ops = NULL;
+	struct cam_vfe_mux_camif_data    *rsrc_data = NULL;
+
+	if (arg_size != sizeof(struct cam_isp_hw_get_cdm_args)) {
+		CAM_ERR(CAM_ISP, "Invalid cmd size");
+		return -EINVAL;
+	}
+
+	if (!cdm_args || !cdm_args->res) {
+		CAM_ERR(CAM_ISP, "Invalid args");
+		return -EINVAL;
+	}
+
+	cdm_util_ops = (struct cam_cdm_utils_ops *)cdm_args->res->cdm_ops;
+
+	if (!cdm_util_ops) {
+		CAM_ERR(CAM_ISP, "Invalid CDM ops");
+		return -EINVAL;
+	}
+
+	size = cdm_util_ops->cdm_required_size_reg_random(1);
+	/* since cdm returns dwords, we need to convert it into bytes */
+	if ((size * 4) > cdm_args->size) {
+		CAM_ERR(CAM_ISP, "buf size:%d is not sufficient, expected: %d",
+			cdm_args->size, size);
+		return -EINVAL;
+	}
+
+	rsrc_data = camif_res->res_priv;
+	reg_val_pair[0] = rsrc_data->camif_reg->reg_update_cmd;
+	reg_val_pair[1] = rsrc_data->reg_data->reg_update_cmd_data;
+	CAM_DBG(CAM_ISP, "CAMIF reg_update_cmd %x offset %x",
+		reg_val_pair[1], reg_val_pair[0]);
+
+	cdm_util_ops->cdm_write_regrandom(cdm_args->cmd_buf_addr,
+		1, reg_val_pair);
+
+	cdm_args->used_bytes = size * 4;
+
+	return 0;
+}
+
 int cam_vfe_camif_ver2_acquire_resource(
 	struct cam_isp_resource_node  *camif_res,
 	void                          *acquire_param)
@@ -117,15 +168,16 @@ static int cam_vfe_camif_resource_start(
 			rsrc_data->camif_reg->pixel_skip_pattern);
 
 	/* epoch config with 20 line */
-	cam_io_w_mb(0x00140014,
+	cam_io_w_mb(rsrc_data->reg_data->epoch_line_cfg,
 		rsrc_data->mem_base + rsrc_data->camif_reg->epoch_irq);
 
 	camif_res->res_state = CAM_ISP_RESOURCE_STATE_STREAMING;
 
 	/* Reg Update */
-	cam_io_w_mb(0x1, rsrc_data->mem_base + 0x4AC);
+	cam_io_w_mb(rsrc_data->reg_data->reg_update_cmd_data,
+		rsrc_data->mem_base + rsrc_data->camif_reg->reg_update_cmd);
 
-	CAM_DBG(CAM_ISP, "Exit");
+	CAM_DBG(CAM_ISP, "Start Camif IFE %d Done", camif_res->hw_intf->hw_idx);
 	return 0;
 }
 
@@ -155,10 +207,28 @@ static int cam_vfe_camif_resource_stop(
 	return rc;
 }
 
-int cam_vfe_camif_process_cmd(void *priv,
+static int cam_vfe_camif_process_cmd(struct cam_isp_resource_node *rsrc_node,
 	uint32_t cmd_type, void *cmd_args, uint32_t arg_size)
 {
-	return -EPERM;
+	int rc = -EINVAL;
+
+	if (!rsrc_node || !cmd_args) {
+		CAM_ERR(CAM_ISP, "Invalid input arguments");
+		return -EINVAL;
+	}
+
+	switch (cmd_type) {
+	case CAM_VFE_HW_CMD_GET_REG_UPDATE:
+		rc = cam_vfe_camif_get_reg_update(rsrc_node, cmd_args,
+			arg_size);
+		break;
+	default:
+		CAM_ERR(CAM_ISP,
+			"unsupported process command:%d", cmd_type);
+		break;
+	}
+
+	return rc;
 }
 
 static int cam_vfe_camif_handle_irq_top_half(uint32_t evt_id,
@@ -247,6 +317,7 @@ int cam_vfe_camif_ver2_init(
 
 	camif_node->start = cam_vfe_camif_resource_start;
 	camif_node->stop  = cam_vfe_camif_resource_stop;
+	camif_node->process_cmd = cam_vfe_camif_process_cmd;
 	camif_node->top_half_handler = cam_vfe_camif_handle_irq_top_half;
 	camif_node->bottom_half_handler = cam_vfe_camif_handle_irq_bottom_half;
 
@@ -260,6 +331,7 @@ int cam_vfe_camif_ver2_deinit(
 
 	camif_node->start = NULL;
 	camif_node->stop  = NULL;
+	camif_node->process_cmd = NULL;
 	camif_node->top_half_handler = NULL;
 	camif_node->bottom_half_handler = NULL;
 
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.h b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.h
index 485389a..847b7d5 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.h
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_camif_ver2.h
@@ -50,6 +50,7 @@ struct cam_vfe_camif_reg_data {
 	uint32_t     pixel_pattern_shift;
 	uint32_t     pixel_pattern_mask;
 
+	uint32_t     reg_update_cmd_data;
 	uint32_t     epoch_line_cfg;
 	uint32_t     sof_irq_mask;
 	uint32_t     epoch0_irq_mask;
@@ -67,9 +68,6 @@ int cam_vfe_camif_ver2_acquire_resource(
 	struct cam_isp_resource_node  *camif_res,
 	void                          *acquire_param);
 
-int cam_vfe_camif_process_cmd(void *priv,
-	uint32_t cmd_type, void *cmd_args, uint32_t arg_size);
-
 int cam_vfe_camif_ver2_init(
 	struct cam_hw_intf            *hw_intf,
 	struct cam_hw_soc_info        *soc_info,
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.c
index df7b0f9..461e3c3 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.c
@@ -13,9 +13,11 @@
 #include <linux/slab.h>
 #include "cam_vfe_rdi.h"
 #include "cam_isp_hw_mgr_intf.h"
+#include "cam_isp_hw.h"
 #include "cam_vfe_hw_intf.h"
 #include "cam_io_util.h"
 #include "cam_debug_util.h"
+#include "cam_cdm_util.h"
 
 struct cam_vfe_mux_rdi_data {
 	void __iomem                                *mem_base;
@@ -27,6 +29,54 @@ struct cam_vfe_mux_rdi_data {
 	enum cam_isp_hw_sync_mode          sync_mode;
 };
 
+static int cam_vfe_rdi_get_reg_update(
+	struct cam_isp_resource_node  *rdi_res,
+	void *cmd_args, uint32_t arg_size)
+{
+	uint32_t                          size = 0;
+	uint32_t                          reg_val_pair[2];
+	struct cam_isp_hw_get_cdm_args   *cdm_args = cmd_args;
+	struct cam_cdm_utils_ops         *cdm_util_ops = NULL;
+	struct cam_vfe_mux_rdi_data      *rsrc_data = NULL;
+
+	if (arg_size != sizeof(struct cam_isp_hw_get_cdm_args)) {
+		CAM_ERR(CAM_ISP, "Error - Invalid cmd size");
+		return -EINVAL;
+	}
+
+	if (!cdm_args || !cdm_args->res) {
+		CAM_ERR(CAM_ISP, "Error - Invalid args");
+		return -EINVAL;
+	}
+
+	cdm_util_ops = (struct cam_cdm_utils_ops *)cdm_args->res->cdm_ops;
+	if (!cdm_util_ops) {
+		CAM_ERR(CAM_ISP, "Error - Invalid CDM ops");
+		return -EINVAL;
+	}
+
+	size = cdm_util_ops->cdm_required_size_reg_random(1);
+	/* since cdm returns dwords, we need to convert it into bytes */
+	if ((size * 4) > cdm_args->size) {
+		CAM_ERR(CAM_ISP,
+			"Error - buf size:%d is not sufficient, expected: %d",
+			cdm_args->size, size * 4);
+		return -EINVAL;
+	}
+
+	rsrc_data = rdi_res->res_priv;
+	reg_val_pair[0] = rsrc_data->rdi_reg->reg_update_cmd;
+	reg_val_pair[1] = rsrc_data->reg_data->reg_update_cmd_data;
+	CAM_DBG(CAM_ISP, "Error - RDI%d reg_update_cmd %x",
+		rdi_res->res_id - CAM_ISP_HW_VFE_IN_RDI0, reg_val_pair[1]);
+
+	cdm_util_ops->cdm_write_regrandom(cdm_args->cmd_buf_addr,
+		1, reg_val_pair);
+	cdm_args->used_bytes = size * 4;
+
+	return 0;
+}
+
 int cam_vfe_rdi_ver2_acquire_resource(
 	struct cam_isp_resource_node  *rdi_res,
 	void                          *acquire_param)
@@ -63,9 +113,11 @@ static int cam_vfe_rdi_resource_start(
 	rdi_res->res_state = CAM_ISP_RESOURCE_STATE_STREAMING;
 
 	/* Reg Update */
-	cam_io_w_mb(0x2, rsrc_data->mem_base + 0x4AC);
+	cam_io_w_mb(rsrc_data->reg_data->reg_update_cmd_data,
+		rsrc_data->mem_base + rsrc_data->rdi_reg->reg_update_cmd);
 
-	CAM_DBG(CAM_ISP, "Exit");
+	CAM_DBG(CAM_ISP, "Start RDI %d",
+		rdi_res->res_id - CAM_ISP_HW_VFE_IN_RDI0);
 
 	return rc;
 }
@@ -95,17 +147,21 @@ static int cam_vfe_rdi_resource_stop(
 	return rc;
 }
 
-int cam_vfe_rdi_process_cmd(void *priv,
+static int cam_vfe_rdi_process_cmd(struct cam_isp_resource_node *rsrc_node,
 	uint32_t cmd_type, void *cmd_args, uint32_t arg_size)
 {
 	int rc = -EINVAL;
 
-	if (!priv || !cmd_args) {
+	if (!rsrc_node || !cmd_args) {
 		CAM_ERR(CAM_ISP, "Error! Invalid input arguments");
 		return -EINVAL;
 	}
 
 	switch (cmd_type) {
+	case CAM_VFE_HW_CMD_GET_REG_UPDATE:
+		rc = cam_vfe_rdi_get_reg_update(rsrc_node, cmd_args,
+			arg_size);
+		break;
 	default:
 		CAM_ERR(CAM_ISP,
 			"unsupported RDI process command:%d", cmd_type);
@@ -211,6 +267,7 @@ int cam_vfe_rdi_ver2_init(
 
 	rdi_node->start = cam_vfe_rdi_resource_start;
 	rdi_node->stop  = cam_vfe_rdi_resource_stop;
+	rdi_node->process_cmd = cam_vfe_rdi_process_cmd;
 	rdi_node->top_half_handler = cam_vfe_rdi_handle_irq_top_half;
 	rdi_node->bottom_half_handler = cam_vfe_rdi_handle_irq_bottom_half;
 
@@ -227,6 +284,7 @@ int cam_vfe_rdi_ver2_deinit(
 
 	rdi_node->start = NULL;
 	rdi_node->stop  = NULL;
+	rdi_node->process_cmd = NULL;
 	rdi_node->top_half_handler = NULL;
 	rdi_node->bottom_half_handler = NULL;
 
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.h b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.h
index 04e4f02..32a67c4 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.h
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_rdi.h
@@ -38,9 +38,6 @@ int cam_vfe_rdi_ver2_acquire_resource(
 	struct cam_isp_resource_node  *rdi_res,
 	void                          *acquire_param);
 
-int cam_vfe_rdi_process_cmd(void *priv,
-	uint32_t cmd_type, void *cmd_args, uint32_t arg_size);
-
 int cam_vfe_rdi_ver2_init(
 	struct cam_hw_intf            *hw_intf,
 	struct cam_hw_soc_info        *soc_info,
diff --git a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver2.c b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver2.c
index 1a3eeae..f87953d 100644
--- a/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver2.c
+++ b/drivers/media/platform/msm/camera/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver2.c
@@ -80,53 +80,13 @@ static int cam_vfe_top_mux_get_reg_update(
 	struct cam_vfe_top_ver2_priv *top_priv,
 	void *cmd_args, uint32_t arg_size)
 {
-	uint32_t                          size = 0;
-	uint32_t                          reg_val_pair[2];
 	struct cam_isp_hw_get_cdm_args   *cdm_args = cmd_args;
-	struct cam_cdm_utils_ops         *cdm_util_ops = NULL;
 
-	if (arg_size != sizeof(struct cam_isp_hw_get_cdm_args)) {
-		CAM_ERR(CAM_ISP, "Error! Invalid cmd size");
-		return -EINVAL;
-	}
+	if (cdm_args->res->process_cmd)
+		return cdm_args->res->process_cmd(cdm_args->res,
+			CAM_VFE_HW_CMD_GET_REG_UPDATE, cmd_args, arg_size);
 
-	if (!cdm_args || !cdm_args->res) {
-		CAM_ERR(CAM_ISP, "Error! Invalid args");
-		return -EINVAL;
-	}
-
-	cdm_util_ops = (struct cam_cdm_utils_ops *)cdm_args->res->cdm_ops;
-
-	if (!cdm_util_ops) {
-		CAM_ERR(CAM_ISP, "Error! Invalid CDM ops");
-		return -EINVAL;
-	}
-
-	size = cdm_util_ops->cdm_required_size_reg_random(1);
-	/* since cdm returns dwords, we need to convert it into bytes */
-	if ((size * 4) > cdm_args->size) {
-		CAM_ERR(CAM_ISP, "buf size:%d is not sufficient, expected: %d",
-			cdm_args->size, size);
-		return -EINVAL;
-	}
-
-	reg_val_pair[0] = top_priv->common_data.common_reg->reg_update_cmd;
-
-	if (cdm_args->res->res_id == CAM_ISP_HW_VFE_IN_CAMIF)
-		reg_val_pair[1] = BIT(0);
-	else {
-		uint32_t rdi_num = cdm_args->res->res_id -
-			CAM_ISP_HW_VFE_IN_RDI0;
-		/* RDI reg_update starts at BIT 1, so add 1 */
-		reg_val_pair[1] = BIT(rdi_num + 1);
-	}
-
-	cdm_util_ops->cdm_write_regrandom(cdm_args->cmd_buf_addr,
-		1, reg_val_pair);
-
-	cdm_args->used_bytes = size * 4;
-
-	return 0;
+	return -EINVAL;
 }
 
 int cam_vfe_top_get_hw_caps(void *device_priv,
@@ -257,12 +217,8 @@ int cam_vfe_top_start(void *device_priv,
 	top_priv = (struct cam_vfe_top_ver2_priv   *)device_priv;
 	mux_res = (struct cam_isp_resource_node *)start_args;
 
-	if (mux_res->res_id == CAM_ISP_HW_VFE_IN_CAMIF) {
+	if (mux_res->start) {
 		rc = mux_res->start(mux_res);
-	} else if (mux_res->res_id >= CAM_ISP_HW_VFE_IN_RDI0 &&
-		mux_res->res_id <= CAM_ISP_HW_VFE_IN_RDI3) {
-		mux_res->res_state = CAM_ISP_RESOURCE_STATE_STREAMING;
-		rc = 0;
 	} else {
 		CAM_ERR(CAM_ISP, "Invalid res id:%d", mux_res->res_id);
 		rc = -EINVAL;