msm: sde: Update v4l2 rotator driver to latest v4l2 framework

This patch upgrades v4l2 rotator driver to be compatible with the
latest v4l2 framework.

CRs-Fixed: 972831

Change-Id: Iddbaaceaeba6cee5c7935077f4a92a0361fa8c75
Signed-off-by: Alan Kwong <akwong@codeaurora.org>
diff --git a/drivers/media/platform/msm/sde/Kconfig b/drivers/media/platform/msm/sde/Kconfig
index 3795972..fcd461b 100644
--- a/drivers/media/platform/msm/sde/Kconfig
+++ b/drivers/media/platform/msm/sde/Kconfig
@@ -1,6 +1,6 @@
 config MSM_SDE_ROTATOR
 	bool "QTI V4L2 based SDE Rotator"
-	depends on ARCH_MSM && VIDEO_V4L2
+	depends on ARCH_QCOM && VIDEO_V4L2
 	select V4L2_MEM2MEM_DEV
 	select VIDEOBUF2_CORE
 	select SW_SYNC if SYNC
diff --git a/drivers/media/platform/msm/sde/rotator/Makefile b/drivers/media/platform/msm/sde/rotator/Makefile
index 8793b1e..4c3ec132 100644
--- a/drivers/media/platform/msm/sde/rotator/Makefile
+++ b/drivers/media/platform/msm/sde/rotator/Makefile
@@ -1,4 +1,4 @@
-ccflags-y += -I$(src)
+ccflags-y += -I$(src) -Idrivers/staging/android
 
 obj-y := \
 		sde_rotator_dev.o \
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_core.c b/drivers/media/platform/msm/sde/rotator/sde_rotator_core.c
index c2d586d..f52e145 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_core.c
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_core.c
@@ -2345,7 +2345,7 @@
 	}
 }
 
-#if defined(CONFIG_PM_RUNTIME)
+#if defined(CONFIG_PM)
 /*
  * sde_rotator_runtime_suspend - Turn off power upon runtime suspend event
  * @dev: Pointer to device structure
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_core.h b/drivers/media/platform/msm/sde/rotator/sde_rotator_core.h
index 0aee4f7..4d0c5e2 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_core.h
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_core.h
@@ -390,7 +390,7 @@
 	mutex_unlock(&mgr->lock);
 }
 
-#if defined(CONFIG_PM_RUNTIME)
+#if defined(CONFIG_PM)
 int sde_rotator_runtime_resume(struct device *dev);
 int sde_rotator_runtime_suspend(struct device *dev);
 int sde_rotator_runtime_idle(struct device *dev);
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.c b/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.c
index 5183a7b..ef3194a 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.c
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.c
@@ -24,7 +24,7 @@
 #include <linux/of.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-event.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-mem2mem.h>
 
 #include "sde_rotator_base.h"
@@ -338,7 +338,7 @@
 	item->session_id = ctx->session_id;
 	item->sequence_id = 0;
 	/* assign high/low priority */
-	item->wb_idx = (ctx->priority >= V4L2_PRIORITY_DEFAULT) ? 0 : 1;
+	item->wb_idx = (ctx->fh.prio >= V4L2_PRIORITY_DEFAULT) ? 0 : 1;
 	item->src_rect.x = ctx->crop_out.left;
 	item->src_rect.y = ctx->crop_out.top;
 	item->src_rect.w = ctx->crop_out.width;
@@ -430,18 +430,19 @@
 /*
  * sde_rotator_queue_setup - vb2_ops queue_setup callback.
  * @q: Pointer to vb2 queue struct.
- * @fmt: Pointer to v4l2 format struct (NULL is valid argument).
+ * @parg: Pointer to v4l2 format struct (NULL is valid argument).
  * @num_buffers: Pointer of number of buffers requested.
  * @num_planes: Pointer to number of planes requested.
  * @sizes: Array containing sizes of planes.
  * @alloc_ctxs: Array of allocated contexts for each plane.
  */
 static int sde_rotator_queue_setup(struct vb2_queue *q,
-	const struct v4l2_format *fmt,
+	const void *parg,
 	unsigned int *num_buffers, unsigned int *num_planes,
 	unsigned int sizes[], void *alloc_ctxs[])
 {
 	struct sde_rotator_ctx *ctx = vb2_get_drv_priv(q);
+	const struct v4l2_format *fmt = parg;
 	int i;
 
 	if (!num_buffers)
@@ -500,8 +501,9 @@
 static void sde_rotator_buf_queue(struct vb2_buffer *vb)
 {
 	struct sde_rotator_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-	v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 /*
@@ -523,23 +525,23 @@
 
 	/* return buffers according videobuffer2-core.h */
 	if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-		struct vb2_buffer *buf;
+		struct vb2_v4l2_buffer *buf;
 
-		while ((buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) {
+		while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) {
 			SDEDEV_DBG(rot_dev->dev,
 					"return vb t:%d i:%d\n",
-					buf->v4l2_buf.type,
-					buf->v4l2_buf.index);
+					buf->vb2_buf.type,
+					buf->vb2_buf.index);
 			v4l2_m2m_buf_done(buf, state);
 		}
 	} else if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
-		struct vb2_buffer *buf;
+		struct vb2_v4l2_buffer *buf;
 
-		while ((buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) {
+		while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) {
 			SDEDEV_DBG(rot_dev->dev,
 					"return vb t:%d i:%d\n",
-					buf->v4l2_buf.type,
-					buf->v4l2_buf.index);
+					buf->vb2_buf.type,
+					buf->vb2_buf.index);
 			v4l2_m2m_buf_done(buf, state);
 		}
 	} else {
@@ -667,10 +669,11 @@
  * @alloc_ctx: Contexts allocated in buf_setup.
  * @vaddr: Virtual addr passed from userpsace (in our case ion fd)
  * @size: Size of the buffer
- * @write: True if buffer will be used for writing the data.
+ * @dma_dir: DMA data direction of the given buffer.
  */
 static void *sde_rotator_get_userptr(void *alloc_ctx,
-	unsigned long vaddr, unsigned long size, int write)
+	unsigned long vaddr, unsigned long size,
+	enum dma_data_direction dma_dir)
 {
 	struct sde_rotator_ctx *ctx = alloc_ctx;
 	struct sde_rotator_device *rot_dev = ctx->rot_dev;
@@ -847,7 +850,7 @@
 	SPRINT("rotate=%d\n", ctx->rotate);
 	SPRINT("hflip=%d\n", ctx->hflip);
 	SPRINT("vflip=%d\n", ctx->vflip);
-	SPRINT("priority=%d\n", ctx->priority);
+	SPRINT("priority=%d\n", ctx->fh.prio);
 	SPRINT("secure=%d\n", ctx->secure);
 	SPRINT("timeperframe=%u %u\n", ctx->timeperframe.numerator,
 			ctx->timeperframe.denominator);
@@ -1021,7 +1024,6 @@
 	ctx->hflip = 0;
 	ctx->vflip = 0;
 	ctx->rotate = 0;
-	ctx->priority = V4L2_PRIORITY_DEFAULT;
 	ctx->secure = 0;
 	atomic_set(&ctx->command_pending, 0);
 	ctx->abort_pending = 0;
@@ -1045,10 +1047,10 @@
 	file->private_data = &ctx->fh;
 	v4l2_fh_add(&ctx->fh);
 
-	ctx->m2m_ctx = v4l2_m2m_ctx_init(rot_dev->m2m_dev,
+	ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(rot_dev->m2m_dev,
 		ctx, sde_rotator_queue_init);
-	if (IS_ERR_OR_NULL(ctx->m2m_ctx)) {
-		ret = PTR_ERR(ctx->m2m_ctx);
+	if (IS_ERR_OR_NULL(ctx->fh.m2m_ctx)) {
+		ret = PTR_ERR(ctx->fh.m2m_ctx);
 		goto error_m2m_init;
 	}
 
@@ -1155,8 +1157,8 @@
 	mutex_lock(&rot_dev->lock);
 	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
 	SDEDEV_DBG(rot_dev->dev, "release streams s:%d\n", session_id);
-	v4l2_m2m_streamoff(file, ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
-	v4l2_m2m_streamoff(file, ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+	v4l2_m2m_streamoff(file, ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+	v4l2_m2m_streamoff(file, ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 	mutex_unlock(&rot_dev->lock);
 	SDEDEV_DBG(rot_dev->dev, "release submit work s:%d w:%x\n",
 			session_id, work_busy(&ctx->submit_work));
@@ -1174,7 +1176,7 @@
 	destroy_workqueue(ctx->work_queue.rot_work_queue);
 	sysfs_remove_group(&ctx->kobj, &sde_rotator_fs_attr_group);
 	kobject_put(&ctx->kobj);
-	v4l2_m2m_ctx_release(ctx->m2m_ctx);
+	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 	kfree(ctx->vbinfo_out);
@@ -1199,7 +1201,7 @@
 	int ret;
 
 	mutex_lock(&rot_dev->lock);
-	ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
+	ret = v4l2_m2m_poll(file, ctx->fh.m2m_ctx, wait);
 	mutex_unlock(&rot_dev->lock);
 	return ret;
 }
@@ -1228,8 +1230,9 @@
 	cap->bus_info[0] = 0;
 	strlcpy(cap->driver, SDE_ROTATOR_DRV_NAME, sizeof(cap->driver));
 	strlcpy(cap->card, SDE_ROTATOR_DRV_NAME, sizeof(cap->card));
-	cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M |
-		V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_CAPTURE;
+	cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M |
+			V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_CAPTURE;
+	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
 
 	return 0;
 }
@@ -1481,7 +1484,7 @@
 {
 	struct sde_rotator_ctx *ctx = sde_rotator_ctx_from_fh(fh);
 
-	return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, req);
+	return v4l2_m2m_reqbufs(file, ctx->fh.m2m_ctx, req);
 }
 
 /*
@@ -1521,7 +1524,7 @@
 		ctx->vbinfo_out[idx].dqbuf_ts = NULL;
 	}
 
-	ret = v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
+	ret = v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf);
 	if (ret < 0)
 		SDEDEV_ERR(ctx->rot_dev->dev, "fail qbuf s:%d t:%d r:%d\n",
 				ctx->session_id, buf->type, ret);
@@ -1541,7 +1544,7 @@
 	struct sde_rotator_ctx *ctx = sde_rotator_ctx_from_fh(fh);
 	int ret;
 
-	ret = v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
+	ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf);
 
 	if (ret) {
 		SDEDEV_ERR(ctx->rot_dev->dev,
@@ -1592,7 +1595,7 @@
 {
 	struct sde_rotator_ctx *ctx = sde_rotator_ctx_from_fh(fh);
 
-	return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
+	return v4l2_m2m_querybuf(file, ctx->fh.m2m_ctx, buf);
 }
 
 /*
@@ -1610,7 +1613,7 @@
 	SDEDEV_DBG(ctx->rot_dev->dev, "stream on s:%d t:%d\n",
 			ctx->session_id, buf_type);
 
-	ret = v4l2_m2m_streamon(file, ctx->m2m_ctx, buf_type);
+	ret = v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, buf_type);
 	if (ret < 0)
 		SDEDEV_ERR(ctx->rot_dev->dev, "fail stream on s:%d t:%d\n",
 				ctx->session_id, buf_type);
@@ -1633,7 +1636,7 @@
 	SDEDEV_DBG(ctx->rot_dev->dev, "stream off s:%d t:%d\n",
 			ctx->session_id, buf_type);
 
-	ret = v4l2_m2m_streamoff(file, ctx->m2m_ctx, buf_type);
+	ret = v4l2_m2m_streamoff(file, ctx->fh.m2m_ctx, buf_type);
 	if (ret < 0)
 		SDEDEV_ERR(ctx->rot_dev->dev, "fail stream off s:%d t:%d\n",
 				ctx->session_id, buf_type);
@@ -1845,38 +1848,6 @@
 }
 
 /*
- * sde_rotator_g_priority - Get the priority
- * @file: Pointer to file struct.
- * @fh: V4l2 file handle.
- * @p: Pointer to priority enumeration.
- */
-static int sde_rotator_g_priority(struct file *file, void *fh,
-			    enum v4l2_priority *p)
-{
-	struct sde_rotator_ctx *ctx = sde_rotator_ctx_from_fh(fh);
-
-	if (!p)
-		return -EINVAL;
-	*p = ctx->priority;
-	return 0;
-}
-
-/*
- * sde_rotator_s_priority - Set the priority
- * @file: Pointer to file struct.
- * @fh: V4l2 file handle.
- * @p: Pointer to priority enumeration.
- */
-static int sde_rotator_s_priority(struct file *file, void *fh,
-			    enum v4l2_priority p)
-{
-	struct sde_rotator_ctx *ctx = sde_rotator_ctx_from_fh(fh);
-
-	ctx->priority = p;
-	return 0;
-}
-
-/*
  * sde_rotator_private_ioctl - V4l2 private ioctl handler.
  * @file: Pointer to file struct.
  * @fd: V4l2 device file handle.
@@ -2040,8 +2011,6 @@
 	.vidioc_s_crop            = sde_rotator_s_crop,
 	.vidioc_g_parm            = sde_rotator_g_parm,
 	.vidioc_s_parm            = sde_rotator_s_parm,
-	.vidioc_g_priority	  = sde_rotator_g_priority,
-	.vidioc_s_priority	  = sde_rotator_s_priority,
 	.vidioc_default           = sde_rotator_private_ioctl,
 	.vidioc_log_status        = v4l2_ctrl_log_status,
 	.vidioc_subscribe_event   = v4l2_ctrl_subscribe_event,
@@ -2056,8 +2025,8 @@
  */
 static void sde_rotator_retire_handler(struct work_struct *work)
 {
-	struct vb2_buffer *src_buf;
-	struct vb2_buffer *dst_buf;
+	struct vb2_v4l2_buffer *src_buf;
+	struct vb2_v4l2_buffer *dst_buf;
 	struct sde_rotator_ctx *ctx;
 	struct sde_rotator_device *rot_dev;
 
@@ -2092,11 +2061,11 @@
 		}
 
 		/* pending request. reschedule this context. */
-		v4l2_m2m_try_schedule(ctx->m2m_ctx);
+		v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
 	} else {
 		/* no pending request. acknowledge the usual way. */
-		src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
-		dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
+		src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+		dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
 
 		if (!src_buf || !dst_buf) {
 			SDEDEV_ERR(rot_dev->dev,
@@ -2110,7 +2079,7 @@
 		wake_up(&ctx->wait_queue);
 		v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
 		v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
-		v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->m2m_ctx);
+		v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->fh.m2m_ctx);
 	}
 	mutex_unlock(&rot_dev->lock);
 }
@@ -2150,8 +2119,8 @@
 		goto error_null_buffer;
 	}
 
-	vbinfo_out = &ctx->vbinfo_out[src_buf->v4l2_buf.index];
-	vbinfo_cap = &ctx->vbinfo_cap[dst_buf->v4l2_buf.index];
+	vbinfo_out = &ctx->vbinfo_out[src_buf->index];
+	vbinfo_cap = &ctx->vbinfo_cap[dst_buf->index];
 
 	SDEDEV_DBG(rot_dev->dev,
 		"process buffer s:%d.%u src:(%u,%u,%u,%u) dst:(%u,%u,%u,%u) rot:%d flip:%d/%d sec:%d\n",
@@ -2173,7 +2142,7 @@
 
 	trace_rot_entry_fence(
 		ctx->session_id, vbinfo_cap->fence_ts,
-		ctx->priority,
+		ctx->fh.prio,
 		(ctx->rotate << 0) | (ctx->hflip << 8) |
 			(ctx->hflip << 9) | (ctx->secure << 10),
 		ctx->format_out.fmt.pix.pixelformat,
@@ -2267,8 +2236,8 @@
 {
 	struct sde_rotator_ctx *ctx;
 	struct sde_rotator_device *rot_dev;
-	struct vb2_buffer *src_buf;
-	struct vb2_buffer *dst_buf;
+	struct vb2_v4l2_buffer *src_buf;
+	struct vb2_v4l2_buffer *dst_buf;
 	int ret;
 
 	ctx = container_of(work, struct sde_rotator_ctx, submit_work);
@@ -2293,17 +2262,18 @@
 	}
 
 	/* submit new request */
-	dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
-	src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
+	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
+	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	sde_rot_mgr_lock(rot_dev->mgr);
-	ret = sde_rotator_process_buffers(ctx, src_buf, dst_buf);
+	ret = sde_rotator_process_buffers(ctx, &src_buf->vb2_buf,
+			&dst_buf->vb2_buf);
 	sde_rot_mgr_unlock(rot_dev->mgr);
 	if (ret) {
 		SDEDEV_ERR(rot_dev->dev,
 			"fail process buffer in submit s:%d\n",
 			ctx->session_id);
 		/* advance to device run to clean up buffers */
-		v4l2_m2m_try_schedule(ctx->m2m_ctx);
+		v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
 	}
 
 	mutex_unlock(&rot_dev->lock);
@@ -2317,8 +2287,8 @@
 {
 	struct sde_rotator_ctx *ctx = priv;
 	struct sde_rotator_device *rot_dev;
-	struct vb2_buffer *src_buf;
-	struct vb2_buffer *dst_buf;
+	struct vb2_v4l2_buffer *src_buf;
+	struct vb2_v4l2_buffer *dst_buf;
 	int ret;
 
 	if (!ctx || !ctx->rot_dev) {
@@ -2365,8 +2335,8 @@
 				goto error_process_buffers;
 			}
 
-			src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
-			dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
+			src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+			dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
 			if (!src_buf || !dst_buf) {
 				SDEDEV_ERR(rot_dev->dev,
 					"null buffer in device run s:%d sb:%p db:%p\n",
@@ -2379,7 +2349,7 @@
 			wake_up(&ctx->wait_queue);
 			v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
 			v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
-			v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->m2m_ctx);
+			v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->fh.m2m_ctx);
 		} else {
 			/* pending request not complete. something wrong. */
 			SDEDEV_ERR(rot_dev->dev,
@@ -2399,8 +2369,8 @@
 		/* no pending request. submit buffer the usual way. */
 		atomic_inc(&ctx->command_pending);
 
-		dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
-		src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
+		dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
+		src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 		if (!src_buf || !dst_buf) {
 			SDEDEV_ERR(rot_dev->dev,
 				"null buffer in device run s:%d sb:%p db:%p\n",
@@ -2410,7 +2380,8 @@
 		}
 
 		sde_rot_mgr_lock(rot_dev->mgr);
-		ret = sde_rotator_process_buffers(ctx, src_buf, dst_buf);
+		ret = sde_rotator_process_buffers(ctx, &src_buf->vb2_buf,
+				&dst_buf->vb2_buf);
 		sde_rot_mgr_unlock(rot_dev->mgr);
 		if (ret) {
 			SDEDEV_ERR(rot_dev->dev,
@@ -2428,14 +2399,14 @@
 error_empty_buffer:
 	atomic_dec(&ctx->command_pending);
 	wake_up(&ctx->wait_queue);
-	src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
-	dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
+	src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+	dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
 	if (src_buf)
 		v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
 	if (dst_buf)
 		v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR);
 	sde_rotator_resync_timeline(ctx->work_queue.timeline);
-	v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->m2m_ctx);
+	v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->fh.m2m_ctx);
 }
 
 /*
@@ -2455,7 +2426,7 @@
 	rot_dev = ctx->rot_dev;
 	SDEDEV_DBG(rot_dev->dev, "job abort s:%d\n", ctx->session_id);
 
-	v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->m2m_ctx);
+	v4l2_m2m_job_finish(rot_dev->m2m_dev, ctx->fh.m2m_ctx);
 }
 
 /*
@@ -2490,8 +2461,8 @@
 		SDEDEV_DBG(rot_dev->dev,
 				"submit job s:%d sc:%d dc:%d p:%d\n",
 				ctx->session_id,
-				v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx),
-				v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx),
+				v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx),
+				v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx),
 				atomic_read(&ctx->command_pending));
 		atomic_inc(&ctx->command_pending);
 		queue_work(ctx->work_queue.rot_work_queue, &ctx->submit_work);
@@ -2679,7 +2650,6 @@
 	.resume = sde_rotator_resume,
 	.driver = {
 		.name = SDE_ROTATOR_DRV_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = sde_rotator_dt_match,
 		.pm = &sde_rotator_pm_ops,
 	},
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.h b/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.h
index b3d51a9..a9bbe7a 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.h
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_dev.h
@@ -80,7 +80,6 @@
  * @kobj: kernel object of this context
  * @rot_dev: Pointer to rotator device.
  * @fh: V4l2 file handle.
- * @m2m_ctx: Memory to memory context.
  * @ctrl_handler: control handler
  * @format_cap: Current capture format.
  * @format_out: Current output format.
@@ -91,7 +90,6 @@
  * @hflip: horizontal flip (1-flip)
  * @vflip: vertical flip (1-flip)
  * @rotate: rotation angle (0,90,180,270)
- * @priority: Priority of this context
  * @secure: Non-secure (0) / Secure processing
  * @command_pending: Number of pending transaction in h/w
  * @abort_pending: True if abort is requested for async handling.
@@ -110,7 +108,6 @@
 	struct kobject kobj;
 	struct sde_rotator_device *rot_dev;
 	struct v4l2_fh fh;
-	struct v4l2_m2m_ctx *m2m_ctx;
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_format format_cap;
 	struct v4l2_format format_out;
@@ -121,7 +118,6 @@
 	s32 hflip;
 	s32 vflip;
 	s32 rotate;
-	enum v4l2_priority priority;
 	s32 secure;
 	atomic_t command_pending;
 	int abort_pending;
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_io_util.c b/drivers/media/platform/msm/sde/rotator/sde_rotator_io_util.c
index cd99a92..9f87fdd 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_io_util.c
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_io_util.c
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
+#include <linux/regulator/consumer.h>
 #include <linux/delay.h>
 
 #include "sde_rotator_io_util.h"
@@ -197,7 +198,7 @@
 
 vreg_unconfig:
 if (type == SDE_REG_LDO)
-	regulator_set_optimum_mode(curr_vreg->vreg, 0);
+	regulator_set_load(curr_vreg->vreg, 0);
 
 vreg_set_voltage_fail:
 	regulator_put(curr_vreg->vreg);
@@ -237,7 +238,7 @@
 			if (in_vreg[i].pre_on_sleep && need_sleep)
 				usleep_range(in_vreg[i].pre_on_sleep * 1000,
 					in_vreg[i].pre_on_sleep * 1000);
-			rc = regulator_set_optimum_mode(in_vreg[i].vreg,
+			rc = regulator_set_load(in_vreg[i].vreg,
 				in_vreg[i].enable_load);
 			if (rc < 0) {
 				DEV_ERR("%pS->%s: %s set opt m fail\n",
@@ -261,7 +262,7 @@
 			if (in_vreg[i].pre_off_sleep)
 				usleep_range(in_vreg[i].pre_off_sleep * 1000,
 					in_vreg[i].pre_off_sleep * 1000);
-			regulator_set_optimum_mode(in_vreg[i].vreg,
+			regulator_set_load(in_vreg[i].vreg,
 				in_vreg[i].disable_load);
 			regulator_disable(in_vreg[i].vreg);
 			if (in_vreg[i].post_off_sleep)
@@ -272,14 +273,14 @@
 	return rc;
 
 disable_vreg:
-	regulator_set_optimum_mode(in_vreg[i].vreg, in_vreg[i].disable_load);
+	regulator_set_load(in_vreg[i].vreg, in_vreg[i].disable_load);
 
 vreg_set_opt_mode_fail:
 	for (i--; i >= 0; i--) {
 		if (in_vreg[i].pre_off_sleep)
 			usleep_range(in_vreg[i].pre_off_sleep * 1000,
 				in_vreg[i].pre_off_sleep * 1000);
-		regulator_set_optimum_mode(in_vreg[i].vreg,
+		regulator_set_load(in_vreg[i].vreg,
 			in_vreg[i].disable_load);
 		regulator_disable(in_vreg[i].vreg);
 		if (in_vreg[i].post_off_sleep)
diff --git a/drivers/media/platform/msm/sde/rotator/sde_rotator_sync.c b/drivers/media/platform/msm/sde/rotator/sde_rotator_sync.c
index 2990522..dd8f69c 100644
--- a/drivers/media/platform/msm/sde/rotator/sde_rotator_sync.c
+++ b/drivers/media/platform/msm/sde/rotator/sde_rotator_sync.c
@@ -16,8 +16,8 @@
 #include <linux/fs.h>
 #include <linux/file.h>
 #include <linux/slab.h>
-#include <linux/sync.h>
-#include <linux/sw_sync.h>
+#include <sync.h>
+#include <sw_sync.h>
 
 #include "sde_rotator_util.h"
 #include "sde_rotator_sync.h"