Skip to contentSkip to conversation

drm/exynos: add ipp subsystem and each ipp drivers

RFC Superseded Eunchul Kim 3 participants 18 messages Dec 12, 2012 – Dec 14, 2012 Page 1 of 2

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover drm/exynos: add ipp subsystem and each ipp drivers

Changelog v3:
Hi All.

This RFC v3 changed ipp subsystem for arrangement. Fixed scaler problem in GSC.
Added/Removed comment from Inki.Dae.
Fixed Joonyoung.Shim comment.
Added rotator comments.

Changelog v2:
Hi All.

This RFC v2 supports iommu in ipp. and Added/Removed comment from Inki.Dae. Fixed GSC part bugs and next time I will send our local git commit. and We finished implementation of SC for post-processing.
SC driver not fully tested yet. so, I didn't add SC feature in this patch.

Thank's

Changelog v1:

Hi All.

I am responsible for a display part from Samsung Electronics Telecommunication Division. and I am going to add post-processing features in exynos drm.
If you have some opinions of this patch,
please give some comments about my patch.

This patch is post-processing(IPP) support for exynos drm driver.

IPP is stands for Image Post Processing and supports image scaler/rotator and input/output DMA operations using IPP drivers(FIMC, Rotator, GSC, SC, so on.) IPP is integration device driver of same attibute hardware.

Exynos4xxxx SoC support FIMC, Rotator for post-processing. and Exynos5xxxx SoC support GSC, Rotator, SC for post-processing. SC driver not tested yet. so, I didn't add SC feature in this patch. and IPP subsystem works on Exynos SoC version independently.

IPP drivers supports Memory to Memory operations with various converting. and some drivers supports Writeback and Display output operations using local path. User can make converted image using this driver.
and also supports streaming concept for multimedia data processing.

And supports various operations
1. Scale operation generates various sizes of image.
2. CSC(Color Space Conversion) operation supports format converting.
3. Crop operation supports cutting the image.
4. Rotate operation supports to 90, 180, 270 degree.
5. Flip operation supports to vertical, horizontal, and both.
6. Writeback operation genertates cloned image from display controller(FIMD).
7. Display output operation support various format display to display controller(FIMD).
8. Input DMA reads image data from the memory.
9. Output DMA writes image data to memory.
10. Supports image effect functions.

Descriptions)
User should make property informations and set this property to registers.
and IPP subsystem manages property id using command node and make queue list using memory node. IPP subsystem supports register function of IPP drivers.
IPP driver manages input/output DMA with various operations. and some driver supports optional operations(writeback, output).
IPP driver needs various informations, so User set property information to IPP driver. and also IPP driver needs memory base address of image for various operations. User doesn't know its address, so fills the gem handle of that memory than address of image base. and than IPP driver start operation.

Ioctls)
We adds four ioctls and one event for IPP subsystem.

- ioctls
DRM_EXYNOS_IPP_GET_PROPERTY : get ipp driver capabilitis and id. DRM_EXYNOS_IPP_SET_PROPERTY : set format, position, rotation, flip about source/destination. DRM_EXYNOS_IPP_QUEUE_BUF : enqueue/dequeue buffer and make event list. DRM_EXYNOS_IPP_CMD_CTRL : play/stop/pause/resume control.

- event
DRM_EXYNOS_IPP_EVENT : event to give notification completion of buffer DMA with buffer list

Basic control flow and Sample pseudo application)
1. Basic control flow is same as below
Open -> Get properties -> User choose IPP driver and set property information -> Set Property -> Create gem handle -> Queue buffer(Enqueue) of source/destination -> Command control(Play) -> Event occured to User
-> User handle converted image -> (Queue buffer(Enqueue) of source/destination -> Event occured to User)*N -> Queue buffer(Dequeue) of source/destination -> Command control(Stop) -> Free gem handle -> Close

2. Sample pseudo application
#include "exynos_drm.h"
static int exynos_drm_ipp_set_property(int fd ...)

{
	struct drm_exynos_pos crop_pos = {0, 0, hsize, vsize};
	struct drm_exynos_pos scale_pos = {0, 0, hsize, vsize};
	struct drm_exynos_sz src_sz = {hsize, vsize};
	struct drm_exynos_sz dst_sz = {hsize, vsize};
	int ret = 0;

	memset(property, 0x00, sizeof(struct drm_exynos_ipp_property));
	property->cmd = cmd;

	property->config[EXYNOS_DRM_OPS_SRC].ops_id = EXYNOS_DRM_OPS_SRC;
	property->config[EXYNOS_DRM_OPS_SRC].flip = EXYNOS_DRM_FLIP_NONE;
	property->config[EXYNOS_DRM_OPS_SRC].degree = EXYNOS_DRM_DEGREE_0;
	property->config[EXYNOS_DRM_OPS_SRC].fmt = DRM_FORMAT_XRGB8888;
	property->config[EXYNOS_DRM_OPS_SRC].pos = crop_pos;
	property->config[EXYNOS_DRM_OPS_SRC].sz = src_sz;

	property->config[EXYNOS_DRM_OPS_DST].ops_id = EXYNOS_DRM_OPS_DST;
	property->config[EXYNOS_DRM_OPS_DST].flip = EXYNOS_DRM_FLIP_NONE;
	property->config[EXYNOS_DRM_OPS_DST].degree = degree;
	property->config[EXYNOS_DRM_OPS_DST].fmt = DRM_FORMAT_XRGB8888;
	property->config[EXYNOS_DRM_OPS_DST].pos = scale_pos;
	property->config[EXYNOS_DRM_OPS_DST].sz = dst_sz;

	ret = ioctl(fd, DRM_IOCTL_EXYNOS_IPP_SET_PROPERTY, property);
	if (ret)
		fprintf(stderr,
			"failed to DRM_IOCTL_EXYNOS_IPP_SET_PROPERTY : %s\n",
			strerror(errno));
	
	printf("DRM_IOCTL_EXYNOS_IPP_SET_PROPERTY : prop_id[%d]\n",
		property->prop_id);

	return ret;
}

static int exynos_drm_ipp_queue_buf(int fd, ..., unsigned int gem_handle)

{
	int ret = 0;

	memset(qbuf, 0x00, sizeof(struct drm_exynos_ipp_queue_buf));

	qbuf->ops_id = ops_id;
	qbuf->buf = buf;
	qbuf->user_data = 0;
	qbuf->prop_id = prop_id;
	qbuf->buf_id = buf_id;
	qbuf->handle[EXYNOS_DRM_PLANAR_Y] = gem_handle;
	qbuf->handle[EXYNOS_DRM_PLANAR_CB] = 0;
	qbuf->handle[EXYNOS_DRM_PLANAR_CR] = 0;

	ret = ioctl(fd, DRM_IOCTL_EXYNOS_IPP_QUEUE_BUF, qbuf);
	if (ret)
		fprintf(stderr,
		"failed to DRM_IOCTL_EXYNOS_IPP_QUEUE_BUF[id:%d][buf:%d] : %s\n",
		ops_id, buf, strerror(errno));
 
	return ret;
}

static int exynos_drm_ipp_cmd_ctrl(int fd, ...)

{
	int ret = 0;

	memset(cmd_ctrl, 0x00, sizeof(struct drm_exynos_ipp_cmd_ctrl));

	cmd_ctrl->prop_id = prop_id;
	cmd_ctrl->ctrl = ctrl;

	ret = ioctl(fd, DRM_IOCTL_EXYNOS_IPP_CMD_CTRL, cmd_ctrl);
	if (ret)
		fprintf(stderr,
		"failed to DRM_IOCTL_EXYNOS_IPP_CMD_CTRL[prop_id:%d][ctrl:%d] : %s\n",
		prop_id, ctrl, strerror(errno));

	return ret;
}

int ipp_event_handler(...)

{
	char buffer[1024];
	int len, i;
	struct drm_event *e;
	struct drm_exynos_ipp_event *ipp_event;
	char filename[100];
	int ret = 0;
	int src_buf_id, dst_buf_id;
	static bmp_idx = 0;

	len = read(fd, buffer, sizeof buffer);
	if (len == 0)
		return 0;
	if (len < sizeof *e)
		return -1;

	i = 0;
	while (i < len) {
		e = (struct drm_event *) &buffer[i];
		switch (e->type) {
		case DRM_EXYNOS_IPP_EVENT:
			ipp_event = (struct drm_exynos_ipp_event *) e;
			src_buf_id = ipp_event->buf_id[EXYNOS_DRM_OPS_SRC];
			dst_buf_id = ipp_event->buf_id[EXYNOS_DRM_OPS_DST];

			/* For source buffer queue to IPP */
			ret = exynos_drm_ipp_queue_buf(fd, &src_qbuf[src_buf_id], EXYNOS_DRM_OPS_SRC,
						IPP_BUF_ENQUEUE, property->prop_id,
						src_buf_id, src_gem[src_buf_id].handle);
			if (ret) {
				fprintf(stderr, "failed to ipp buf src queue\n");
				goto err_ipp_ctrl_close;
			}

			/* For destination buffer queue to IPP */
			ret = exynos_drm_ipp_queue_buf(fd, &dst_qbuf[dst_buf_id], EXYNOS_DRM_OPS_DST,
						IPP_BUF_ENQUEUE, property->prop_id,
						dst_buf_id, dst_gem[dst_buf_id].handle);
			if (ret) {
				fprintf(stderr, "failed to ipp buf dst queue\n");
				goto err_ipp_ctrl_close;
			}
			break;
		default:
			break;
		}
		i += e->length;
	}

err_ipp_ctrl_close:

	return ret;
}

void ipp_main(...)

{
	struct drm_exynos_ipp_property property;
	struct drm_exynos_ipp_cmd_ctrl cmd_ctrl;
	struct drm_exynos_sz def_sz = {720, 1280};
	struct drm_exynos_ipp_queue_buf qbuf1[MAX_BUF], qbuf2[MAX_BUF];
	unsigned int width=720, height=1280, stride;
	int ret, i, j, x;
	struct drm_exynos_gem_create gem1[MAX_BUF], gem2[MAX_BUF];
	struct drm_exynos_gem_mmap mmap1[MAX_BUF], mmap2[MAX_BUF];
	void *usr_addr1[MAX_BUF], *usr_addr2[MAX_BUF];
	struct timeval begin, end;
	struct drm_gem_close args;
	char filename[100];

	/* For property */
	ret = exynos_drm_ipp_set_property(fd, &property, &def_sz, IPP_CMD_M2M, EXYNOS_DRM_DEGREE_0);
	if (ret) {
		fprintf(stderr, "failed to ipp property\n");
		return;
	}

	for (i = 0; i < MAX_BUF; i++) {
		/* For source buffer map to IPP */
		ret = exynos_drm_ipp_queue_buf(fd, &qbuf1[i], EXYNOS_DRM_OPS_SRC,
				IPP_BUF_ENQUEUE, property.prop_id, i, gem1[i].handle);
		if (ret) {
			fprintf(stderr, "failed to ipp buf src map\n");
			goto err_ipp_ctrl_close;
		}
	}

	for (i = 0; i < MAX_BUF; i++) {
		/* For destination buffer map to IPP */
		ret = exynos_drm_ipp_queue_buf(fd, &qbuf2[i], EXYNOS_DRM_OPS_DST,
			IPP_BUF_ENQUEUE, property.prop_id, i, gem2[i].handle);
		if (ret) {
			fprintf(stderr, "failed to ipp buf dst map\n");
			goto err_ipp_ctrl_close;
		}
	}

	/* Start */
	gettimeofday(&begin, NULL);
	ret = exynos_drm_ipp_cmd_ctrl(fd, &cmd_ctrl, property.prop_id, IPP_CTRL_PLAY);
	if (ret) {
		fprintf(stderr,
		"failed to ipp ctrl IPP_CMD_M2M start\n");
		goto err_ipp_ctrl_close;
	}
        
	j=0;
	while (1) {
		struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
		fd_set fds;

		FD_ZERO(&fds);
		FD_SET(0, &fds);
		FD_SET(fd, &fds);
		ret = select(fd + 1, &fds, NULL, NULL, &timeout);
		if (ret <= 0) {
			fprintf(stderr, "select timed out or error.\n");
			continue;
		} else if (FD_ISSET(0, &fds)) {
			break;
		}

		gettimeofday(&end, NULL);
		usec[j] = (end.tv_sec - begin.tv_sec) * 1000000 +
		(end.tv_usec - begin.tv_usec);

		if(ipp_event_handler() < 0)
			break;

		if (++j > MAX_LOOP)
			break;

		gettimeofday(&begin, NULL);
	}

err_ipp_ctrl_close:

	/* For source buffer dequeue to IPP */
	for (i = 0; i < MAX_BUF; i++) {
		ret = exynos_drm_ipp_queue_buf(fd, &qbuf1[i], EXYNOS_DRM_OPS_SRC,
						IPP_BUF_DEQUEUE, property.prop_id, i, gem1[i].handle);
		if (ret < 0)
			fprintf(stderr, "failed to ipp buf dst dequeue\n");
	}

	/* For destination buffer dequeue to IPP */
	for (i = 0; i < MAX_BUF; i++) {
		ret = exynos_drm_ipp_queue_buf(fd, &qbuf2[i], EXYNOS_DRM_OPS_DST,
						IPP_BUF_DEQUEUE, property.prop_id, i, gem2[i].handle);
		if (ret < 0)
			fprintf(stderr, "failed to ipp buf dst dequeue\n");
	}

	/* Stop */
	ret = exynos_drm_ipp_cmd_ctrl(fd, &cmd_ctrl, property.prop_id, IPP_CTRL_STOP);
	if (ret)
		fprintf(stderr, "failed to ipp ctrl IPP_CMD_WB stop\n");

	return;
}

Eunchul Kim (5):
drm/exynos: add ipp subsystem
drm/exynos: add iommu support for ipp
drm/exynos: add fimc ipp driver
drm/exynos: add rotator ipp driver
drm/exynos: add gsc ipp driver

 drivers/gpu/drm/exynos/Kconfig              |   24 +
 drivers/gpu/drm/exynos/Makefile             |    4 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |   69 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |   10 +
 drivers/gpu/drm/exynos/exynos_drm_fimc.c    | 2022 ++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_fimc.h    |   34 +
 drivers/gpu/drm/exynos/exynos_drm_gsc.c     | 1927 +++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_gsc.h     |   34 +
 drivers/gpu/drm/exynos/exynos_drm_ipp.c     | 2077 +++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_ipp.h     |  266 ++++
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829 +++++++++++
 drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
 drivers/gpu/drm/exynos/regs-fimc.h          |  669 +++++++++
 drivers/gpu/drm/exynos/regs-gsc.h           |  295 ++++
 drivers/gpu/drm/exynos/regs-rotator.h       |   73 +
 include/drm/exynos_drm.h                    |   26 +
 include/uapi/drm/exynos_drm.h               |  190 +++
 17 files changed, 8562 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_fimc.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_fimc.h
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_gsc.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_gsc.h
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.h
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h
 create mode 100644 drivers/gpu/drm/exynos/regs-fimc.h
 create mode 100644 drivers/gpu/drm/exynos/regs-gsc.h
 create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h
#1 lore raw

RFC v3 1/5 drm/exynos: add ipp subsystem

IPP stand for Image Post Processing and supports image scaler/rotator /crop/flip/csc(color space conversion) and input/output DMA operations using ipp drivers. also supports writeback and display output operations.
ipp driver include FIMC, Rotator, GSC, SC, so on.
and ipp is integration device driver for each hardware.

---
 drivers/gpu/drm/exynos/Kconfig          |    6 +
 drivers/gpu/drm/exynos/Makefile         |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c |   24 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h |    7 +
 drivers/gpu/drm/exynos/exynos_drm_ipp.c | 2059 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_ipp.h |  266 ++++
 include/uapi/drm/exynos_drm.h           |  190 +++
 7 files changed, 2553 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.h
drivers/gpu/drm/exynos/Kconfig +6 -0
index 4ea8cdc..bcf1c9d 100644
@@ -45,3 +45,9 @@ config DRM_EXYNOS_G2D
 	depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_G2D
 	help
 	  Choose this option if you want to use Exynos G2D for DRM.
+
+config DRM_EXYNOS_IPP
+	bool "Exynos DRM IPP"
+	depends on DRM_EXYNOS
+	help
+	  Choose this option if you want to use IPP feature for DRM.
drivers/gpu/drm/exynos/Makefile +1 -0
index 26813b8..6c536ce 100644
@@ -16,5 +16,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI)	+= exynos_hdmi.o exynos_mixer.o \
 					   exynos_drm_hdmi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+= exynos_drm_vidi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
 
 obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +24 -0
index 4a1168d..0eb8a97 100644
@@ -40,6 +40,7 @@
 #include "exynos_drm_vidi.h"
 #include "exynos_drm_dmabuf.h"
 #include "exynos_drm_g2d.h"
+#include "exynos_drm_ipp.h"
 #include "exynos_drm_iommu.h"
 
 #define DRIVER_NAME	"exynos"
@@ -249,6 +250,14 @@ static struct drm_ioctl_desc exynos_ioctls[] = {
 			exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
 	DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
 			exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY,
+			exynos_drm_ipp_get_property, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY,
+			exynos_drm_ipp_set_property, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF,
+			exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL,
+			exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH),
 };
 
 static const struct file_operations exynos_drm_driver_fops = {
@@ -363,6 +372,12 @@ static int __init exynos_drm_init(void)
 		goto out_g2d;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	ret = platform_driver_register(&ipp_driver);
+	if (ret < 0)
+		goto out_ipp;
+#endif
+
 	ret = platform_driver_register(&exynos_drm_platform_driver);
 	if (ret < 0)
 		goto out_drm;
@@ -380,6 +395,11 @@ out:
 	platform_driver_unregister(&exynos_drm_platform_driver);
 
 out_drm:
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+out_ipp:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 out_g2d:
@@ -416,6 +436,10 @@ static void __exit exynos_drm_exit(void)
 
 	platform_driver_unregister(&exynos_drm_platform_driver);
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +7 -0
index a9db025..a365788 100644
@@ -235,8 +235,14 @@ struct exynos_drm_g2d_private {
 	unsigned int		gem_nr;
 };
 
+struct exynos_drm_ipp_private {
+	struct device	*dev;
+	struct list_head	event_list;
+};
+
 struct drm_exynos_file_private {
 	struct exynos_drm_g2d_private	*g2d_priv;
+	struct exynos_drm_ipp_private	*ipp_priv;
 };
 
 /*
@@ -346,4 +352,5 @@ extern struct platform_driver mixer_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
+extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2059 -0

2,059 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_ipp.h new file +266 -0

266 lines not on this page · raw message

include/uapi/drm/exynos_drm.h +190 -0

214 lines not on this page · raw message

Signature · 1 line
1.7.0.4
maintainer
#2 lore raw

RE: [RFC v3 1/5] drm/exynos: add ipp subsystem

Quoted 75 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 1/5] drm/exynos: add ipp subsystem

IPP stand for Image Post Processing and supports image scaler/rotator /crop/flip/csc(color space conversion) and input/output DMA operations using ipp drivers.
also supports writeback and display output operations.
ipp driver include FIMC, Rotator, GSC, SC, so on.
and ipp is integration device driver for each hardware.

---
 drivers/gpu/drm/exynos/Kconfig          |    6 +
 drivers/gpu/drm/exynos/Makefile         |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c |   24 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h |    7 +
 drivers/gpu/drm/exynos/exynos_drm_ipp.c | 2059
+++++++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_ipp.h |  266 ++++
 include/uapi/drm/exynos_drm.h           |  190 +++
 7 files changed, 2553 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.h
drivers/gpu/drm/exynos/Kconfig +6 -0
index 4ea8cdc..bcf1c9d 100644
@@ -45,3 +45,9 @@ config DRM_EXYNOS_G2D
 	depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_G2D
 	help
 	  Choose this option if you want to use Exynos G2D for DRM.
+
+config DRM_EXYNOS_IPP
+	bool "Exynos DRM IPP"
+	depends on DRM_EXYNOS
+	help
+	  Choose this option if you want to use IPP feature for DRM.
drivers/gpu/drm/exynos/Makefile +1 -0
index 26813b8..6c536ce 100644
@@ -16,5 +16,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI)	+=
 exynos_hdmi.o exynos_mixer.o \
 					   exynos_drm_hdmi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+= exynos_drm_vidi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
 

obj-$(CONFIG_DRM_EXYNOS) += exynosdrm.o

drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -0
index 4a1168d..0eb8a97 100644
@@ -40,6 +40,7 @@
 #include "exynos_drm_vidi.h"
 #include "exynos_drm_dmabuf.h"
 #include "exynos_drm_g2d.h"
+#include "exynos_drm_ipp.h"
 #include "exynos_drm_iommu.h"
 
 #define DRIVER_NAME	"exynos"

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = { · line 250

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -0
@@ -249,6 +250,14 @@ static struct drm_ioctl_desc exynos_ioctls[] = {
 			exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED |

DRM_AUTH),

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = {

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -0
 	DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
 			exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY,
+			exynos_drm_ipp_get_property, DRM_UNLOCKED |

DRM_AUTH),

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = { · line 256

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -0
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY,
+			exynos_drm_ipp_set_property, DRM_UNLOCKED |

DRM_AUTH),

Quoted 266 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +19 -0
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF,
+			exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL,
+			exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH),
 };
 
 static const struct file_operations exynos_drm_driver_fops = {
@@ -363,6 +372,12 @@ static int __init exynos_drm_init(void)
 		goto out_g2d;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	ret = platform_driver_register(&ipp_driver);
+	if (ret < 0)
+		goto out_ipp;
+#endif
+
 	ret = platform_driver_register(&exynos_drm_platform_driver);
 	if (ret < 0)
 		goto out_drm;
@@ -380,6 +395,11 @@ out:
 	platform_driver_unregister(&exynos_drm_platform_driver);
 
 out_drm:
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+out_ipp:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 out_g2d:
@@ -416,6 +436,10 @@ static void __exit exynos_drm_exit(void)
 
 	platform_driver_unregister(&exynos_drm_platform_driver);
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +7 -0
index a9db025..a365788 100644
@@ -235,8 +235,14 @@ struct exynos_drm_g2d_private {
 	unsigned int		gem_nr;
 };
 
+struct exynos_drm_ipp_private {
+	struct device	*dev;
+	struct list_head	event_list;
+};
+
 struct drm_exynos_file_private {
 	struct exynos_drm_g2d_private	*g2d_priv;
+	struct exynos_drm_ipp_private	*ipp_priv;
 };
 
 /*
@@ -346,4 +352,5 @@ extern struct platform_driver mixer_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
+extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +8 -0
new file mode 100644
index 0000000..eb12cb5
@@ -0,0 +1,2059 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	Eunchul Kim <[email protected]>
+ *	Jinyoung Jeon <[email protected]>
+ *	Sangmin Lee <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify

it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +21 -0
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+#include <plat/map-base.h>
+
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "exynos_drm_drv.h"
+#include "exynos_drm_gem.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * IPP is stand for Image Post Processing and
+ * supports image scaler/rotator and input/output DMA operations.
+ * using FIMC, GSC, Rotator, so on.
+ * IPP is integration device driver of same attribute h/w
+ */
+
+#define get_ipp_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +88 -0
+#define ipp_is_m2m_cmd(c)	(c == IPP_CMD_M2M)
+
+/*
+ * A structure of event.
+ *
+ * @base: base of event.
+ * @event: ipp event.
+ */
+struct drm_exynos_ipp_send_event {
+	struct drm_pending_event	base;
+	struct drm_exynos_ipp_event	event;
+};
+
+/*
+ * A structure of memory node.
+ *
+ * @list: list head to memory queue information.
+ * @ops_id: id of operations.
+ * @prop_id: id of property.
+ * @buf_id: id of buffer.
+ * @buf_info: gem objects and dma address, size.
+ * @filp: a pointer to drm_file.
+ */
+struct drm_exynos_ipp_mem_node {
+	struct list_head	list;
+	enum drm_exynos_ops_id	ops_id;
+	u32	prop_id;
+	u32	buf_id;
+	struct drm_exynos_ipp_buf_info	buf_info;
+	struct drm_file		*filp;
+};
+
+/*
+ * A structure of ipp context.
+ *
+ * @subdrv: prepare initialization using subdrv.
+ * @ipp_lock: lock for synchronization of access to ipp_idr.
+ * @prop_lock: lock for synchronization of access to prop_idr.
+ * @ipp_idr: ipp driver idr.
+ * @prop_idr: property idr.
+ * @event_workq: event work queue.
+ * @cmd_workq: command work queue.
+ */
+struct ipp_context {
+	struct exynos_drm_subdrv	subdrv;
+	struct mutex	ipp_lock;
+	struct mutex	prop_lock;
+	struct idr	ipp_idr;
+	struct idr	prop_idr;
+	struct workqueue_struct	*event_workq;
+	struct workqueue_struct	*cmd_workq;
+};
+
+static LIST_HEAD(exynos_drm_ippdrv_list);
+static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
+static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
+
+int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv *ippdrv)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ippdrv)
+		return -EINVAL;
+
+	mutex_lock(&exynos_drm_ippdrv_lock);
+	list_add_tail(&ippdrv->drv_list, &exynos_drm_ippdrv_list);
+	mutex_unlock(&exynos_drm_ippdrv_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippdrv_register);
+
+int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv *ippdrv)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ippdrv)
+		return -EINVAL;
+
+	mutex_lock(&exynos_drm_ippdrv_lock);
+	list_del(&ippdrv->drv_list);
+	mutex_unlock(&exynos_drm_ippdrv_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippdrv_unregister);
+
+static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void

*obj,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +63 -0
+		u32 *idp)
+{
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+again:
+	/* ensure there is space available to allocate a handle */
+	if (idr_pre_get(id_idr, GFP_KERNEL) == 0) {
+		DRM_ERROR("failed to get idr.\n");
+		return -ENOMEM;
+	}
+
+	/* do the allocation under our mutexlock */
+	mutex_lock(lock);
+	ret = idr_get_new_above(id_idr, obj, 1, (int *)idp);
+	mutex_unlock(lock);
+	if (ret == -EAGAIN)
+		goto again;
+
+	return ret;
+}
+
+static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id)
+{
+	void *obj;
+
+	DRM_DEBUG_KMS("%s:id[%d]\n", __func__, id);
+
+	mutex_lock(lock);
+
+	/* find object using handle */
+	obj = idr_find(id_idr, id);
+	if (!obj) {
+		DRM_ERROR("failed to find object.\n");
+		mutex_unlock(lock);
+		return ERR_PTR(-ENODEV);
+	}
+
+	mutex_unlock(lock);
+
+	return obj;
+}
+
+static inline bool ipp_check_dedicated(struct exynos_drm_ippdrv *ippdrv,
+		enum drm_exynos_ipp_cmd	cmd)
+{
+	/*
+	 * check dedicated flag and WB, OUTPUT operation with
+	 * power on state.
+	 */
+	if (ippdrv->dedicated || (!ipp_is_m2m_cmd(cmd) &&
+	    !pm_runtime_suspended(ippdrv->dev)))
+		return true;
+
+	return false;
+}
+
+static struct exynos_drm_ippdrv *ipp_find_driver(struct ipp_context *ctx,
+		struct drm_exynos_ipp_property *property)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	u32 ipp_id = property->ipp_id;

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 195

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+	DRM_DEBUG_KMS("%s:ipp_id[%d]\n", __func__, ipp_id);
+
+	if (ipp_id) {
+		/* find ipp driver using idr */
+		ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
+			ipp_id);
+		if (IS_ERR_OR_NULL(ippdrv)) {
+			DRM_ERROR("not found ipp%d driver.\n", ipp_id);
+			goto err_null;

Just return ippdrv;

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+		}
+
+		/*
+		 * WB, OUTPUT opertion not supported multi-operation.
+		 * so, make dedicated state at set property ioctl.
+		 * when ipp driver finished operations, clear dedicated

flags.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 205

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +4 -0
+		 */
+		if (ipp_check_dedicated(ippdrv, property->cmd)) {
+			DRM_ERROR("already used choose device.\n");
+			goto err_null;

Just return proper error;

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 216

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +11 -0
+		}
+
+		/*
+		 * This is necessary to find correct device in ipp drivers.
+		 * ipp drivers have different abilities,
+		 * so need to check property.
+		 */
+		if (ippdrv->check_property &&
+		    ippdrv->check_property(ippdrv->dev, property)) {
+			DRM_ERROR("not support property.\n");
+			goto err_null;

Just return proper error;

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+		}
+
+		return ippdrv;
+	} else {
+		/*
+		 * This case is search all ipp driver for finding.
+		 * user application don't set ipp_id in this case,
+		 * so ipp subsystem search correct driver in driver list.
+		 */
+		list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list,

drv_list) {

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+			if (ipp_check_dedicated(ippdrv, property->cmd)) {
+				DRM_DEBUG_KMS("%s:used device.\n",

__func__);

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+				continue;
+			}
+
+			if (ippdrv->check_property &&
+			    ippdrv->check_property(ippdrv->dev, property)) {
+				DRM_DEBUG_KMS("%s:not support property.\n",
+					__func__);
+				continue;
+			}
+

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 248

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+			return ippdrv;
+		}
+
+		DRM_ERROR("not support ipp driver operations.\n");
+	}
+
+	return ERR_PTR(-ENODEV);
+
+err_null:
+	return NULL;

And remove the above codes.

Quoted 80 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +61 -0
+}
+
+static struct exynos_drm_ippdrv *ipp_find_drv_by_handle(u32 prop_id)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, prop_id);
+
+	if (list_empty(&exynos_drm_ippdrv_list)) {
+		DRM_DEBUG_KMS("%s:ippdrv_list is empty.\n", __func__);
+		return ERR_PTR(-ENODEV);
+	}
+
+	/*
+	 * This case is search ipp driver by prop_id handle.
+	 * sometimes, ipp subsystem find driver by prop_id.
+	 * e.g PAUSE state, queue buf, command contro.
+	 */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		DRM_DEBUG_KMS("%s:count[%d]ippdrv[0x%x]\n", __func__,
+			count++, (int)ippdrv);
+
+		if (!list_empty(&ippdrv->cmd_list)) {
+			list_for_each_entry(c_node, &ippdrv->cmd_list, list)
+				if (c_node->property.prop_id == prop_id)
+					return ippdrv;
+		}
+	}
+
+	return ERR_PTR(-ENODEV);
+}
+
+int exynos_drm_ipp_get_property(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_prop_list *prop_list = data;
+	struct exynos_drm_ippdrv *ippdrv;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+
+	if (!prop_list) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:ipp_id[%d]\n", __func__, prop_list->ipp_id);
+
+	if (!prop_list->ipp_id) {
+		list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list,

drv_list)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +18 -0
+			count++;
+		/*
+		 * Supports ippdrv list count for user application.
+		 * First step user application getting ippdrv count.
+		 * and second step getting ippdrv capability using ipp_id.
+		 */
+		prop_list->count = count;
+	} else {
+		/*
+		 * Getting ippdrv capability by ipp_id.
+		 * some deivce not supported wb, output interface.
+		 * so, user application detect correct ipp driver
+		 * using this ioctl.
+		 */
+		ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
+						prop_list->ipp_id);
+		if (!ippdrv) {
+			DRM_ERROR("not found ipp%d driver.\n",

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 337

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+					prop_list->ipp_id);
+			return -EINVAL;
+		}
+
+		prop_list = ippdrv->prop_list;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_get_property);

Should this function really be exported? Which external module calls this function? If not so, remove it.

Quoted 376 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+static void ipp_print_property(struct drm_exynos_ipp_property *property,
+		int idx)
+{
+	struct drm_exynos_ipp_config *config = &property->config[idx];
+	struct drm_exynos_pos *pos = &config->pos;
+	struct drm_exynos_sz *sz = &config->sz;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]ops[%s]fmt[0x%x]\n",
+		__func__, property->prop_id, idx ? "dst" : "src", config-
Quoted 1 line

fmt);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+	DRM_DEBUG_KMS("%s:pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n",
+		__func__, pos->x, pos->y, pos->w, pos->h,
+		sz->hsize, sz->vsize, config->flip, config->degree);
+}
+
+static int ipp_find_and_set_property(struct drm_exynos_ipp_property

*property)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +103 -0
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	u32 prop_id = property->prop_id;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, prop_id);
+
+	ippdrv = ipp_find_drv_by_handle(prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find command node using command list in ippdrv.
+	 * when we find this command no using prop_id.
+	 * return property information set in this command node.
+	 */
+	list_for_each_entry(c_node, &ippdrv->cmd_list, list) {
+		if ((c_node->property.prop_id == prop_id) &&
+		    (c_node->state == IPP_STATE_STOP)) {
+			DRM_DEBUG_KMS("%s:found cmd[%d]ippdrv[0x%x]\n",
+				__func__, property->cmd, (int)ippdrv);
+
+			c_node->property = *property;
+			return 0;
+		}
+	}
+
+	DRM_ERROR("failed to search property.\n");
+
+	return -EINVAL;
+}
+
+static struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void)
+{
+	struct drm_exynos_ipp_cmd_work *cmd_work;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL);
+	if (!cmd_work) {
+		DRM_ERROR("failed to alloc cmd_work.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd);
+
+	return cmd_work;
+}
+
+static struct drm_exynos_ipp_event_work *ipp_create_event_work(void)
+{
+	struct drm_exynos_ipp_event_work *event_work;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	event_work = kzalloc(sizeof(*event_work), GFP_KERNEL);
+	if (!event_work) {
+		DRM_ERROR("failed to alloc event_work.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	INIT_WORK((struct work_struct *)event_work, ipp_sched_event);
+
+	return event_work;
+}
+
+int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_property *property = data;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret, i;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+
+	if (!property) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * This is log print for user application property.
+	 * user application set various property.
+	 */
+	for_each_ipp_ops(i)
+		ipp_print_property(property, i);
+
+	/*
+	 * set property ioctl generated new prop_id.
+	 * but in this case already asigned prop_id using old set property.
+	 * e.g PAUSE state. this case supports find current prop_id and use

it

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +4 -0
+	 * instead of allocation.
+	 */
+	if (property->prop_id) {
+		DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property-
Quoted 1 line

prop_id);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +124 -0
+		return ipp_find_and_set_property(property);
+	}
+
+	/* find ipp driver using ipp id */
+	ippdrv = ipp_find_driver(ctx, property);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;
+	}
+
+	/* allocate command node */
+	c_node = kzalloc(sizeof(*c_node), GFP_KERNEL);
+	if (!c_node) {
+		DRM_ERROR("failed to allocate map node.\n");
+		return -ENOMEM;
+	}
+
+	/* create property id */
+	ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node,
+		&property->prop_id);
+	if (ret) {
+		DRM_ERROR("failed to create id.\n");
+		goto err_clear;
+	}
+
+	DRM_DEBUG_KMS("%s:created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
+		__func__, property->prop_id, property->cmd, (int)ippdrv);
+
+	/* stored property information and ippdrv in private data */
+	c_node->priv = priv;
+	c_node->property = *property;
+	c_node->state = IPP_STATE_IDLE;
+
+	c_node->start_work = ipp_create_cmd_work();
+	if (IS_ERR_OR_NULL(c_node->start_work)) {
+		DRM_ERROR("failed to create start work.\n");
+		goto err_clear;
+	}
+
+	c_node->stop_work = ipp_create_cmd_work();
+	if (IS_ERR_OR_NULL(c_node->stop_work)) {
+		DRM_ERROR("failed to create stop work.\n");
+		goto err_free_start;
+	}
+
+	c_node->event_work = ipp_create_event_work();
+	if (IS_ERR_OR_NULL(c_node->event_work)) {
+		DRM_ERROR("failed to create event work.\n");
+		goto err_free_stop;
+	}
+
+	mutex_init(&c_node->cmd_lock);
+	mutex_init(&c_node->mem_lock);
+	mutex_init(&c_node->event_lock);
+
+	init_completion(&c_node->start_complete);
+	init_completion(&c_node->stop_complete);
+
+	for_each_ipp_ops(i)
+		INIT_LIST_HEAD(&c_node->mem_list[i]);
+
+	INIT_LIST_HEAD(&c_node->event_list);
+	list_splice_init(&priv->event_list, &c_node->event_list);
+	list_add_tail(&c_node->list, &ippdrv->cmd_list);
+
+	/* make dedicated state without m2m */
+	if (!ipp_is_m2m_cmd(property->cmd))
+		ippdrv->dedicated = true;
+
+	return 0;
+
+err_free_stop:
+	kfree(c_node->stop_work);
+err_free_start:
+	kfree(c_node->start_work);
+err_clear:
+	kfree(c_node);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_set_property);
+
+static void ipp_clean_cmd_node(struct drm_exynos_ipp_cmd_node *c_node)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* delete list */
+	list_del(&c_node->list);
+
+	/* destroy mutex */
+	mutex_destroy(&c_node->cmd_lock);
+	mutex_destroy(&c_node->mem_lock);
+	mutex_destroy(&c_node->event_lock);
+
+	/* free command node */
+	kfree(c_node->start_work);
+	kfree(c_node->stop_work);
+	kfree(c_node->event_work);
+	kfree(c_node);
+}
+
+static int ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct list_head *head;
+	int ret, i, count[EXYNOS_DRM_OPS_MAX] = { 0, };
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	mutex_lock(&c_node->mem_lock);
+
+	for_each_ipp_ops(i) {
+		/* source/destination memory list */
+		head = &c_node->mem_list[i];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:%s memory empty.\n", __func__,
+				i ? "dst" : "src");
+			continue;
+		}
+
+		/* find memory node entry */
+		list_for_each_entry(m_node, head, list) {
+			DRM_DEBUG_KMS("%s:%s,count[%d]m_node[0x%x]\n",

__func__,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +123 -0
+				i ? "dst" : "src", count[i], (int)m_node);
+			count[i]++;
+		}
+	}
+
+	DRM_DEBUG_KMS("%s:min[%d]max[%d]\n", __func__,
+		min(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]),
+		max(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]));
+
+	/*
+	 * M2M operations should be need paired memory address.
+	 * so, need to check minimum count about src, dst.
+	 * other case not use paired memory, so use maximum count
+	 */
+	if (ipp_is_m2m_cmd(property->cmd))
+		ret = min(count[EXYNOS_DRM_OPS_SRC],
+			count[EXYNOS_DRM_OPS_DST]);
+	else
+		ret = max(count[EXYNOS_DRM_OPS_SRC],
+			count[EXYNOS_DRM_OPS_DST]);
+
+	mutex_unlock(&c_node->mem_lock);
+
+	return ret;
+}
+
+static struct drm_exynos_ipp_mem_node
+		*ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct list_head *head;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:buf_id[%d]\n", __func__, qbuf->buf_id);
+
+	/* source/destination memory list */
+	head = &c_node->mem_list[qbuf->ops_id];
+
+	/* find memory node from memory list */
+	list_for_each_entry(m_node, head, list) {
+		DRM_DEBUG_KMS("%s:count[%d]m_node[0x%x]\n",
+			__func__, count++, (int)m_node);
+
+		/* compare buffer id */
+		if (m_node->buf_id == qbuf->buf_id)
+			return m_node;
+	}
+
+	return NULL;
+}
+
+static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node)
+{
+	struct exynos_drm_ipp_ops *ops = NULL;
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s:node[0x%x]\n", __func__, (int)m_node);
+
+	if (!m_node) {
+		DRM_ERROR("invalid queue node.\n");
+		return -EFAULT;
+	}
+
+	mutex_lock(&c_node->mem_lock);
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]\n", __func__, m_node->ops_id);
+
+	/* get operations callback */
+	ops = ippdrv->ops[m_node->ops_id];
+	if (!ops) {
+		DRM_ERROR("not support ops.\n");
+		ret = -EFAULT;
+		goto err_unlock;
+	}
+
+	/* set address and enable irq */
+	if (ops->set_addr) {
+		ret = ops->set_addr(ippdrv->dev, &m_node->buf_info,
+			m_node->buf_id, IPP_BUF_ENQUEUE);
+		if (ret) {
+			DRM_ERROR("failed to set addr.\n");
+			goto err_unlock;
+		}
+	}
+
+err_unlock:
+	mutex_unlock(&c_node->mem_lock);
+	return ret;
+}
+
+static struct drm_exynos_ipp_mem_node
+		*ipp_get_mem_node(struct drm_device *drm_dev,
+		struct drm_file *file,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_buf_info buf_info;
+	void *addr;
+	int i;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	mutex_lock(&c_node->mem_lock);
+
+	m_node = kzalloc(sizeof(*m_node), GFP_KERNEL);
+	if (!m_node) {
+		DRM_ERROR("failed to allocate queue node.\n");
+		goto err_unlock;
+	}
+
+	/* clear base address for error handling */
+	memset(&buf_info, 0x0, sizeof(buf_info));
+
+	/* operations, buffer id */
+	m_node->ops_id = qbuf->ops_id;
+	m_node->prop_id = qbuf->prop_id;
+	m_node->buf_id = qbuf->buf_id;
+
+	DRM_DEBUG_KMS("%s:m_node[0x%x]ops_id[%d]\n", __func__,

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 718

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+		(int)m_node, qbuf->ops_id);
+	DRM_DEBUG_KMS("%s:prop_id[%d]buf_id[%d]\n", __func__,
+		qbuf->prop_id, m_node->buf_id);
+
+	for_each_ipp_planar(i) {
+		DRM_DEBUG_KMS("%s:i[%d]handle[0x%x]\n", __func__,
+			i, qbuf->handle[i]);
+
+		/* get dma address by handle */
+		if (qbuf->handle[i] != 0) {

if (qbuf->handle[i]) {

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 721

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0
+			addr = exynos_drm_gem_get_dma_addr(drm_dev,
+					qbuf->handle[i], file);
+			if (!addr) {

if (IS_ERR(addr))

Quoted 56 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +56 -0
+				DRM_ERROR("failed to get addr.\n");
+				goto err_clear;
+			}
+
+			buf_info.handles[i] = qbuf->handle[i];
+			buf_info.base[i] = *(dma_addr_t *) addr;
+			DRM_DEBUG_KMS("%s:i[%d]base[0x%x]hd[0x%x]\n",
+				__func__, i, buf_info.base[i],
+				(int)buf_info.handles[i]);
+		}
+	}
+
+	m_node->filp = file;
+	m_node->buf_info = buf_info;
+	list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]);
+
+	mutex_unlock(&c_node->mem_lock);
+	return m_node;
+
+err_clear:
+	kfree(m_node);
+err_unlock:
+	mutex_unlock(&c_node->mem_lock);
+	return ERR_PTR(-EFAULT);
+}
+
+static int ipp_put_mem_node(struct drm_device *drm_dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node)
+{
+	int i;
+
+	DRM_DEBUG_KMS("%s:node[0x%x]\n", __func__, (int)m_node);
+
+	if (!m_node) {
+		DRM_ERROR("invalid dequeue node.\n");
+		return -EFAULT;
+	}
+
+	if (list_empty(&m_node->list)) {
+		DRM_ERROR("empty memory node.\n");
+		return -ENOMEM;
+	}
+
+	mutex_lock(&c_node->mem_lock);
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]\n", __func__, m_node->ops_id);
+
+	/* put gem buffer */
+	for_each_ipp_planar(i) {
+		unsigned long handle = m_node->buf_info.handles[i];
+		if (handle)
+			exynos_drm_gem_put_dma_addr(drm_dev, handle,
+							m_node->filp);
+	}
+

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 787

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	/* delete list in queue */
+	list_del(&m_node->list);
+	kfree(m_node);
+
+	mutex_unlock(&c_node->mem_lock);
+
+	return 0;
+}
+
+static void ipp_free_event(struct drm_pending_event *event)

Does this function need? This function just calls kfree. Just call kfree instead of wrapper.

Quoted 106 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +106 -0
+{
+	kfree(event);
+}
+
+static int ipp_get_event(struct drm_device *drm_dev,
+		struct drm_file *file,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_send_event *e;
+	unsigned long flags;
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]buf_id[%d]\n", __func__,
+		qbuf->ops_id, qbuf->buf_id);
+
+	e = kzalloc(sizeof(*e), GFP_KERNEL);
+
+	if (!e) {
+		DRM_ERROR("failed to allocate event.\n");
+		spin_lock_irqsave(&drm_dev->event_lock, flags);
+		file->event_space += sizeof(e->event);
+		spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+		return -ENOMEM;
+	}
+
+	/* make event */
+	e->event.base.type = DRM_EXYNOS_IPP_EVENT;
+	e->event.base.length = sizeof(e->event);
+	e->event.user_data = qbuf->user_data;
+	e->event.prop_id = qbuf->prop_id;
+	e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id;
+	e->base.event = &e->event.base;
+	e->base.file_priv = file;
+	e->base.destroy = ipp_free_event;
+	list_add_tail(&e->base.link, &c_node->event_list);
+
+	return 0;
+}
+
+static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_send_event *e, *te;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (list_empty(&c_node->event_list)) {
+		DRM_DEBUG_KMS("%s:event_list is empty.\n", __func__);
+		return;
+	}
+
+	list_for_each_entry_safe(e, te, &c_node->event_list, base.link) {
+		DRM_DEBUG_KMS("%s:count[%d]e[0x%x]\n",
+			__func__, count++, (int)e);
+
+		/*
+		 * quf == NULL condition means all event deletion.
+		 * stop operations want to delete all event list.
+		 * another case delete only same buf id.
+		 */
+		if (!qbuf) {
+			/* delete list */
+			list_del(&e->base.link);
+			kfree(e);
+		}
+
+		/* compare buffer id */
+		if (qbuf && (qbuf->buf_id ==
+		    e->event.buf_id[EXYNOS_DRM_OPS_DST])) {
+			/* delete list */
+			list_del(&e->base.link);
+			kfree(e);
+			return;
+		}
+	}
+}
+
+void ipp_handle_cmd_work(struct device *dev,
+		struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_work *cmd_work,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct ipp_context *ctx = get_ipp_context(dev);
+
+	cmd_work->ippdrv = ippdrv;
+	cmd_work->c_node = c_node;
+	queue_work(ctx->cmd_workq, (struct work_struct *)cmd_work);
+}
+
+static int ipp_queue_buf_with_run(struct device *dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_property *property;
+	struct exynos_drm_ipp_ops *ops;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	ippdrv = ipp_find_drv_by_handle(qbuf->prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EFAULT;

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 903

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	}
+
+	ops = ippdrv->ops[qbuf->ops_id];
+	if (!ops) {
+		DRM_ERROR("failed to get ops.\n");
+		return -EFAULT;
+	}
+
+	property = &c_node->property;
+	if (!property) {

Property couldn't be NULL. remove it.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 910

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	if (c_node->state != IPP_STATE_START) {
+		DRM_DEBUG_KMS("%s:bypass for invalid state.\n" , __func__);
+		return 0;

No error?

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 915

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+	}
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return 0;

No error?

Quoted 74 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +8 -0
+	}
+
+	/*
+	 * If set destination buffer and enabled clock,
+	 * then m2m operations need start operations at queue_buf
+	 */
+	if (ipp_is_m2m_cmd(property->cmd)) {
+		struct drm_exynos_ipp_cmd_work *cmd_work = c_node-
Quoted 1 line

start_work;

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +65 -0
+
+		cmd_work->ctrl = IPP_CTRL_PLAY;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+	} else {
+		ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+		if (ret) {
+			DRM_ERROR("failed to set m node.\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static void ipp_clean_queue_buf(struct drm_device *drm_dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node, *tm_node;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!list_empty(&c_node->mem_list[qbuf->ops_id])) {
+		/* delete list */
+		list_for_each_entry_safe(m_node, tm_node,
+			&c_node->mem_list[qbuf->ops_id], list) {
+			if (m_node->buf_id == qbuf->buf_id &&
+			    m_node->ops_id == qbuf->ops_id)
+				ipp_put_mem_node(drm_dev, c_node, m_node);
+		}
+	}
+}
+
+int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_queue_buf *qbuf = data;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	struct drm_exynos_ipp_mem_node *m_node;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!qbuf) {
+		DRM_ERROR("invalid buf parameter.\n");
+		return -EINVAL;
+	}
+
+	if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) {
+		DRM_ERROR("invalid ops parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
+		__func__, qbuf->prop_id, qbuf->ops_id ? "dst" : "src",
+		qbuf->buf_id, qbuf->buf_type);
+
+	/* find command node */
+	c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
+		qbuf->prop_id);
+	if (!c_node) {

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 998

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+		DRM_ERROR("failed to get command node.\n");
+		return -EFAULT;
+	}
+
+	/* buffer control */
+	switch (qbuf->buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* get memory node */
+		m_node = ipp_get_mem_node(drm_dev, file, c_node, qbuf);
+		if (IS_ERR_OR_NULL(m_node)) {

This function never returns error. Use IS_ERR(m_node) instead.

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+			DRM_ERROR("failed to get m_node.\n");
+			return -EINVAL;

And return PTR_ERR(m_node);

Quoted 42 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +20 -0
+		}
+
+		/*
+		 * first step get event for destination buffer.
+		 * and second step when M2M case run with destination buffer
+		 * if needed.
+		 */
+		if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) {
+			/* get event for destination buffer */
+			ret = ipp_get_event(drm_dev, file, c_node, qbuf);
+			if (ret) {
+				DRM_ERROR("failed to get event.\n");
+				goto err_clean_node;
+			}
+
+			/*
+			 * M2M case run play control for streaming feature.
+			 * other case set address and waiting.
+			 */
+			ret = ipp_queue_buf_with_run(dev, c_node, m_node,

qbuf);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +21 -0
+			if (ret) {
+				DRM_ERROR("failed to run command.\n");
+				goto err_clean_node;
+			}
+		}
+		break;
+	case IPP_BUF_DEQUEUE:
+		mutex_lock(&c_node->cmd_lock);
+
+		/* put event for destination buffer */
+		if (qbuf->ops_id == EXYNOS_DRM_OPS_DST)
+			ipp_put_event(c_node, qbuf);
+
+		ipp_clean_queue_buf(drm_dev, c_node, qbuf);
+
+		mutex_unlock(&c_node->cmd_lock);
+		break;
+	default:
+		DRM_ERROR("invalid buffer control.\n");
+		return -EINVAL;
+	}

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1051

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+	return 0;
+
+err_clean_node:
+	DRM_ERROR("clean memory nodes.\n");
+
+	ipp_clean_queue_buf(drm_dev, c_node, qbuf);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_queue_buf);

Remove EXPORT_SYMBOL_GPL.

Quoted 64 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0
+
+static bool exynos_drm_ipp_check_valid(struct device *dev,
+		enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state

state)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +60 -0
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (ctrl != IPP_CTRL_PLAY) {
+		if (pm_runtime_suspended(dev)) {
+			DRM_ERROR("pm:runtime_suspended.\n");
+			goto err_status;
+		}
+	}
+
+	switch (ctrl) {
+	case IPP_CTRL_PLAY:
+		if (state != IPP_STATE_IDLE)
+			goto err_status;
+		break;
+	case IPP_CTRL_STOP:
+		if (state == IPP_STATE_STOP)
+			goto err_status;
+		break;
+	case IPP_CTRL_PAUSE:
+		if (state != IPP_STATE_START)
+			goto err_status;
+		break;
+	case IPP_CTRL_RESUME:
+		if (state != IPP_STATE_STOP)
+			goto err_status;
+		break;
+	default:
+		DRM_ERROR("invalid state.\n");
+		goto err_status;
+		break;
+	}
+
+	return true;
+
+err_status:
+	DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
+	return false;
+}
+
+int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct exynos_drm_ippdrv *ippdrv = NULL;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
+	struct drm_exynos_ipp_cmd_work *cmd_work;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1124

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	if (!cmd_ctrl) {
+		DRM_ERROR("invalid control parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:ctrl[%d]prop_id[%d]\n", __func__,
+		cmd_ctrl->ctrl, cmd_ctrl->prop_id);
+
+	ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {

Never return NULL. just use IS_ERR(ippdrv)

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;

And return PTR_ERR(ippdrv);

Quoted 57 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +57 -0
+	}
+
+	c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
+		cmd_ctrl->prop_id);
+	if (!c_node) {
+		DRM_ERROR("invalid command node list.\n");
+		return -EINVAL;
+	}
+
+	if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
+	    c_node->state)) {
+		DRM_ERROR("invalid state.\n");
+		return -EINVAL;
+	}
+
+	switch (cmd_ctrl->ctrl) {
+	case IPP_CTRL_PLAY:
+		if (pm_runtime_suspended(ippdrv->dev))
+			pm_runtime_get_sync(ippdrv->dev);
+		c_node->state = IPP_STATE_START;
+
+		cmd_work = c_node->start_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+		c_node->state = IPP_STATE_START;
+		break;
+	case IPP_CTRL_STOP:
+		cmd_work = c_node->stop_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+
+		if (!wait_for_completion_timeout(&c_node->stop_complete,
+		    msecs_to_jiffies(300))) {
+			DRM_ERROR("timeout stop:prop_id[%d]\n",
+				c_node->property.prop_id);
+		}
+
+		c_node->state = IPP_STATE_STOP;
+		ippdrv->dedicated = false;
+		ipp_clean_cmd_node(c_node);
+
+		if (list_empty(&ippdrv->cmd_list))
+			pm_runtime_put_sync(ippdrv->dev);
+		break;
+	case IPP_CTRL_PAUSE:
+		cmd_work = c_node->stop_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+
+		if (!wait_for_completion_timeout(&c_node->stop_complete,
+		    msecs_to_jiffies(200))) {
+			DRM_ERROR("timeout stop:prop_id[%d]\n",
+				c_node->property.prop_id);
+		}
+
+		c_node->state = IPP_STATE_STOP;
+		break;

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1193

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	case IPP_CTRL_RESUME:
+		c_node->state = IPP_STATE_START;
+		cmd_work = c_node->start_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+		break;
+	default:
+		/* ToDo: expand ctrl operation */
+		DRM_ERROR("could not support this state currently.\n");
+		goto err_clear;

Just return error;

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1202

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +9 -0
+	}
+
+	DRM_DEBUG_KMS("%s:done ctrl[%d]prop_id[%d]\n", __func__,
+		cmd_ctrl->ctrl, cmd_ctrl->prop_id);
+
+	return 0;
+
+err_clear:
+	return ret;

And remove the above label.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1204

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_cmd_ctrl);

Remove it.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1211

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_register(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(
+			&exynos_drm_ippnb_list, nb);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_register);

Remove it.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1218

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_unregister(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(
+			&exynos_drm_ippnb_list, nb);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_unregister);

Remove it.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1225

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_send_event(unsigned long val, void *v)
+{
+	return blocking_notifier_call_chain(
+			&exynos_drm_ippnb_list, val, v);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_send_event);

Remove it.

Quoted 183 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +183 -0
+
+static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_property *property)
+{
+	struct exynos_drm_ipp_ops *ops = NULL;
+	int ret, i, swap = 0;
+
+	if (!property) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* reset h/w block */
+	if (ippdrv->reset &&
+	    ippdrv->reset(ippdrv->dev)) {
+		DRM_ERROR("failed to reset.\n");
+		return -EINVAL;
+	}
+
+	/* set source,destination operations */
+	for_each_ipp_ops(i) {
+		/* ToDo: integrate property and config */
+		struct drm_exynos_ipp_config *config =
+			&property->config[i];
+
+		ops = ippdrv->ops[i];
+		if (!ops || !config) {
+			DRM_ERROR("not support ops and config.\n");
+			return -EINVAL;
+		}
+
+		/* set format */
+		if (ops->set_fmt) {
+			ret = ops->set_fmt(ippdrv->dev, config->fmt);
+			if (ret) {
+				DRM_ERROR("not support format.\n");
+				return ret;
+			}
+		}
+
+		/* set transform for rotation, flip */
+		if (ops->set_transf) {
+			swap = ops->set_transf(ippdrv->dev, config->degree,
+				config->flip);
+			if (swap < 0) {
+				DRM_ERROR("not support tranf.\n");
+				return -EINVAL;
+			}
+		}
+
+		/* set size */
+		if (ops->set_size) {
+			ret = ops->set_size(ippdrv->dev, swap, &config->pos,
+				&config->sz);
+			if (ret) {
+				DRM_ERROR("not support size.\n");
+				return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct list_head *head;
+	int ret, i;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* store command info in ippdrv */
+	ippdrv->cmd = c_node;
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return -ENOMEM;
+	}
+
+	/* set current property in ippdrv */
+	ret = ipp_set_property(ippdrv, property);
+	if (ret) {
+		DRM_ERROR("failed to set property.\n");
+		ippdrv->cmd = NULL;
+		return ret;
+	}
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			m_node = list_first_entry(head,
+				struct drm_exynos_ipp_mem_node, list);
+			if (!m_node) {
+				DRM_ERROR("failed to get node.\n");
+				ret = -EFAULT;
+				return ret;
+			}
+
+			DRM_DEBUG_KMS("%s:m_node[0x%x]\n",
+				__func__, (int)m_node);
+
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	case IPP_CMD_WB:
+		/* destination memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
+
+		list_for_each_entry(m_node, head, list) {
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		list_for_each_entry(m_node, head, list) {
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:cmd[%d]\n", __func__, property->cmd);
+
+	/* start operations */
+	if (ippdrv->start) {
+		ret = ippdrv->start(ippdrv->dev, property->cmd);
+		if (ret) {
+			DRM_ERROR("failed to start ops.\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int ipp_stop_property(struct drm_device *drm_dev,
+		struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_mem_node *m_node, *tm_node;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct list_head *head;
+	int ret = 0, i;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* put event */
+	ipp_put_event(c_node, NULL);
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			if (list_empty(head)) {
+				DRM_DEBUG_KMS("%s:mem_list is empty.\n",

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+					__func__);
+				break;
+			}
+
+			list_for_each_entry_safe(m_node, tm_node,
+				head, list) {
+				ret = ipp_put_mem_node(drm_dev, c_node,
+					m_node);
+				if (ret) {
+					DRM_ERROR("failed to put

m_node.\n");

Quoted 94 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +94 -0
+					goto err_clear;
+				}
+			}
+		}
+		break;
+	case IPP_CMD_WB:
+		/* destination memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:mem_list is empty.\n", __func__);
+			break;
+		}
+
+		list_for_each_entry_safe(m_node, tm_node, head, list) {
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to put m_node.\n");
+				goto err_clear;
+			}
+		}
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:mem_list is empty.\n", __func__);
+			break;
+		}
+
+		list_for_each_entry_safe(m_node, tm_node, head, list) {
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to put m_node.\n");
+				goto err_clear;
+			}
+		}
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		ret = -EINVAL;
+		goto err_clear;
+	}
+
+err_clear:
+	/* stop operations */
+	if (ippdrv->stop)
+		ippdrv->stop(ippdrv->dev, property->cmd);
+
+	return ret;
+}
+
+void ipp_sched_cmd(struct work_struct *work)
+{
+	struct drm_exynos_ipp_cmd_work *cmd_work =
+		(struct drm_exynos_ipp_cmd_work *)work;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	struct drm_exynos_ipp_property *property;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	ippdrv = cmd_work->ippdrv;
+	if (!ippdrv) {
+		DRM_ERROR("invalid ippdrv list.\n");
+		return;
+	}
+
+	c_node = cmd_work->c_node;
+	if (!c_node) {
+		DRM_ERROR("invalid command node list.\n");
+		return;
+	}
+
+	mutex_lock(&c_node->cmd_lock);
+
+	property = &c_node->property;
+	if (!property) {
+		DRM_ERROR("failed to get property:prop_id[%d]\n",
+			c_node->property.prop_id);
+		goto err_unlock;
+	}
+
+	switch (cmd_work->ctrl) {
+	case IPP_CTRL_PLAY:
+	case IPP_CTRL_RESUME:
+		ret = ipp_start_property(ippdrv, c_node);
+		if (ret) {
+			DRM_ERROR("failed to start property:prop_id[%d]\n",
+				c_node->property.prop_id);
+			goto err_unlock;
+		}

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+		/*
+		 * M2M case supports wait_completion of transfer.
+		 * because M2M case supports single unit operation
+		 * with multiple queue.
+		 * M2M need to wait completion of data transfer.
+		 */
+		if (ipp_is_m2m_cmd(property->cmd)) {
+			if (!wait_for_completion_timeout
+			    (&c_node->start_complete,

msecs_to_jiffies(200))) {

Quoted 285 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +169 -0
+				DRM_ERROR("timeout event:prop_id[%d]\n",
+					c_node->property.prop_id);
+				goto err_unlock;
+			}
+		}
+		break;
+	case IPP_CTRL_STOP:
+	case IPP_CTRL_PAUSE:
+		ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
+			c_node);
+		if (ret) {
+			DRM_ERROR("failed to stop property.\n");
+			goto err_unlock;
+		}
+
+		complete(&c_node->stop_complete);
+		break;
+	default:
+		DRM_ERROR("unknown control type\n");
+		break;
+	}
+
+	DRM_DEBUG_KMS("%s:ctrl[%d] done.\n", __func__, cmd_work->ctrl);
+
+err_unlock:
+	mutex_unlock(&c_node->cmd_lock);
+}
+
+static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
+{
+	struct drm_device *drm_dev = ippdrv->drm_dev;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_queue_buf qbuf;
+	struct drm_exynos_ipp_send_event *e;
+	struct list_head *head;
+	struct timeval now;
+	unsigned long flags;
+	u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
+	int ret, i;
+
+	for_each_ipp_ops(i)
+		DRM_DEBUG_KMS("%s:%s buf_id[%d]\n", __func__,
+			i ? "dst" : "src", buf_id[i]);
+
+	if (!drm_dev) {
+		DRM_ERROR("failed to get drm_dev.\n");
+		return -EINVAL;
+	}
+
+	if (!property) {
+		DRM_ERROR("failed to get property.\n");
+		return -EINVAL;
+	}
+
+	if (list_empty(&c_node->event_list)) {
+		DRM_DEBUG_KMS("%s:event list is empty.\n", __func__);
+		return 0;
+	}
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return 0;
+	}
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			m_node = list_first_entry(head,
+				struct drm_exynos_ipp_mem_node, list);
+			if (!m_node) {
+				DRM_ERROR("empty memory node.\n");
+				return -ENOMEM;
+			}
+
+			tbuf_id[i] = m_node->buf_id;
+			DRM_DEBUG_KMS("%s:%s buf_id[%d]\n", __func__,
+				i ? "dst" : "src", tbuf_id[i]);
+
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret)
+				DRM_ERROR("failed to put m_node.\n");
+		}
+		break;
+	case IPP_CMD_WB:
+		/* clear buf for finding */
+		memset(&qbuf, 0x0, sizeof(qbuf));
+		qbuf.ops_id = EXYNOS_DRM_OPS_DST;
+		qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
+
+		/* get memory node entry */
+		m_node = ipp_find_mem_node(c_node, &qbuf);
+		if (!m_node) {
+			DRM_ERROR("empty memory node.\n");
+			return -ENOMEM;
+		}
+
+		tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
+
+		ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+		if (ret)
+			DRM_ERROR("failed to put m_node.\n");
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		m_node = list_first_entry(head,
+			struct drm_exynos_ipp_mem_node, list);
+		if (!m_node) {
+			DRM_ERROR("empty memory node.\n");
+			return -ENOMEM;
+		}
+
+		tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
+
+		ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+		if (ret)
+			DRM_ERROR("failed to put m_node.\n");
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		return -EINVAL;
+	}
+
+	/* ToDo: Fix buffer id */
+	if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
+		DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
+			tbuf_id[1], buf_id[1], property->prop_id);
+
+	/*
+	 * command node have event list of destination buffer
+	 * If destination buffer enqueue to mem list,
+	 * then we make event and link to event list tail.
+	 * so, we get first event for first enqueued buffer.
+	 */
+	e = list_first_entry(&c_node->event_list,
+		struct drm_exynos_ipp_send_event, base.link);
+
+	if (!e) {
+		DRM_ERROR("empty event.\n");
+		return -EINVAL;
+	}
+
+	do_gettimeofday(&now);
+	DRM_DEBUG_KMS("%s:tv_sec[%ld]tv_usec[%ld]\n"
+		, __func__, now.tv_sec, now.tv_usec);
+	e->event.tv_sec = now.tv_sec;
+	e->event.tv_usec = now.tv_usec;
+	e->event.prop_id = property->prop_id;
+
+	/* set buffer id about source destination */
+	for_each_ipp_ops(i)
+		e->event.buf_id[i] = tbuf_id[i];
+
+	/* ToDo: compare index. If needed */
+
+	spin_lock_irqsave(&drm_dev->event_lock, flags);
+	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
+	wake_up_interruptible(&e->base.file_priv->event_wait);
+	spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+
+	DRM_DEBUG_KMS("%s:done cmd[%d]prop_id[%d]buf_id[%d]\n", __func__,
+		property->cmd, property->prop_id,

tbuf_id[EXYNOS_DRM_OPS_DST]);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +60 -0
+
+	return 0;
+}
+
+void ipp_sched_event(struct work_struct *work)
+{
+	struct drm_exynos_ipp_event_work *event_work =
+		(struct drm_exynos_ipp_event_work *)work;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret;
+
+	if (!event_work) {
+		DRM_ERROR("failed to get event_work.\n");
+		return;
+	}
+
+	DRM_DEBUG_KMS("%s:buf_id[%d]\n", __func__,
+		event_work->buf_id[EXYNOS_DRM_OPS_DST]);
+
+	ippdrv = event_work->ippdrv;
+	if (!ippdrv) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return;
+	}
+
+	c_node = ippdrv->cmd;
+	if (!c_node) {
+		DRM_ERROR("failed to get command node.\n");
+		return;
+	}
+
+	/*
+	 * IPP supports command thread, event thread synchronization.
+	 * If IPP close immediately from user land, then IPP make
+	 * synchronization with command thread, so make complete event.
+	 * or going out operations.
+	 */
+	if (c_node->state != IPP_STATE_START) {
+		DRM_DEBUG_KMS("%s:bypass state[%d]prop_id[%d]\n",
+			__func__, c_node->state, c_node->property.prop_id);
+		goto err_completion;
+	}
+
+	mutex_lock(&c_node->event_lock);
+
+	ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
+	if (ret) {
+		DRM_ERROR("failed to send event.\n");
+		goto err_completion;
+	}
+
+err_completion:
+	if (ipp_is_m2m_cmd(c_node->property.cmd))
+		complete(&c_node->start_complete);
+
+	mutex_unlock(&c_node->event_lock);
+}
+
+static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device

*dev)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +19 -0
+{
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret, count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* get ipp driver entry */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		ippdrv->drm_dev = drm_dev;
+
+		ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv,
+			&ippdrv->ipp_id);
+		if (ret) {
+			DRM_ERROR("failed to create id.\n");
+			goto err_idr;
+		}
+
+		DRM_DEBUG_KMS("%s:count[%d]ippdrv[0x%x]ipp_id[%d]\n",

__func__,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +28 -0
+			count++, (int)ippdrv, ippdrv->ipp_id);
+
+		if (ippdrv->ipp_id == 0) {
+			DRM_ERROR("failed to get ipp_id[%d]\n",
+				ippdrv->ipp_id);
+			goto err_idr;
+		}
+
+		/* store parent device for node */
+		ippdrv->parent_dev = dev;
+
+		/* store event work queue and handler */
+		ippdrv->event_workq = ctx->event_workq;
+		ippdrv->sched_event = ipp_sched_event;
+		INIT_LIST_HEAD(&ippdrv->cmd_list);
+	}
+
+	return 0;
+
+err_idr:
+	idr_remove_all(&ctx->ipp_idr);
+	idr_remove_all(&ctx->prop_idr);
+	idr_destroy(&ctx->ipp_idr);
+	idr_destroy(&ctx->prop_idr);
+	return ret;
+}
+
+static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device

*dev)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+{
+	struct exynos_drm_ippdrv *ippdrv;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	/* get ipp driver entry */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		ippdrv->drm_dev = NULL;
+		exynos_drm_ippdrv_unregister(ippdrv);
+	}
+
+	/* ToDo: free notifier callback list if needed */
+}
+
+static int ipp_subdrv_open(struct drm_device *drm_dev, struct device

*dev,

Quoted 43 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +25 -0
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* ToDo: multi device open */
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv) {
+		DRM_ERROR("failed to allocate priv.\n");
+		return -ENOMEM;
+	}
+	priv->dev = dev;
+	file_priv->ipp_priv = priv;
+
+	INIT_LIST_HEAD(&priv->event_list);
+
+	DRM_DEBUG_KMS("%s:done priv[0x%x]\n", __func__, (int)priv);
+
+	return 0;
+}
+
+static void ipp_subdrv_close(struct drm_device *drm_dev, struct device

*dev,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +17 -0
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct exynos_drm_ippdrv *ippdrv = NULL;
+	struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:for priv[0x%x]\n", __func__, (int)priv);
+
+	if (list_empty(&exynos_drm_ippdrv_list)) {
+		DRM_DEBUG_KMS("%s:ippdrv_list is empty.\n", __func__);
+		goto err_clear;
+	}
+
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		if (list_empty(&ippdrv->cmd_list))

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+			continue;
+
+		list_for_each_entry_safe(c_node, tc_node,
+			&ippdrv->cmd_list, list) {
+			DRM_DEBUG_KMS("%s:count[%d]ippdrv[0x%x]\n",
+				__func__, count++, (int)ippdrv);
+
+			if (c_node->priv == priv) {
+				/*
+				 * userland goto unnormal state. process

killed.

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0
+				 * and close the file.
+				 * so, IPP didn't called stop cmd ctrl.
+				 * so, we are make stop operation in this

state.

drivers/gpu/drm/exynos/exynos_drm_ipp.h

Quoted 356 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +191 -0
+				 */
+				if (c_node->state == IPP_STATE_START) {
+					ipp_stop_property(drm_dev, ippdrv,
+						c_node);
+					c_node->state = IPP_STATE_STOP;
+				}
+
+				ippdrv->dedicated = false;
+				ipp_clean_cmd_node(c_node);
+				if (list_empty(&ippdrv->cmd_list))
+					pm_runtime_put_sync(ippdrv->dev);
+			}
+		}
+	}
+
+err_clear:
+	kfree(priv);
+	return;
+}
+
+static int __devinit ipp_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ipp_context *ctx;
+	struct exynos_drm_subdrv *subdrv;
+	int ret;
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/exynos/exynos_drm_ipp.h new file +9 -0
new file mode 100644
index 0000000..baab1f0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

28 lines not shown · raw message

drivers/gpu/drm/exynos/exynos_drm_ipp.h new file +121 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

358 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#3 lore raw

Re: [RFC v3 1/5] drm/exynos: add ipp subsystem

Thank's your comment.

I anwer your comment, please check that.

Thank's

BR
Eunchul Kim.

Quoted 355 lines · Inki Dae
Quoted 75 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 1/5] drm/exynos: add ipp subsystem

IPP stand for Image Post Processing and supports image scaler/rotator /crop/flip/csc(color space conversion) and input/output DMA operations using ipp drivers.
also supports writeback and display output operations.
ipp driver include FIMC, Rotator, GSC, SC, so on.
and ipp is integration device driver for each hardware.

---
  drivers/gpu/drm/exynos/Kconfig          |    6 +
  drivers/gpu/drm/exynos/Makefile         |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c |   24 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h |    7 +
  drivers/gpu/drm/exynos/exynos_drm_ipp.c | 2059
+++++++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_ipp.h |  266 ++++
  include/uapi/drm/exynos_drm.h           |  190 +++
  7 files changed, 2553 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_ipp.h

drivers/gpu/drm/exynos/Kconfig +6 -0
index 4ea8cdc..bcf1c9d 100644
@@ -45,3 +45,9 @@ config DRM_EXYNOS_G2D
  	depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_G2D
  	help
  	  Choose this option if you want to use Exynos G2D for DRM.
+
+config DRM_EXYNOS_IPP
+	bool "Exynos DRM IPP"
+	depends on DRM_EXYNOS
+	help
+	  Choose this option if you want to use IPP feature for DRM.
drivers/gpu/drm/exynos/Makefile +1 -0
index 26813b8..6c536ce 100644
@@ -16,5 +16,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI)	+=
 exynos_hdmi.o exynos_mixer.o \
  					   exynos_drm_hdmi.o
  exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+= exynos_drm_vidi.o
  exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
 
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -0
index 4a1168d..0eb8a97 100644
@@ -40,6 +40,7 @@
  #include "exynos_drm_vidi.h"
  #include "exynos_drm_dmabuf.h"
  #include "exynos_drm_g2d.h"
+#include "exynos_drm_ipp.h"
  #include "exynos_drm_iommu.h"
 
  #define DRIVER_NAME	"exynos"

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = { · line 250

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -0
@@ -249,6 +250,14 @@ static struct drm_ioctl_desc exynos_ioctls[] = {
  			exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED |

DRM_AUTH),

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = {

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -0
  	DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
  			exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY,
+			exynos_drm_ipp_get_property, DRM_UNLOCKED |

DRM_AUTH),

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct drm_ioctl_desc exynos_ioctls[] = { · line 256

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -0
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY,
+			exynos_drm_ipp_set_property, DRM_UNLOCKED |

DRM_AUTH),

Quoted 270 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +19 -0
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF,
+			exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL,
+			exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH),
  };
 
  static const struct file_operations exynos_drm_driver_fops = {
@@ -363,6 +372,12 @@ static int __init exynos_drm_init(void)
  		goto out_g2d;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	ret = platform_driver_register(&ipp_driver);
+	if (ret < 0)
+		goto out_ipp;
+#endif
+
  	ret = platform_driver_register(&exynos_drm_platform_driver);
  	if (ret < 0)
  		goto out_drm;
@@ -380,6 +395,11 @@ out:
  	platform_driver_unregister(&exynos_drm_platform_driver);
 
  out_drm:
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+out_ipp:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_G2D
  	platform_driver_unregister(&g2d_driver);
  out_g2d:
@@ -416,6 +436,10 @@ static void __exit exynos_drm_exit(void)
 
  	platform_driver_unregister(&exynos_drm_platform_driver);
 
+#ifdef CONFIG_DRM_EXYNOS_IPP
+	platform_driver_unregister(&ipp_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_G2D
  	platform_driver_unregister(&g2d_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +7 -0
index a9db025..a365788 100644
@@ -235,8 +235,14 @@ struct exynos_drm_g2d_private {
  	unsigned int		gem_nr;
  };
 
+struct exynos_drm_ipp_private {
+	struct device	*dev;
+	struct list_head	event_list;
+};
+
  struct drm_exynos_file_private {
  	struct exynos_drm_g2d_private	*g2d_priv;
+	struct exynos_drm_ipp_private	*ipp_priv;
  };
 
  /*
@@ -346,4 +352,5 @@ extern struct platform_driver mixer_driver;
  extern struct platform_driver exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
+extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +8 -0
new file mode 100644
index 0000000..eb12cb5
@@ -0,0 +1,2059 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	Eunchul Kim <[email protected]>
+ *	Jinyoung Jeon <[email protected]>
+ *	Sangmin Lee <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify

it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +21 -0
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+#include <plat/map-base.h>
+
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "exynos_drm_drv.h"
+#include "exynos_drm_gem.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * IPP is stand for Image Post Processing and
+ * supports image scaler/rotator and input/output DMA operations.
+ * using FIMC, GSC, Rotator, so on.
+ * IPP is integration device driver of same attribute h/w
+ */
+
+#define get_ipp_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +88 -0
+#define ipp_is_m2m_cmd(c)	(c == IPP_CMD_M2M)
+
+/*
+ * A structure of event.
+ *
+ * @base: base of event.
+ * @event: ipp event.
+ */
+struct drm_exynos_ipp_send_event {
+	struct drm_pending_event	base;
+	struct drm_exynos_ipp_event	event;
+};
+
+/*
+ * A structure of memory node.
+ *
+ * @list: list head to memory queue information.
+ * @ops_id: id of operations.
+ * @prop_id: id of property.
+ * @buf_id: id of buffer.
+ * @buf_info: gem objects and dma address, size.
+ * @filp: a pointer to drm_file.
+ */
+struct drm_exynos_ipp_mem_node {
+	struct list_head	list;
+	enum drm_exynos_ops_id	ops_id;
+	u32	prop_id;
+	u32	buf_id;
+	struct drm_exynos_ipp_buf_info	buf_info;
+	struct drm_file		*filp;
+};
+
+/*
+ * A structure of ipp context.
+ *
+ * @subdrv: prepare initialization using subdrv.
+ * @ipp_lock: lock for synchronization of access to ipp_idr.
+ * @prop_lock: lock for synchronization of access to prop_idr.
+ * @ipp_idr: ipp driver idr.
+ * @prop_idr: property idr.
+ * @event_workq: event work queue.
+ * @cmd_workq: command work queue.
+ */
+struct ipp_context {
+	struct exynos_drm_subdrv	subdrv;
+	struct mutex	ipp_lock;
+	struct mutex	prop_lock;
+	struct idr	ipp_idr;
+	struct idr	prop_idr;
+	struct workqueue_struct	*event_workq;
+	struct workqueue_struct	*cmd_workq;
+};
+
+static LIST_HEAD(exynos_drm_ippdrv_list);
+static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
+static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
+
+int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv *ippdrv)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ippdrv)
+		return -EINVAL;
+
+	mutex_lock(&exynos_drm_ippdrv_lock);
+	list_add_tail(&ippdrv->drv_list, &exynos_drm_ippdrv_list);
+	mutex_unlock(&exynos_drm_ippdrv_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippdrv_register);
+
+int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv *ippdrv)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ippdrv)
+		return -EINVAL;
+
+	mutex_lock(&exynos_drm_ippdrv_lock);
+	list_del(&ippdrv->drv_list);
+	mutex_unlock(&exynos_drm_ippdrv_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippdrv_unregister);
+
+static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void

*obj,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +67 -0
+		u32 *idp)
+{
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+again:
+	/* ensure there is space available to allocate a handle */
+	if (idr_pre_get(id_idr, GFP_KERNEL) == 0) {
+		DRM_ERROR("failed to get idr.\n");
+		return -ENOMEM;
+	}
+
+	/* do the allocation under our mutexlock */
+	mutex_lock(lock);
+	ret = idr_get_new_above(id_idr, obj, 1, (int *)idp);
+	mutex_unlock(lock);
+	if (ret == -EAGAIN)
+		goto again;
+
+	return ret;
+}
+
+static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id)
+{
+	void *obj;
+
+	DRM_DEBUG_KMS("%s:id[%d]\n", __func__, id);
+
+	mutex_lock(lock);
+
+	/* find object using handle */
+	obj = idr_find(id_idr, id);
+	if (!obj) {
+		DRM_ERROR("failed to find object.\n");
+		mutex_unlock(lock);
+		return ERR_PTR(-ENODEV);
+	}
+
+	mutex_unlock(lock);
+
+	return obj;
+}
+
+static inline bool ipp_check_dedicated(struct exynos_drm_ippdrv *ippdrv,
+		enum drm_exynos_ipp_cmd	cmd)
+{
+	/*
+	 * check dedicated flag and WB, OUTPUT operation with
+	 * power on state.
+	 */
+	if (ippdrv->dedicated || (!ipp_is_m2m_cmd(cmd) &&
+	    !pm_runtime_suspended(ippdrv->dev)))
+		return true;
+
+	return false;
+}
+
+static struct exynos_drm_ippdrv *ipp_find_driver(struct ipp_context *ctx,
+		struct drm_exynos_ipp_property *property)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	u32 ipp_id = property->ipp_id;
+
+	DRM_DEBUG_KMS("%s:ipp_id[%d]\n", __func__, ipp_id);
+
+	if (ipp_id) {
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 195

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+		/* find ipp driver using idr */
+		ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
+			ipp_id);
+		if (IS_ERR_OR_NULL(ippdrv)) {
+			DRM_ERROR("not found ipp%d driver.\n", ipp_id);
+			goto err_null;

Just return ippdrv;

- done.

Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+		}
+
+		/*
+		 * WB, OUTPUT opertion not supported multi-operation.
+		 * so, make dedicated state at set property ioctl.
+		 * when ipp driver finished operations, clear dedicated

flags.

Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 205

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +4 -0
+		 */
+		if (ipp_check_dedicated(ippdrv, property->cmd)) {
+			DRM_ERROR("already used choose device.\n");
+			goto err_null;

Just return proper error;

- done ERR_PTR(-EBUSY);

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 216

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +11 -0
+		}
+
+		/*
+		 * This is necessary to find correct device in ipp drivers.
+		 * ipp drivers have different abilities,
+		 * so need to check property.
+		 */
+		if (ippdrv->check_property &&
+		    ippdrv->check_property(ippdrv->dev, property)) {
+			DRM_ERROR("not support property.\n");
+			goto err_null;

Just return proper error;

- done ERR_PTR(-EINVAL);

Quoted 29 lines
Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+		}
+
+		return ippdrv;
+	} else {
+		/*
+		 * This case is search all ipp driver for finding.
+		 * user application don't set ipp_id in this case,
+		 * so ipp subsystem search correct driver in driver list.
+		 */
+		list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list,

drv_list) {

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+			if (ipp_check_dedicated(ippdrv, property->cmd)) {
+				DRM_DEBUG_KMS("%s:used device.\n",

__func__);

Quoted 14 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +14 -0
+				continue;
+			}
+
+			if (ippdrv->check_property &&
+			    ippdrv->check_property(ippdrv->dev, property)) {
+				DRM_DEBUG_KMS("%s:not support property.\n",
+					__func__);
+				continue;
+			}
+
+			return ippdrv;
+		}
+
+		DRM_ERROR("not support ipp driver operations.\n");
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 248

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+	}
+
+	return ERR_PTR(-ENODEV);
+
+err_null:
+	return NULL;

And remove the above codes.

- removed.

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +61 -0
+}
+
+static struct exynos_drm_ippdrv *ipp_find_drv_by_handle(u32 prop_id)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, prop_id);
+
+	if (list_empty(&exynos_drm_ippdrv_list)) {
+		DRM_DEBUG_KMS("%s:ippdrv_list is empty.\n", __func__);
+		return ERR_PTR(-ENODEV);
+	}
+
+	/*
+	 * This case is search ipp driver by prop_id handle.
+	 * sometimes, ipp subsystem find driver by prop_id.
+	 * e.g PAUSE state, queue buf, command contro.
+	 */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		DRM_DEBUG_KMS("%s:count[%d]ippdrv[0x%x]\n", __func__,
+			count++, (int)ippdrv);
+
+		if (!list_empty(&ippdrv->cmd_list)) {
+			list_for_each_entry(c_node, &ippdrv->cmd_list, list)
+				if (c_node->property.prop_id == prop_id)
+					return ippdrv;
+		}
+	}
+
+	return ERR_PTR(-ENODEV);
+}
+
+int exynos_drm_ipp_get_property(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_prop_list *prop_list = data;
+	struct exynos_drm_ippdrv *ippdrv;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+
+	if (!prop_list) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:ipp_id[%d]\n", __func__, prop_list->ipp_id);
+
+	if (!prop_list->ipp_id) {
+		list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list,

drv_list)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +23 -0
+			count++;
+		/*
+		 * Supports ippdrv list count for user application.
+		 * First step user application getting ippdrv count.
+		 * and second step getting ippdrv capability using ipp_id.
+		 */
+		prop_list->count = count;
+	} else {
+		/*
+		 * Getting ippdrv capability by ipp_id.
+		 * some deivce not supported wb, output interface.
+		 * so, user application detect correct ipp driver
+		 * using this ioctl.
+		 */
+		ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
+						prop_list->ipp_id);
+		if (!ippdrv) {
+			DRM_ERROR("not found ipp%d driver.\n",
+					prop_list->ipp_id);
+			return -EINVAL;
+		}
+
+		prop_list = ippdrv->prop_list;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 337

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_get_property);

Should this function really be exported? Which external module calls this function? If not so, remove it.

- removed all EXPORT_SYMBOL_GPL

Quoted 381 lines
Quoted 381 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+static void ipp_print_property(struct drm_exynos_ipp_property *property,
+		int idx)
+{
+	struct drm_exynos_ipp_config *config = &property->config[idx];
+	struct drm_exynos_pos *pos = &config->pos;
+	struct drm_exynos_sz *sz = &config->sz;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]ops[%s]fmt[0x%x]\n",
+		__func__, property->prop_id, idx ? "dst" : "src", config-
Quoted 1 line

fmt);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+	DRM_DEBUG_KMS("%s:pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n",
+		__func__, pos->x, pos->y, pos->w, pos->h,
+		sz->hsize, sz->vsize, config->flip, config->degree);
+}
+
+static int ipp_find_and_set_property(struct drm_exynos_ipp_property

*property)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +103 -0
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	u32 prop_id = property->prop_id;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, prop_id);
+
+	ippdrv = ipp_find_drv_by_handle(prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find command node using command list in ippdrv.
+	 * when we find this command no using prop_id.
+	 * return property information set in this command node.
+	 */
+	list_for_each_entry(c_node, &ippdrv->cmd_list, list) {
+		if ((c_node->property.prop_id == prop_id) &&
+		    (c_node->state == IPP_STATE_STOP)) {
+			DRM_DEBUG_KMS("%s:found cmd[%d]ippdrv[0x%x]\n",
+				__func__, property->cmd, (int)ippdrv);
+
+			c_node->property = *property;
+			return 0;
+		}
+	}
+
+	DRM_ERROR("failed to search property.\n");
+
+	return -EINVAL;
+}
+
+static struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void)
+{
+	struct drm_exynos_ipp_cmd_work *cmd_work;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL);
+	if (!cmd_work) {
+		DRM_ERROR("failed to alloc cmd_work.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd);
+
+	return cmd_work;
+}
+
+static struct drm_exynos_ipp_event_work *ipp_create_event_work(void)
+{
+	struct drm_exynos_ipp_event_work *event_work;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	event_work = kzalloc(sizeof(*event_work), GFP_KERNEL);
+	if (!event_work) {
+		DRM_ERROR("failed to alloc event_work.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	INIT_WORK((struct work_struct *)event_work, ipp_sched_event);
+
+	return event_work;
+}
+
+int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_property *property = data;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret, i;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+
+	if (!property) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * This is log print for user application property.
+	 * user application set various property.
+	 */
+	for_each_ipp_ops(i)
+		ipp_print_property(property, i);
+
+	/*
+	 * set property ioctl generated new prop_id.
+	 * but in this case already asigned prop_id using old set property.
+	 * e.g PAUSE state. this case supports find current prop_id and use

it

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +4 -0
+	 * instead of allocation.
+	 */
+	if (property->prop_id) {
+		DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property-
Quoted 1 line

prop_id);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +124 -0
+		return ipp_find_and_set_property(property);
+	}
+
+	/* find ipp driver using ipp id */
+	ippdrv = ipp_find_driver(ctx, property);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;
+	}
+
+	/* allocate command node */
+	c_node = kzalloc(sizeof(*c_node), GFP_KERNEL);
+	if (!c_node) {
+		DRM_ERROR("failed to allocate map node.\n");
+		return -ENOMEM;
+	}
+
+	/* create property id */
+	ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node,
+		&property->prop_id);
+	if (ret) {
+		DRM_ERROR("failed to create id.\n");
+		goto err_clear;
+	}
+
+	DRM_DEBUG_KMS("%s:created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
+		__func__, property->prop_id, property->cmd, (int)ippdrv);
+
+	/* stored property information and ippdrv in private data */
+	c_node->priv = priv;
+	c_node->property = *property;
+	c_node->state = IPP_STATE_IDLE;
+
+	c_node->start_work = ipp_create_cmd_work();
+	if (IS_ERR_OR_NULL(c_node->start_work)) {
+		DRM_ERROR("failed to create start work.\n");
+		goto err_clear;
+	}
+
+	c_node->stop_work = ipp_create_cmd_work();
+	if (IS_ERR_OR_NULL(c_node->stop_work)) {
+		DRM_ERROR("failed to create stop work.\n");
+		goto err_free_start;
+	}
+
+	c_node->event_work = ipp_create_event_work();
+	if (IS_ERR_OR_NULL(c_node->event_work)) {
+		DRM_ERROR("failed to create event work.\n");
+		goto err_free_stop;
+	}
+
+	mutex_init(&c_node->cmd_lock);
+	mutex_init(&c_node->mem_lock);
+	mutex_init(&c_node->event_lock);
+
+	init_completion(&c_node->start_complete);
+	init_completion(&c_node->stop_complete);
+
+	for_each_ipp_ops(i)
+		INIT_LIST_HEAD(&c_node->mem_list[i]);
+
+	INIT_LIST_HEAD(&c_node->event_list);
+	list_splice_init(&priv->event_list, &c_node->event_list);
+	list_add_tail(&c_node->list, &ippdrv->cmd_list);
+
+	/* make dedicated state without m2m */
+	if (!ipp_is_m2m_cmd(property->cmd))
+		ippdrv->dedicated = true;
+
+	return 0;
+
+err_free_stop:
+	kfree(c_node->stop_work);
+err_free_start:
+	kfree(c_node->start_work);
+err_clear:
+	kfree(c_node);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_set_property);
+
+static void ipp_clean_cmd_node(struct drm_exynos_ipp_cmd_node *c_node)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* delete list */
+	list_del(&c_node->list);
+
+	/* destroy mutex */
+	mutex_destroy(&c_node->cmd_lock);
+	mutex_destroy(&c_node->mem_lock);
+	mutex_destroy(&c_node->event_lock);
+
+	/* free command node */
+	kfree(c_node->start_work);
+	kfree(c_node->stop_work);
+	kfree(c_node->event_work);
+	kfree(c_node);
+}
+
+static int ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct list_head *head;
+	int ret, i, count[EXYNOS_DRM_OPS_MAX] = { 0, };
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	mutex_lock(&c_node->mem_lock);
+
+	for_each_ipp_ops(i) {
+		/* source/destination memory list */
+		head = &c_node->mem_list[i];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:%s memory empty.\n", __func__,
+				i ? "dst" : "src");
+			continue;
+		}
+
+		/* find memory node entry */
+		list_for_each_entry(m_node, head, list) {
+			DRM_DEBUG_KMS("%s:%s,count[%d]m_node[0x%x]\n",

__func__,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +127 -0
+				i ? "dst" : "src", count[i], (int)m_node);
+			count[i]++;
+		}
+	}
+
+	DRM_DEBUG_KMS("%s:min[%d]max[%d]\n", __func__,
+		min(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]),
+		max(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]));
+
+	/*
+	 * M2M operations should be need paired memory address.
+	 * so, need to check minimum count about src, dst.
+	 * other case not use paired memory, so use maximum count
+	 */
+	if (ipp_is_m2m_cmd(property->cmd))
+		ret = min(count[EXYNOS_DRM_OPS_SRC],
+			count[EXYNOS_DRM_OPS_DST]);
+	else
+		ret = max(count[EXYNOS_DRM_OPS_SRC],
+			count[EXYNOS_DRM_OPS_DST]);
+
+	mutex_unlock(&c_node->mem_lock);
+
+	return ret;
+}
+
+static struct drm_exynos_ipp_mem_node
+		*ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct list_head *head;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:buf_id[%d]\n", __func__, qbuf->buf_id);
+
+	/* source/destination memory list */
+	head = &c_node->mem_list[qbuf->ops_id];
+
+	/* find memory node from memory list */
+	list_for_each_entry(m_node, head, list) {
+		DRM_DEBUG_KMS("%s:count[%d]m_node[0x%x]\n",
+			__func__, count++, (int)m_node);
+
+		/* compare buffer id */
+		if (m_node->buf_id == qbuf->buf_id)
+			return m_node;
+	}
+
+	return NULL;
+}
+
+static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node)
+{
+	struct exynos_drm_ipp_ops *ops = NULL;
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s:node[0x%x]\n", __func__, (int)m_node);
+
+	if (!m_node) {
+		DRM_ERROR("invalid queue node.\n");
+		return -EFAULT;
+	}
+
+	mutex_lock(&c_node->mem_lock);
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]\n", __func__, m_node->ops_id);
+
+	/* get operations callback */
+	ops = ippdrv->ops[m_node->ops_id];
+	if (!ops) {
+		DRM_ERROR("not support ops.\n");
+		ret = -EFAULT;
+		goto err_unlock;
+	}
+
+	/* set address and enable irq */
+	if (ops->set_addr) {
+		ret = ops->set_addr(ippdrv->dev, &m_node->buf_info,
+			m_node->buf_id, IPP_BUF_ENQUEUE);
+		if (ret) {
+			DRM_ERROR("failed to set addr.\n");
+			goto err_unlock;
+		}
+	}
+
+err_unlock:
+	mutex_unlock(&c_node->mem_lock);
+	return ret;
+}
+
+static struct drm_exynos_ipp_mem_node
+		*ipp_get_mem_node(struct drm_device *drm_dev,
+		struct drm_file *file,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_buf_info buf_info;
+	void *addr;
+	int i;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	mutex_lock(&c_node->mem_lock);
+
+	m_node = kzalloc(sizeof(*m_node), GFP_KERNEL);
+	if (!m_node) {
+		DRM_ERROR("failed to allocate queue node.\n");
+		goto err_unlock;
+	}
+
+	/* clear base address for error handling */
+	memset(&buf_info, 0x0, sizeof(buf_info));
+
+	/* operations, buffer id */
+	m_node->ops_id = qbuf->ops_id;
+	m_node->prop_id = qbuf->prop_id;
+	m_node->buf_id = qbuf->buf_id;
+
+	DRM_DEBUG_KMS("%s:m_node[0x%x]ops_id[%d]\n", __func__,
+		(int)m_node, qbuf->ops_id);
+	DRM_DEBUG_KMS("%s:prop_id[%d]buf_id[%d]\n", __func__,
+		qbuf->prop_id, m_node->buf_id);
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 718

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+	for_each_ipp_planar(i) {
+		DRM_DEBUG_KMS("%s:i[%d]handle[0x%x]\n", __func__,
+			i, qbuf->handle[i]);
+
+		/* get dma address by handle */
+		if (qbuf->handle[i] != 0) {

if (qbuf->handle[i]) {

- done.

Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 721

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0
+			addr = exynos_drm_gem_get_dma_addr(drm_dev,
+					qbuf->handle[i], file);
+			if (!addr) {

if (IS_ERR(addr))

- done.

Quoted 62 lines
Quoted 62 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +61 -0
+				DRM_ERROR("failed to get addr.\n");
+				goto err_clear;
+			}
+
+			buf_info.handles[i] = qbuf->handle[i];
+			buf_info.base[i] = *(dma_addr_t *) addr;
+			DRM_DEBUG_KMS("%s:i[%d]base[0x%x]hd[0x%x]\n",
+				__func__, i, buf_info.base[i],
+				(int)buf_info.handles[i]);
+		}
+	}
+
+	m_node->filp = file;
+	m_node->buf_info = buf_info;
+	list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]);
+
+	mutex_unlock(&c_node->mem_lock);
+	return m_node;
+
+err_clear:
+	kfree(m_node);
+err_unlock:
+	mutex_unlock(&c_node->mem_lock);
+	return ERR_PTR(-EFAULT);
+}
+
+static int ipp_put_mem_node(struct drm_device *drm_dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node)
+{
+	int i;
+
+	DRM_DEBUG_KMS("%s:node[0x%x]\n", __func__, (int)m_node);
+
+	if (!m_node) {
+		DRM_ERROR("invalid dequeue node.\n");
+		return -EFAULT;
+	}
+
+	if (list_empty(&m_node->list)) {
+		DRM_ERROR("empty memory node.\n");
+		return -ENOMEM;
+	}
+
+	mutex_lock(&c_node->mem_lock);
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]\n", __func__, m_node->ops_id);
+
+	/* put gem buffer */
+	for_each_ipp_planar(i) {
+		unsigned long handle = m_node->buf_info.handles[i];
+		if (handle)
+			exynos_drm_gem_put_dma_addr(drm_dev, handle,
+							m_node->filp);
+	}
+
+	/* delete list in queue */
+	list_del(&m_node->list);
+	kfree(m_node);
+
+	mutex_unlock(&c_node->mem_lock);
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 787

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+
+	return 0;
+}
+
+static void ipp_free_event(struct drm_pending_event *event)

Does this function need? This function just calls kfree. Just call kfree instead of wrapper.

- It is Kyungmin.Park review.

Quoted 111 lines
Quoted 111 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +110 -0
+{
+	kfree(event);
+}
+
+static int ipp_get_event(struct drm_device *drm_dev,
+		struct drm_file *file,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_send_event *e;
+	unsigned long flags;
+
+	DRM_DEBUG_KMS("%s:ops_id[%d]buf_id[%d]\n", __func__,
+		qbuf->ops_id, qbuf->buf_id);
+
+	e = kzalloc(sizeof(*e), GFP_KERNEL);
+
+	if (!e) {
+		DRM_ERROR("failed to allocate event.\n");
+		spin_lock_irqsave(&drm_dev->event_lock, flags);
+		file->event_space += sizeof(e->event);
+		spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+		return -ENOMEM;
+	}
+
+	/* make event */
+	e->event.base.type = DRM_EXYNOS_IPP_EVENT;
+	e->event.base.length = sizeof(e->event);
+	e->event.user_data = qbuf->user_data;
+	e->event.prop_id = qbuf->prop_id;
+	e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id;
+	e->base.event = &e->event.base;
+	e->base.file_priv = file;
+	e->base.destroy = ipp_free_event;
+	list_add_tail(&e->base.link, &c_node->event_list);
+
+	return 0;
+}
+
+static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_send_event *e, *te;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (list_empty(&c_node->event_list)) {
+		DRM_DEBUG_KMS("%s:event_list is empty.\n", __func__);
+		return;
+	}
+
+	list_for_each_entry_safe(e, te, &c_node->event_list, base.link) {
+		DRM_DEBUG_KMS("%s:count[%d]e[0x%x]\n",
+			__func__, count++, (int)e);
+
+		/*
+		 * quf == NULL condition means all event deletion.
+		 * stop operations want to delete all event list.
+		 * another case delete only same buf id.
+		 */
+		if (!qbuf) {
+			/* delete list */
+			list_del(&e->base.link);
+			kfree(e);
+		}
+
+		/* compare buffer id */
+		if (qbuf && (qbuf->buf_id ==
+		    e->event.buf_id[EXYNOS_DRM_OPS_DST])) {
+			/* delete list */
+			list_del(&e->base.link);
+			kfree(e);
+			return;
+		}
+	}
+}
+
+void ipp_handle_cmd_work(struct device *dev,
+		struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_work *cmd_work,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct ipp_context *ctx = get_ipp_context(dev);
+
+	cmd_work->ippdrv = ippdrv;
+	cmd_work->c_node = c_node;
+	queue_work(ctx->cmd_workq, (struct work_struct *)cmd_work);
+}
+
+static int ipp_queue_buf_with_run(struct device *dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_mem_node *m_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_property *property;
+	struct exynos_drm_ipp_ops *ops;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	ippdrv = ipp_find_drv_by_handle(qbuf->prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EFAULT;
+	}
+
+	ops = ippdrv->ops[qbuf->ops_id];
+	if (!ops) {
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 903

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+		DRM_ERROR("failed to get ops.\n");
+		return -EFAULT;
+	}
+
+	property = &c_node->property;
+	if (!property) {

Property couldn't be NULL. remove it.

- done.

Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 910

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	if (c_node->state != IPP_STATE_START) {
+		DRM_DEBUG_KMS("%s:bypass for invalid state.\n" , __func__);
+		return 0;

No error?

- This is no error. command started yet. user application make play command control.

Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 915

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+	}
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return 0;

No error?

- also, this case no error. not finished memory list.

Quoted 79 lines
Quoted 79 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +8 -0
+	}
+
+	/*
+	 * If set destination buffer and enabled clock,
+	 * then m2m operations need start operations at queue_buf
+	 */
+	if (ipp_is_m2m_cmd(property->cmd)) {
+		struct drm_exynos_ipp_cmd_work *cmd_work = c_node-
Quoted 1 line

start_work;

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +69 -0
+
+		cmd_work->ctrl = IPP_CTRL_PLAY;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+	} else {
+		ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+		if (ret) {
+			DRM_ERROR("failed to set m node.\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static void ipp_clean_queue_buf(struct drm_device *drm_dev,
+		struct drm_exynos_ipp_cmd_node *c_node,
+		struct drm_exynos_ipp_queue_buf *qbuf)
+{
+	struct drm_exynos_ipp_mem_node *m_node, *tm_node;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!list_empty(&c_node->mem_list[qbuf->ops_id])) {
+		/* delete list */
+		list_for_each_entry_safe(m_node, tm_node,
+			&c_node->mem_list[qbuf->ops_id], list) {
+			if (m_node->buf_id == qbuf->buf_id &&
+			    m_node->ops_id == qbuf->ops_id)
+				ipp_put_mem_node(drm_dev, c_node, m_node);
+		}
+	}
+}
+
+int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_queue_buf *qbuf = data;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	struct drm_exynos_ipp_mem_node *m_node;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!qbuf) {
+		DRM_ERROR("invalid buf parameter.\n");
+		return -EINVAL;
+	}
+
+	if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) {
+		DRM_ERROR("invalid ops parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
+		__func__, qbuf->prop_id, qbuf->ops_id ? "dst" : "src",
+		qbuf->buf_id, qbuf->buf_type);
+
+	/* find command node */
+	c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
+		qbuf->prop_id);
+	if (!c_node) {
+		DRM_ERROR("failed to get command node.\n");
+		return -EFAULT;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 998

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+	/* buffer control */
+	switch (qbuf->buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* get memory node */
+		m_node = ipp_get_mem_node(drm_dev, file, c_node, qbuf);
+		if (IS_ERR_OR_NULL(m_node)) {

This function never returns error. Use IS_ERR(m_node) instead.

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+			DRM_ERROR("failed to get m_node.\n");
+			return -EINVAL;

And return PTR_ERR(m_node);

- done.

Quoted 47 lines
Quoted 47 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +20 -0
+		}
+
+		/*
+		 * first step get event for destination buffer.
+		 * and second step when M2M case run with destination buffer
+		 * if needed.
+		 */
+		if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) {
+			/* get event for destination buffer */
+			ret = ipp_get_event(drm_dev, file, c_node, qbuf);
+			if (ret) {
+				DRM_ERROR("failed to get event.\n");
+				goto err_clean_node;
+			}
+
+			/*
+			 * M2M case run play control for streaming feature.
+			 * other case set address and waiting.
+			 */
+			ret = ipp_queue_buf_with_run(dev, c_node, m_node,

qbuf);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +25 -0
+			if (ret) {
+				DRM_ERROR("failed to run command.\n");
+				goto err_clean_node;
+			}
+		}
+		break;
+	case IPP_BUF_DEQUEUE:
+		mutex_lock(&c_node->cmd_lock);
+
+		/* put event for destination buffer */
+		if (qbuf->ops_id == EXYNOS_DRM_OPS_DST)
+			ipp_put_event(c_node, qbuf);
+
+		ipp_clean_queue_buf(drm_dev, c_node, qbuf);
+
+		mutex_unlock(&c_node->cmd_lock);
+		break;
+	default:
+		DRM_ERROR("invalid buffer control.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+
+err_clean_node:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1051

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+	DRM_ERROR("clean memory nodes.\n");
+
+	ipp_clean_queue_buf(drm_dev, c_node, qbuf);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_queue_buf);

Remove EXPORT_SYMBOL_GPL.

- done.

Quoted 69 lines
Quoted 69 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0
+
+static bool exynos_drm_ipp_check_valid(struct device *dev,
+		enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state

state)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +64 -0
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (ctrl != IPP_CTRL_PLAY) {
+		if (pm_runtime_suspended(dev)) {
+			DRM_ERROR("pm:runtime_suspended.\n");
+			goto err_status;
+		}
+	}
+
+	switch (ctrl) {
+	case IPP_CTRL_PLAY:
+		if (state != IPP_STATE_IDLE)
+			goto err_status;
+		break;
+	case IPP_CTRL_STOP:
+		if (state == IPP_STATE_STOP)
+			goto err_status;
+		break;
+	case IPP_CTRL_PAUSE:
+		if (state != IPP_STATE_START)
+			goto err_status;
+		break;
+	case IPP_CTRL_RESUME:
+		if (state != IPP_STATE_STOP)
+			goto err_status;
+		break;
+	default:
+		DRM_ERROR("invalid state.\n");
+		goto err_status;
+		break;
+	}
+
+	return true;
+
+err_status:
+	DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
+	return false;
+}
+
+int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
+	struct exynos_drm_ippdrv *ippdrv = NULL;
+	struct device *dev = priv->dev;
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
+	struct drm_exynos_ipp_cmd_work *cmd_work;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!ctx) {
+		DRM_ERROR("invalid context.\n");
+		return -EINVAL;
+	}
+
+	if (!cmd_ctrl) {
+		DRM_ERROR("invalid control parameter.\n");
+		return -EINVAL;
+	}
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1124

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+
+	DRM_DEBUG_KMS("%s:ctrl[%d]prop_id[%d]\n", __func__,
+		cmd_ctrl->ctrl, cmd_ctrl->prop_id);
+
+	ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
+	if (IS_ERR_OR_NULL(ippdrv)) {

Never return NULL. just use IS_ERR(ippdrv)

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+		DRM_ERROR("failed to get ipp driver.\n");
+		return -EINVAL;

And return PTR_ERR(ippdrv);

- done.

Quoted 62 lines
Quoted 62 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +61 -0
+	}
+
+	c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
+		cmd_ctrl->prop_id);
+	if (!c_node) {
+		DRM_ERROR("invalid command node list.\n");
+		return -EINVAL;
+	}
+
+	if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
+	    c_node->state)) {
+		DRM_ERROR("invalid state.\n");
+		return -EINVAL;
+	}
+
+	switch (cmd_ctrl->ctrl) {
+	case IPP_CTRL_PLAY:
+		if (pm_runtime_suspended(ippdrv->dev))
+			pm_runtime_get_sync(ippdrv->dev);
+		c_node->state = IPP_STATE_START;
+
+		cmd_work = c_node->start_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+		c_node->state = IPP_STATE_START;
+		break;
+	case IPP_CTRL_STOP:
+		cmd_work = c_node->stop_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+
+		if (!wait_for_completion_timeout(&c_node->stop_complete,
+		    msecs_to_jiffies(300))) {
+			DRM_ERROR("timeout stop:prop_id[%d]\n",
+				c_node->property.prop_id);
+		}
+
+		c_node->state = IPP_STATE_STOP;
+		ippdrv->dedicated = false;
+		ipp_clean_cmd_node(c_node);
+
+		if (list_empty(&ippdrv->cmd_list))
+			pm_runtime_put_sync(ippdrv->dev);
+		break;
+	case IPP_CTRL_PAUSE:
+		cmd_work = c_node->stop_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+
+		if (!wait_for_completion_timeout(&c_node->stop_complete,
+		    msecs_to_jiffies(200))) {
+			DRM_ERROR("timeout stop:prop_id[%d]\n",
+				c_node->property.prop_id);
+		}
+
+		c_node->state = IPP_STATE_STOP;
+		break;
+	case IPP_CTRL_RESUME:
+		c_node->state = IPP_STATE_START;
+		cmd_work = c_node->start_work;
+		cmd_work->ctrl = cmd_ctrl->ctrl;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1193

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +6 -0
+		ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
+		break;
+	default:
+		/* ToDo: expand ctrl operation */
+		DRM_ERROR("could not support this state currently.\n");
+		goto err_clear;

Just return error;

- added return -EINVAL;

Quoted 12 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1202

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +9 -0
+	}
+
+	DRM_DEBUG_KMS("%s:done ctrl[%d]prop_id[%d]\n", __func__,
+		cmd_ctrl->ctrl, cmd_ctrl->prop_id);
+
+	return 0;
+
+err_clear:
+	return ret;

And remove the above label.

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1204

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +2 -0
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ipp_cmd_ctrl);

Remove it.

- done.

Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1211

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_register(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(
+			&exynos_drm_ippnb_list, nb);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_register);

Remove it.

- done.

Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1218

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_unregister(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(
+			&exynos_drm_ippnb_list, nb);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_unregister);

Remove it.

- done.

Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1225

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +7 -0
+
+int exynos_drm_ippnb_send_event(unsigned long val, void *v)
+{
+	return blocking_notifier_call_chain(
+			&exynos_drm_ippnb_list, val, v);
+}
+EXPORT_SYMBOL_GPL(exynos_drm_ippnb_send_event);

Remove it.

- done.

Quoted 1,370 lines
Quoted 184 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +183 -0
+
+static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_property *property)
+{
+	struct exynos_drm_ipp_ops *ops = NULL;
+	int ret, i, swap = 0;
+
+	if (!property) {
+		DRM_ERROR("invalid property parameter.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* reset h/w block */
+	if (ippdrv->reset &&
+	    ippdrv->reset(ippdrv->dev)) {
+		DRM_ERROR("failed to reset.\n");
+		return -EINVAL;
+	}
+
+	/* set source,destination operations */
+	for_each_ipp_ops(i) {
+		/* ToDo: integrate property and config */
+		struct drm_exynos_ipp_config *config =
+			&property->config[i];
+
+		ops = ippdrv->ops[i];
+		if (!ops || !config) {
+			DRM_ERROR("not support ops and config.\n");
+			return -EINVAL;
+		}
+
+		/* set format */
+		if (ops->set_fmt) {
+			ret = ops->set_fmt(ippdrv->dev, config->fmt);
+			if (ret) {
+				DRM_ERROR("not support format.\n");
+				return ret;
+			}
+		}
+
+		/* set transform for rotation, flip */
+		if (ops->set_transf) {
+			swap = ops->set_transf(ippdrv->dev, config->degree,
+				config->flip);
+			if (swap < 0) {
+				DRM_ERROR("not support tranf.\n");
+				return -EINVAL;
+			}
+		}
+
+		/* set size */
+		if (ops->set_size) {
+			ret = ops->set_size(ippdrv->dev, swap, &config->pos,
+				&config->sz);
+			if (ret) {
+				DRM_ERROR("not support size.\n");
+				return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct list_head *head;
+	int ret, i;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* store command info in ippdrv */
+	ippdrv->cmd = c_node;
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return -ENOMEM;
+	}
+
+	/* set current property in ippdrv */
+	ret = ipp_set_property(ippdrv, property);
+	if (ret) {
+		DRM_ERROR("failed to set property.\n");
+		ippdrv->cmd = NULL;
+		return ret;
+	}
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			m_node = list_first_entry(head,
+				struct drm_exynos_ipp_mem_node, list);
+			if (!m_node) {
+				DRM_ERROR("failed to get node.\n");
+				ret = -EFAULT;
+				return ret;
+			}
+
+			DRM_DEBUG_KMS("%s:m_node[0x%x]\n",
+				__func__, (int)m_node);
+
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	case IPP_CMD_WB:
+		/* destination memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
+
+		list_for_each_entry(m_node, head, list) {
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		list_for_each_entry(m_node, head, list) {
+			ret = ipp_set_mem_node(ippdrv, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to set m node.\n");
+				return ret;
+			}
+		}
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		return -EINVAL;
+	}
+
+	DRM_DEBUG_KMS("%s:cmd[%d]\n", __func__, property->cmd);
+
+	/* start operations */
+	if (ippdrv->start) {
+		ret = ippdrv->start(ippdrv->dev, property->cmd);
+		if (ret) {
+			DRM_ERROR("failed to start ops.\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int ipp_stop_property(struct drm_device *drm_dev,
+		struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node)
+{
+	struct drm_exynos_ipp_mem_node *m_node, *tm_node;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct list_head *head;
+	int ret = 0, i;
+
+	DRM_DEBUG_KMS("%s:prop_id[%d]\n", __func__, property->prop_id);
+
+	/* put event */
+	ipp_put_event(c_node, NULL);
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			if (list_empty(head)) {
+				DRM_DEBUG_KMS("%s:mem_list is empty.\n",

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+					__func__);
+				break;
+			}
+
+			list_for_each_entry_safe(m_node, tm_node,
+				head, list) {
+				ret = ipp_put_mem_node(drm_dev, c_node,
+					m_node);
+				if (ret) {
+					DRM_ERROR("failed to put

m_node.\n");

Quoted 94 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +94 -0
+					goto err_clear;
+				}
+			}
+		}
+		break;
+	case IPP_CMD_WB:
+		/* destination memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:mem_list is empty.\n", __func__);
+			break;
+		}
+
+		list_for_each_entry_safe(m_node, tm_node, head, list) {
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to put m_node.\n");
+				goto err_clear;
+			}
+		}
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		if (list_empty(head)) {
+			DRM_DEBUG_KMS("%s:mem_list is empty.\n", __func__);
+			break;
+		}
+
+		list_for_each_entry_safe(m_node, tm_node, head, list) {
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret) {
+				DRM_ERROR("failed to put m_node.\n");
+				goto err_clear;
+			}
+		}
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		ret = -EINVAL;
+		goto err_clear;
+	}
+
+err_clear:
+	/* stop operations */
+	if (ippdrv->stop)
+		ippdrv->stop(ippdrv->dev, property->cmd);
+
+	return ret;
+}
+
+void ipp_sched_cmd(struct work_struct *work)
+{
+	struct drm_exynos_ipp_cmd_work *cmd_work =
+		(struct drm_exynos_ipp_cmd_work *)work;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	struct drm_exynos_ipp_property *property;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	ippdrv = cmd_work->ippdrv;
+	if (!ippdrv) {
+		DRM_ERROR("invalid ippdrv list.\n");
+		return;
+	}
+
+	c_node = cmd_work->c_node;
+	if (!c_node) {
+		DRM_ERROR("invalid command node list.\n");
+		return;
+	}
+
+	mutex_lock(&c_node->cmd_lock);
+
+	property = &c_node->property;
+	if (!property) {
+		DRM_ERROR("failed to get property:prop_id[%d]\n",
+			c_node->property.prop_id);
+		goto err_unlock;
+	}
+
+	switch (cmd_work->ctrl) {
+	case IPP_CTRL_PLAY:
+	case IPP_CTRL_RESUME:
+		ret = ipp_start_property(ippdrv, c_node);
+		if (ret) {
+			DRM_ERROR("failed to start property:prop_id[%d]\n",
+				c_node->property.prop_id);
+			goto err_unlock;
+		}

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+
+		/*
+		 * M2M case supports wait_completion of transfer.
+		 * because M2M case supports single unit operation
+		 * with multiple queue.
+		 * M2M need to wait completion of data transfer.
+		 */
+		if (ipp_is_m2m_cmd(property->cmd)) {
+			if (!wait_for_completion_timeout
+			    (&c_node->start_complete,

msecs_to_jiffies(200))) {

Quoted 285 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +169 -0
+				DRM_ERROR("timeout event:prop_id[%d]\n",
+					c_node->property.prop_id);
+				goto err_unlock;
+			}
+		}
+		break;
+	case IPP_CTRL_STOP:
+	case IPP_CTRL_PAUSE:
+		ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
+			c_node);
+		if (ret) {
+			DRM_ERROR("failed to stop property.\n");
+			goto err_unlock;
+		}
+
+		complete(&c_node->stop_complete);
+		break;
+	default:
+		DRM_ERROR("unknown control type\n");
+		break;
+	}
+
+	DRM_DEBUG_KMS("%s:ctrl[%d] done.\n", __func__, cmd_work->ctrl);
+
+err_unlock:
+	mutex_unlock(&c_node->cmd_lock);
+}
+
+static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
+		struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
+{
+	struct drm_device *drm_dev = ippdrv->drm_dev;
+	struct drm_exynos_ipp_property *property = &c_node->property;
+	struct drm_exynos_ipp_mem_node *m_node;
+	struct drm_exynos_ipp_queue_buf qbuf;
+	struct drm_exynos_ipp_send_event *e;
+	struct list_head *head;
+	struct timeval now;
+	unsigned long flags;
+	u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
+	int ret, i;
+
+	for_each_ipp_ops(i)
+		DRM_DEBUG_KMS("%s:%s buf_id[%d]\n", __func__,
+			i ? "dst" : "src", buf_id[i]);
+
+	if (!drm_dev) {
+		DRM_ERROR("failed to get drm_dev.\n");
+		return -EINVAL;
+	}
+
+	if (!property) {
+		DRM_ERROR("failed to get property.\n");
+		return -EINVAL;
+	}
+
+	if (list_empty(&c_node->event_list)) {
+		DRM_DEBUG_KMS("%s:event list is empty.\n", __func__);
+		return 0;
+	}
+
+	if (!ipp_check_mem_list(c_node)) {
+		DRM_DEBUG_KMS("%s:empty memory.\n", __func__);
+		return 0;
+	}
+
+	/* check command */
+	switch (property->cmd) {
+	case IPP_CMD_M2M:
+		for_each_ipp_ops(i) {
+			/* source/destination memory list */
+			head = &c_node->mem_list[i];
+
+			m_node = list_first_entry(head,
+				struct drm_exynos_ipp_mem_node, list);
+			if (!m_node) {
+				DRM_ERROR("empty memory node.\n");
+				return -ENOMEM;
+			}
+
+			tbuf_id[i] = m_node->buf_id;
+			DRM_DEBUG_KMS("%s:%s buf_id[%d]\n", __func__,
+				i ? "dst" : "src", tbuf_id[i]);
+
+			ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+			if (ret)
+				DRM_ERROR("failed to put m_node.\n");
+		}
+		break;
+	case IPP_CMD_WB:
+		/* clear buf for finding */
+		memset(&qbuf, 0x0, sizeof(qbuf));
+		qbuf.ops_id = EXYNOS_DRM_OPS_DST;
+		qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
+
+		/* get memory node entry */
+		m_node = ipp_find_mem_node(c_node, &qbuf);
+		if (!m_node) {
+			DRM_ERROR("empty memory node.\n");
+			return -ENOMEM;
+		}
+
+		tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
+
+		ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+		if (ret)
+			DRM_ERROR("failed to put m_node.\n");
+		break;
+	case IPP_CMD_OUTPUT:
+		/* source memory list */
+		head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
+
+		m_node = list_first_entry(head,
+			struct drm_exynos_ipp_mem_node, list);
+		if (!m_node) {
+			DRM_ERROR("empty memory node.\n");
+			return -ENOMEM;
+		}
+
+		tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
+
+		ret = ipp_put_mem_node(drm_dev, c_node, m_node);
+		if (ret)
+			DRM_ERROR("failed to put m_node.\n");
+		break;
+	default:
+		DRM_ERROR("invalid operations.\n");
+		return -EINVAL;
+	}
+
+	/* ToDo: Fix buffer id */
+	if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
+		DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
+			tbuf_id[1], buf_id[1], property->prop_id);
+
+	/*
+	 * command node have event list of destination buffer
+	 * If destination buffer enqueue to mem list,
+	 * then we make event and link to event list tail.
+	 * so, we get first event for first enqueued buffer.
+	 */
+	e = list_first_entry(&c_node->event_list,
+		struct drm_exynos_ipp_send_event, base.link);
+
+	if (!e) {
+		DRM_ERROR("empty event.\n");
+		return -EINVAL;
+	}
+
+	do_gettimeofday(&now);
+	DRM_DEBUG_KMS("%s:tv_sec[%ld]tv_usec[%ld]\n"
+		, __func__, now.tv_sec, now.tv_usec);
+	e->event.tv_sec = now.tv_sec;
+	e->event.tv_usec = now.tv_usec;
+	e->event.prop_id = property->prop_id;
+
+	/* set buffer id about source destination */
+	for_each_ipp_ops(i)
+		e->event.buf_id[i] = tbuf_id[i];
+
+	/* ToDo: compare index. If needed */
+
+	spin_lock_irqsave(&drm_dev->event_lock, flags);
+	list_move_tail(&e->base.link, &e->base.file_priv->event_list);
+	wake_up_interruptible(&e->base.file_priv->event_wait);
+	spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+
+	DRM_DEBUG_KMS("%s:done cmd[%d]prop_id[%d]buf_id[%d]\n", __func__,
+		property->cmd, property->prop_id,

tbuf_id[EXYNOS_DRM_OPS_DST]);

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +60 -0
+
+	return 0;
+}
+
+void ipp_sched_event(struct work_struct *work)
+{
+	struct drm_exynos_ipp_event_work *event_work =
+		(struct drm_exynos_ipp_event_work *)work;
+	struct exynos_drm_ippdrv *ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node;
+	int ret;
+
+	if (!event_work) {
+		DRM_ERROR("failed to get event_work.\n");
+		return;
+	}
+
+	DRM_DEBUG_KMS("%s:buf_id[%d]\n", __func__,
+		event_work->buf_id[EXYNOS_DRM_OPS_DST]);
+
+	ippdrv = event_work->ippdrv;
+	if (!ippdrv) {
+		DRM_ERROR("failed to get ipp driver.\n");
+		return;
+	}
+
+	c_node = ippdrv->cmd;
+	if (!c_node) {
+		DRM_ERROR("failed to get command node.\n");
+		return;
+	}
+
+	/*
+	 * IPP supports command thread, event thread synchronization.
+	 * If IPP close immediately from user land, then IPP make
+	 * synchronization with command thread, so make complete event.
+	 * or going out operations.
+	 */
+	if (c_node->state != IPP_STATE_START) {
+		DRM_DEBUG_KMS("%s:bypass state[%d]prop_id[%d]\n",
+			__func__, c_node->state, c_node->property.prop_id);
+		goto err_completion;
+	}
+
+	mutex_lock(&c_node->event_lock);
+
+	ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
+	if (ret) {
+		DRM_ERROR("failed to send event.\n");
+		goto err_completion;
+	}
+
+err_completion:
+	if (ipp_is_m2m_cmd(c_node->property.cmd))
+		complete(&c_node->start_complete);
+
+	mutex_unlock(&c_node->event_lock);
+}
+
+static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device

*dev)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +19 -0
+{
+	struct ipp_context *ctx = get_ipp_context(dev);
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret, count = 0;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* get ipp driver entry */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		ippdrv->drm_dev = drm_dev;
+
+		ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv,
+			&ippdrv->ipp_id);
+		if (ret) {
+			DRM_ERROR("failed to create id.\n");
+			goto err_idr;
+		}
+
+		DRM_DEBUG_KMS("%s:count[%d]ippdrv[0x%x]ipp_id[%d]\n",

__func__,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +28 -0
+			count++, (int)ippdrv, ippdrv->ipp_id);
+
+		if (ippdrv->ipp_id == 0) {
+			DRM_ERROR("failed to get ipp_id[%d]\n",
+				ippdrv->ipp_id);
+			goto err_idr;
+		}
+
+		/* store parent device for node */
+		ippdrv->parent_dev = dev;
+
+		/* store event work queue and handler */
+		ippdrv->event_workq = ctx->event_workq;
+		ippdrv->sched_event = ipp_sched_event;
+		INIT_LIST_HEAD(&ippdrv->cmd_list);
+	}
+
+	return 0;
+
+err_idr:
+	idr_remove_all(&ctx->ipp_idr);
+	idr_remove_all(&ctx->prop_idr);
+	idr_destroy(&ctx->ipp_idr);
+	idr_destroy(&ctx->prop_idr);
+	return ret;
+}
+
+static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device

*dev)

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +5 -0
+{
+	struct exynos_drm_ippdrv *ippdrv;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	/* get ipp driver entry */
+	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		ippdrv->drm_dev = NULL;
+		exynos_drm_ippdrv_unregister(ippdrv);
+	}
+
+	/* ToDo: free notifier callback list if needed */
+}
+
+static int ipp_subdrv_open(struct drm_device *drm_dev, struct device

*dev,

Quoted 43 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +25 -0
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	/* ToDo: multi device open */
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv) {
+		DRM_ERROR("failed to allocate priv.\n");
+		return -ENOMEM;
+	}
+	priv->dev = dev;
+	file_priv->ipp_priv = priv;
+
+	INIT_LIST_HEAD(&priv->event_list);
+
+	DRM_DEBUG_KMS("%s:done priv[0x%x]\n", __func__, (int)priv);
+
+	return 0;
+}
+
+static void ipp_subdrv_close(struct drm_device *drm_dev, struct device

*dev,

drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +17 -0
+		struct drm_file *file)
+{
+	struct drm_exynos_file_private *file_priv = file->driver_priv;
+	struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/gpu/drm/exynos/exynos_drm_ipp.c line 1852

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +10 -0
+	struct exynos_drm_ippdrv *ippdrv = NULL;
+	struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
+	int count = 0;
+
+	DRM_DEBUG_KMS("%s:for priv[0x%x]\n", __func__, (int)priv);
+
+	if (list_empty(&exynos_drm_ippdrv_list)) {
+		DRM_DEBUG_KMS("%s:ippdrv_list is empty.\n", __func__);
+		goto err_clear;
+	}
[… more lines in the raw message]

killed.

drivers/gpu/drm/exynos/exynos_drm_ipp.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

state.

drivers/gpu/drm/exynos/exynos_drm_ipp.h

Quoted 356 lines
drivers/gpu/drm/exynos/exynos_drm_ipp.c new file +191 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/exynos/exynos_drm_ipp.h new file +9 -0
new file mode 100644
index 0000000..baab1f0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

28 lines not shown · raw message

drivers/gpu/drm/exynos/exynos_drm_ipp.h new file +121 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

358 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#4 lore raw

RFC v3 2/5 drm/exynos: add iommu support for ipp

In reply to Eunchul Kim

This patch adds iommu support for ipp.
For this, it adds subdrv_probe/remove callback to enable or disable ipp iommu. we can get or put device address to a gem handle from user through exynos_drm_gem_get/put_dma_addr().

---
 drivers/gpu/drm/exynos/exynos_drm_ipp.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_ipp.c +18 -0
index eb12cb5..cb2165a 100644
@@ -23,6 +23,7 @@
 #include "exynos_drm_drv.h"
 #include "exynos_drm_gem.h"
 #include "exynos_drm_ipp.h"
+#include "exynos_drm_iommu.h"
 
 /*
  * IPP is stand for Image Post Processing and
@@ -1783,10 +1784,24 @@ static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
 		ippdrv->event_workq = ctx->event_workq;
 		ippdrv->sched_event = ipp_sched_event;
 		INIT_LIST_HEAD(&ippdrv->cmd_list);
+
+		if (is_drm_iommu_supported(drm_dev)) {
+			ret = drm_iommu_attach_device(drm_dev, ippdrv->dev);
+			if (ret) {
+				DRM_ERROR("failed to activate iommu\n");
+				goto err_iommu;
+			}
+		}
 	}
 
 	return 0;
 
+err_iommu:
+	/* get ipp driver entry */
+	list_for_each_entry_reverse(ippdrv, &exynos_drm_ippdrv_list, drv_list)
+		if (is_drm_iommu_supported(drm_dev))
+			drm_iommu_detach_device(drm_dev, ippdrv->dev);
+
 err_idr:
 	idr_remove_all(&ctx->ipp_idr);
 	idr_remove_all(&ctx->prop_idr);
@@ -1803,6 +1818,9 @@ static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
 
 	/* get ipp driver entry */
 	list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
+		if (is_drm_iommu_supported(drm_dev))
+			drm_iommu_detach_device(drm_dev, ippdrv->dev);
+
 		ippdrv->drm_dev = NULL;
 		exynos_drm_ippdrv_unregister(ippdrv);
 	}
Signature · 1 line
1.7.0.4
#5 lore raw

RFC v3 3/5 drm/exynos: add fimc ipp driver

In reply to Eunchul Kim

FIMC is stand for Fully Interfactive Mobile Camera and
supports image scaler/rotator/crop/flip/csc and input/output DMA operations. input DMA reads image data from the memory.
output DMA writes image data to memory.
FIMC supports image rotation and image effect functions.
also supports writeback and display output operations.

---
 drivers/gpu/drm/exynos/Kconfig           |    6 +
 drivers/gpu/drm/exynos/Makefile          |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |   15 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h  |    1 +
 drivers/gpu/drm/exynos/exynos_drm_fimc.c | 2022 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_fimc.h |   34 +
 drivers/gpu/drm/exynos/regs-fimc.h       |  669 ++++++++++
 include/drm/exynos_drm.h                 |   26 +
 8 files changed, 2774 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_fimc.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_fimc.h
 create mode 100644 drivers/gpu/drm/exynos/regs-fimc.h
drivers/gpu/drm/exynos/Kconfig +6 -0
index bcf1c9d..4915ab6 100644
@@ -51,3 +51,9 @@ config DRM_EXYNOS_IPP
 	depends on DRM_EXYNOS
 	help
 	  Choose this option if you want to use IPP feature for DRM.
+
+config DRM_EXYNOS_FIMC
+	bool "Exynos DRM FIMC"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos FIMC for DRM.
drivers/gpu/drm/exynos/Makefile +1 -0
index 6c536ce..9710024 100644
@@ -17,5 +17,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI)	+= exynos_hdmi.o exynos_mixer.o \
 exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+= exynos_drm_vidi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC)	+= exynos_drm_fimc.o
 
 obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 0eb8a97..73f02ac 100644
@@ -372,6 +372,12 @@ static int __init exynos_drm_init(void)
 		goto out_g2d;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_FIMC
+	ret = platform_driver_register(&fimc_driver);
+	if (ret < 0)
+		goto out_fimc;
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_IPP
 	ret = platform_driver_register(&ipp_driver);
 	if (ret < 0)
@@ -400,6 +406,11 @@ out_drm:
 out_ipp:
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_FIMC
+	platform_driver_unregister(&fimc_driver);
+out_fimc:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 out_g2d:
@@ -440,6 +451,10 @@ static void __exit exynos_drm_exit(void)
 	platform_driver_unregister(&ipp_driver);
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_FIMC
+	platform_driver_unregister(&fimc_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	platform_driver_unregister(&g2d_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index a365788..14f9490 100644
@@ -352,5 +352,6 @@ extern struct platform_driver mixer_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
+extern struct platform_driver fimc_driver;
 extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_fimc.c new file +2022 -0

2,022 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_fimc.h new file +34 -0
new file mode 100644
index 0000000..d9dbf0e
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Eunchul Kim <[email protected]>
+ *	Jinyoung Jeon <[email protected]>
+ *	Sangmin Lee <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _EXYNOS_DRM_FIMC_H_
+#define _EXYNOS_DRM_FIMC_H_
+
+/* ToDo */
+
+#endif /* _EXYNOS_DRM_FIMC_H_ */
drivers/gpu/drm/exynos/regs-fimc.h new file +669 -0

669 lines not on this page · raw message

include/drm/exynos_drm.h +26 -0
index 3c13a3a..808dad2 100644
@@ -85,4 +85,30 @@ struct exynos_drm_hdmi_pdata {
 	int (*get_hpd)(void);
 };
 
+/**
+ * Platform Specific Structure for DRM based IPP.
+ *
+ * @inv_pclk: if set 1. invert pixel clock
+ * @inv_vsync: if set 1. invert vsync signal for wb
+ * @inv_href: if set 1. invert href signal
+ * @inv_hsync: if set 1. invert hsync signal for wb
+ */
+struct exynos_drm_ipp_pol {
+	unsigned int inv_pclk;
+	unsigned int inv_vsync;
+	unsigned int inv_href;
+	unsigned int inv_hsync;
+};
+
+/**
+ * Platform Specific Structure for DRM based FIMC.
+ *
+ * @pol: current hardware block polarity settings.
+ * @clk_rate: current hardware clock rate.
+ */
+struct exynos_drm_fimc_pdata {
+	struct exynos_drm_ipp_pol pol;
+	int clk_rate;
+};
+
 #endif	/* _EXYNOS_DRM_H_ */
Signature · 1 line
1.7.0.4
#6 lore raw

RFC v3 4/5 drm/exynos: add rotator ipp driver

In reply to Eunchul Kim

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip. and has some limitations(source and destination format have to be same, no scaler)

---
 drivers/gpu/drm/exynos/Kconfig              |    7 +
 drivers/gpu/drm/exynos/Makefile             |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829 +++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
 drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
 7 files changed, 939 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h
 create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h
drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
 	depends on DRM_EXYNOS_IPP
 	help
 	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +1 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+= exynos_drm_vidi.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC)	+= exynos_drm_fimc.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
 obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
 		goto out_fimc;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_IPP
 	ret = platform_driver_register(&ipp_driver);
 	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
 out_ipp:
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_FIMC
 	platform_driver_unregister(&fimc_driver);
 out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
 	platform_driver_unregister(&ipp_driver);
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_FIMC
 	platform_driver_unregister(&fimc_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
 extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
 extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +829 -0

829 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +13 -0
new file mode 100644
index 0000000..fe929c9
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.7.0.4
maintainer
#7 lore raw

RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 240 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be same, no scaler)

---
 drivers/gpu/drm/exynos/Kconfig              |    7 +
 drivers/gpu/drm/exynos/Makefile             |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
 drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
 7 files changed, 939 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h
 create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h
drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
 	depends on DRM_EXYNOS_IPP
 	help
 	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
 obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
 		goto out_fimc;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_IPP
 	ret = platform_driver_register(&ipp_driver);
 	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
 out_ipp:
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_FIMC
 	platform_driver_unregister(&fimc_driver);
 out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
 	platform_driver_unregister(&ipp_driver);
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_FIMC
 	platform_driver_unregister(&fimc_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
 extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
 extern struct platform_driver ipp_driver;

#endif

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
new file mode 100644
index 0000000..121569c
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA operations.
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +82 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct rot_context

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

Quoted 129 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +95 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

What is 0x00?

Quoted 61 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +61 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+		/* Rotation 0 Degree */
+		break;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

Quoted 27 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +27 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 389

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

Quoted 63 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +63 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n", __func__);
+		return -EINVAL;
+	}

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side rotation\n",
+								__func__);
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n", __func__);
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

Quoted 53 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +41 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+				platform_get_device_id(pdev)->driver_data;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 622

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start, resource_size(res),
+

dev_name(dev));

Quoted 191 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +191 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL, rotator_irq_handler,
+					IRQF_ONESHOT, "drm_rotator", rot);
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator device\n");
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed successfully\n");
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 819

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
+

NULL)

Quoted 116 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +13 -0
new file mode 100644
index 0000000..fe929c9
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +6 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +56 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) - 1))) &

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +7 -1
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

#8 lore raw

Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 242 lines · Inki Dae
Quoted 242 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be same, no scaler)

---
  drivers/gpu/drm/exynos/Kconfig              |    7 +
  drivers/gpu/drm/exynos/Makefile             |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
  drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
  7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
  	depends on DRM_EXYNOS_IPP
  	help
  	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
  		goto out_fimc;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_IPP
  	ret = platform_driver_register(&ipp_driver);
  	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
  out_ipp:
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
  	platform_driver_unregister(&ipp_driver);
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
  extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
  extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
new file mode 100644
index 0000000..121569c
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA operations.
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +82 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct rot_context

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+{
+	u32 val = rot_read(ROT_STATUS);
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 134 lines
Quoted 134 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +99 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +65 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and me).

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +31 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 264

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- done.

Quoted 98 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

Quoted 63 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +63 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 15 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +15 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n", __func__);
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

- I don't thing so, If we make macro about this. then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt == DRM_FORMAT_NV12) \
					return true;
Quoted 25 lines
Quoted 14 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side rotation\n",
+								__func__);
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

Quoted 420 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n", __func__);
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

Quoted 53 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +41 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+				platform_get_device_id(pdev)->driver_data;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 622

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start, resource_size(res),
+

dev_name(dev));

Quoted 191 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +191 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL, rotator_irq_handler,
+					IRQF_ONESHOT, "drm_rotator", rot);
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator device\n");
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed successfully\n");
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 819

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
+

NULL)

Quoted 116 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +13 -0
new file mode 100644
index 0000000..fe929c9
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +6 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +56 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) - 1))) &

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +7 -1
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

maintainer
#9 lore raw

RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 166 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 11 lines · Inki Dae
Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 4 lines
Quoted 4 lines

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be same,

no

Quoted 107 lines
Quoted 107 lines

scaler)

---
  drivers/gpu/drm/exynos/Kconfig              |    7 +
  drivers/gpu/drm/exynos/Makefile             |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
  drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
  7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
  	depends on DRM_EXYNOS_IPP
  	help
  	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
  		goto out_fimc;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_IPP
  	ret = platform_driver_register(&ipp_driver);
  	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
  out_ipp:
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
  	platform_driver_unregister(&ipp_driver);
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
  extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
  extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 517 lines
Quoted 80 lines
Quoted 80 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +74 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 134 lines
Quoted 134 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +99 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +65 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and me).

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +31 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 264

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- done.

Quoted 98 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

Quoted 63 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +63 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 15 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +15 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n", __func__);
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

Quoted 8 lines

- I don't thing so, If we make macro about this. then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;

#define drm_check_fmt(fmt) ((fmt & (DRM_FORMAT_XRGB8888 |
DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))

	Something;
else
	Something;
Quoted 42 lines
Quoted 26 lines
Quoted 15 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side rotation\n",
+								__func__);
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

Quoted 2 lines

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

What does each case do? Just check? If so, use macro as I mentioned. We can't accept this codes.

Quoted 423 lines
Quoted 319 lines
Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+
+	/* Check size configuration */

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n", __func__);
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

Quoted 53 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +41 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+				platform_get_device_id(pdev)->driver_data;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 622

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start, resource_size(res),
+

dev_name(dev));

Quoted 191 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +191 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL, rotator_irq_handler,
+					IRQF_ONESHOT, "drm_rotator", rot);
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator device\n");
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed successfully\n");
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 819

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +8 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +1 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +5 -0
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 70 lines
Quoted 68 lines

+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +56 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) - 1))) &

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +7 -1
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

maintainer
#10 lore raw

RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 70 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Inki Dae
Sent: Wednesday, December 12, 2012 6:42 PM
To: 'Eunchul Kim'
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

Quoted 15 lines

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 7 lines · Inki Dae
Quoted 7 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected];

[email protected];

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be

same,

Quoted 19 lines

no

Quoted 18 lines
Quoted 18 lines

scaler)

---
  drivers/gpu/drm/exynos/Kconfig              |    7 +
  drivers/gpu/drm/exynos/Makefile             |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
  drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
  7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/exynos/Kconfig +0 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
  	depends on DRM_EXYNOS_IPP
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/Kconfig config DRM_EXYNOS_FIMC

Quoted 8 lines
drivers/gpu/drm/exynos/Kconfig +6 -0
  	help
  	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for

DRM.

Quoted 164 lines
Quoted 96 lines
Quoted 74 lines
Quoted 74 lines
drivers/gpu/drm/exynos/Kconfig +1 -0
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
  		goto out_fimc;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_IPP
  	ret = platform_driver_register(&ipp_driver);
  	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
  out_ipp:
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
  	platform_driver_unregister(&ipp_driver);
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
  extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
  extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +53 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool

enable)

Quoted 37 lines
Quoted 37 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 1 line
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work =

c_node->event_work;

Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +24 -0
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +75 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) |

ROT_SRC_CROP_SIZE_W(pos->w);

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +16 -0
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 136 lines
Quoted 136 lines
Quoted 57 lines
Quoted 57 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +57 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and me).

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 40 lines
Quoted 28 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +27 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 389

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

Quoted 7 lines
Quoted 7 lines

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

0x00)) {

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 54 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +54 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n",

__func__);

Quoted 24 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

Quoted 8 lines

- I don't thing so, If we make macro about this. then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;
Quoted 7 lines

#define drm_check_fmt(fmt) ((fmt & (DRM_FORMAT_XRGB8888 |
DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))

	Something;
else
	Something;

Again,

#define DRM_FORMAT_MASK (DRM_FORMAT_XRGB888 |
DRM_FORMAT_NV12)
#define drm_check_fmt(fmt) (((fmt & DRM_FORMAT_MASK) &
(DRM_FORMAT_XRGB8888 | \

DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))
Something;
else
Something;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side

rotation\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 43 lines
Quoted 35 lines
Quoted 19 lines
Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

Quoted 2 lines

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

What does each case do? Just check? If so, use macro as I mentioned. We can't accept this codes.

Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n",

__func__);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 607

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+

platform_get_device_id(pdev)->driver_data;

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start,

resource_size(res),

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line

+

dev_name(dev));

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL,

rotator_irq_handler,

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+					IRQF_ONESHOT, "drm_rotator",

rot);

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +25 -0
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator

device\n");

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed

successfully\n");

Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +132 -0
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend,

rotator_runtime_resume,

Quoted 102 lines
Quoted 102 lines
Quoted 18 lines
Quoted 1 line

+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +8 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +1 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +5 -0
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 50 lines
Quoted 50 lines

+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +48 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/regs-rotator.h

Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +8 -0
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) -

1))) &

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +3 -0
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +4 -1
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#11 lore raw

RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 98 lines

-----Original Message-----
From: Inki Dae [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 7:01 PM
To: 'Inki Dae'; 'Eunchul Kim'
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Inki Dae
Sent: Wednesday, December 12, 2012 6:42 PM
To: 'Eunchul Kim'
Cc: [email protected]; [email protected];

[email protected];

Quoted 61 lines

[email protected]; [email protected]; [email protected]
Subject: RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

Quoted 15 lines

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 7 lines · Inki Dae
Quoted 7 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected];

[email protected];

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be

same,

Quoted 19 lines

no

Quoted 18 lines
Quoted 18 lines

scaler)

---
  drivers/gpu/drm/exynos/Kconfig              |    7 +
  drivers/gpu/drm/exynos/Makefile             |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
  drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
  7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/exynos/Kconfig +0 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
  	depends on DRM_EXYNOS_IPP
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/Kconfig config DRM_EXYNOS_FIMC

Quoted 8 lines
drivers/gpu/drm/exynos/Kconfig +6 -0
  	help
  	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for

DRM.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/exynos/Kconfig +1 -0
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/Makefile +0 -0
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR) +=

exynos_drm_rotator.o

Quoted 94 lines
Quoted 71 lines
Quoted 71 lines
Quoted 62 lines
Quoted 62 lines
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
  		goto out_fimc;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_IPP
  	ret = platform_driver_register(&ipp_driver);
  	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
  out_ipp:
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
  	platform_driver_unregister(&ipp_driver);
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
  extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
  extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 8

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+ * it under the terms of the GNU General Public License version 2

as

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs +

(offset))

Quoted 259 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +49 -0
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool

enable)

Quoted 37 lines
Quoted 37 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 1 line
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work =

c_node->event_work;

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +16 -0
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt,

u32

Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +75 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) |

ROT_SRC_CROP_SIZE_W(pos->w);

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +16 -0
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 1 line
Quoted 78 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 69 lines
Quoted 69 lines
Quoted 57 lines
Quoted 57 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +57 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and

me).

Quoted 108 lines
Quoted 67 lines
Quoted 67 lines
Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 40 lines
Quoted 28 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +27 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 389

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

Quoted 7 lines
Quoted 7 lines

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

0x00)) {

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +22 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv

*ippdrv)

Quoted 91 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 24 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +24 -0
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n",

__func__);

Quoted 24 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

Quoted 8 lines

- I don't thing so, If we make macro about this. then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;
Quoted 7 lines

#define drm_check_fmt(fmt) ((fmt & (DRM_FORMAT_XRGB8888 |
DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))

	Something;
else
	Something;

Again,

#define DRM_FORMAT_MASK (DRM_FORMAT_XRGB888 |
DRM_FORMAT_NV12)
#define drm_check_fmt(fmt) (((fmt & DRM_FORMAT_MASK) &
(DRM_FORMAT_XRGB8888 | \

DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))

Review

Quoted 3 lines
(quoted diff) +0 -0
 	Something;
 else
 	Something;

Ah, these format types have no bit field base. Just use switch-case and make this code to one function. And then just call that function.

Quoted 408 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side

rotation\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 43 lines
Quoted 35 lines
Quoted 19 lines
Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

Quoted 2 lines

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

What does each case do? Just check? If so, use macro as I mentioned. We can't accept this codes.

Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n",

__func__);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 607

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+

platform_get_device_id(pdev)->driver_data;

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start,

resource_size(res),

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line

+

dev_name(dev));

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL,

rotator_irq_handler,

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+					IRQF_ONESHOT, "drm_rotator",

rot);

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +25 -0
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator

device\n");

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed

successfully\n");

Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +132 -0
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend,

rotator_runtime_resume,

Quoted 27 lines
Quoted 27 lines
Quoted 18 lines
Quoted 1 line

+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 6

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +1 -0
+ * it under the terms of the GNU General Public License version 2

as

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +7 -0
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +0 -1
new file mode 100644
index 0000000..a09ac6e
--- /dev/null
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/regs-rotator.h line 6

Quoted 8 lines

+++ b/drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/regs-rotator.h new file +6 -0
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface

(Rotator)

Quoted 81 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line

+ * it under the terms of the GNU General Public License version 2

as

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +48 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/regs-rotator.h

Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +8 -0
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) -

1))) &

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +3 -0
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +4 -1
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment

BR
Eunchul Kim

Quoted 550 lines · Inki Dae
Quoted 98 lines

-----Original Message-----
From: Inki Dae [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 7:01 PM
To: 'Inki Dae'; 'Eunchul Kim'
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Inki Dae
Sent: Wednesday, December 12, 2012 6:42 PM
To: 'Eunchul Kim'
Cc: [email protected]; [email protected];

[email protected];

Quoted 61 lines

[email protected]; [email protected]; [email protected]
Subject: RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

Quoted 15 lines

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 7 lines · Inki Dae
Quoted 7 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected];

[email protected];

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be

same,

Quoted 19 lines

no

Quoted 18 lines
Quoted 18 lines

scaler)

---
   drivers/gpu/drm/exynos/Kconfig              |    7 +
   drivers/gpu/drm/exynos/Makefile             |    1 +
   drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
   drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
   drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
   drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
   drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
   7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/exynos/Kconfig +0 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
   	depends on DRM_EXYNOS_IPP
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/Kconfig config DRM_EXYNOS_FIMC

Quoted 8 lines
drivers/gpu/drm/exynos/Kconfig +6 -0
   	help
   	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for

DRM.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/exynos/Kconfig +1 -0
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/Makefile +0 -0
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR) +=

exynos_drm_rotator.o

Quoted 94 lines
Quoted 71 lines
Quoted 71 lines
Quoted 62 lines
Quoted 62 lines
   obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
   		goto out_fimc;
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_IPP
   	ret = platform_driver_register(&ipp_driver);
   	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
   out_ipp:
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_FIMC
   	platform_driver_unregister(&fimc_driver);
   out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
   	platform_driver_unregister(&ipp_driver);
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_FIMC
   	platform_driver_unregister(&fimc_driver);
   #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
   extern struct platform_driver vidi_driver;
   extern struct platform_driver g2d_driver;
   extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
   extern struct platform_driver ipp_driver;
   #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 8

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+ * it under the terms of the GNU General Public License version 2

as

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs +

(offset))

Quoted 334 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +49 -0
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool

enable)

Quoted 37 lines
Quoted 37 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 1 line
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work =

c_node->event_work;

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +16 -0
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt,

u32

Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +75 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) |

ROT_SRC_CROP_SIZE_W(pos->w);

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +16 -0
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 66 lines
Quoted 66 lines
Quoted 65 lines
Quoted 53 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +53 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+		/* Rotation 0 Degree */
+		break;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

Quoted 12 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and

me).

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

- modified it.

Quoted 198 lines
Quoted 100 lines
Quoted 59 lines
Quoted 59 lines
Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 40 lines
Quoted 28 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +27 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 389

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

Quoted 7 lines
Quoted 7 lines

- done.

Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB]

==

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

0x00)) {

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize *

vsize;

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +22 -0
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv

*ippdrv)

Quoted 89 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 24 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +24 -0
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n",

__func__);

Quoted 24 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

Quoted 8 lines

- I don't thing so, If we make macro about this.
then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;
Quoted 7 lines

#define drm_check_fmt(fmt) ((fmt & (DRM_FORMAT_XRGB8888 |
DRM_FORMAT_NV12)) ? true : false)

if (drm_check_fmt(src_config->fmt))

	Something;
else
	Something;

Again,

#define DRM_FORMAT_MASK (DRM_FORMAT_XRGB888 |
DRM_FORMAT_NV12)
#define drm_check_fmt(fmt) (((fmt & DRM_FORMAT_MASK) &
(DRM_FORMAT_XRGB8888 | \

DRM_FORMAT_NV12)) ? true : false)

Quoted 8 lines
Quoted 5 lines

if (drm_check_fmt(src_config->fmt))
Something;
else
Something;

Ah, these format types have no bit field base. Just use switch-case and make this code to one function. And then just call that function.

- OK I make one function and used it.

Quoted 48 lines
Quoted 48 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side

rotation\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

What does each case do? Just check? If so, use macro as I mentioned. We can't accept this codes.

- ditto.

Quoted 449 lines
Quoted 357 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n",

__func__);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

Quoted 1 line

+

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 2 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+			DRM_DEBUG_KMS("%s:not support scale

feature\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

__func__);

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 607

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+

platform_get_device_id(pdev)->driver_data;

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +9 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start,

resource_size(res),

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line

+

dev_name(dev));

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL,

rotator_irq_handler,

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +1 -0
+					IRQF_ONESHOT, "drm_rotator",

rot);

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +25 -0
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator

device\n");

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed

successfully\n");

Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +132 -0
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend,

rotator_runtime_resume,

Quoted 27 lines
Quoted 27 lines
Quoted 18 lines
Quoted 1 line

+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 6

Quoted 1 line
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +1 -0
+ * it under the terms of the GNU General Public License version 2

as

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +7 -0
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +0 -1
new file mode 100644
index 0000000..a09ac6e
--- /dev/null
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/regs-rotator.h line 6

Quoted 8 lines

+++ b/drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/regs-rotator.h new file +6 -0
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface

(Rotator)

Quoted 81 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 1 line
Quoted 1 line

+ * it under the terms of the GNU General Public License version 2

as

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +48 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/regs-rotator.h

Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +8 -0
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) -

1))) &

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +3 -0
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +4 -1
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#13 lore raw

RE: [RFC v3 4/5] drm/exynos: add rotator ipp driver

In reply to Eunchul Kim

One more comment.

Quoted 164 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 11 lines · Inki Dae
Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 4 lines
Quoted 4 lines

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be same,

no

Quoted 107 lines
Quoted 107 lines

scaler)

---
  drivers/gpu/drm/exynos/Kconfig              |    7 +
  drivers/gpu/drm/exynos/Makefile             |    1 +
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
  drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
  drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
  7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
  	depends on DRM_EXYNOS_IPP
  	help
  	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
  obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
  		goto out_fimc;
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_IPP
  	ret = platform_driver_register(&ipp_driver);
  	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
  out_ipp:
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
  	platform_driver_unregister(&ipp_driver);
  #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
  #ifdef CONFIG_DRM_EXYNOS_FIMC
  	platform_driver_unregister(&fimc_driver);
  #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
  extern struct platform_driver g2d_driver;
  extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
  extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 338 lines
Quoted 80 lines
Quoted 80 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +74 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 134 lines
Quoted 134 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +99 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +65 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

Quoted 4 lines

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and me).

Ok, then what do the below codes mean?

	/* set transform for rotation, flip */
	if (ops->set_transf) {
		swap = ops->set_transf(ippdrv->dev, config->degree,
			config->flip);
		if (swap < 0) {
			DRM_ERROR("not support tranf.\n");
			return -EINVAL;
		}

If return value should be true or false then make sure error checking.

Quoted 650 lines
Quoted 5 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +31 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 264

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- done.

Quoted 98 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

Quoted 63 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +63 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 15 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +15 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n", __func__);
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

- I don't thing so, If we make macro about this. then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;
Quoted 25 lines
Quoted 14 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side rotation\n",
+								__func__);
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

Quoted 318 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n", __func__);
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

Quoted 53 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +41 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+				platform_get_device_id(pdev)->driver_data;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 622

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start, resource_size(res),
+

dev_name(dev));

Quoted 191 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +191 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL, rotator_irq_handler,
+					IRQF_ONESHOT, "drm_rotator", rot);
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator device\n");
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed successfully\n");
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 819

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +8 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +1 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +5 -0
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 70 lines
Quoted 68 lines

+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +56 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) - 1))) &

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +7 -1
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

#14 lore raw

Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's for your comment.

BR
Eunchul Kim.

Quoted 531 lines · Inki Dae

One more comment.

Quoted 164 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 6:26 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Joonyoung Shim
Subject: Re: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Thank's your comment.

I answer your comment. please check that.

Thank's

BR
Eunchul Kim

Quoted 11 lines · Inki Dae
Quoted 11 lines

-----Original Message-----
From: Eunchul Kim [mailto:[email protected]]
Sent: Wednesday, December 12, 2012 4:35 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC v3 4/5] drm/exynos: add rotator ipp driver

Quoted 4 lines
Quoted 4 lines

Rotator supports rotation/crop/flip and input/output DMA operations Rotator ipp driver supports 90,180,270 degree rotaion and vertical, horizontal flip.
and has some limitations(source and destination format have to be same,

no

Quoted 107 lines
Quoted 107 lines

scaler)

---
   drivers/gpu/drm/exynos/Kconfig              |    7 +
   drivers/gpu/drm/exynos/Makefile             |    1 +
   drivers/gpu/drm/exynos/exynos_drm_drv.c     |   15 +
   drivers/gpu/drm/exynos/exynos_drm_drv.h     |    1 +
   drivers/gpu/drm/exynos/exynos_drm_rotator.c |  829
+++++++++++++++++++++++++++
   drivers/gpu/drm/exynos/exynos_drm_rotator.h |   13 +
   drivers/gpu/drm/exynos/regs-rotator.h       |   73 +++
   7 files changed, 939 insertions(+), 0 deletions(-)

create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_rotator.h create mode 100644 drivers/gpu/drm/exynos/regs-rotator.h

drivers/gpu/drm/exynos/Kconfig +7 -0
index 4915ab6..4860835 100644
@@ -57,3 +57,10 @@ config DRM_EXYNOS_FIMC
   	depends on DRM_EXYNOS_IPP
   	help
   	  Choose this option if you want to use Exynos FIMC for DRM.
+
+config DRM_EXYNOS_ROTATOR
+	bool "Exynos DRM Rotator"
+	depends on DRM_EXYNOS_IPP
+	help
+	  Choose this option if you want to use Exynos Rotator for DRM.
+
drivers/gpu/drm/exynos/Makefile +0 -0
index 9710024..3b70668 100644
@@ -18,5 +18,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_VIDI)	+=

exynos_drm_vidi.o
exynosdrm-$(CONFIG_DRM_EXYNOS_G2D) += exynos_drm_g2d.o
exynosdrm-$(CONFIG_DRM_EXYNOS_IPP) += exynos_drm_ipp.o
exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC) += exynos_drm_fimc.o

drivers/gpu/drm/exynos/Makefile +1 -0
+exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
 
   obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 73f02ac..09d884b 100644
@@ -378,6 +378,12 @@ static int __init exynos_drm_init(void)
   		goto out_fimc;
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	ret = platform_driver_register(&rotator_driver);
+	if (ret < 0)
+		goto out_rotator;
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_IPP
   	ret = platform_driver_register(&ipp_driver);
   	if (ret < 0)
@@ -406,6 +412,11 @@ out_drm:
   out_ipp:
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+out_rotator:
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_FIMC
   	platform_driver_unregister(&fimc_driver);
   out_fimc:
@@ -451,6 +462,10 @@ static void __exit exynos_drm_exit(void)
   	platform_driver_unregister(&ipp_driver);
   #endif
 
+#ifdef CONFIG_DRM_EXYNOS_ROTATOR
+	platform_driver_unregister(&rotator_driver);
+#endif
+
   #ifdef CONFIG_DRM_EXYNOS_FIMC
   	platform_driver_unregister(&fimc_driver);
   #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index 14f9490..a74e37c 100644
@@ -353,5 +353,6 @@ extern struct platform_driver
 exynos_drm_common_hdmi_driver;
   extern struct platform_driver vidi_driver;
   extern struct platform_driver g2d_driver;
   extern struct platform_driver fimc_driver;
+extern struct platform_driver rotator_driver;
   extern struct platform_driver ipp_driver;
   #endif
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +0 -0
new file mode 100644
index 0000000..121569c
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 7

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
@@ -0,0 +1,829 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors:
+ *	YoungJun Cho <[email protected]>
+ *	Eunchul Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+#include <drm/drmP.h>
+#include <drm/exynos_drm.h>
+#include "regs-rotator.h"
+#include "exynos_drm.h"
+#include "exynos_drm_ipp.h"
+
+/*
+ * Rotator supports image crop/rotator and input/output DMA

operations.

Quoted 338 lines
Quoted 80 lines
Quoted 80 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+ * input DMA reads image data from the memory.
+ * output DMA writes image data to memory.
+ */
+
+#define get_rot_context(dev)

platform_get_drvdata(to_platform_device(dev))

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +74 -0
+#define get_ctx_from_ippdrv(ippdrv)	container_of(ippdrv,\
+					struct rot_context, ippdrv);
+#define rot_read(offset)		readl(rot->regs + (offset))
+#define rot_write(cfg, offset)	writel(cfg, rot->regs + (offset))
+
+enum rot_irq_status {
+	ROT_IRQ_STATUS_COMPLETE	= 8,
+	ROT_IRQ_STATUS_ILLEGAL	= 9,
+};
+
+/*
+ * A structure of limitation.
+ *
+ * @min_w: minimum width.
+ * @min_h: minimum height.
+ * @max_w: maximum width.
+ * @max_h: maximum height.
+ * @align: align size.
+ */
+struct rot_limit {
+	u32	min_w;
+	u32	min_h;
+	u32	max_w;
+	u32	max_h;
+	u32	align;
+};
+
+/*
+ * A structure of limitation table.
+ *
+ * @ycbcr420_2p: case of YUV.
+ * @rgb888: case of RGB.
+ */
+struct rot_limit_table {
+	struct rot_limit	ycbcr420_2p;
+	struct rot_limit	rgb888;
+};
+
+/*
+ * A structure of rotator context.
+ * @ippdrv: prepare initialization using ippdrv.
+ * @regs_res: register resources.
+ * @regs: memory mapped io registers.
+ * @clock: rotator gate clock.
+ * @limit_tbl: limitation of rotator.
+ * @irq: irq number.
+ * @cur_buf_id: current operation buffer id.
+ * @suspended: suspended state.
+ */
+struct rot_context {
+	struct exynos_drm_ippdrv	ippdrv;
+	struct resource	*regs_res;
+	void __iomem	*regs;
+	struct clk	*clock;
+	struct rot_limit_table	*limit_tbl;
+	int	irq;
+	int	cur_buf_id[EXYNOS_DRM_OPS_MAX];
+	bool	suspended;
+};
+
+static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
+{
+	u32 val = rot_read(ROT_CONFIG);
+
+	if (enable == true)
+		val |= ROT_CONFIG_IRQ;
+	else
+		val &= ~ROT_CONFIG_IRQ;
+
+	rot_write(val, ROT_CONFIG);
+}
+
+static u32 rotator_reg_get_format(struct rot_context *rot)
+{
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+	u32 val = rot_read(ROT_CONTROL);
+
+	val &= ROT_CONTROL_FMT_MASK;
+
+	return val;
+}
+
+static enum rot_irq_status rotator_reg_get_irq_status(struct

rot_context

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 123

Quoted 9 lines

*rot)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+{
+	u32 val = rot_read(ROT_STATUS);
+
+	val = ROT_STATUS_IRQ(val);
+
+	if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
+		return ROT_IRQ_STATUS_COMPLETE;
+	else

Remove else.

- done.

Quoted 134 lines
Quoted 134 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +33 -0
+		return ROT_IRQ_STATUS_ILLEGAL;
+}
+
+static irqreturn_t rotator_irq_handler(int irq, void *arg)
+{
+	struct rot_context *rot = arg;
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+	struct drm_exynos_ipp_cmd_node *c_node = ippdrv->cmd;
+	struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
+	enum rot_irq_status irq_status;
+	u32 val;
+
+	/* Get execution result */
+	irq_status = rotator_reg_get_irq_status(rot);
+
+	/* clear status */
+	val = rot_read(ROT_STATUS);
+	val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
+	rot_write(val, ROT_STATUS);
+
+	if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
+		event_work->ippdrv = ippdrv;
+		event_work->buf_id[EXYNOS_DRM_OPS_DST] =
+			rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
+		queue_work(ippdrv->event_workq,
+			(struct work_struct *)event_work);
+	} else
+		DRM_ERROR("the SFR is set illegally\n");
+
+	return IRQ_HANDLED;
+}
+
+static void rotator_align_size(struct rot_context *rot, u32 fmt, u32

*hsize,

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +99 -0
+		u32 *vsize)
+{
+	struct rot_limit_table *limit_tbl = rot->limit_tbl;
+	struct rot_limit *limit;
+	u32 mask, val;
+
+	/* Get size limit */
+	if (fmt == ROT_CONTROL_FMT_RGB888)
+		limit = &limit_tbl->rgb888;
+	else
+		limit = &limit_tbl->ycbcr420_2p;
+
+	/* Get mask for rounding to nearest aligned val */
+	mask = ~((1 << limit->align) - 1);
+
+	/* Set aligned width */
+	val = ROT_ALIGN(*hsize, limit->align, mask);
+	if (val < limit->min_w)
+		*hsize = ROT_MIN(limit->min_w, mask);
+	else if (val > limit->max_w)
+		*hsize = ROT_MAX(limit->max_w, mask);
+	else
+		*hsize = val;
+
+	/* Set aligned height */
+	val = ROT_ALIGN(*vsize, limit->align, mask);
+	if (val < limit->min_h)
+		*vsize = ROT_MIN(limit->min_h, mask);
+	else if (val > limit->max_h)
+		*vsize = ROT_MAX(limit->max_h, mask);
+	else
+		*vsize = val;
+}
+
+static int rotator_src_set_fmt(struct device *dev, u32 fmt)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FMT_MASK;
+
+	switch (fmt) {
+	case DRM_FORMAT_NV12:
+		val |= ROT_CONTROL_FMT_YCBCR420_2P;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		val |= ROT_CONTROL_FMT_RGB888;
+		break;
+	default:
+		DRM_ERROR("invalid image format\n");
+		return -EINVAL;
+	}
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int rotator_src_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 fmt, hsize, vsize;
+	u32 val;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_SRC_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_SRC_CROP_POS);
+	val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
+	rot_write(val, ROT_SRC_CROP_SIZE);
+
+	return 0;
+}
+
+static int rotator_src_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 261

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];

Check NULL.

- If not copy this state, we need to memset about addr. no need check null.

Quoted 11 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +7 -0
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

What is 0x00?

- It is NULL, I changed !addr instead of addr == 0x00

Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +65 -0
+
+			val = rot_read(ROT_SRC_BUF_SIZE);
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_SRC_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static int rotator_dst_set_transf(struct device *dev,
+		enum drm_exynos_degree degree,
+		enum drm_exynos_flip flip)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	/* Set transform configuration */
+	val = rot_read(ROT_CONTROL);
+	val &= ~ROT_CONTROL_FLIP_MASK;
+
+	switch (flip) {
+	case EXYNOS_DRM_FLIP_VERTICAL:
+		val |= ROT_CONTROL_FLIP_VERTICAL;
+		break;
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		val |= ROT_CONTROL_FLIP_HORIZONTAL;
+		break;
+	default:
+		/* Flip None */
+		break;
+	}
+
+	val &= ~ROT_CONTROL_ROT_MASK;
+
+	switch (degree) {
+	case EXYNOS_DRM_DEGREE_90:
+		val |= ROT_CONTROL_ROT_90;
+		break;
+	case EXYNOS_DRM_DEGREE_180:
+		val |= ROT_CONTROL_ROT_180;
+		break;
+	case EXYNOS_DRM_DEGREE_270:
+		val |= ROT_CONTROL_ROT_270;
+		break;
+	default:
+		/* Rotation 0 Degree */
+		break;
+	}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 339

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+	rot_write(val, ROT_CONTROL);
+
+	/* Check degree for setting buffer size swap */
+	if ((degree == EXYNOS_DRM_DEGREE_90) ||
+		(degree == EXYNOS_DRM_DEGREE_270))
+		return 1;

Correct return type. This function should return 0 or negative.

Quoted 4 lines

- no ~ this return type is boolean true or false.
but we need to error handling so, we use integer as you know we reviewed this routine at our local git from our team(you and me).

Ok, then what do the below codes mean?

	/* set transform for rotation, flip */
	if (ops->set_transf) {
		swap = ops->set_transf(ippdrv->dev, config->degree,
			config->flip);
		if (swap < 0) {
			DRM_ERROR("not support tranf.\n");
			return -EINVAL;
		}
Quoted 1 line

If return value should be true or false then make sure error checking.

- modified it. using pointer.

Quoted 653 lines
Quoted 651 lines
Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	else
+		return 0;

Ditto.

- ditto.

Quoted 14 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 352

Quoted 12 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +11 -0
+}
+
+static int rotator_dst_set_size(struct device *dev, int swap,
+		struct drm_exynos_pos *pos,
+		struct drm_exynos_sz *sz)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val, fmt, hsize, vsize;
+
+	/* Get format */
+	fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- added rotator_check_fmt()

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +31 -0
+
+	/* Align buffer size */
+	hsize = sz->hsize;
+	vsize = sz->vsize;
+	rotator_align_size(rot, fmt, &hsize, &vsize);
+
+	/* Set buffer size configuration */
+	val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
+	rot_write(val, ROT_DST_BUF_SIZE);
+
+	/* Set crop image position configuration */
+	val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
+	rot_write(val, ROT_DST_CROP_POS);
+
+	return 0;
+}
+
+static int rotator_dst_set_addr(struct device *dev,
+		struct drm_exynos_ipp_buf_info *buf_info,
+		u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
+	u32 val, fmt, hsize, vsize;
+	int i;
+
+	/* Set current buf_id */
+	rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
+
+	switch (buf_type) {
+	case IPP_BUF_ENQUEUE:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 264

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* Set address configuration */
+		for_each_ipp_planar(i)
+			addr[i] = buf_info->base[i];
+
+		/* Get format */
+		fmt = rotator_reg_get_format(rot);

Check if fmt is valid or not.

- done.

Quoted 98 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +4 -0
+
+		/* Re-set cb planar for NV12 format */
+		if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
+					(addr[EXYNOS_DRM_PLANAR_CB] ==

0x00)) {

Quoted 63 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +63 -0
+			/* Get buf size */
+			val = rot_read(ROT_DST_BUF_SIZE);
+
+			hsize = ROT_GET_BUF_SIZE_W(val);
+			vsize = ROT_GET_BUF_SIZE_H(val);
+
+			/* Set cb planar */
+			addr[EXYNOS_DRM_PLANAR_CB] =
+				addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
+		}
+
+		for_each_ipp_planar(i)
+			rot_write(addr[i], ROT_DST_BUF_ADDR(i));
+		break;
+	case IPP_BUF_DEQUEUE:
+		for_each_ipp_planar(i)
+			rot_write(0x0, ROT_DST_BUF_ADDR(i));
+		break;
+	default:
+		/* Nothing to do */
+		break;
+	}
+
+	return 0;
+}
+
+static struct exynos_drm_ipp_ops rot_src_ops = {
+	.set_fmt	=	rotator_src_set_fmt,
+	.set_size	=	rotator_src_set_size,
+	.set_addr	=	rotator_src_set_addr,
+};
+
+static struct exynos_drm_ipp_ops rot_dst_ops = {
+	.set_transf	=	rotator_dst_set_transf,
+	.set_size	=	rotator_dst_set_size,
+	.set_addr	=	rotator_dst_set_addr,
+};
+
+static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
+{
+	struct drm_exynos_ipp_prop_list *prop_list;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	prop_list = kzalloc(sizeof(*prop_list), GFP_KERNEL);
+	if (!prop_list) {
+		DRM_ERROR("failed to alloc property list.\n");
+		return -ENOMEM;
+	}
+
+	/*ToDo fix support function list*/
+
+	prop_list->version = 1;
+	prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
+				(1 << EXYNOS_DRM_FLIP_HORIZONTAL);
+	prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
+				(1 << EXYNOS_DRM_DEGREE_90) |
+				(1 << EXYNOS_DRM_DEGREE_180) |
+				(1 << EXYNOS_DRM_DEGREE_270);
+	prop_list->csc = 0;
+	prop_list->crop = 0;
+	prop_list->scale = 0;
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	ippdrv->prop_list = prop_list;
+
+	return 0;
+}
+
+static int rotator_ippdrv_check_property(struct device *dev,
+		struct drm_exynos_ipp_property *property)
+{
+	struct drm_exynos_ipp_config *src_config =
+

&property->config[EXYNOS_DRM_OPS_SRC];

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 474

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +2 -0
+	struct drm_exynos_ipp_config *dst_config =
+

&property->config[EXYNOS_DRM_OPS_DST];

Quoted 15 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +15 -0
+	struct drm_exynos_pos *src_pos = &src_config->pos;
+	struct drm_exynos_pos *dst_pos = &dst_config->pos;
+	struct drm_exynos_sz *src_sz = &src_config->sz;
+	struct drm_exynos_sz *dst_sz = &dst_config->sz;
+	bool swap = false;
+
+	/* Check format configuration */
+	if (src_config->fmt != dst_config->fmt) {
+		DRM_DEBUG_KMS("%s:not support csc feature\n", __func__);
+		return -EINVAL;
+	}
+
+	switch (src_config->fmt) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_NV12:
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 489

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +6 -0
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:not support format\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only format type.

- I don't thing so, If we make macro about this.
then we got some confusion about this macro at next change. this case switch-case is better.
Do you prefer this ? please one more comment.

#define drm_check_fmt(fmt) if (fmt == DRM_FORMAT_XRGB8888 || fmt ==

DRM_FORMAT_NV12) \
					return true;
Quoted 25 lines
Quoted 14 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+
+	/* Check transform configuration */
+	if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
+		DRM_DEBUG_KMS("%s:not support source-side rotation\n",
+								__func__);
+		return -EINVAL;
+	}
+
+	switch (dst_config->degree) {
+	case EXYNOS_DRM_DEGREE_90:
+	case EXYNOS_DRM_DEGREE_270:
+		swap = true;
+	case EXYNOS_DRM_DEGREE_0:

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	case EXYNOS_DRM_DEGREE_180:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid degree\n", __func__);
+		return -EINVAL;
+	}
+
+	if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
+		DRM_DEBUG_KMS("%s:not support source-side flip\n",

__func__);

Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 525

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +13 -0
+		return -EINVAL;
+	}
+
+	switch (dst_config->flip) {
+	case EXYNOS_DRM_FLIP_NONE:
+	case EXYNOS_DRM_FLIP_VERTICAL:
+	case EXYNOS_DRM_FLIP_HORIZONTAL:
+		/* No problem */
+		break;
+	default:
+		DRM_DEBUG_KMS("%s:invalid flip\n", __func__);
+		return -EINVAL;
+	}

Use macro instead of switch-case. this just checks only flip type.

- ditto. please one more comment.
in my opinion: I prefer enumeration use switch-case.

Quoted 318 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+
+	/* Check size configuration */
+	if ((src_pos->x + src_pos->w > src_sz->hsize) ||
+		(src_pos->y + src_pos->h > src_sz->vsize)) {
+		DRM_DEBUG_KMS("%s:out of source buffer bound\n", __func__);
+		return -EINVAL;
+	}
+
+	if (swap) {
+		if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
+			(dst_pos->y + dst_pos->w > dst_sz->hsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->h) || (src_pos->h !=

dst_pos->w))

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 9 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +8 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	} else {
+		if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
+			(dst_pos->y + dst_pos->h > dst_sz->vsize)) {
+			DRM_DEBUG_KMS("%s:out of destination buffer

bound\n",

drivers/gpu/drm/exynos/exynos_drm_rotator.c

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +5 -0
+								__func__);
+			return -EINVAL;
+		}
+
+		if ((src_pos->w != dst_pos->w) || (src_pos->h !=

dst_pos->h))

Quoted 53 lines

{

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+			DRM_DEBUG_KMS("%s:not support scale feature\n",
+								__func__);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int rotator_ippdrv_start(struct device *dev, enum

drm_exynos_ipp_cmd cmd)

drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +41 -0
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+	u32 val;
+
+	if (rot->suspended) {
+		DRM_ERROR("suspended state\n");
+		return -EPERM;
+	}
+
+	if (cmd != IPP_CMD_M2M) {
+		DRM_ERROR("not support cmd: %d\n", cmd);
+		return -EINVAL;
+	}
+
+	/* Set interrupt enable */
+	rotator_reg_set_irq(rot, true);
+
+	val = rot_read(ROT_CONTROL);
+	val |= ROT_CONTROL_START;
+
+	rot_write(val, ROT_CONTROL);
+
+	return 0;
+}
+
+static int __devinit rotator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot;
+	struct resource *res;
+	struct exynos_drm_ippdrv *ippdrv;
+	int ret;
+
+	rot = kzalloc(sizeof(*rot), GFP_KERNEL);
+	if (!rot) {
+		dev_err(dev, "failed to allocate rot\n");
+		return -ENOMEM;
+	}
+
+	rot->limit_tbl = (struct rot_limit_table *)
+				platform_get_device_id(pdev)->driver_data;

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 622

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs_res = request_mem_region(res->start, resource_size(res),
+

dev_name(dev));

Quoted 191 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +191 -0
+	if (!rot->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_get_resource;
+	}
+
+	rot->regs = ioremap(res->start, resource_size(res));
+	if (!rot->regs) {
+		dev_err(dev, "failed to map register\n");
+		ret = -ENXIO;
+		goto err_ioremap;
+	}
+
+	rot->irq = platform_get_irq(pdev, 0);
+	if (rot->irq < 0) {
+		dev_err(dev, "failed to get irq\n");
+		ret = rot->irq;
+		goto err_get_irq;
+	}
+
+	ret = request_threaded_irq(rot->irq, NULL, rotator_irq_handler,
+					IRQF_ONESHOT, "drm_rotator", rot);
+	if (ret < 0) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_get_irq;
+	}
+
+	rot->clock = clk_get(dev, "rotator");
+	if (IS_ERR_OR_NULL(rot->clock)) {
+		dev_err(dev, "failed to get clock\n");
+		ret = PTR_ERR(rot->clock);
+		goto err_clk_get;
+	}
+
+	pm_runtime_enable(dev);
+
+	ippdrv = &rot->ippdrv;
+	ippdrv->dev = dev;
+	ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
+	ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
+	ippdrv->check_property = rotator_ippdrv_check_property;
+	ippdrv->start = rotator_ippdrv_start;
+	ret = rotator_init_prop_list(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to init property list.\n");
+		goto err_ippdrv_register;
+	}
+
+	DRM_DEBUG_KMS("%s:ippdrv[0x%x]\n", __func__, (int)ippdrv);
+
+	platform_set_drvdata(pdev, rot);
+
+	ret = exynos_drm_ippdrv_register(ippdrv);
+	if (ret < 0) {
+		dev_err(dev, "failed to register drm rotator device\n");
+		kfree(ippdrv->prop_list);
+		goto err_ippdrv_register;
+	}
+
+	dev_info(dev, "The exynos rotator is probed successfully\n");
+
+	return 0;
+
+err_ippdrv_register:
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+err_clk_get:
+	free_irq(rot->irq, rot);
+err_get_irq:
+	iounmap(rot->regs);
+err_ioremap:
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+err_get_resource:
+	kfree(rot);
+	return ret;
+}
+
+static int __devexit rotator_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rot_context *rot = dev_get_drvdata(dev);
+	struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
+
+	kfree(ippdrv->prop_list);
+	exynos_drm_ippdrv_unregister(ippdrv);
+
+	pm_runtime_disable(dev);
+	clk_put(rot->clock);
+
+	free_irq(rot->irq, rot);
+
+	iounmap(rot->regs);
+
+	release_resource(rot->regs_res);
+	kfree(rot->regs_res);
+
+	kfree(rot);
+
+	return 0;
+}
+
+struct rot_limit_table rot_limit_tbl = {
+	.ycbcr420_2p = {
+		.min_w = 32,
+		.min_h = 32,
+		.max_w = SZ_32K,
+		.max_h = SZ_32K,
+		.align = 3,
+	},
+	.rgb888 = {
+		.min_w = 8,
+		.min_h = 8,
+		.max_w = SZ_8K,
+		.max_h = SZ_8K,
+		.align = 2,
+	},
+};
+
+struct platform_device_id rotator_driver_ids[] = {
+	{
+		.name		= "exynos-rot",
+		.driver_data	= (unsigned long)&rot_limit_tbl,
+	},
+	{},
+};
+
+static int rotator_clk_crtl(struct rot_context *rot, bool enable)
+{
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (enable) {
+		clk_enable(rot->clock);
+		rot->suspended = false;
+	} else {
+		clk_disable(rot->clock);
+		rot->suspended = true;
+	}
+
+	return 0;
+}
+
+
+#ifdef CONFIG_PM_SLEEP
+static int rotator_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	return rotator_clk_crtl(rot, false);
+}
+
+static int rotator_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	if (!pm_runtime_suspended(dev))
+		return rotator_clk_crtl(rot, true);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PM_RUNTIME
+static int rotator_runtime_suspend(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, false);
+}
+
+static int rotator_runtime_resume(struct device *dev)
+{
+	struct rot_context *rot = dev_get_drvdata(dev);
+
+	/* ToDo */
+

drivers/gpu/drm/exynos/exynos_drm_rotator.c line 819

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +10 -0
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	return  rotator_clk_crtl(rot, true);
+}
+#endif
+
+static const struct dev_pm_ops rotator_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
+	SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
+

NULL)

Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c new file +12 -0
+};
+
+struct platform_driver rotator_driver = {
+	.probe		= rotator_probe,
+	.remove		= __devexit_p(rotator_remove),
+	.id_table	= rotator_driver_ids,
+	.driver		= {
+		.name	= "exynos-rot",
+		.owner	= THIS_MODULE,
+		.pm	= &rotator_pm_ops,
+	},
+};
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +0 -0
new file mode 100644
index 0000000..fe929c9
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_rotator.h line 5

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +5 -0
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ * Authors: YoungJun Cho <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.h new file +8 -0
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef	_EXYNOS_DRM_ROTATOR_H_
+#define	_EXYNOS_DRM_ROTATOR_H_
+
+#endif
drivers/gpu/drm/exynos/regs-rotator.h new file +1 -0
new file mode 100644
index 0000000..a09ac6e
@@ -0,0 +1,73 @@
+/* drivers/gpu/drm/exynos/regs-rotator.h
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/exynos/regs-rotator.h new file +5 -0
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com/
+ *
+ * Register definition file for Samsung Rotator Interface (Rotator)

driver
+ *
+ * This program is free software; you can redistribute it and/or

modify

Quoted 70 lines
Quoted 68 lines

+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/gpu/drm/exynos/regs-rotator.h new file +56 -0
+*/
+
+#ifndef EXYNOS_REGS_ROTATOR_H
+#define EXYNOS_REGS_ROTATOR_H
+
+/* Configuration */
+#define ROT_CONFIG			0x00
+#define ROT_CONFIG_IRQ			(3 << 8)
+
+/* Image Control */
+#define ROT_CONTROL			0x10
+#define ROT_CONTROL_PATTERN_WRITE	(1 << 16)
+#define ROT_CONTROL_FMT_YCBCR420_2P	(1 << 8)
+#define ROT_CONTROL_FMT_RGB888		(6 << 8)
+#define ROT_CONTROL_FMT_MASK		(7 << 8)
+#define ROT_CONTROL_FLIP_VERTICAL	(2 << 6)
+#define ROT_CONTROL_FLIP_HORIZONTAL	(3 << 6)
+#define ROT_CONTROL_FLIP_MASK		(3 << 6)
+#define ROT_CONTROL_ROT_90		(1 << 4)
+#define ROT_CONTROL_ROT_180		(2 << 4)
+#define ROT_CONTROL_ROT_270		(3 << 4)
+#define ROT_CONTROL_ROT_MASK		(3 << 4)
+#define ROT_CONTROL_START		(1 << 0)
+
+/* Status */
+#define ROT_STATUS			0x20
+#define ROT_STATUS_IRQ_PENDING(x)	(1 << (x))
+#define ROT_STATUS_IRQ(x)		(((x) >> 8) & 0x3)
+#define ROT_STATUS_IRQ_VAL_COMPLETE	1
+#define ROT_STATUS_IRQ_VAL_ILLEGAL	2
+
+/* Buffer Address */
+#define ROT_SRC_BUF_ADDR(n)		(0x30 + ((n) << 2))
+#define ROT_DST_BUF_ADDR(n)		(0x50 + ((n) << 2))
+
+/* Buffer Size */
+#define ROT_SRC_BUF_SIZE		0x3c
+#define ROT_DST_BUF_SIZE		0x5c
+#define ROT_SET_BUF_SIZE_H(x)		((x) << 16)
+#define ROT_SET_BUF_SIZE_W(x)		((x) << 0)
+#define ROT_GET_BUF_SIZE_H(x)		((x) >> 16)
+#define ROT_GET_BUF_SIZE_W(x)		((x) & 0xffff)
+
+/* Crop Position */
+#define ROT_SRC_CROP_POS		0x40
+#define ROT_DST_CROP_POS		0x60
+#define ROT_CROP_POS_Y(x)		((x) << 16)
+#define ROT_CROP_POS_X(x)		((x) << 0)
+
+/* Source Crop Size */
+#define ROT_SRC_CROP_SIZE		0x44
+#define ROT_SRC_CROP_SIZE_H(x)		((x) << 16)
+#define ROT_SRC_CROP_SIZE_W(x)		((x) << 0)
+
+/* Round to nearest aligned value */
+#define ROT_ALIGN(x, align, mask)	(((x) + (1 << ((align) - 1))) &

(mask))

drivers/gpu/drm/exynos/regs-rotator.h new file +7 -1
+/* Minimum limit value */
+#define ROT_MIN(min, mask)		(((min) + ~(mask)) & (mask))
+/* Maximum limit value */
+#define ROT_MAX(max, mask)		((max) & (mask))
+
+#endif /* EXYNOS_REGS_ROTATOR_H */
+
--

1.7.0.4

#15 lore raw

RFC v3 5/5 drm/exynos: add gsc ipp driver

In reply to Eunchul Kim

GSC is stand for General SCaler and supports supports image scaler/rotator/crop/flip/csc and input/output DMA operations. input DMA reads image data from the memory.
output DMA writes image data to memory.
GSC supports image rotation and imag effect functions. also supports writeback and display output operations.

---
 drivers/gpu/drm/exynos/Kconfig          |    5 +
 drivers/gpu/drm/exynos/Makefile         |    1 +
 drivers/gpu/drm/exynos/exynos_drm_drv.c |   15 +
 drivers/gpu/drm/exynos/exynos_drm_drv.h |    1 +
 drivers/gpu/drm/exynos/exynos_drm_gsc.c | 1927 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_gsc.h |   34 +
 drivers/gpu/drm/exynos/regs-gsc.h       |  295 +++++
 7 files changed, 2278 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_gsc.c
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_gsc.h
 create mode 100644 drivers/gpu/drm/exynos/regs-gsc.h
drivers/gpu/drm/exynos/Kconfig +5 -0
index 4860835..c93d776 100644
@@ -64,3 +64,8 @@ config DRM_EXYNOS_ROTATOR
 	help
 	  Choose this option if you want to use Exynos Rotator for DRM.
 
+config DRM_EXYNOS_GSC
+	bool "Exynos DRM GSC"
+	depends on DRM_EXYNOS_IPP && ARCH_EXYNOS5
+	help
+	  Choose this option if you want to use Exynos GSC for DRM.
drivers/gpu/drm/exynos/Makefile +1 -0
index 3b70668..639b49e 100644
@@ -19,5 +19,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_G2D)	+= exynos_drm_g2d.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_IPP)	+= exynos_drm_ipp.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_FIMC)	+= exynos_drm_fimc.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)	+= exynos_drm_rotator.o
+exynosdrm-$(CONFIG_DRM_EXYNOS_GSC)	+= exynos_drm_gsc.o
 
 obj-$(CONFIG_DRM_EXYNOS)		+= exynosdrm.o
drivers/gpu/drm/exynos/exynos_drm_drv.c +15 -0
index 09d884b..e0a8e80 100644
@@ -384,6 +384,12 @@ static int __init exynos_drm_init(void)
 		goto out_rotator;
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_GSC
+	ret = platform_driver_register(&gsc_driver);
+	if (ret < 0)
+		goto out_gsc;
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_IPP
 	ret = platform_driver_register(&ipp_driver);
 	if (ret < 0)
@@ -412,6 +418,11 @@ out_drm:
 out_ipp:
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_GSC
+	platform_driver_unregister(&gsc_driver);
+out_gsc:
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
 	platform_driver_unregister(&rotator_driver);
 out_rotator:
@@ -462,6 +473,10 @@ static void __exit exynos_drm_exit(void)
 	platform_driver_unregister(&ipp_driver);
 #endif
 
+#ifdef CONFIG_DRM_EXYNOS_GSC
+	platform_driver_unregister(&gsc_driver);
+#endif
+
 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
 	platform_driver_unregister(&rotator_driver);
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -0
index a74e37c..afe556c 100644
@@ -354,5 +354,6 @@ extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
 extern struct platform_driver fimc_driver;
 extern struct platform_driver rotator_driver;
+extern struct platform_driver gsc_driver;
 extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_gsc.c new file +1927 -0

1,927 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_gsc.h new file +34 -0
new file mode 100644
index 0000000..b3ef7a0
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Eunchul Kim <[email protected]>
+ *	Jinyoung Jeon <[email protected]>
+ *	Sangmin Lee <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _EXYNOS_DRM_GSC_H_
+#define _EXYNOS_DRM_GSC_H_
+
+/* ToDo */
+
+#endif /* _EXYNOS_DRM_GSC_H_ */
drivers/gpu/drm/exynos/regs-gsc.h new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
1.7.0.4