msm: camera: Correct the reserve buffer logic in mctl_pp.

When the daemon asks to reserve a free buffer, get the
correct address by using the image mode to get to the
correct camera instance and populating the buffer address.

Change-Id: I23c6e00458562ef2b9880cbffe2d6a100de80ea1
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
Signed-off-by: Kiran Kumar H N <hurlisal@codeaurora.org>
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
diff --git a/drivers/media/video/msm/msm.c b/drivers/media/video/msm/msm.c
index a9aa28b..682b4fa 100644
--- a/drivers/media/video/msm/msm.c
+++ b/drivers/media/video/msm/msm.c
@@ -1991,7 +1991,6 @@
 				(*((uint32_t *)ev.u.data));
 		/* Copy the event structure into user struct. */
 		u_isp_event = *k_isp_event;
-
 		if (ev.type != (V4L2_EVENT_PRIVATE_START +
 				MSM_CAM_RESP_DIV_FRAME_EVT_MSG) &&
 				ev.type != (V4L2_EVENT_PRIVATE_START +
diff --git a/drivers/media/video/msm/msm_mctl_buf.c b/drivers/media/video/msm/msm_mctl_buf.c
index 7a0cc02..2d25ef0 100644
--- a/drivers/media/video/msm/msm_mctl_buf.c
+++ b/drivers/media/video/msm/msm_mctl_buf.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -431,6 +431,7 @@
 	return 0;
 }
 
+
 int msm_mctl_buf_done(struct msm_cam_media_controller *p_mctl,
 			int msg_type, struct msm_free_buf *fbuf,
 			uint32_t frame_id)
diff --git a/drivers/media/video/msm/msm_mctl_pp.c b/drivers/media/video/msm/msm_mctl_pp.c
index 6a2c8aa..a92668e 100644
--- a/drivers/media/video/msm/msm_mctl_pp.c
+++ b/drivers/media/video/msm/msm_mctl_pp.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -145,6 +145,7 @@
 	p_mctl->pp_info.cur_frame_id[pcam_inst->image_mode] = frame_id;
 	div.frame.frame_id =
 		p_mctl->pp_info.cur_frame_id[pcam_inst->image_mode];
+	div.frame.buf_idx  = buf_idx;
 	div.frame.handle = (uint32_t)vb;
 	msm_mctl_gettimeofday(&div.frame.timestamp);
 	vb->vidbuf.v4l2_buf.timestamp = div.frame.timestamp;
@@ -703,6 +704,9 @@
 	struct msm_cam_evt_divert_frame frame;
 	int msg_type, image_mode, rc = 0;
 	struct msm_free_buf free_buf;
+	int idx;
+	struct msm_cam_v4l2_dev_inst *pcam_inst;
+
 	memset(&free_buf, 0, sizeof(struct msm_free_buf));
 	if (copy_from_user(&frame, arg,
 		sizeof(struct msm_cam_evt_divert_frame)))
@@ -725,10 +729,18 @@
 		rc = -EFAULT;
 		return rc;
 	}
+
+	idx = msm_mctl_out_type_to_inst_index(
+		p_mctl->sync.pcam_sync, msg_type);
+	if (idx < 0) {
+		pr_err("%s Invalid instance. returning\n", __func__);
+		return -EINVAL;
+	}
+	pcam_inst = p_mctl->sync.pcam_sync->dev_inst[idx];
+
 	rc = msm_mctl_reserve_free_buf(p_mctl, msg_type, &free_buf);
 	if (rc == 0) {
-		frame.frame.sp.phy_addr = free_buf.ch_paddr[0];
-		frame.frame.handle = free_buf.vb;
+		msm_mctl_pp_get_phy_addr(pcam_inst, free_buf.vb, &frame.frame);
 		if (copy_to_user((void *)arg,
 				&frame,
 				sizeof(frame))) {
@@ -864,11 +876,13 @@
 	int dirty = 0;
 	struct msm_free_buf buf;
 	unsigned long flags;
+	D("%s enter\n", __func__);
 
 	if (copy_from_user(&frame, arg, sizeof(frame)))
 		return -EFAULT;
 
 	spin_lock_irqsave(&p_mctl->pp_info.lock, flags);
+	D("%s Frame path: %d\n", __func__, frame.path);
 	switch (frame.path) {
 	case OUTPUT_TYPE_P:
 		msg_type = VFE_MSG_OUTPUT_P;
@@ -887,12 +901,14 @@
 		rc = -EFAULT;
 		goto err;
 	}
+
 	if (frame.num_planes > 1)
 		buf.ch_paddr[0] = frame.mp[0].phy_addr;
 	else
 		buf.ch_paddr[0] = frame.sp.phy_addr;
+
 	spin_unlock_irqrestore(&p_mctl->pp_info.lock, flags);
-	/* here buf.addr is phy_addr */
+	D("%s Frame done id: %d\n", __func__, frame.frame_id);
 	rc = msm_mctl_buf_done_pp(p_mctl, msg_type, &buf, dirty);
 	return rc;
 err:
diff --git a/drivers/media/video/videobuf2-msm-mem.c b/drivers/media/video/videobuf2-msm-mem.c
index 37b935b..c12bed3 100644
--- a/drivers/media/video/videobuf2-msm-mem.c
+++ b/drivers/media/video/videobuf2-msm-mem.c
@@ -239,6 +239,7 @@
 	}
 	paddr = mem->msm_buffer->iova[0];
 	mem->mapped_phyaddr = paddr + addr_offset;
+	mem->addr_offset = addr_offset;
 	return rc;
 }
 EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_user_get);
diff --git a/include/media/msm_camera.h b/include/media/msm_camera.h
index d905b22..58129bb 100644
--- a/include/media/msm_camera.h
+++ b/include/media/msm_camera.h
@@ -265,6 +265,7 @@
 struct msm_pp_frame {
 	uint32_t       handle; /* stores vb cookie */
 	uint32_t       frame_id;
+	unsigned short buf_idx;
 	int            path;
 	unsigned short image_type;
 	unsigned short num_planes; /* 1 for sp */
diff --git a/include/media/msm_isp.h b/include/media/msm_isp.h
index dae4a12..12d3220 100644
--- a/include/media/msm_isp.h
+++ b/include/media/msm_isp.h
@@ -201,6 +201,7 @@
 #define VPE_CMD_SCALE_CFG_TYPE                          11
 #define VPE_CMD_DIS_OFFSET_CFG                          12
 #define VPE_CMD_ZOOM                                    13
+#define VPE_CMD_MAX                                     14
 
 #define MSM_PP_CMD_TYPE_NOT_USED        0  /* not used */
 #define MSM_PP_CMD_TYPE_VPE             1  /* VPE cmd */