From 2f7c68cb55ecb7331f2381deb497c27155f32faf Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Wed, 03 Jan 2024 09:43:39 +0000
Subject: [PATCH] update kernel to 5.10.198

---
 kernel/drivers/media/platform/rockchip/ispp/fec.c |  386 ++++++++++++++++++++++++++----------------------------
 1 files changed, 184 insertions(+), 202 deletions(-)

diff --git a/kernel/drivers/media/platform/rockchip/ispp/fec.c b/kernel/drivers/media/platform/rockchip/ispp/fec.c
index e5f14fa..8004f3c 100644
--- a/kernel/drivers/media/platform/rockchip/ispp/fec.c
+++ b/kernel/drivers/media/platform/rockchip/ispp/fec.c
@@ -5,12 +5,12 @@
 #include <linux/delay.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fh.h>
-#include <media/v4l2-mem2mem.h>
 #include <media/v4l2-ioctl.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/videobuf2-v4l2.h>
 #include <linux/pm_runtime.h>
-#include <linux/rkispp-config.h>
+#include <linux/rk-ispp-config.h>
+#include <uapi/linux/rk-video-format.h>
 
 #include "hw.h"
 #include "ispp.h"
@@ -18,24 +18,126 @@
 #include "stream.h"
 #include "common.h"
 
+struct rkispp_fec_buf {
+	struct list_head list;
+	struct file *file;
+	int fd;
+	struct dma_buf *dbuf;
+	void *mem;
+};
+
 static const struct vb2_mem_ops *g_ops = &vb2_dma_contig_memops;
 
-static int fec_running(struct rkispp_fec_dev *fec,
-			struct rkispp_fec_in_out *buf)
+static void *fec_buf_add(struct file *file, int fd, int size)
 {
+	struct rkispp_fec_dev *fec = video_drvdata(file);
+	struct rkispp_fec_buf *buf = NULL;
+	struct dma_buf *dbuf;
+	void *mem = NULL;
+	bool is_add = true;
+
+	dbuf = dma_buf_get(fd);
+	v4l2_dbg(4, rkispp_debug, &fec->v4l2_dev,
+		 "%s file:%p fd:%d dbuf:%p\n", __func__, file, fd, dbuf);
+	if (IS_ERR_OR_NULL(dbuf)) {
+		v4l2_err(&fec->v4l2_dev, "invalid dmabuf fd:%d for in picture", fd);
+		return mem;
+	}
+	if (size && dbuf->size < size) {
+		v4l2_err(&fec->v4l2_dev,
+			 "input fd:%d size error:%zu < %u\n", fd, dbuf->size, size);
+		dma_buf_put(dbuf);
+		return mem;
+	}
+
+	mutex_lock(&fec->hw->dev_lock);
+	list_for_each_entry(buf, &fec->list, list) {
+		if (buf->file == file && buf->fd == fd && buf->dbuf == dbuf) {
+			is_add = false;
+			break;
+		}
+	}
+
+	if (is_add) {
+		mem = g_ops->attach_dmabuf(fec->hw->dev, dbuf, dbuf->size, DMA_BIDIRECTIONAL);
+		if (IS_ERR(mem)) {
+			v4l2_err(&fec->v4l2_dev, "failed to attach dmabuf, fd:%d\n", fd);
+			dma_buf_put(dbuf);
+			goto end;
+		}
+		if (g_ops->map_dmabuf(mem)) {
+			v4l2_err(&fec->v4l2_dev, "failed to map, fd:%d\n", fd);
+			g_ops->detach_dmabuf(mem);
+			dma_buf_put(dbuf);
+			mem = NULL;
+			goto end;
+		}
+		buf = kzalloc(sizeof(struct rkispp_fec_buf), GFP_KERNEL);
+		if (!buf) {
+			g_ops->unmap_dmabuf(mem);
+			g_ops->detach_dmabuf(mem);
+			dma_buf_put(dbuf);
+			mem = NULL;
+			goto end;
+		}
+		buf->fd = fd;
+		buf->file = file;
+		buf->dbuf = dbuf;
+		buf->mem = mem;
+		list_add_tail(&buf->list, &fec->list);
+	} else {
+		dma_buf_put(dbuf);
+		mem = buf->mem;
+	}
+end:
+	mutex_unlock(&fec->hw->dev_lock);
+	return mem;
+}
+
+static void fec_buf_del(struct file *file, int fd, bool is_all)
+{
+	struct rkispp_fec_dev *fec = video_drvdata(file);
+	struct rkispp_fec_buf *buf, *next;
+
+	mutex_lock(&fec->hw->dev_lock);
+	list_for_each_entry_safe(buf, next, &fec->list, list) {
+		if (buf->file == file && (is_all || buf->fd == fd)) {
+			v4l2_dbg(4, rkispp_debug, &fec->v4l2_dev,
+				 "%s file:%p fd:%d dbuf:%p\n",
+				 __func__, file, buf->fd, buf->dbuf);
+			g_ops->unmap_dmabuf(buf->mem);
+			g_ops->detach_dmabuf(buf->mem);
+			dma_buf_put(buf->dbuf);
+			buf->file = NULL;
+			buf->mem = NULL;
+			buf->dbuf = NULL;
+			buf->fd = -1;
+			list_del(&buf->list);
+			kfree(buf);
+		}
+	}
+	mutex_unlock(&fec->hw->dev_lock);
+}
+
+static int fec_running(struct file *file, struct rkispp_fec_in_out *buf)
+{
+	struct rkispp_fec_dev *fec = video_drvdata(file);
 	u32 in_fmt, out_fmt, in_mult = 1, out_mult = 1;
 	u32 in_size, in_offs, out_size, out_offs, val;
-	u32 w = buf->width, h = buf->height, density, mesh_size;
-	struct dma_buf *in_dbuf, *out_dbuf;
-	struct dma_buf *xint_dbuf, *xfra_dbuf, *yint_dbuf, *yfra_dbuf;
-	void *in_mem, *out_mem;
-	void *xint_mem, *xfra_mem, *yint_mem, *yfra_mem;
+	u32 in_w = buf->in_width, in_h = buf->in_height;
+	u32 out_w = buf->out_width, out_h = buf->out_height;
+	u32 density, mesh_size;
 	void __iomem *base = fec->hw->base_addr;
+	void *mem;
 	int ret = -EINVAL;
+	ktime_t t = 0;
+	s64 us = 0;
 
+	if (rkispp_debug)
+		t = ktime_get();
 	v4l2_dbg(3, rkispp_debug, &fec->v4l2_dev,
-		 "%s enter %dx%d format(in:%c%c%c%c out:%c%c%c%c)\n",
-		 __func__, w, h,
+		 "%s enter %dx%d->%dx%d format(in:%c%c%c%c out:%c%c%c%c)\n",
+		 __func__, in_w, in_h, out_w, out_h,
 		 buf->in_fourcc, buf->in_fourcc >> 8,
 		 buf->in_fourcc >> 16, buf->in_fourcc >> 24,
 		 buf->out_fourcc, buf->out_fourcc >> 8,
@@ -45,8 +147,8 @@
 		rkispp_set_clk_rate(fec->hw->clks[0], fec->hw->core_clk_max);
 
 	init_completion(&fec->cmpl);
-	density = w > 1920 ? SW_MESH_DENSITY : 0;
-	mesh_size = cal_fec_mesh(w, h, !!density);
+	density = out_w > 1920 ? SW_MESH_DENSITY : 0;
+	mesh_size = cal_fec_mesh(out_w, out_h, !!density);
 
 	switch (buf->in_fourcc) {
 	case V4L2_PIX_FMT_YUYV:
@@ -68,12 +170,11 @@
 			 "no support in format:%c%c%c%c\n",
 			 buf->in_fourcc, buf->in_fourcc >> 8,
 			 buf->in_fourcc >> 16, buf->in_fourcc >> 24);
-		ret = -EINVAL;
-		goto end;
+		return -EINVAL;
 	}
-	in_offs = w * h;
+	in_offs = in_w * in_h;
 	in_size = (in_fmt & FMT_YUV422) ?
-		w * h * 2 : w * h * 3 / 2;
+		in_w * in_h * 2 : in_w * in_h * 3 / 2;
 
 	switch (buf->out_fourcc) {
 	case V4L2_PIX_FMT_YUYV:
@@ -100,177 +201,75 @@
 		v4l2_err(&fec->v4l2_dev, "no support out format:%c%c%c%c\n",
 			 buf->out_fourcc, buf->out_fourcc >> 8,
 			 buf->out_fourcc >> 16, buf->out_fourcc >> 24);
-		ret = -EINVAL;
-		goto end;
+		return -EINVAL;
 	}
 	out_size = 0;
-	out_offs = w * h;
+	out_offs = out_w * out_h;
 	if (out_fmt & FMT_FBC) {
-		w = ALIGN(w, 16);
-		h = ALIGN(h, 16);
-		out_offs = w * h >> 4;
+		out_w = ALIGN(out_w, 16);
+		out_h = ALIGN(out_h, 16);
+		out_offs = out_w * out_h >> 4;
 		out_size = out_offs;
 	}
 	out_size += (out_fmt & FMT_YUV422) ?
-		w * h * 2 : w * h * 3 / 2;
+		out_w * out_h * 2 : out_w * out_h * 3 / 2;
 
 	/* input picture buf */
-	in_dbuf = dma_buf_get(buf->in_pic_fd);
-	if (IS_ERR_OR_NULL(in_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd:%d for in picture", buf->in_pic_fd);
-		ret = -EINVAL;
-		goto end;
-	}
-	if (in_dbuf->size < in_size) {
-		v4l2_err(&fec->v4l2_dev,
-			 "in picture size error:%zu < %u\n", in_dbuf->size, in_size);
-		goto put_in_dbuf;
-	}
-	in_mem = g_ops->attach_dmabuf(fec->hw->dev, in_dbuf,
-				in_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(in_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach in dmabuf\n");
-		goto put_in_dbuf;
-	}
-	if (g_ops->map_dmabuf(in_mem))
-		goto detach_in_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(in_mem));
+	mem = fec_buf_add(file, buf->in_pic_fd, in_size);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_RD_Y_BASE);
 	val += in_offs;
 	writel(val, base + RKISPP_FEC_RD_UV_BASE);
 
 	/* output picture buf */
-	out_dbuf = dma_buf_get(buf->out_pic_fd);
-	if (IS_ERR_OR_NULL(out_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd:%d for out picture", buf->out_pic_fd);
-		goto unmap_in_dbuf;
-	}
-	if (out_dbuf->size < out_size) {
-		v4l2_err(&fec->v4l2_dev,
-			 "out picture size error:%zu < %u\n", out_dbuf->size, out_size);
-		goto put_out_dbuf;
-	}
-	out_mem = g_ops->attach_dmabuf(fec->hw->dev, out_dbuf,
-				out_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(out_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach out dmabuf\n");
-		goto put_out_dbuf;
-	}
-	if (g_ops->map_dmabuf(out_mem))
-		goto detach_out_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(out_mem));
+	mem = fec_buf_add(file, buf->out_pic_fd, out_size);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_WR_Y_BASE);
 	val += out_offs;
 	writel(val, base + RKISPP_FEC_WR_UV_BASE);
 
 	/* mesh xint buf */
-	xint_dbuf = dma_buf_get(buf->mesh_xint_fd);
-	if (IS_ERR_OR_NULL(xint_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd for xint picture");
-		goto unmap_out_dbuf;
-	}
-	if (xint_dbuf->size < mesh_size * 2) {
-		v4l2_err(&fec->v4l2_dev,
-			 "mesh xint size error:%zu < %u\n", xint_dbuf->size, mesh_size * 2);
-		goto put_xint_dbuf;
-	}
-	xint_mem = g_ops->attach_dmabuf(fec->hw->dev, xint_dbuf,
-				xint_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(xint_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach xint dmabuf\n");
-		goto put_xint_dbuf;
-	}
-	if (g_ops->map_dmabuf(xint_mem))
-		goto detach_xint_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(xint_mem));
+	mem = fec_buf_add(file, buf->mesh_xint_fd, mesh_size * 2);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_MESH_XINT_BASE);
 
 	/* mesh xfra buf */
-	xfra_dbuf = dma_buf_get(buf->mesh_xfra_fd);
-	if (IS_ERR_OR_NULL(xfra_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd for xfra picture");
-		goto unmap_xint_dbuf;
-	}
-	if (xfra_dbuf->size < mesh_size) {
-		v4l2_err(&fec->v4l2_dev,
-			 "mesh xfra size error:%zu < %u\n", xfra_dbuf->size, mesh_size);
-		goto put_xfra_dbuf;
-	}
-	xfra_mem = g_ops->attach_dmabuf(fec->hw->dev, xfra_dbuf,
-				xfra_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(xfra_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach xfra dmabuf\n");
-		goto put_xfra_dbuf;
-	}
-	if (g_ops->map_dmabuf(xfra_mem))
-		goto detach_xfra_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(xfra_mem));
+	mem = fec_buf_add(file, buf->mesh_xfra_fd, mesh_size);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_MESH_XFRA_BASE);
 
 	/* mesh yint buf */
-	yint_dbuf = dma_buf_get(buf->mesh_yint_fd);
-	if (IS_ERR_OR_NULL(yint_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd for yint picture");
-		goto unmap_xfra_dbuf;
-	}
-	if (yint_dbuf->size < mesh_size * 2) {
-		v4l2_err(&fec->v4l2_dev,
-			 "mesh yint size error:%zu < %u\n", yint_dbuf->size, mesh_size * 2);
-		goto put_yint_dbuf;
-	}
-	yint_mem = g_ops->attach_dmabuf(fec->hw->dev, yint_dbuf,
-				yint_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(yint_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach yint dmabuf\n");
-		goto put_yint_dbuf;
-	}
-	if (g_ops->map_dmabuf(yint_mem))
-		goto detach_yint_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(yint_mem));
+	mem = fec_buf_add(file, buf->mesh_yint_fd, mesh_size * 2);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_MESH_YINT_BASE);
 
 	/* mesh yfra buf */
-	yfra_dbuf = dma_buf_get(buf->mesh_yfra_fd);
-	if (IS_ERR_OR_NULL(yfra_dbuf)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "invalid dmabuf fd for yfra picture");
-		goto unmap_yint_dbuf;
-	}
-	if (yfra_dbuf->size < mesh_size) {
-		v4l2_err(&fec->v4l2_dev,
-			 "mesh yfra size error:%zu < %u\n", yfra_dbuf->size, mesh_size);
-		goto put_yfra_dbuf;
-	}
-	yfra_mem = g_ops->attach_dmabuf(fec->hw->dev, yfra_dbuf,
-				yfra_dbuf->size, DMA_BIDIRECTIONAL);
-	if (IS_ERR(yfra_mem)) {
-		v4l2_err(&fec->v4l2_dev,
-			 "failed to attach yfra dmabuf\n");
-		goto put_yfra_dbuf;
-	}
-	if (g_ops->map_dmabuf(yfra_mem))
-		goto detach_yfra_dbuf;
-	val = *((dma_addr_t *)g_ops->cookie(yfra_mem));
+	mem = fec_buf_add(file, buf->mesh_yfra_fd, mesh_size);
+	if (!mem)
+		goto free_buf;
+	val = *((dma_addr_t *)g_ops->cookie(mem));
 	writel(val, base + RKISPP_FEC_MESH_YFRA_BASE);
 
 	val = out_fmt << 4 | in_fmt;
 	writel(val, base + RKISPP_FEC_CTRL);
-	val = ALIGN(buf->width * in_mult, 16) >> 2;
+	val = ALIGN(in_w * in_mult, 16) >> 2;
 	writel(val, base + RKISPP_FEC_RD_VIR_STRIDE);
-	val = ALIGN(buf->width * out_mult, 16) >> 2;
+	val = ALIGN(out_w * out_mult, 16) >> 2;
 	writel(val, base + RKISPP_FEC_WR_VIR_STRIDE);
-	val = buf->height << 16 | buf->width;
-	writel(val, base + RKISPP_FEC_PIC_SIZE);
+	val = out_h << 16 | out_w;
+	writel(val, base + RKISPP_FEC_DST_SIZE);
+	val = in_h << 16 | in_w;
+	writel(val, base + RKISPP_FEC_SRC_SIZE);
 	writel(mesh_size, base + RKISPP_FEC_MESH_SIZE);
 	val = SW_FEC_EN | density;
 	writel(val, base + RKISPP_FEC_CORE_CTRL);
@@ -279,7 +278,7 @@
 	v4l2_dbg(3, rkispp_debug, &fec->v4l2_dev,
 		 "0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x\n"
 		 "0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x\n"
-		 "0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x\n",
+		 "0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x 0x%x:0x%x\n",
 		 RKISPP_CTRL_SYS_STATUS, readl(base + RKISPP_CTRL_SYS_STATUS),
 		 RKISPP_FEC_CTRL, readl(base + RKISPP_FEC_CTRL),
 		 RKISPP_FEC_RD_VIR_STRIDE, readl(base + RKISPP_FEC_RD_VIR_STRIDE),
@@ -293,7 +292,8 @@
 		 RKISPP_FEC_WR_Y_BASE_SHD, readl(base + RKISPP_FEC_WR_Y_BASE_SHD),
 		 RKISPP_FEC_WR_UV_BASE_SHD, readl(base + RKISPP_FEC_WR_UV_BASE_SHD),
 		 RKISPP_FEC_CORE_CTRL, readl(base + RKISPP_FEC_CORE_CTRL),
-		 RKISPP_FEC_PIC_SIZE, readl(base + RKISPP_FEC_PIC_SIZE),
+		 RKISPP_FEC_DST_SIZE, readl(base + RKISPP_FEC_DST_SIZE),
+		 RKISPP_FEC_SRC_SIZE, readl(base + RKISPP_FEC_SRC_SIZE),
 		 RKISPP_FEC_MESH_SIZE, readl(base + RKISPP_FEC_MESH_SIZE));
 	if (!fec->hw->is_shutdown)
 		writel(FEC_ST, base + RKISPP_CTRL_STRT);
@@ -307,51 +307,19 @@
 	}
 	writel(SW_FEC2DDR_DIS, base + RKISPP_FEC_CORE_CTRL);
 
-	g_ops->unmap_dmabuf(yfra_mem);
-detach_yfra_dbuf:
-	g_ops->detach_dmabuf(yfra_mem);
-put_yfra_dbuf:
-	dma_buf_put(yfra_dbuf);
-unmap_yint_dbuf:
-	g_ops->unmap_dmabuf(yint_mem);
-detach_yint_dbuf:
-	g_ops->detach_dmabuf(yint_mem);
-put_yint_dbuf:
-	dma_buf_put(yint_dbuf);
-unmap_xfra_dbuf:
-	g_ops->unmap_dmabuf(xfra_mem);
-detach_xfra_dbuf:
-	g_ops->detach_dmabuf(xfra_mem);
-put_xfra_dbuf:
-	dma_buf_put(xfra_dbuf);
-unmap_xint_dbuf:
-	g_ops->unmap_dmabuf(xint_mem);
-detach_xint_dbuf:
-	g_ops->detach_dmabuf(xint_mem);
-put_xint_dbuf:
-	dma_buf_put(xint_dbuf);
-unmap_out_dbuf:
-	g_ops->unmap_dmabuf(out_mem);
-detach_out_dbuf:
-	g_ops->detach_dmabuf(out_mem);
-put_out_dbuf:
-	dma_buf_put(out_dbuf);
-unmap_in_dbuf:
-	g_ops->unmap_dmabuf(in_mem);
-detach_in_dbuf:
-	g_ops->detach_dmabuf(in_mem);
-put_in_dbuf:
-	dma_buf_put(in_dbuf);
-end:
+	if (rkispp_debug)
+		us = ktime_us_delta(ktime_get(), t);
 	v4l2_dbg(3, rkispp_debug, &fec->v4l2_dev,
-		 "%s exit ret:%d\n", __func__, ret);
+		 "%s exit ret:%d, time:%lldus\n", __func__, ret, us);
+	return ret;
+free_buf:
+	fec_buf_del(file, 0, true);
 	return ret;
 }
 
 static long fec_ioctl_default(struct file *file, void *fh,
 			bool valid_prio, unsigned int cmd, void *arg)
 {
-	struct rkispp_fec_dev *fec = video_drvdata(file);
 	long ret = 0;
 
 	if (!arg)
@@ -359,7 +327,14 @@
 
 	switch (cmd) {
 	case RKISPP_CMD_FEC_IN_OUT:
-		ret = fec_running(fec, arg);
+		ret = fec_running(file, arg);
+		break;
+	case RKISPP_CMD_FEC_BUF_ADD:
+		if (!fec_buf_add(file, *(int *)arg, 0))
+			ret = -ENOMEM;
+		break;
+	case RKISPP_CMD_FEC_BUF_DEL:
+		fec_buf_del(file, *(int *)arg, false);
 		break;
 	default:
 		ret = -EFAULT;
@@ -368,7 +343,7 @@
 	return ret;
 }
 
-static const struct v4l2_ioctl_ops m2m_ioctl_ops = {
+static const struct v4l2_ioctl_ops fec_ioctl_ops = {
 	.vidioc_default = fec_ioctl_default,
 };
 
@@ -399,6 +374,7 @@
 	v4l2_dbg(1, rkispp_debug, &fec->v4l2_dev, "%s\n", __func__);
 
 	v4l2_fh_release(file);
+	fec_buf_del(file, 0, true);
 	mutex_lock(&fec->hw->dev_lock);
 	pm_runtime_put_sync(fec->hw->dev);
 	mutex_unlock(&fec->hw->dev_lock);
@@ -409,16 +385,17 @@
 	.owner = THIS_MODULE,
 	.open = fec_open,
 	.release = fec_release,
-	.poll = v4l2_m2m_fop_poll,
 	.unlocked_ioctl = video_ioctl2,
-	.mmap = v4l2_m2m_fop_mmap,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl32 = video_ioctl2,
+#endif
 };
 
 static const struct video_device fec_videodev = {
 	.name = "rkispp_fec",
-	.vfl_dir = VFL_DIR_M2M,
+	.vfl_dir = VFL_DIR_RX,
 	.fops = &fec_fops,
-	.ioctl_ops = &m2m_ioctl_ops,
+	.ioctl_ops = &fec_ioctl_ops,
 	.minor = -1,
 	.release = video_device_release_empty,
 };
@@ -450,18 +427,22 @@
 	if (ret)
 		return ret;
 
+	mutex_init(&fec->apilock);
 	fec->vfd = fec_videodev;
 	vfd = &fec->vfd;
+	vfd->device_caps = V4L2_CAP_STREAMING;
 	vfd->lock = &fec->apilock;
 	vfd->v4l2_dev = v4l2_dev;
-	ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
+	ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0);
 	if (ret) {
 		v4l2_err(v4l2_dev, "Failed to register video device\n");
 		goto unreg_v4l2;
 	}
 	video_set_drvdata(vfd, fec);
+	INIT_LIST_HEAD(&fec->list);
 	return 0;
 unreg_v4l2:
+	mutex_destroy(&fec->apilock);
 	v4l2_device_unregister(v4l2_dev);
 	return ret;
 }
@@ -471,6 +452,7 @@
 	if (!IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_ISPP_FEC))
 		return;
 
+	mutex_destroy(&hw->fec_dev.apilock);
 	video_unregister_device(&hw->fec_dev.vfd);
 	v4l2_device_unregister(&hw->fec_dev.v4l2_dev);
 }

--
Gitblit v1.6.2